@@ -208,7 +208,7 @@ func TestConfigMapUnpacker(t *testing.T) {
208
208
ObjectMeta : metav1.ObjectMeta {
209
209
Name : pathHash ,
210
210
Namespace : "ns-a" ,
211
- Labels : map [string ]string {install .OLMManagedLabelKey : install .OLMManagedLabelValue },
211
+ Labels : map [string ]string {install .OLMManagedLabelKey : install .OLMManagedLabelValue , bundleUnpackRefLabel : pathHash },
212
212
OwnerReferences : []metav1.OwnerReference {
213
213
{
214
214
APIVersion : "v1" ,
@@ -1839,3 +1839,115 @@ func TestOperatorGroupBundleUnpackTimeout(t *testing.T) {
1839
1839
})
1840
1840
}
1841
1841
}
1842
+
1843
+ func TestOperatorGroupBundleUnpackRetryInterval (t * testing.T ) {
1844
+ nsName := "fake-ns"
1845
+
1846
+ for _ , tc := range []struct {
1847
+ name string
1848
+ operatorGroups []* operatorsv1.OperatorGroup
1849
+ expectedTimeout time.Duration
1850
+ expectedError error
1851
+ }{
1852
+ {
1853
+ name : "No operator groups exist" ,
1854
+ expectedTimeout : 0 ,
1855
+ expectedError : errors .New ("found 0 operatorGroups, expected 1" ),
1856
+ },
1857
+ {
1858
+ name : "Multiple operator groups exist" ,
1859
+ operatorGroups : []* operatorsv1.OperatorGroup {
1860
+ {
1861
+ TypeMeta : metav1.TypeMeta {
1862
+ Kind : operatorsv1 .OperatorGroupKind ,
1863
+ APIVersion : operatorsv1 .GroupVersion .String (),
1864
+ },
1865
+ ObjectMeta : metav1.ObjectMeta {
1866
+ Name : "og1" ,
1867
+ Namespace : nsName ,
1868
+ },
1869
+ },
1870
+ {
1871
+ TypeMeta : metav1.TypeMeta {
1872
+ Kind : operatorsv1 .OperatorGroupKind ,
1873
+ APIVersion : operatorsv1 .GroupVersion .String (),
1874
+ },
1875
+ ObjectMeta : metav1.ObjectMeta {
1876
+ Name : "og2" ,
1877
+ Namespace : nsName ,
1878
+ },
1879
+ },
1880
+ },
1881
+ expectedTimeout : 0 ,
1882
+ expectedError : errors .New ("found 2 operatorGroups, expected 1" ),
1883
+ },
1884
+ {
1885
+ name : "One operator group exists with valid unpack retry annotation" ,
1886
+ operatorGroups : []* operatorsv1.OperatorGroup {
1887
+ {
1888
+ TypeMeta : metav1.TypeMeta {
1889
+ Kind : operatorsv1 .OperatorGroupKind ,
1890
+ APIVersion : operatorsv1 .GroupVersion .String (),
1891
+ },
1892
+ ObjectMeta : metav1.ObjectMeta {
1893
+ Name : "og" ,
1894
+ Namespace : nsName ,
1895
+ Annotations : map [string ]string {BundleUnpackRetryMinimumIntervalAnnotationKey : "1m" },
1896
+ },
1897
+ },
1898
+ },
1899
+ expectedTimeout : 1 * time .Minute ,
1900
+ expectedError : nil ,
1901
+ },
1902
+ {
1903
+ name : "One operator group exists with no unpack retry annotation" ,
1904
+ operatorGroups : []* operatorsv1.OperatorGroup {
1905
+ {
1906
+ TypeMeta : metav1.TypeMeta {
1907
+ Kind : operatorsv1 .OperatorGroupKind ,
1908
+ APIVersion : operatorsv1 .GroupVersion .String (),
1909
+ },
1910
+ ObjectMeta : metav1.ObjectMeta {
1911
+ Name : "og" ,
1912
+ Namespace : nsName ,
1913
+ },
1914
+ },
1915
+ },
1916
+ expectedTimeout : 0 ,
1917
+ expectedError : nil ,
1918
+ },
1919
+ {
1920
+ name : "One operator group exists with invalid unpack retry annotation" ,
1921
+ operatorGroups : []* operatorsv1.OperatorGroup {
1922
+ {
1923
+ TypeMeta : metav1.TypeMeta {
1924
+ Kind : operatorsv1 .OperatorGroupKind ,
1925
+ APIVersion : operatorsv1 .GroupVersion .String (),
1926
+ },
1927
+ ObjectMeta : metav1.ObjectMeta {
1928
+ Name : "og" ,
1929
+ Namespace : nsName ,
1930
+ Annotations : map [string ]string {BundleUnpackRetryMinimumIntervalAnnotationKey : "invalid" },
1931
+ },
1932
+ },
1933
+ },
1934
+ expectedTimeout : 0 ,
1935
+ expectedError : fmt .Errorf ("failed to parse unpack retry annotation(operatorframework.io/bundle-unpack-min-retry-interval: invalid): %w" , errors .New ("time: invalid duration \" invalid\" " )),
1936
+ },
1937
+ } {
1938
+ t .Run (tc .name , func (t * testing.T ) {
1939
+ ogIndexer := cache .NewIndexer (cache .MetaNamespaceKeyFunc , cache.Indexers {})
1940
+ ogLister := v1listers .NewOperatorGroupLister (ogIndexer ).OperatorGroups (nsName )
1941
+
1942
+ for _ , og := range tc .operatorGroups {
1943
+ err := ogIndexer .Add (og )
1944
+ assert .NoError (t , err )
1945
+ }
1946
+
1947
+ timeout , err := OperatorGroupBundleUnpackRetryInterval (ogLister )
1948
+
1949
+ assert .Equal (t , tc .expectedTimeout , timeout )
1950
+ assert .Equal (t , tc .expectedError , err )
1951
+ })
1952
+ }
1953
+ }
0 commit comments