From af455e1137806cd02467ac316ff1a09b49d8f18a Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Wed, 29 Jul 2020 12:28:05 -0700 Subject: [PATCH] ` + OLM namespace is no longer required by this command. + - description: Changed the `--operator-namespace` flag to `--namespace` in `run packagemanifests`. + kind: change + breaking: true + migration: + header: Change the `run packagemanifests` flag `--operator-namespace` to `--namespace` + body: > + `--operator-namespace` is now `--namespace`. diff --git a/internal/olm/operator/operator_manager.go b/internal/olm/operator/operator_manager.go index b789613ac0..0d291f0f35 100644 --- a/internal/olm/operator/operator_manager.go +++ b/internal/olm/operator/operator_manager.go @@ -29,7 +29,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes/scheme" - "github.com/operator-framework/operator-sdk/internal/olm" internalolmclient "github.com/operator-framework/operator-sdk/internal/olm/client" "github.com/operator-framework/operator-sdk/internal/util/k8sutil" ) @@ -59,12 +58,9 @@ type OperatorCmd struct { // KubeconfigPath is the local path to a kubeconfig. This uses well-defined // default loading rules to load the config if empty. KubeconfigPath string - // OperatorNamespace is the cluster namespace in which operator resources - // are created. - // OperatorNamespace must already exist in the cluster. - OperatorNamespace string - // OLMNamespace is the namespace in which OLM is installed. - OLMNamespace string + // Namespace is the cluster namespace in which operator resources are created. + // Namespace must already exist in the cluster. + Namespace string // InstallMode specifies which supported installMode should be used to // create an OperatorGroup. The format for this field is as follows: // @@ -87,9 +83,7 @@ func (c *OperatorCmd) AddToFlagSet(fs *pflag.FlagSet) { fs.StringVar(&c.KubeconfigPath, "kubeconfig", "", "The file path to kubernetes configuration file. Defaults to location "+ "specified by $KUBECONFIG, or to default file rules if not set") - fs.StringVar(&c.OLMNamespace, "olm-namespace", olm.DefaultOLMNamespace, - "The namespace where OLM is installed") - fs.StringVar(&c.OperatorNamespace, "operator-namespace", "", + fs.StringVar(&c.Namespace, "namespace", "", "The namespace where operator resources are created. It must already exist in the cluster") fs.StringVar(&c.InstallMode, "install-mode", "", "InstallMode to create OperatorGroup with. Format: "+installModeFormat) @@ -116,10 +110,8 @@ func (c *OperatorCmd) initialize() { type operatorManager struct { client *internalolmclient.Client - // olmNamespace is the namespace where olm is installed - // and operator registry server resources are created - olmNamespace string - operatorNamespace string + // Namespace in which operator and OLM objects are created. + namespace string installMode operatorsv1alpha1.InstallModeType //nolint:structcheck targetNamespaces []string //nolint:structcheck @@ -128,11 +120,6 @@ type operatorManager struct { func (c *OperatorCmd) newManager() (*operatorManager, error) { m := &operatorManager{} - // Namespace in which OLM is deployed. - if m.olmNamespace = c.OLMNamespace; m.olmNamespace == "" { - m.olmNamespace = olm.DefaultOLMNamespace - } - // Cluster and operator namespace info. rc, ns, err := k8sutil.GetKubeconfigAndNamespace(c.KubeconfigPath) if err != nil { @@ -141,8 +128,8 @@ func (c *OperatorCmd) newManager() (*operatorManager, error) { if ns == "" { ns = defaultNamespace } - if m.operatorNamespace = c.OperatorNamespace; m.operatorNamespace == "" { - m.operatorNamespace = ns + if m.namespace = c.Namespace; m.namespace == "" { + m.namespace = ns } if m.client == nil { m.client, err = internalolmclient.ClientForConfig(rc) @@ -159,7 +146,7 @@ func (m *operatorManager) status(ctx context.Context, us ...*unstructured.Unstru objs := []runtime.Object{} for _, u := range us { uc := u.DeepCopy() - uc.SetNamespace(m.operatorNamespace) + uc.SetNamespace(m.namespace) objs = append(objs, uc) } return m.client.GetObjectsStatus(ctx, objs...) diff --git a/internal/olm/operator/packagemanifests_manager.go b/internal/olm/operator/packagemanifests_manager.go index 608e4b5355..0804bb4b8b 100644 --- a/internal/olm/operator/packagemanifests_manager.go +++ b/internal/olm/operator/packagemanifests_manager.go @@ -64,7 +64,7 @@ func (c *PackageManifestsCmd) newManager() (m *packageManifestsManager, err erro if c.InstallMode == "" { // Default to OwnNamespace. m.installMode = operatorsv1alpha1.InstallModeTypeOwnNamespace - m.targetNamespaces = []string{m.operatorNamespace} + m.targetNamespaces = []string{m.namespace} } else { m.installMode, m.targetNamespaces, err = parseInstallModeKV(c.InstallMode) if err != nil { @@ -77,7 +77,7 @@ func (c *PackageManifestsCmd) newManager() (m *packageManifestsManager, err erro if err != nil { return nil, err } - if err := installModeCompatible(bundle.CSV, m.installMode, m.operatorNamespace, m.targetNamespaces); err != nil { + if err := installModeCompatible(bundle.CSV, m.installMode, m.namespace, m.targetNamespaces); err != nil { return nil, err } @@ -85,11 +85,7 @@ func (c *PackageManifestsCmd) newManager() (m *packageManifestsManager, err erro } func (m *packageManifestsManager) run(ctx context.Context) (err error) { - // Ensure OLM is installed. - olmVer, err := m.client.GetInstalledVersion(ctx, m.olmNamespace) - if err != nil { - return fmt.Errorf("error getting installed OLM version: %w", err) - } + // TODO: ensure OLM is installed by checking OLM CRDs. pkgName := m.pkg.PackageName bundle, err := getPackageForVersion(m.bundles, m.version) @@ -112,23 +108,23 @@ func (m *packageManifestsManager) run(ctx context.Context) (err error) { return fmt.Errorf("an operator with name %q is present and has resource errors\n%s", pkgName, status) } - if err = m.registryUp(ctx, m.olmNamespace); err != nil { + if err = m.registryUp(ctx, m.namespace); err != nil { return fmt.Errorf("error creating registry resources: %w", err) } // New CatalogSource. - registryGRPCAddr := internalregistry.GetRegistryServiceAddr(pkgName, m.olmNamespace) - catsrc := newCatalogSource(pkgName, m.operatorNamespace, withGRPC(registryGRPCAddr)) + registryGRPCAddr := internalregistry.GetRegistryServiceAddr(pkgName, m.namespace) + catsrc := newCatalogSource(pkgName, m.namespace, withGRPC(registryGRPCAddr)) // New Subscription. channel, err := getChannelForCSVName(m.pkg, csv.GetName()) if err != nil { return err } - sub := newSubscription(csv.GetName(), m.operatorNamespace, + sub := newSubscription(csv.GetName(), m.namespace, withPackageChannel(pkgName, channel), - withCatalogSource(getCatalogSourceName(pkgName), m.operatorNamespace)) + withCatalogSource(getCatalogSourceName(pkgName), m.namespace)) // New SDK-managed OperatorGroup. - og := newSDKOperatorGroup(m.operatorNamespace, + og := newSDKOperatorGroup(m.namespace, withTargetNamespaces(m.targetNamespaces...)) objects := []runtime.Object{catsrc, sub, og} log.Info("Creating resources") @@ -136,11 +132,11 @@ func (m *packageManifestsManager) run(ctx context.Context) (err error) { return fmt.Errorf("error creating operator resources: %w", err) } - // BUG(estroz): if operatorNamespace is not contained in targetNamespaces, - // DoCSVWait will fail because the CSV is not deployed in operatorNamespace. + // BUG(estroz): if namespace is not contained in targetNamespaces, + // DoCSVWait will fail because the CSV is not deployed in namespace. nn := types.NamespacedName{ Name: csv.GetName(), - Namespace: m.operatorNamespace, + Namespace: m.namespace, } log.Printf("Waiting for ClusterServiceVersion %q to reach 'Succeeded' phase", nn) if err = m.client.DoCSVWait(ctx, nn); err != nil { @@ -153,19 +149,13 @@ func (m *packageManifestsManager) run(ctx context.Context) (err error) { } else if err != nil { return fmt.Errorf("operator %q has resource errors\n%s", pkgName, status) } - log.Infof("Successfully installed %q on OLM version %q", csv.GetName(), olmVer) + log.Infof("OLM has successfully installed %q", csv.GetName()) fmt.Print(status) return nil } func (m *packageManifestsManager) cleanup(ctx context.Context) (err error) { - // Ensure OLM is installed. - olmVer, err := m.client.GetInstalledVersion(ctx, m.olmNamespace) - if err != nil { - return fmt.Errorf("error getting installed OLM version: %w", err) - } - pkgName := m.pkg.PackageName bundle, err := getPackageForVersion(m.bundles, m.version) if err != nil { @@ -173,19 +163,19 @@ func (m *packageManifestsManager) cleanup(ctx context.Context) (err error) { } csv := bundle.CSV - if err = m.registryDown(ctx, m.olmNamespace); err != nil { + if err = m.registryDown(ctx, m.namespace); err != nil { return fmt.Errorf("error removing registry resources: %w", err) } // Delete CatalogSource, Subscription, the SDK-managed OperatorGroup, and any bundle objects. toDelete := []runtime.Object{ - newCatalogSource(pkgName, m.operatorNamespace), - newSubscription(csv.GetName(), m.operatorNamespace), - newSDKOperatorGroup(m.operatorNamespace), + newCatalogSource(pkgName, m.namespace), + newSubscription(csv.GetName(), m.namespace), + newSDKOperatorGroup(m.namespace), } for _, obj := range bundle.Objects { objc := obj.DeepCopy() - objc.SetNamespace(m.operatorNamespace) + objc.SetNamespace(m.namespace) toDelete = append(toDelete, objc) } log.Info("Deleting resources") @@ -199,7 +189,7 @@ func (m *packageManifestsManager) cleanup(ctx context.Context) (err error) { } else if err != nil { return fmt.Errorf("operator %q still exists and has resource errors\n%s", pkgName, status) } - log.Infof("Successfully uninstalled %q on OLM version %q", csv.GetName(), olmVer) + log.Infof("OLM has successfully uninstalled %q and related resources have been deleted", csv.GetName()) return nil } diff --git a/test/e2e/e2e_suite.go b/test/e2e/e2e_suite.go index 08b196e091..ee058f906c 100644 --- a/test/e2e/e2e_suite.go +++ b/test/e2e/e2e_suite.go @@ -196,7 +196,7 @@ var _ = Describe("operator-sdk", func() { Expect(err).NotTo(HaveOccurred()) runPkgManCmd := exec.Command(tc.BinaryName, "run", "packagemanifests", "--install-mode", "AllNamespaces", - "--operator-namespace", tc.Kubectl.Namespace, + "--namespace", tc.Kubectl.Namespace, "--version", operatorVersion, "--timeout", "4m") _, err = tc.Run(runPkgManCmd) @@ -204,7 +204,7 @@ var _ = Describe("operator-sdk", func() { By("destroying the deployed package manifests-formatted operator") cleanupPkgManCmd := exec.Command(tc.BinaryName, "cleanup", "packagemanifests", - "--operator-namespace", tc.Kubectl.Namespace, + "--namespace", tc.Kubectl.Namespace, "--version", operatorVersion, "--timeout", "4m") _, err = tc.Run(cleanupPkgManCmd) diff --git a/test/integration/operator_olm_test.go b/test/integration/operator_olm_test.go index 718cdc6cc8..e807b185cd 100644 --- a/test/integration/operator_olm_test.go +++ b/test/integration/operator_olm_test.go @@ -22,7 +22,6 @@ import ( "time" apimanifests "github.com/operator-framework/api/pkg/manifests" - "github.com/operator-framework/operator-sdk/internal/olm" operator "github.com/operator-framework/operator-sdk/internal/olm/operator" "github.com/operator-framework/operator-sdk/internal/util/k8sutil" @@ -99,7 +98,6 @@ func PackageManifestsAllNamespaces(t *testing.T) { OperatorCmd: operator.OperatorCmd{ KubeconfigPath: kubeconfigPath, Timeout: defaultTimeout, - OLMNamespace: olm.DefaultOLMNamespace, InstallMode: string(operatorsv1alpha1.InstallModeTypeAllNamespaces), }, ManifestsDir: manifestsDir, @@ -162,7 +160,6 @@ func PackageManifestsBasic(t *testing.T) { OperatorCmd: operator.OperatorCmd{ KubeconfigPath: kubeconfigPath, Timeout: defaultTimeout, - OLMNamespace: olm.DefaultOLMNamespace, }, ManifestsDir: manifestsDir, Version: defaultOperatorVersion, @@ -265,7 +262,6 @@ func PackageManifestsMultiplePackages(t *testing.T) { OperatorCmd: operator.OperatorCmd{ KubeconfigPath: kubeconfigPath, Timeout: defaultTimeout, - OLMNamespace: olm.DefaultOLMNamespace, }, ManifestsDir: manifestsDir, Version: operatorVersion2, diff --git a/website/content/en/docs/cli/operator-sdk_cleanup_packagemanifests.md b/website/content/en/docs/cli/operator-sdk_cleanup_packagemanifests.md index 6c1ef41673..976cf0bb53 100644 --- a/website/content/en/docs/cli/operator-sdk_cleanup_packagemanifests.md +++ b/website/content/en/docs/cli/operator-sdk_cleanup_packagemanifests.md @@ -18,13 +18,12 @@ operator-sdk cleanup packagemanifests [flags] ### Options ``` - -h, --help help for packagemanifests - --install-mode string InstallMode to create OperatorGroup with. Format: InstallModeType[=ns1,ns2[, ...]] - --kubeconfig string The file path to kubernetes configuration file. Defaults to location specified by $KUBECONFIG, or to default file rules if not set - --olm-namespace string The namespace where OLM is installed (default "olm") - --operator-namespace string The namespace where operator resources are created. It must already exist in the cluster - --timeout duration Time to wait for the command to complete before failing (default 2m0s) - --version string Packaged version of the operator to deploy + -h, --help help for packagemanifests + --install-mode string InstallMode to create OperatorGroup with. Format: InstallModeType[=ns1,ns2[, ...]] + --kubeconfig string The file path to kubernetes configuration file. Defaults to location specified by $KUBECONFIG, or to default file rules if not set + --namespace string The namespace where operator resources are created. It must already exist in the cluster + --timeout duration Time to wait for the command to complete before failing (default 2m0s) + --version string Packaged version of the operator to deploy ``` ### Options inherited from parent commands diff --git a/website/content/en/docs/cli/operator-sdk_run_packagemanifests.md b/website/content/en/docs/cli/operator-sdk_run_packagemanifests.md index c14ee4d4bb..d171f0b519 100644 --- a/website/content/en/docs/cli/operator-sdk_run_packagemanifests.md +++ b/website/content/en/docs/cli/operator-sdk_run_packagemanifests.md @@ -17,13 +17,12 @@ operator-sdk run packagemanifests [flags] ### Options ``` - -h, --help help for packagemanifests - --install-mode string InstallMode to create OperatorGroup with. Format: InstallModeType[=ns1,ns2[, ...]] - --kubeconfig string The file path to kubernetes configuration file. Defaults to location specified by $KUBECONFIG, or to default file rules if not set - --olm-namespace string The namespace where OLM is installed (default "olm") - --operator-namespace string The namespace where operator resources are created. It must already exist in the cluster - --timeout duration Time to wait for the command to complete before failing (default 2m0s) - --version string Packaged version of the operator to deploy + -h, --help help for packagemanifests + --install-mode string InstallMode to create OperatorGroup with. Format: InstallModeType[=ns1,ns2[, ...]] + --kubeconfig string The file path to kubernetes configuration file. Defaults to location specified by $KUBECONFIG, or to default file rules if not set + --namespace string The namespace where operator resources are created. It must already exist in the cluster + --timeout duration Time to wait for the command to complete before failing (default 2m0s) + --version string Packaged version of the operator to deploy ``` ### Options inherited from parent commands diff --git a/website/content/en/docs/olm-integration/quickstart-bundle.md b/website/content/en/docs/olm-integration/quickstart-bundle.md index b84d6723e1..7f99a36fa8 100644 --- a/website/content/en/docs/olm-integration/quickstart-bundle.md +++ b/website/content/en/docs/olm-integration/quickstart-bundle.md @@ -30,8 +30,7 @@ Ensure OLM is enabled on your cluster before following this guide. [`operator-sd has several subcommands that can install, uninstall, and check the status of particular OLM versions in a cluster. **Note:** Certain cluster types may already have OLM enabled, but under a non-default (`"olm"`) namespace, -which can be configured by setting `--olm-namespace=[non-default-olm-namespace]` for `operator-sdk olm` subcommands -and `operator-sdk run packagemanifests`. +which can be configured by setting `--olm-namespace=[non-default-olm-namespace]` for `operator-sdk olm` subcommands. You can check if OLM is already installed by running the following command, which will detect the installed OLM version automatically (0.15.1 in this example): diff --git a/website/content/en/docs/olm-integration/testing-deployment.md b/website/content/en/docs/olm-integration/testing-deployment.md index 18f0fce0ff..0ba4a81d08 100644 --- a/website/content/en/docs/olm-integration/testing-deployment.md +++ b/website/content/en/docs/olm-integration/testing-deployment.md @@ -22,9 +22,8 @@ Let's look at the anatomy of the `run packagemanifests` (which is the same for ` - **kubeconfig-path**: the local path to a kubeconfig. - This uses well-defined default loading rules to load the config if empty. -- **olm-namespace**: the namespace in which OLM is installed. -- **operator-namespace**: the cluster namespace in which Operator resources are created. - - This namespace must already exist in the cluster or be defined in a manifest passed to **include-paths**. +- **namespace**: the cluster namespace in which Operator resources are created. + - This namespace must already exist in the cluster. - **manifests-dir**: a directory containing the Operator's package manifests. - **version**: the version of the Operator to deploy. It must be a semantic version, ex. 0.0.1. - This version must match the version of the CSV manifest found in **manifests-dir**, @@ -34,8 +33,7 @@ Let's look at the anatomy of the `run packagemanifests` (which is the same for ` - The `InstallModeType` string passed must be marked as "supported" in the CSV being installed. The namespaces passed must exist or be created by passing a `Namespace` manifest to IncludePaths. - This option understands the following strings (assuming your CSV does as well): - - `OwnNamespace`: the Operator will watch its own namespace (from **operator-namespace** or the kubeconfig default). - This is the default. + - `OwnNamespace`: the Operator will watch its own namespace (from **namespace** or the kubeconfig default). This is the default. - `SingleNamespace="my-ns"`: the Operator will watch a namespace, not necessarily its own. - `AllNamespaces=""`: the Operator will watch all namespaces (cluster-scoped Operators). - **timeout**: a time string dictating the maximum time that `run` can run. The command will