diff --git a/changelog/fragments/enable-run-bundle-cmd.yaml b/changelog/fragments/enable-run-bundle-cmd.yaml new file mode 100644 index 0000000000..b59d19eee3 --- /dev/null +++ b/changelog/fragments/enable-run-bundle-cmd.yaml @@ -0,0 +1,4 @@ +entries: + - description: > + Enable `run bundle` command and include e2e tests. + kind: addition diff --git a/internal/cmd/operator-sdk/run/cmd.go b/internal/cmd/operator-sdk/run/cmd.go index 5fb87cda1b..e44c78f294 100644 --- a/internal/cmd/operator-sdk/run/cmd.go +++ b/internal/cmd/operator-sdk/run/cmd.go @@ -17,6 +17,7 @@ package run import ( "github.com/spf13/cobra" + "github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/run/bundle" "github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/run/packagemanifests" "github.com/operator-framework/operator-sdk/internal/olm/operator" ) @@ -34,7 +35,7 @@ Currently only the package manifests format is supported via the 'packagemanifes cmd.AddCommand( // TODO(joelanford): enable bundle command when implementation is complete - // bundle.NewCmd(cfg), + bundle.NewCmd(cfg), packagemanifests.NewCmd(cfg), ) diff --git a/internal/cmd/operator-sdk/run/cmd_test.go b/internal/cmd/operator-sdk/run/cmd_test.go index c7784db851..12981ff5b9 100644 --- a/internal/cmd/operator-sdk/run/cmd_test.go +++ b/internal/cmd/operator-sdk/run/cmd_test.go @@ -29,8 +29,7 @@ var _ = Describe("Running a run command", func() { Expect(cmd.Long).NotTo(BeNil()) subcommands := cmd.Commands() - Expect(len(subcommands)).To(Equal(1)) - Expect(subcommands[0].Use).To(Equal("packagemanifests [packagemanifests-root-dir]")) + Expect(len(subcommands)).To(Equal(2)) }) }) }) diff --git a/test/e2e-ansible/e2e_ansible_olm_test.go b/test/e2e-ansible/e2e_ansible_olm_test.go index 3678d21b6d..04de50c2fc 100644 --- a/test/e2e-ansible/e2e_ansible_olm_test.go +++ b/test/e2e-ansible/e2e_ansible_olm_test.go @@ -67,6 +67,17 @@ var _ = Describe("Integrating ansible Projects with OLM", func() { Expect(err).NotTo(HaveOccurred()) } + By("running the operator bundle using `run bundle` command") + runBundleCmd := exec.Command(tc.BinaryName, "run", "bundle", bundleImage, "--namespace", tc.Kubectl.Namespace) + _, err = tc.Run(runBundleCmd) + Expect(err).NotTo(HaveOccurred()) + + By("destroying the Operator deployed with the 'run' subcommand") + cleanupPkgManCmd := exec.Command(tc.BinaryName, "cleanup", projectName, + "--timeout", "4m") + _, err = tc.Run(cleanupPkgManCmd) + Expect(err).NotTo(HaveOccurred()) + By("adding the 'packagemanifests' rule to the Makefile") err = tc.AddPackagemanifestsTarget() Expect(err).NotTo(HaveOccurred()) @@ -122,7 +133,7 @@ var _ = Describe("Integrating ansible Projects with OLM", func() { } By("destroying the deployed package manifests-formatted operator") - cleanupPkgManCmd := exec.Command(tc.BinaryName, "cleanup", projectName, + cleanupPkgManCmd = exec.Command(tc.BinaryName, "cleanup", projectName, "--timeout", "4m") _, err = tc.Run(cleanupPkgManCmd) Expect(err).NotTo(HaveOccurred()) diff --git a/test/e2e-go/e2e_go_olm_test.go b/test/e2e-go/e2e_go_olm_test.go index 5e63bd6400..939b2a103f 100644 --- a/test/e2e-go/e2e_go_olm_test.go +++ b/test/e2e-go/e2e_go_olm_test.go @@ -18,7 +18,6 @@ import ( "encoding/json" "os/exec" "path/filepath" - "strings" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -27,6 +26,10 @@ import ( testutils "github.com/operator-framework/operator-sdk/test/internal" ) +var ( + runBundleImg = "quay.io/vnarsing/run-bundle-test-img:v1" +) + var _ = Describe("Integrating Go Projects with OLM", func() { Context("with operator-sdk", func() { const operatorVersion = "0.0.1" @@ -44,24 +47,37 @@ var _ = Describe("Integrating Go Projects with OLM", func() { // Turn off interactive prompts for all generation tasks. replace := "operator-sdk generate kustomize manifests" testutils.ReplaceInFile(filepath.Join(tc.Dir, "Makefile"), replace, replace+" --interactive=false") - err := tc.Make("bundle", "IMG="+tc.ImageName) + + // Specifying stable channel. + // work around for Bug 1883377 - opm fails with FOREIGN KEY constraint when bundle default channel is empty + replace = "operator-sdk generate bundle" + testutils.ReplaceInFile(filepath.Join(tc.Dir, "Makefile"), replace, replace+" --default-channel stable --channels stable") + err := tc.Make("bundle") Expect(err).NotTo(HaveOccurred()) By("building the operator bundle image") - // Use the existing image tag but with a "-bundle" suffix. - imageSplit := strings.SplitN(tc.ImageName, ":", 2) - bundleImage := imageSplit[0] + "-bundle" - if len(imageSplit) == 2 { - bundleImage += ":" + imageSplit[1] - } - err = tc.Make("bundle-build", "BUNDLE_IMG="+bundleImage) + err = tc.Make("bundle-build", "BUNDLE_IMG="+runBundleImg) Expect(err).NotTo(HaveOccurred()) - if isRunningOnKind() { - By("loading the bundle image into Kind cluster") - err = tc.LoadImageToKindClusterWithName(bundleImage) - Expect(err).NotTo(HaveOccurred()) - } + _, err = tc.Kubectl.Command("create", "namespace", tc.Kubectl.Namespace) + Expect(err).NotTo(HaveOccurred()) + + // bundle image should be present in the remote repository in run bundle + // implementation. + By("push the image to a remote repository") + err = tc.Make("docker-push", "IMG="+runBundleImg) + Expect(err).NotTo(HaveOccurred()) + + By("running the operator bundle using `run bundle` command") + runBundleCmd := exec.Command(tc.BinaryName, "run", "bundle", runBundleImg, "--namespace", tc.Kubectl.Namespace, "--timeout", "4m") + _, err = tc.Run(runBundleCmd) + Expect(err).NotTo(HaveOccurred()) + + By("destroying the Operator deployed with the 'run' subcommand") + cleanupPkgManCmd := exec.Command(tc.BinaryName, "cleanup", projectName, + "--timeout", "4m") + _, err = tc.Run(cleanupPkgManCmd) + Expect(err).NotTo(HaveOccurred()) By("adding the 'packagemanifests' rule to the Makefile") err = tc.AddPackagemanifestsTarget() @@ -127,10 +143,13 @@ var _ = Describe("Integrating Go Projects with OLM", func() { } By("destroying the deployed package manifests-formatted operator") - cleanupPkgManCmd := exec.Command(tc.BinaryName, "cleanup", projectName, + cleanupPkgManCmd = exec.Command(tc.BinaryName, "cleanup", projectName, "--timeout", "4m") _, err = tc.Run(cleanupPkgManCmd) Expect(err).NotTo(HaveOccurred()) + + _, err = tc.Kubectl.Command("delete", "namespace", tc.Kubectl.Namespace) + Expect(err).NotTo(HaveOccurred()) }) }) }) diff --git a/test/e2e-helm/e2e_helm_olm_test.go b/test/e2e-helm/e2e_helm_olm_test.go index a7c9cc44a3..f55fa69799 100644 --- a/test/e2e-helm/e2e_helm_olm_test.go +++ b/test/e2e-helm/e2e_helm_olm_test.go @@ -67,6 +67,17 @@ var _ = Describe("Integrating Helm Projects with OLM", func() { Expect(err).NotTo(HaveOccurred()) } + By("running the operator bundle using `run bundle` command") + runBundleCmd := exec.Command(tc.BinaryName, "run", "bundle", bundleImage, "--namespace", tc.Kubectl.Namespace) + _, err = tc.Run(runBundleCmd) + Expect(err).NotTo(HaveOccurred()) + + By("destroying the Operator deployed with the 'run' subcommand") + cleanupPkgManCmd := exec.Command(tc.BinaryName, "cleanup", projectName, + "--timeout", "4m") + _, err = tc.Run(cleanupPkgManCmd) + Expect(err).NotTo(HaveOccurred()) + By("adding the 'packagemanifests' rule to the Makefile") err = tc.AddPackagemanifestsTarget() Expect(err).NotTo(HaveOccurred()) @@ -97,7 +108,7 @@ var _ = Describe("Integrating Helm Projects with OLM", func() { Expect(err).NotTo(HaveOccurred()) By("destroying the deployed package manifests-formatted operator") - cleanupPkgManCmd := exec.Command(tc.BinaryName, "cleanup", projectName, + cleanupPkgManCmd = exec.Command(tc.BinaryName, "cleanup", projectName, "--timeout", "4m") _, err = tc.Run(cleanupPkgManCmd) Expect(err).NotTo(HaveOccurred()) diff --git a/website/content/en/docs/cli/operator-sdk_run.md b/website/content/en/docs/cli/operator-sdk_run.md index 414fccc760..1c7573ba5c 100644 --- a/website/content/en/docs/cli/operator-sdk_run.md +++ b/website/content/en/docs/cli/operator-sdk_run.md @@ -25,5 +25,6 @@ Currently only the package manifests format is supported via the 'packagemanifes ### SEE ALSO * [operator-sdk](../operator-sdk) - Development kit for building Kubernetes extensions and tools. +* [operator-sdk run bundle](../operator-sdk_run_bundle) - Deploy an Operator in the bundle format with OLM * [operator-sdk run packagemanifests](../operator-sdk_run_packagemanifests) - Deploy an Operator in the package manifests format with OLM diff --git a/website/content/en/docs/cli/operator-sdk_run_bundle.md b/website/content/en/docs/cli/operator-sdk_run_bundle.md new file mode 100644 index 0000000000..5708e29187 --- /dev/null +++ b/website/content/en/docs/cli/operator-sdk_run_bundle.md @@ -0,0 +1,36 @@ +--- +title: "operator-sdk run bundle" +--- +## operator-sdk run bundle + +Deploy an Operator in the bundle format with OLM + +### Synopsis + +Deploy an Operator in the bundle format with OLM + +``` +operator-sdk run bundle [flags] +``` + +### Options + +``` + --index-image string index image in which to inject bundle (default "quay.io/operator-framework/upstream-opm-builder:latest") + --install-mode InstallModeValue install mode + --timeout duration install timeout (default 2m0s) + --kubeconfig string Path to the kubeconfig file to use for CLI requests. + -n, --namespace string If present, namespace scope for this CLI request + -h, --help help for bundle +``` + +### Options inherited from parent commands + +``` + --verbose Enable verbose logging +``` + +### SEE ALSO + +* [operator-sdk run](../operator-sdk_run) - Run an Operator in a variety of environments +