Skip to content

Commit 8c3a7b9

Browse files
committed
unpack retry e2e tests
Signed-off-by: Ankita Thomas <[email protected]> Upstream-repository: operator-lifecycle-manager Upstream-commit: 218a6bb495152b89bd84286b051190b3e58e2b00
1 parent d1619eb commit 8c3a7b9

File tree

9 files changed

+361
-18
lines changed

9 files changed

+361
-18
lines changed

staging/operator-lifecycle-manager/pkg/controller/bundle/bundle_unpacker.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"k8s.io/apimachinery/pkg/api/resource"
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020
k8slabels "k8s.io/apimachinery/pkg/labels"
21+
"k8s.io/apiserver/pkg/storage/names"
2122
"k8s.io/client-go/kubernetes"
2223
listersbatchv1 "k8s.io/client-go/listers/batch/v1"
2324
listerscorev1 "k8s.io/client-go/listers/core/v1"
@@ -93,6 +94,12 @@ func newBundleUnpackResult(lookup *operatorsv1alpha1.BundleLookup) *BundleUnpack
9394

9495
func (c *ConfigMapUnpacker) job(cmRef *corev1.ObjectReference, bundlePath string, secrets []corev1.LocalObjectReference, annotationUnpackTimeout time.Duration) *batchv1.Job {
9596
job := &batchv1.Job{
97+
ObjectMeta: metav1.ObjectMeta{
98+
Labels: map[string]string{
99+
install.OLMManagedLabelKey: install.OLMManagedLabelValue,
100+
bundleUnpackRefLabel: cmRef.Name,
101+
},
102+
},
96103
Spec: batchv1.JobSpec{
97104
//ttlSecondsAfterFinished: 0 // can use in the future to not have to clean up job
98105
Template: corev1.PodTemplateSpec{
@@ -246,7 +253,6 @@ func (c *ConfigMapUnpacker) job(cmRef *corev1.ObjectReference, bundlePath string
246253
}
247254
job.SetNamespace(cmRef.Namespace)
248255
job.SetName(cmRef.Name)
249-
job.SetLabels(map[string]string{bundleUnpackRefLabel: cmRef.Name})
250256
job.SetOwnerReferences([]metav1.OwnerReference{ownerRef(cmRef)})
251257
if c.runAsUser > 0 {
252258
job.Spec.Template.Spec.SecurityContext.RunAsUser = &c.runAsUser
@@ -687,10 +693,10 @@ func (c *ConfigMapUnpacker) ensureJob(cmRef *corev1.ObjectReference, bundlePath
687693

688694
if failed {
689695
if time.Now().After(lastFailureTime.Add(unpackRetryInterval)) {
690-
fresh.SetName(fmt.Sprintf("%s-%d", fresh.GetName(), len(jobs)))
696+
fresh.SetName(names.SimpleNameGenerator.GenerateName(fresh.GetName()))
691697
job, err = c.client.BatchV1().Jobs(fresh.GetNamespace()).Create(context.TODO(), fresh, metav1.CreateOptions{})
692-
return
693698
}
699+
return
694700
}
695701
}
696702
}
@@ -880,7 +886,7 @@ func OperatorGroupBundleUnpackRetryInterval(ogLister v1listers.OperatorGroupName
880886

881887
d, err := time.ParseDuration(timeoutStr)
882888
if err != nil {
883-
return 0, fmt.Errorf("failed to parse unpack timeout annotation(%s: %s): %w", BundleUnpackRetryMinimumIntervalAnnotationKey, timeoutStr, err)
889+
return 0, fmt.Errorf("failed to parse unpack retry annotation(%s: %s): %w", BundleUnpackRetryMinimumIntervalAnnotationKey, timeoutStr, err)
884890
}
885891

886892
return d, nil

staging/operator-lifecycle-manager/pkg/controller/bundle/bundle_unpacker_test.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func TestConfigMapUnpacker(t *testing.T) {
208208
ObjectMeta: metav1.ObjectMeta{
209209
Name: pathHash,
210210
Namespace: "ns-a",
211+
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue, bundleUnpackRefLabel: pathHash},
211212
OwnerReferences: []metav1.OwnerReference{
212213
{
213214
APIVersion: "v1",
@@ -1820,3 +1821,115 @@ func TestOperatorGroupBundleUnpackTimeout(t *testing.T) {
18201821
})
18211822
}
18221823
}
1824+
1825+
func TestOperatorGroupBundleUnpackRetryInterval(t *testing.T) {
1826+
nsName := "fake-ns"
1827+
1828+
for _, tc := range []struct {
1829+
name string
1830+
operatorGroups []*operatorsv1.OperatorGroup
1831+
expectedTimeout time.Duration
1832+
expectedError error
1833+
}{
1834+
{
1835+
name: "No operator groups exist",
1836+
expectedTimeout: 0,
1837+
expectedError: errors.New("found 0 operatorGroups, expected 1"),
1838+
},
1839+
{
1840+
name: "Multiple operator groups exist",
1841+
operatorGroups: []*operatorsv1.OperatorGroup{
1842+
{
1843+
TypeMeta: metav1.TypeMeta{
1844+
Kind: operatorsv1.OperatorGroupKind,
1845+
APIVersion: operatorsv1.GroupVersion.String(),
1846+
},
1847+
ObjectMeta: metav1.ObjectMeta{
1848+
Name: "og1",
1849+
Namespace: nsName,
1850+
},
1851+
},
1852+
{
1853+
TypeMeta: metav1.TypeMeta{
1854+
Kind: operatorsv1.OperatorGroupKind,
1855+
APIVersion: operatorsv1.GroupVersion.String(),
1856+
},
1857+
ObjectMeta: metav1.ObjectMeta{
1858+
Name: "og2",
1859+
Namespace: nsName,
1860+
},
1861+
},
1862+
},
1863+
expectedTimeout: 0,
1864+
expectedError: errors.New("found 2 operatorGroups, expected 1"),
1865+
},
1866+
{
1867+
name: "One operator group exists with valid unpack retry annotation",
1868+
operatorGroups: []*operatorsv1.OperatorGroup{
1869+
{
1870+
TypeMeta: metav1.TypeMeta{
1871+
Kind: operatorsv1.OperatorGroupKind,
1872+
APIVersion: operatorsv1.GroupVersion.String(),
1873+
},
1874+
ObjectMeta: metav1.ObjectMeta{
1875+
Name: "og",
1876+
Namespace: nsName,
1877+
Annotations: map[string]string{BundleUnpackRetryMinimumIntervalAnnotationKey: "1m"},
1878+
},
1879+
},
1880+
},
1881+
expectedTimeout: 1 * time.Minute,
1882+
expectedError: nil,
1883+
},
1884+
{
1885+
name: "One operator group exists with no 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+
},
1896+
},
1897+
},
1898+
expectedTimeout: 0,
1899+
expectedError: nil,
1900+
},
1901+
{
1902+
name: "One operator group exists with invalid unpack retry annotation",
1903+
operatorGroups: []*operatorsv1.OperatorGroup{
1904+
{
1905+
TypeMeta: metav1.TypeMeta{
1906+
Kind: operatorsv1.OperatorGroupKind,
1907+
APIVersion: operatorsv1.GroupVersion.String(),
1908+
},
1909+
ObjectMeta: metav1.ObjectMeta{
1910+
Name: "og",
1911+
Namespace: nsName,
1912+
Annotations: map[string]string{BundleUnpackRetryMinimumIntervalAnnotationKey: "invalid"},
1913+
},
1914+
},
1915+
},
1916+
expectedTimeout: 0,
1917+
expectedError: fmt.Errorf("failed to parse unpack retry annotation(operatorframework.io/bundle-unpack-min-retry-interval: invalid): %w", errors.New("time: invalid duration \"invalid\"")),
1918+
},
1919+
} {
1920+
t.Run(tc.name, func(t *testing.T) {
1921+
ogIndexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{})
1922+
ogLister := v1listers.NewOperatorGroupLister(ogIndexer).OperatorGroups(nsName)
1923+
1924+
for _, og := range tc.operatorGroups {
1925+
err := ogIndexer.Add(og)
1926+
assert.NoError(t, err)
1927+
}
1928+
1929+
timeout, err := OperatorGroupBundleUnpackRetryInterval(ogLister)
1930+
1931+
assert.Equal(t, tc.expectedTimeout, timeout)
1932+
assert.Equal(t, tc.expectedError, err)
1933+
})
1934+
}
1935+
}

staging/operator-lifecycle-manager/pkg/controller/bundle/bundlefakes/fake_unpacker.go

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/operator-lifecycle-manager/pkg/controller/operators/catalog/subscriptions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ func TestSyncSubscriptions(t *testing.T) {
11721172
defer cancel()
11731173

11741174
fakeBundleUnpacker := &bundlefakes.FakeUnpacker{
1175-
UnpackBundleStub: func(lookup *v1alpha1.BundleLookup, timeout time.Duration) (*bundle.BundleUnpackResult, error) {
1175+
UnpackBundleStub: func(lookup *v1alpha1.BundleLookup, timeout, retryInterval time.Duration) (*bundle.BundleUnpackResult, error) {
11761176
return &bundle.BundleUnpackResult{BundleLookup: lookup.DeepCopy()}, tt.fields.unpackBundleErr
11771177
},
11781178
}

staging/operator-lifecycle-manager/test/e2e/fbc_provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ func NewFileBasedFiledBasedCatalogProvider(path string) (FileBasedCatalogProvide
3131
func (f *fileBasedFileBasedCatalogProvider) GetCatalog() string {
3232
return f.fbc
3333
}
34+
35+
func NewRawFileBasedCatalogProvider(data string) (FileBasedCatalogProvider, error) {
36+
return &fileBasedFileBasedCatalogProvider{
37+
fbc: string(data),
38+
}, nil
39+
}

staging/operator-lifecycle-manager/test/e2e/registry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func createDockerRegistry(client operatorclient.ClientInterface, namespace strin
5454
Port: int32(5000),
5555
},
5656
},
57+
Type: corev1.ServiceTypeNodePort,
5758
},
5859
}
5960

0 commit comments

Comments
 (0)