Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<run|cleanup> packagemanifests: remove --olm-namespace, change --operator-namespace to --namespace #3601

Merged
Merged
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
15 changes: 15 additions & 0 deletions changelog/fragments/run-packagemanifests-flags-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
entries:
- description: Removed the `--olm-namespace` flag from `run packagemanifests`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to using the past tense, Removed, it reads better when the changelog is generated.

kind: removal
breaking: true
migration:
header: Remove `--olm-namespace` from `run packagemanifests` invocations
body: >
OLM namespace is no longer required by this command.
- description: Changed the `--operator-namespace` flag to `--namespace` in `run packagemanifests`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to Changed

kind: change
breaking: true
migration:
header: Change the `run packagemanifests` flag `--operator-namespace` to `--namespace`
body: >
`--operator-namespace` is now `--namespace`.
31 changes: 9 additions & 22 deletions internal/olm/operator/operator_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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:
//
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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...)
Expand Down
48 changes: 19 additions & 29 deletions internal/olm/operator/packagemanifests_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -77,19 +77,15 @@ 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
}

return m, nil
}

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)
Expand All @@ -112,35 +108,35 @@ 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")
if err = m.client.DoCreate(ctx, objects...); err != nil {
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 {
Expand All @@ -153,39 +149,33 @@ 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 {
return fmt.Errorf("error getting package for version %s: %w", m.version, err)
}
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")
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/e2e_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ 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)
Expect(err).NotTo(HaveOccurred())

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)
Expand Down
4 changes: 0 additions & 4 deletions test/integration/operator_olm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -162,7 +160,6 @@ func PackageManifestsBasic(t *testing.T) {
OperatorCmd: operator.OperatorCmd{
KubeconfigPath: kubeconfigPath,
Timeout: defaultTimeout,
OLMNamespace: olm.DefaultOLMNamespace,
},
ManifestsDir: manifestsDir,
Version: defaultOperatorVersion,
Expand Down Expand Up @@ -265,7 +262,6 @@ func PackageManifestsMultiplePackages(t *testing.T) {
OperatorCmd: operator.OperatorCmd{
KubeconfigPath: kubeconfigPath,
Timeout: defaultTimeout,
OLMNamespace: olm.DefaultOLMNamespace,
},
ManifestsDir: manifestsDir,
Version: operatorVersion2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions website/content/en/docs/cli/operator-sdk_run_packagemanifests.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions website/content/en/docs/olm-integration/quickstart-bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 3 additions & 5 deletions website/content/en/docs/olm-integration/testing-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**,
Expand All @@ -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
Expand Down