Skip to content

Commit 6a9c7b3

Browse files
test-e2e/samples/cleanup: centralize code to integrate the project with OLM (#4144)
**Description of the change:** - Move the olm helpers in the `hack/generate/samples/internal/pkg/utils.go` to `internal/testutils/olm.go`. Reason: allow samples and tests to use the same helper and keep it in a more appropriate place. - Remove the duplicates calls made in the e2e tests which are already done in the samples in the e2e tests - Use the e2e test the helper instead of duplicate the code. **Motivation for the change:** - Maintainability - Reduce CI effort by not calling make bundle twice. - Centralize the steps to integrate the projects with OLM and keep samples and e2e tests using the same func - Reduce the duplication of code as of the calls made
1 parent 77f1b5e commit 6a9c7b3

File tree

11 files changed

+48
-50
lines changed

11 files changed

+48
-50
lines changed

hack/generate/samples/internal/ansible/memcached.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ func (ma *MemcachedAnsible) Run() {
7676
ma.addingAnsibleTask()
7777
ma.addingMoleculeMockData()
7878

79-
ma.ctx.CreateBundle()
79+
log.Infof("creating the bundle")
80+
err = ma.ctx.GenerateBundle()
81+
pkg.CheckError("creating the bundle", err)
82+
83+
log.Infof("striping bundle annotations")
84+
err = ma.ctx.StripBundleAnnotations()
85+
pkg.CheckError("striping bundle annotations", err)
8086
}
8187

8288
// addingMoleculeMockData will customize the molecule data

hack/generate/samples/internal/go/v2/memcached_with_webhooks.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ func (mh *MemcachedGoWithWebhooks) Run() {
9393
mh.implementingWebhooks()
9494
mh.uncommentKustomizationFile()
9595

96-
mh.ctx.CreateBundle()
96+
log.Infof("creating the bundle")
97+
err = mh.ctx.GenerateBundle()
98+
pkg.CheckError("creating the bundle", err)
99+
100+
log.Infof("striping bundle annotations")
101+
err = mh.ctx.StripBundleAnnotations()
102+
pkg.CheckError("striping bundle annotations", err)
97103

98104
pkg.CheckError("formatting project", mh.ctx.Make("fmt"))
99105

hack/generate/samples/internal/go/v3/memcached_with_webhooks.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,13 @@ func (mh *MemcachedGoWithWebhooks) Run() {
9494
mh.implementingWebhooks()
9595
mh.uncommentKustomizationFile()
9696

97-
mh.ctx.CreateBundle()
97+
log.Infof("creating the bundle")
98+
err = mh.ctx.GenerateBundle()
99+
pkg.CheckError("creating the bundle", err)
100+
101+
log.Infof("striping bundle annotations")
102+
err = mh.ctx.StripBundleAnnotations()
103+
pkg.CheckError("striping bundle annotations", err)
98104

99105
pkg.CheckError("formatting project", mh.ctx.Make("fmt"))
100106

hack/generate/samples/internal/helm/memcached.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ func (mh *MemcachedHelm) Run() {
9393
"# +kubebuilder:scaffold:rules", policyRolesFragment)
9494
pkg.CheckError("adding customized roles", err)
9595

96-
mh.ctx.CreateBundle()
96+
log.Infof("creating the bundle")
97+
err = mh.ctx.GenerateBundle()
98+
pkg.CheckError("creating the bundle", err)
99+
100+
log.Infof("striping bundle annotations")
101+
err = mh.ctx.StripBundleAnnotations()
102+
pkg.CheckError("striping bundle annotations", err)
97103
}
98104

99105
// GenerateMemcachedHelmSample will call all actions to create the directory and generate the sample

hack/generate/samples/internal/pkg/utils.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,6 @@ func CheckError(msg string, err error) {
3434
}
3535
}
3636

37-
// CreateBundle runs all commands to create an operator bundle.
38-
func (ctx *SampleContext) CreateBundle() {
39-
log.Infof("integrating project with OLM")
40-
err := ctx.DisableManifestsInteractiveMode()
41-
CheckError("disabling `generate kustomize manifests` interactive mode", err)
42-
43-
err = ctx.Make("bundle", "IMG="+ctx.ImageName)
44-
CheckError("running make bundle", err)
45-
46-
err = ctx.StripBundleAnnotations()
47-
CheckError("stripping bundle annotations", err)
48-
}
49-
5037
// StripBundleAnnotations removes all annotations applied to bundle manifests and metadata
5138
// by operator-sdk/internal/annotations/metrics annotators. Doing so decouples samples
5239
// from which operator-sdk version they were build with, as this information is already

internal/testutils/olm.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,16 @@ func (tc TestContext) DisableManifestsInteractiveMode() error {
8989
replace := content + " --interactive=false"
9090
return ReplaceInFile(filepath.Join(tc.Dir, "Makefile"), content, replace)
9191
}
92+
93+
// GenerateBundle runs all commands to create an operator bundle.
94+
func (tc TestContext) GenerateBundle() error {
95+
if err := tc.DisableManifestsInteractiveMode(); err != nil {
96+
return err
97+
}
98+
99+
if err := tc.Make("bundle", "IMG="+tc.ImageName); err != nil {
100+
return err
101+
}
102+
103+
return nil
104+
}

test/e2e-ansible/e2e_ansible_olm_test.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,10 @@ var _ = Describe("Integrating ansible Projects with OLM", func() {
2626
const operatorVersion = "0.0.1"
2727

2828
It("should generate and run a valid OLM bundle and packagemanifests", func() {
29-
By("building the bundle")
30-
err := tc.Make("bundle", "IMG="+tc.ImageName)
31-
Expect(err).NotTo(HaveOccurred())
32-
3329
By("building the operator bundle image")
34-
err = tc.Make("bundle-build", "BUNDLE_IMG="+tc.BundleImageName)
30+
err := tc.Make("bundle-build", "BUNDLE_IMG="+tc.BundleImageName)
3531
Expect(err).NotTo(HaveOccurred())
3632

37-
if tc.IsRunningOnKind() {
38-
By("loading the bundle image into Kind cluster")
39-
err = tc.LoadImageToKindClusterWithName(tc.BundleImageName)
40-
Expect(err).NotTo(HaveOccurred())
41-
}
42-
4333
By("adding the 'packagemanifests' rule to the Makefile")
4434
err = tc.AddPackagemanifestsTarget()
4535
Expect(err).NotTo(HaveOccurred())

test/e2e-ansible/e2e_ansible_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ var _ = BeforeSuite(func() {
121121
Expect(tc.LoadImageToKindClusterWithName("quay.io/operator-framework/scorecard-test:dev")).To(Succeed())
122122
}
123123

124-
By("building the bundle")
125-
err = tc.Make("bundle", "IMG="+tc.ImageName)
124+
By("creating bundle image")
125+
err = tc.GenerateBundle()
126126
Expect(err).NotTo(HaveOccurred())
127127
})
128128

test/e2e-go/e2e_go_suite_test.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,10 @@ var _ = BeforeSuite(func() {
8383
Expect(tc.LoadImageToKindClusterWithName("quay.io/operator-framework/custom-scorecard-tests:dev")).To(Succeed())
8484
}
8585

86-
By("generating the operator bundle")
87-
err = tc.Make("bundle", "IMG="+tc.ImageName)
86+
By("creating bundle image")
87+
err = tc.GenerateBundle()
8888
Expect(err).NotTo(HaveOccurred())
8989

90-
By("building the operator bundle image")
91-
err = tc.Make("bundle-build", "BUNDLE_IMG="+tc.BundleImageName)
92-
Expect(err).NotTo(HaveOccurred())
93-
94-
if tc.IsRunningOnKind() {
95-
By("loading the bundle image into Kind cluster")
96-
err = tc.LoadImageToKindClusterWithName(tc.BundleImageName)
97-
Expect(err).NotTo(HaveOccurred())
98-
}
99-
10090
By("installing cert manager bundle")
10191
Expect(tc.InstallCertManager(true)).To(Succeed())
10292
})

test/e2e-helm/e2e_helm_olm_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ var _ = Describe("Integrating Helm Projects with OLM", func() {
3030
err := tc.Make("bundle-build", "BUNDLE_IMG="+tc.BundleImageName)
3131
Expect(err).NotTo(HaveOccurred())
3232

33-
if tc.IsRunningOnKind() {
34-
By("loading the bundle image into Kind cluster")
35-
err = tc.LoadImageToKindClusterWithName(tc.BundleImageName)
36-
Expect(err).NotTo(HaveOccurred())
37-
}
38-
3933
By("adding the 'packagemanifests' rule to the Makefile")
4034
err = tc.AddPackagemanifestsTarget()
4135
Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)