Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/fragments/enable-run-bundle-cmd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
entries:
- description: >
Enable `run bundle` command and include e2e tests.
kind: addition
3 changes: 2 additions & 1 deletion internal/cmd/operator-sdk/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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),
)

Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/operator-sdk/run/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})
})
15 changes: 13 additions & 2 deletions test/e2e-ansible/e2e_ansible_olm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,23 @@ var _ = Describe("Integrating ansible Projects with OLM", func() {
err = tc.Make("bundle-build", "BUNDLE_IMG="+bundleImage)
Expect(err).NotTo(HaveOccurred())

if isRunningOnKind() {
if tc.IsRunningOnKind() {
By("loading the bundle image into Kind cluster")
err = tc.LoadImageToKindClusterWithName(bundleImage)
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())
Expand Down Expand Up @@ -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())
Expand Down
11 changes: 2 additions & 9 deletions test/e2e-ansible/e2e_ansible_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ var (
isPrometheusManagedBySuite = true
// isOLMManagedBySuite is true when the suite tests is installing/uninstalling the OLM
isOLMManagedBySuite = true
// kubectx stores the k8s context from where the tests are running
kubectx string
// projectName is the name of the test project
projectName string
)
Expand All @@ -59,7 +57,7 @@ var _ = BeforeSuite(func(done Done) {
projectName = filepath.Base(tc.Dir)

By("checking the cluster type")
kubectx, err = tc.Kubectl.Command("config", "current-context")
tc.Kubectx, err = tc.Kubectl.Command("config", "current-context")
Expect(err).NotTo(HaveOccurred())

By("checking API resources applied on Cluster")
Expand Down Expand Up @@ -167,7 +165,7 @@ var _ = BeforeSuite(func(done Done) {
err = tc.Make("docker-build", "IMG="+tc.ImageName)
Expect(err).NotTo(HaveOccurred())

if isRunningOnKind() {
if tc.IsRunningOnKind() {
By("loading the project image into Kind cluster")
err = tc.LoadImageToKindCluster()
Expect(err).NotTo(HaveOccurred())
Expand All @@ -192,11 +190,6 @@ var _ = AfterSuite(func() {
tc.Destroy()
})

// isRunningOnKind returns true when the tests are executed in a Kind Cluster
func isRunningOnKind() bool {
return strings.Contains(kubectx, "kind")
}

const memcachedWithBlackListTask = `- name: start memcached
community.kubernetes.k8s:
definition:
Expand Down
15 changes: 13 additions & 2 deletions test/e2e-go/e2e_go_olm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,23 @@ var _ = Describe("Integrating Go Projects with OLM", func() {
err = tc.Make("bundle-build", "BUNDLE_IMG="+bundleImage)
Expect(err).NotTo(HaveOccurred())

if isRunningOnKind() {
if tc.IsRunningOnKind() {
By("loading the bundle image into Kind cluster")
err = tc.LoadImageToKindClusterWithName(bundleImage)
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())
Expand Down Expand Up @@ -127,7 +138,7 @@ 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())
Expand Down
11 changes: 2 additions & 9 deletions test/e2e-go/e2e_go_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ var (
isPrometheusManagedBySuite = true
// isOLMManagedBySuite is true when the suite tests is installing/uninstalling the OLM
isOLMManagedBySuite = true
// kubectx stores the k8s context from where the tests are running
kubectx string
// projectName is the name of the test project
projectName string
)
Expand All @@ -61,7 +59,7 @@ var _ = BeforeSuite(func(done Done) {
projectName = filepath.Base(tc.Dir)

By("checking the cluster type")
kubectx, err = tc.Kubectl.Command("config", "current-context")
tc.Kubectx, err = tc.Kubectl.Command("config", "current-context")
Expect(err).NotTo(HaveOccurred())

By("checking API resources applied on Cluster")
Expand Down Expand Up @@ -141,7 +139,7 @@ var _ = BeforeSuite(func(done Done) {
err = tc.Make("docker-build", "IMG="+tc.ImageName)
Expect(err).NotTo(HaveOccurred())

if isRunningOnKind() {
if tc.IsRunningOnKind() {
By("loading the project image into Kind cluster")
err = tc.LoadImageToKindCluster()
Expect(err).NotTo(HaveOccurred())
Expand All @@ -165,8 +163,3 @@ var _ = AfterSuite(func() {
By("destroying container image and work dir")
tc.Destroy()
})

// isRunningOnKind returns true when the tests are executed in a Kind Cluster
func isRunningOnKind() bool {
return strings.Contains(kubectx, "kind")
}
15 changes: 13 additions & 2 deletions test/e2e-helm/e2e_helm_olm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,23 @@ var _ = Describe("Integrating Helm Projects with OLM", func() {
err = tc.Make("bundle-build", "BUNDLE_IMG="+bundleImage)
Expect(err).NotTo(HaveOccurred())

if isRunningOnKind() {
if tc.IsRunningOnKind() {
By("loading the bundle image into Kind cluster")
err = tc.LoadImageToKindClusterWithName(bundleImage)
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())
Expand Down Expand Up @@ -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())
Expand Down
11 changes: 2 additions & 9 deletions test/e2e-helm/e2e_helm_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ var (
isPrometheusManagedBySuite = true
// isOLMManagedBySuite is true when the suite tests is installing/uninstalling the OLM
isOLMManagedBySuite = true
// kubectx stores the k8s context from where the tests are running
kubectx string
// projectName is the name of the test project
projectName string
)
Expand All @@ -58,7 +56,7 @@ var _ = BeforeSuite(func(done Done) {
projectName = filepath.Base(tc.Dir)

By("checking the cluster type")
kubectx, err = tc.Kubectl.Command("config", "current-context")
tc.Kubectx, err = tc.Kubectl.Command("config", "current-context")
Expect(err).NotTo(HaveOccurred())

By("checking API resources applied on Cluster")
Expand Down Expand Up @@ -117,7 +115,7 @@ var _ = BeforeSuite(func(done Done) {
err = tc.Make("docker-build", "IMG="+tc.ImageName)
Expect(err).NotTo(HaveOccurred())

if isRunningOnKind() {
if tc.IsRunningOnKind() {
By("loading the project image into Kind cluster")
err = tc.LoadImageToKindCluster()
Expect(err).NotTo(HaveOccurred())
Expand All @@ -141,8 +139,3 @@ var _ = AfterSuite(func() {
By("destroying container image and work dir")
tc.Destroy()
})

// isRunningOnKind returns true when the tests are executed in a Kind Cluster
func isRunningOnKind() bool {
return strings.Contains(kubectx, "kind")
}
14 changes: 13 additions & 1 deletion test/internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import (
// TestContext wraps kubebuilder's e2e TestContext.
type TestContext struct {
*kbtestutils.TestContext

// kubectx stores the k8s context from where the tests are running
Kubectx string
}

// NewTestContext returns a TestContext containing a new kubebuilder TestContext.
Expand Down Expand Up @@ -87,8 +90,17 @@ func ReplaceRegexInFile(path, match, replace string) {

// LoadImageToKindCluster loads a local docker image with the name informed to the kind cluster
func (tc TestContext) LoadImageToKindClusterWithName(image string) error {
kindOptions := []string{"load", "docker-image", image}
cluster := "kind"
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
cluster = v
}
kindOptions := []string{"load", "docker-image", image, "--name", cluster}
cmd := exec.Command("kind", kindOptions...)
_, err := tc.Run(cmd)
return err
}

// IsRunningOnKind returns true when the tests are executed in a Kind Cluster
func (tc TestContext) IsRunningOnKind() bool {
return strings.Contains(tc.Kubectx, "kind")
}
1 change: 1 addition & 0 deletions website/content/en/docs/cli/operator-sdk_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

36 changes: 36 additions & 0 deletions website/content/en/docs/cli/operator-sdk_run_bundle.md
Original file line number Diff line number Diff line change
@@ -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 <bundle-image> [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