From 27a3735b7501d3f10802cb77f4dcffa631959447 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Mon, 13 Jan 2020 13:03:41 -0800 Subject: [PATCH 1/4] 'olm up/down' commands will create and delete an operator using OLM via manifests stored in a registry-server. cmd/operator-sdk/alpha/olm: add operator up/down commands --- cmd/operator-sdk/alpha/cmd.go | 7 +++-- cmd/operator-sdk/alpha/olm/cmd.go | 4 ++- cmd/operator-sdk/alpha/olm/down.go | 44 ++++++++++++++++++++++++++++++ cmd/operator-sdk/alpha/olm/up.go | 44 ++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 cmd/operator-sdk/alpha/olm/down.go create mode 100644 cmd/operator-sdk/alpha/olm/up.go diff --git a/cmd/operator-sdk/alpha/cmd.go b/cmd/operator-sdk/alpha/cmd.go index 9cd977fc81c..ae471b0c398 100644 --- a/cmd/operator-sdk/alpha/cmd.go +++ b/cmd/operator-sdk/alpha/cmd.go @@ -17,6 +17,7 @@ package alpha import ( "github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha/kubebuilder" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha/olm" + "github.com/spf13/cobra" ) @@ -26,7 +27,9 @@ func NewCmd() *cobra.Command { Short: "Run an alpha subcommand", } - cmd.AddCommand(olm.NewCmd()) - cmd.AddCommand(kubebuilder.NewCmd()) + cmd.AddCommand( + olm.NewCmd(), + kubebuilder.NewCmd(), + ) return cmd } diff --git a/cmd/operator-sdk/alpha/olm/cmd.go b/cmd/operator-sdk/alpha/olm/cmd.go index 13fb3c00f1f..03242337ade 100644 --- a/cmd/operator-sdk/alpha/olm/cmd.go +++ b/cmd/operator-sdk/alpha/olm/cmd.go @@ -21,12 +21,14 @@ import ( func NewCmd() *cobra.Command { cmd := &cobra.Command{ Use: "olm", - Short: "Manage the Operator Lifecycle Manager installation in your cluster", + Short: "Manage the Operator Lifecycle Manager installation and Operators in your cluster", } cmd.AddCommand( NewInstallCmd(), NewUninstallCmd(), NewStatusCmd(), + NewUpCmd(), + NewDownCmd(), ) return cmd } diff --git a/cmd/operator-sdk/alpha/olm/down.go b/cmd/operator-sdk/alpha/olm/down.go new file mode 100644 index 00000000000..fabcbc2e25a --- /dev/null +++ b/cmd/operator-sdk/alpha/olm/down.go @@ -0,0 +1,44 @@ +// Copyright 2020 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package olm + +import ( + "fmt" + "log" + + olmoperator "github.com/operator-framework/operator-sdk/internal/olm/operator" + + "github.com/spf13/cobra" +) + +func NewDownCmd() *cobra.Command { + c := &olmoperator.OLMCmd{} + cmd := &cobra.Command{ + Use: "down", + Short: "Delete a running operator using the Operator Lifecycle Manager", + RunE: func(cmd *cobra.Command, args []string) error { + if len(args) != 1 { + return fmt.Errorf("command %q requires exactly one argument", cmd.CommandPath()) + } + c.ManifestsDir = args[0] + if err := c.Down(); err != nil { + log.Fatalf("Failed to delete operator: %v", err) + } + return nil + }, + } + c.AddToFlagSet(cmd.Flags()) + return cmd +} diff --git a/cmd/operator-sdk/alpha/olm/up.go b/cmd/operator-sdk/alpha/olm/up.go new file mode 100644 index 00000000000..1a94f6e0c31 --- /dev/null +++ b/cmd/operator-sdk/alpha/olm/up.go @@ -0,0 +1,44 @@ +// Copyright 2020 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package olm + +import ( + "fmt" + "log" + + olmoperator "github.com/operator-framework/operator-sdk/internal/olm/operator" + + "github.com/spf13/cobra" +) + +func NewUpCmd() *cobra.Command { + c := &olmoperator.OLMCmd{} + cmd := &cobra.Command{ + Use: "up", + Short: "Deploy an operator using the Operator Lifecycle Manager", + RunE: func(cmd *cobra.Command, args []string) error { + if len(args) != 1 { + return fmt.Errorf("command %q requires exactly one argument", cmd.CommandPath()) + } + c.ManifestsDir = args[0] + if err := c.Up(); err != nil { + log.Fatalf("Failed to deploy operator: %v", err) + } + return nil + }, + } + c.AddToFlagSet(cmd.Flags()) + return cmd +} From 664af4389071b66b1359d135dc827dc68c9e677c Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Mon, 13 Jan 2020 13:18:12 -0800 Subject: [PATCH 2/4] CHANGELOG.md,doc/cli: add olm up/down additions --- CHANGELOG.md | 2 ++ doc/cli/operator-sdk_alpha.md | 2 +- doc/cli/operator-sdk_alpha_olm.md | 6 +++-- doc/cli/operator-sdk_alpha_olm_down.md | 29 +++++++++++++++++++++ doc/cli/operator-sdk_alpha_olm_install.md | 2 +- doc/cli/operator-sdk_alpha_olm_status.md | 2 +- doc/cli/operator-sdk_alpha_olm_uninstall.md | 2 +- doc/cli/operator-sdk_alpha_olm_up.md | 29 +++++++++++++++++++++ 8 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 doc/cli/operator-sdk_alpha_olm_down.md create mode 100644 doc/cli/operator-sdk_alpha_olm_up.md diff --git a/CHANGELOG.md b/CHANGELOG.md index b6562e4be62..3d9ffc3d117 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Added +- Added [`olm up`](./doc/cli/operator-sdk_alpha_olm_up.md) amd [`olm down`](./doc/cli/operator-sdk_alpha_olm_down.md) subcommands (under the `alpha` subcommand) to manage deployment/deletion of operators. These commands currently interact with OLM via an in-cluster registry-server created using an operator's on-disk manifests and managed by `operator-sdk`. ([#2402](ttps://github.com/operator-framework/operator-sdk/pull/2402)) + ### Changed ### Deprecated diff --git a/doc/cli/operator-sdk_alpha.md b/doc/cli/operator-sdk_alpha.md index cf209d2b328..dd06e3ee093 100644 --- a/doc/cli/operator-sdk_alpha.md +++ b/doc/cli/operator-sdk_alpha.md @@ -15,5 +15,5 @@ Run an alpha subcommand ### SEE ALSO * [operator-sdk](operator-sdk.md) - An SDK for building operators with ease -* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation in your cluster +* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation and Operators in your cluster diff --git a/doc/cli/operator-sdk_alpha_olm.md b/doc/cli/operator-sdk_alpha_olm.md index f65d097ae95..684e0cfdd6c 100644 --- a/doc/cli/operator-sdk_alpha_olm.md +++ b/doc/cli/operator-sdk_alpha_olm.md @@ -1,10 +1,10 @@ ## operator-sdk alpha olm -Manage the Operator Lifecycle Manager installation in your cluster +Manage the Operator Lifecycle Manager installation and Operators in your cluster ### Synopsis -Manage the Operator Lifecycle Manager installation in your cluster +Manage the Operator Lifecycle Manager installation and Operators in your cluster ### Options @@ -15,7 +15,9 @@ Manage the Operator Lifecycle Manager installation in your cluster ### SEE ALSO * [operator-sdk alpha](operator-sdk_alpha.md) - Run an alpha subcommand +* [operator-sdk alpha olm down](operator-sdk_alpha_olm_down.md) - Delete a running operator using the Operator Lifecycle Manager * [operator-sdk alpha olm install](operator-sdk_alpha_olm_install.md) - Install Operator Lifecycle Manager in your cluster * [operator-sdk alpha olm status](operator-sdk_alpha_olm_status.md) - Get the status of the Operator Lifecycle Manager installation in your cluster * [operator-sdk alpha olm uninstall](operator-sdk_alpha_olm_uninstall.md) - Uninstall Operator Lifecycle Manager from your cluster +* [operator-sdk alpha olm up](operator-sdk_alpha_olm_up.md) - Deploy an operator using the Operator Lifecycle Manager diff --git a/doc/cli/operator-sdk_alpha_olm_down.md b/doc/cli/operator-sdk_alpha_olm_down.md new file mode 100644 index 00000000000..18342a81cce --- /dev/null +++ b/doc/cli/operator-sdk_alpha_olm_down.md @@ -0,0 +1,29 @@ +## operator-sdk alpha olm down + +Delete a running operator using the Operator Lifecycle Manager + +### Synopsis + +Delete a running operator using the Operator Lifecycle Manager + +``` +operator-sdk alpha olm down [flags] +``` + +### Options + +``` + --force-registry Force deletion of the in-cluster registry. This option is a no-op on 'up'. + -h, --help help for down + --include strings Path to Kubernetes resource manifests, ex. Role, Subscription. These supplement or override defaults generated by up/down + --install-mode string InstallMode to create OperatorGroup with. Format: InstallModeType=[ns1,ns2[, ...]] + --kubeconfig string Path to kubeconfig + --namespace string Namespace in which to create resources + --operator-version string Version of operator to deploy + --timeout duration Time to wait for the command to complete before failing (default 2m0s) +``` + +### SEE ALSO + +* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation and Operators in your cluster + diff --git a/doc/cli/operator-sdk_alpha_olm_install.md b/doc/cli/operator-sdk_alpha_olm_install.md index aa62474d40f..a4cc724c7f6 100644 --- a/doc/cli/operator-sdk_alpha_olm_install.md +++ b/doc/cli/operator-sdk_alpha_olm_install.md @@ -20,5 +20,5 @@ operator-sdk alpha olm install [flags] ### SEE ALSO -* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation in your cluster +* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation and Operators in your cluster diff --git a/doc/cli/operator-sdk_alpha_olm_status.md b/doc/cli/operator-sdk_alpha_olm_status.md index 52bc68703b7..adba608b346 100644 --- a/doc/cli/operator-sdk_alpha_olm_status.md +++ b/doc/cli/operator-sdk_alpha_olm_status.md @@ -19,5 +19,5 @@ operator-sdk alpha olm status [flags] ### SEE ALSO -* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation in your cluster +* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation and Operators in your cluster diff --git a/doc/cli/operator-sdk_alpha_olm_uninstall.md b/doc/cli/operator-sdk_alpha_olm_uninstall.md index b74539dd087..31d32d271c0 100644 --- a/doc/cli/operator-sdk_alpha_olm_uninstall.md +++ b/doc/cli/operator-sdk_alpha_olm_uninstall.md @@ -19,5 +19,5 @@ operator-sdk alpha olm uninstall [flags] ### SEE ALSO -* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation in your cluster +* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation and Operators in your cluster diff --git a/doc/cli/operator-sdk_alpha_olm_up.md b/doc/cli/operator-sdk_alpha_olm_up.md new file mode 100644 index 00000000000..0e5c37c90c8 --- /dev/null +++ b/doc/cli/operator-sdk_alpha_olm_up.md @@ -0,0 +1,29 @@ +## operator-sdk alpha olm up + +Deploy an operator using the Operator Lifecycle Manager + +### Synopsis + +Deploy an operator using the Operator Lifecycle Manager + +``` +operator-sdk alpha olm up [flags] +``` + +### Options + +``` + --force-registry Force deletion of the in-cluster registry. This option is a no-op on 'up'. + -h, --help help for up + --include strings Path to Kubernetes resource manifests, ex. Role, Subscription. These supplement or override defaults generated by up/down + --install-mode string InstallMode to create OperatorGroup with. Format: InstallModeType=[ns1,ns2[, ...]] + --kubeconfig string Path to kubeconfig + --namespace string Namespace in which to create resources + --operator-version string Version of operator to deploy + --timeout duration Time to wait for the command to complete before failing (default 2m0s) +``` + +### SEE ALSO + +* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation and Operators in your cluster + From eb6f89a89d85f78f3a6d659c200d8dad2ebb231f Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Tue, 14 Jan 2020 15:53:11 -0800 Subject: [PATCH 3/4] up/down -> run/cleanup --- CHANGELOG.md | 2 +- .../alpha/{olm/up.go => cleanup/cmd.go} | 31 +++++++++++-------- cmd/operator-sdk/alpha/cmd.go | 4 +++ cmd/operator-sdk/alpha/olm/cmd.go | 4 +-- .../alpha/{olm/down.go => run/cmd.go} | 31 +++++++++++-------- doc/cli/operator-sdk_alpha.md | 4 ++- ...lm_up.md => operator-sdk_alpha_cleanup.md} | 14 +++++---- doc/cli/operator-sdk_alpha_olm.md | 6 ++-- doc/cli/operator-sdk_alpha_olm_install.md | 2 +- doc/cli/operator-sdk_alpha_olm_status.md | 2 +- doc/cli/operator-sdk_alpha_olm_uninstall.md | 2 +- ..._olm_down.md => operator-sdk_alpha_run.md} | 14 +++++---- internal/olm/operator/manager.go | 4 +-- internal/olm/operator/operator.go | 11 ++++--- test/integration/operator_olm_test.go | 16 +++++----- 15 files changed, 82 insertions(+), 65 deletions(-) rename cmd/operator-sdk/alpha/{olm/up.go => cleanup/cmd.go} (61%) rename cmd/operator-sdk/alpha/{olm/down.go => run/cmd.go} (62%) rename doc/cli/{operator-sdk_alpha_olm_up.md => operator-sdk_alpha_cleanup.md} (60%) rename doc/cli/{operator-sdk_alpha_olm_down.md => operator-sdk_alpha_run.md} (61%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22c02a7f4b8..224701fef4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Added -- Added [`olm up`](./doc/cli/operator-sdk_alpha_olm_up.md) amd [`olm down`](./doc/cli/operator-sdk_alpha_olm_down.md) subcommands (under the `alpha` subcommand) to manage deployment/deletion of operators. These commands currently interact with OLM via an in-cluster registry-server created using an operator's on-disk manifests and managed by `operator-sdk`. ([#2402](ttps://github.com/operator-framework/operator-sdk/pull/2402)) +- Added [`run`](./doc/cli/operator-sdk_alpha_run.md) amd [`cleanup`](./doc/cli/operator-sdk_alpha_cleanup.md) subcommands (under the `alpha` subcommand) to manage deployment/deletion of operators. These commands currently interact with OLM via an in-cluster registry-server created using an operator's on-disk manifests and managed by `operator-sdk`. ([#2402](ttps://github.com/operator-framework/operator-sdk/pull/2402)) ### Changed diff --git a/cmd/operator-sdk/alpha/olm/up.go b/cmd/operator-sdk/alpha/cleanup/cmd.go similarity index 61% rename from cmd/operator-sdk/alpha/olm/up.go rename to cmd/operator-sdk/alpha/cleanup/cmd.go index 1a94f6e0c31..9477cea40a3 100644 --- a/cmd/operator-sdk/alpha/olm/up.go +++ b/cmd/operator-sdk/alpha/cleanup/cmd.go @@ -12,33 +12,38 @@ // See the License for the specific language governing permissions and // limitations under the License. -package olm +package cleanup import ( - "fmt" - "log" - olmoperator "github.com/operator-framework/operator-sdk/internal/olm/operator" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) -func NewUpCmd() *cobra.Command { +type cleanupArgs struct { + olm bool +} + +func NewCmd() *cobra.Command { + cargs := &cleanupArgs{} c := &olmoperator.OLMCmd{} cmd := &cobra.Command{ - Use: "up", - Short: "Deploy an operator using the Operator Lifecycle Manager", + Use: "cleanup", + Short: "Delete and clean up after a running Operator", RunE: func(cmd *cobra.Command, args []string) error { - if len(args) != 1 { - return fmt.Errorf("command %q requires exactly one argument", cmd.CommandPath()) - } - c.ManifestsDir = args[0] - if err := c.Up(); err != nil { - log.Fatalf("Failed to deploy operator: %v", err) + switch { + case cargs.olm: + if err := c.Cleanup(); err != nil { + log.Fatalf("Failed to clean up operator: %v", err) + } } return nil }, } + // OLM is the default. + cmd.Flags().BoolVar(&cargs.olm, "olm", true, "The operator to be deleted is managed by OLM in a cluster.") + // TODO(estroz): refactor flag setting when new run mode options are added. c.AddToFlagSet(cmd.Flags()) return cmd } diff --git a/cmd/operator-sdk/alpha/cmd.go b/cmd/operator-sdk/alpha/cmd.go index ae471b0c398..de359bb4b6d 100644 --- a/cmd/operator-sdk/alpha/cmd.go +++ b/cmd/operator-sdk/alpha/cmd.go @@ -15,8 +15,10 @@ package alpha import ( + "github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha/cleanup" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha/kubebuilder" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha/olm" + run "github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha/run" "github.com/spf13/cobra" ) @@ -30,6 +32,8 @@ func NewCmd() *cobra.Command { cmd.AddCommand( olm.NewCmd(), kubebuilder.NewCmd(), + run.NewCmd(), + cleanup.NewCmd(), ) return cmd } diff --git a/cmd/operator-sdk/alpha/olm/cmd.go b/cmd/operator-sdk/alpha/olm/cmd.go index 03242337ade..13fb3c00f1f 100644 --- a/cmd/operator-sdk/alpha/olm/cmd.go +++ b/cmd/operator-sdk/alpha/olm/cmd.go @@ -21,14 +21,12 @@ import ( func NewCmd() *cobra.Command { cmd := &cobra.Command{ Use: "olm", - Short: "Manage the Operator Lifecycle Manager installation and Operators in your cluster", + Short: "Manage the Operator Lifecycle Manager installation in your cluster", } cmd.AddCommand( NewInstallCmd(), NewUninstallCmd(), NewStatusCmd(), - NewUpCmd(), - NewDownCmd(), ) return cmd } diff --git a/cmd/operator-sdk/alpha/olm/down.go b/cmd/operator-sdk/alpha/run/cmd.go similarity index 62% rename from cmd/operator-sdk/alpha/olm/down.go rename to cmd/operator-sdk/alpha/run/cmd.go index fabcbc2e25a..46e2028f8b2 100644 --- a/cmd/operator-sdk/alpha/olm/down.go +++ b/cmd/operator-sdk/alpha/run/cmd.go @@ -12,33 +12,38 @@ // See the License for the specific language governing permissions and // limitations under the License. -package olm +package run import ( - "fmt" - "log" - olmoperator "github.com/operator-framework/operator-sdk/internal/olm/operator" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) -func NewDownCmd() *cobra.Command { +type runArgs struct { + olm bool +} + +func NewCmd() *cobra.Command { + cargs := &runArgs{} c := &olmoperator.OLMCmd{} cmd := &cobra.Command{ - Use: "down", - Short: "Delete a running operator using the Operator Lifecycle Manager", + Use: "run", + Short: "Run an Operator in a variety of environments", RunE: func(cmd *cobra.Command, args []string) error { - if len(args) != 1 { - return fmt.Errorf("command %q requires exactly one argument", cmd.CommandPath()) - } - c.ManifestsDir = args[0] - if err := c.Down(); err != nil { - log.Fatalf("Failed to delete operator: %v", err) + switch { + case cargs.olm: + if err := c.Run(); err != nil { + log.Fatalf("Failed to run operator: %v", err) + } } return nil }, } + // OLM is the default. + cmd.Flags().BoolVar(&cargs.olm, "olm", true, "The operator to be run will be managed by OLM in a cluster.") + // TODO(estroz): refactor flag setting when new run mode options are added. c.AddToFlagSet(cmd.Flags()) return cmd } diff --git a/doc/cli/operator-sdk_alpha.md b/doc/cli/operator-sdk_alpha.md index dd06e3ee093..eccadab732a 100644 --- a/doc/cli/operator-sdk_alpha.md +++ b/doc/cli/operator-sdk_alpha.md @@ -15,5 +15,7 @@ Run an alpha subcommand ### SEE ALSO * [operator-sdk](operator-sdk.md) - An SDK for building operators with ease -* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation and Operators in your cluster +* [operator-sdk alpha cleanup](operator-sdk_alpha_cleanup.md) - Delete and clean up after a running Operator +* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation in your cluster +* [operator-sdk alpha run](operator-sdk_alpha_run.md) - Run an Operator in a variety of environments diff --git a/doc/cli/operator-sdk_alpha_olm_up.md b/doc/cli/operator-sdk_alpha_cleanup.md similarity index 60% rename from doc/cli/operator-sdk_alpha_olm_up.md rename to doc/cli/operator-sdk_alpha_cleanup.md index 0e5c37c90c8..154fb1f36d1 100644 --- a/doc/cli/operator-sdk_alpha_olm_up.md +++ b/doc/cli/operator-sdk_alpha_cleanup.md @@ -1,29 +1,31 @@ -## operator-sdk alpha olm up +## operator-sdk alpha cleanup -Deploy an operator using the Operator Lifecycle Manager +Delete and clean up after a running Operator ### Synopsis -Deploy an operator using the Operator Lifecycle Manager +Delete and clean up after a running Operator ``` -operator-sdk alpha olm up [flags] +operator-sdk alpha cleanup [flags] ``` ### Options ``` --force-registry Force deletion of the in-cluster registry. This option is a no-op on 'up'. - -h, --help help for up + -h, --help help for cleanup --include strings Path to Kubernetes resource manifests, ex. Role, Subscription. These supplement or override defaults generated by up/down --install-mode string InstallMode to create OperatorGroup with. Format: InstallModeType=[ns1,ns2[, ...]] --kubeconfig string Path to kubeconfig + --manifests string Directory containing package manifest and operator bundles. --namespace string Namespace in which to create resources + --olm The operator to be deleted is managed by OLM in a cluster. (default true) --operator-version string Version of operator to deploy --timeout duration Time to wait for the command to complete before failing (default 2m0s) ``` ### SEE ALSO -* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation and Operators in your cluster +* [operator-sdk alpha](operator-sdk_alpha.md) - Run an alpha subcommand diff --git a/doc/cli/operator-sdk_alpha_olm.md b/doc/cli/operator-sdk_alpha_olm.md index 684e0cfdd6c..f65d097ae95 100644 --- a/doc/cli/operator-sdk_alpha_olm.md +++ b/doc/cli/operator-sdk_alpha_olm.md @@ -1,10 +1,10 @@ ## operator-sdk alpha olm -Manage the Operator Lifecycle Manager installation and Operators in your cluster +Manage the Operator Lifecycle Manager installation in your cluster ### Synopsis -Manage the Operator Lifecycle Manager installation and Operators in your cluster +Manage the Operator Lifecycle Manager installation in your cluster ### Options @@ -15,9 +15,7 @@ Manage the Operator Lifecycle Manager installation and Operators in your cluster ### SEE ALSO * [operator-sdk alpha](operator-sdk_alpha.md) - Run an alpha subcommand -* [operator-sdk alpha olm down](operator-sdk_alpha_olm_down.md) - Delete a running operator using the Operator Lifecycle Manager * [operator-sdk alpha olm install](operator-sdk_alpha_olm_install.md) - Install Operator Lifecycle Manager in your cluster * [operator-sdk alpha olm status](operator-sdk_alpha_olm_status.md) - Get the status of the Operator Lifecycle Manager installation in your cluster * [operator-sdk alpha olm uninstall](operator-sdk_alpha_olm_uninstall.md) - Uninstall Operator Lifecycle Manager from your cluster -* [operator-sdk alpha olm up](operator-sdk_alpha_olm_up.md) - Deploy an operator using the Operator Lifecycle Manager diff --git a/doc/cli/operator-sdk_alpha_olm_install.md b/doc/cli/operator-sdk_alpha_olm_install.md index a4cc724c7f6..aa62474d40f 100644 --- a/doc/cli/operator-sdk_alpha_olm_install.md +++ b/doc/cli/operator-sdk_alpha_olm_install.md @@ -20,5 +20,5 @@ operator-sdk alpha olm install [flags] ### SEE ALSO -* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation and Operators in your cluster +* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation in your cluster diff --git a/doc/cli/operator-sdk_alpha_olm_status.md b/doc/cli/operator-sdk_alpha_olm_status.md index adba608b346..52bc68703b7 100644 --- a/doc/cli/operator-sdk_alpha_olm_status.md +++ b/doc/cli/operator-sdk_alpha_olm_status.md @@ -19,5 +19,5 @@ operator-sdk alpha olm status [flags] ### SEE ALSO -* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation and Operators in your cluster +* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation in your cluster diff --git a/doc/cli/operator-sdk_alpha_olm_uninstall.md b/doc/cli/operator-sdk_alpha_olm_uninstall.md index 31d32d271c0..b74539dd087 100644 --- a/doc/cli/operator-sdk_alpha_olm_uninstall.md +++ b/doc/cli/operator-sdk_alpha_olm_uninstall.md @@ -19,5 +19,5 @@ operator-sdk alpha olm uninstall [flags] ### SEE ALSO -* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation and Operators in your cluster +* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation in your cluster diff --git a/doc/cli/operator-sdk_alpha_olm_down.md b/doc/cli/operator-sdk_alpha_run.md similarity index 61% rename from doc/cli/operator-sdk_alpha_olm_down.md rename to doc/cli/operator-sdk_alpha_run.md index 18342a81cce..e036c9ce082 100644 --- a/doc/cli/operator-sdk_alpha_olm_down.md +++ b/doc/cli/operator-sdk_alpha_run.md @@ -1,29 +1,31 @@ -## operator-sdk alpha olm down +## operator-sdk alpha run -Delete a running operator using the Operator Lifecycle Manager +Run an Operator in a variety of environments ### Synopsis -Delete a running operator using the Operator Lifecycle Manager +Run an Operator in a variety of environments ``` -operator-sdk alpha olm down [flags] +operator-sdk alpha run [flags] ``` ### Options ``` --force-registry Force deletion of the in-cluster registry. This option is a no-op on 'up'. - -h, --help help for down + -h, --help help for run --include strings Path to Kubernetes resource manifests, ex. Role, Subscription. These supplement or override defaults generated by up/down --install-mode string InstallMode to create OperatorGroup with. Format: InstallModeType=[ns1,ns2[, ...]] --kubeconfig string Path to kubeconfig + --manifests string Directory containing package manifest and operator bundles. --namespace string Namespace in which to create resources + --olm The operator to be run will be managed by OLM in a cluster. (default true) --operator-version string Version of operator to deploy --timeout duration Time to wait for the command to complete before failing (default 2m0s) ``` ### SEE ALSO -* [operator-sdk alpha olm](operator-sdk_alpha_olm.md) - Manage the Operator Lifecycle Manager installation and Operators in your cluster +* [operator-sdk alpha](operator-sdk_alpha.md) - Run an alpha subcommand diff --git a/internal/olm/operator/manager.go b/internal/olm/operator/manager.go index 8374a700dae..2f9c4659bdc 100644 --- a/internal/olm/operator/manager.go +++ b/internal/olm/operator/manager.go @@ -130,7 +130,7 @@ func (c *OLMCmd) newManager() (*operatorManager, error) { return m, nil } -func (m *operatorManager) up(ctx context.Context) (err error) { +func (m *operatorManager) run(ctx context.Context) (err error) { // Ensure OLM is installed. olmVer, err := m.client.GetInstalledVersion(ctx) if err != nil { @@ -221,7 +221,7 @@ func (m *operatorManager) up(ctx context.Context) (err error) { return nil } -func (m *operatorManager) down(ctx context.Context) (err error) { +func (m *operatorManager) cleanup(ctx context.Context) (err error) { // Ensure OLM is installed. olmVer, err := m.client.GetInstalledVersion(ctx) if err != nil { diff --git a/internal/olm/operator/operator.go b/internal/olm/operator/operator.go index 550f5419a89..cfcd0c319f1 100644 --- a/internal/olm/operator/operator.go +++ b/internal/olm/operator/operator.go @@ -36,7 +36,7 @@ const ( type OLMCmd struct { // nolint:golint // ManifestsDir is a directory containing a package manifest and N bundles // of the operator's CSV and CRD's. OperatorVersion can be set to the - // version of the desired operator version's subdir and Up()/Down() will + // version of the desired operator version's subdir and Run()/Down() will // deploy the operator version in that subdir. ManifestsDir string // OperatorVersion is the version of the operator to deploy. It must be @@ -85,6 +85,7 @@ type OLMCmd struct { // nolint:golint var installModeFormat = "InstallModeType=[ns1,ns2[, ...]]" func (c *OLMCmd) AddToFlagSet(fs *pflag.FlagSet) { + fs.StringVar(&c.ManifestsDir, "manifests", "", "Directory containing package manifest and operator bundles.") fs.StringVar(&c.OperatorVersion, "operator-version", "", "Version of operator to deploy") fs.StringVar(&c.InstallMode, "install-mode", "", "InstallMode to create OperatorGroup with. Format: "+installModeFormat) fs.StringVar(&c.KubeconfigPath, "kubeconfig", "", "Path to kubeconfig") @@ -117,7 +118,7 @@ func (c *OLMCmd) initialize() { }) } -func (c *OLMCmd) Up() error { +func (c *OLMCmd) Run() error { c.initialize() if err := c.validate(); err != nil { return fmt.Errorf("validation error: %w", err) @@ -128,10 +129,10 @@ func (c *OLMCmd) Up() error { } ctx, cancel := context.WithTimeout(context.Background(), c.Timeout) defer cancel() - return m.up(ctx) + return m.run(ctx) } -func (c *OLMCmd) Down() (err error) { +func (c *OLMCmd) Cleanup() (err error) { c.initialize() if err := c.validate(); err != nil { return fmt.Errorf("validation error: %w", err) @@ -142,5 +143,5 @@ func (c *OLMCmd) Down() (err error) { } ctx, cancel := context.WithTimeout(context.Background(), c.Timeout) defer cancel() - return m.down(ctx) + return m.cleanup(ctx) } diff --git a/test/integration/operator_olm_test.go b/test/integration/operator_olm_test.go index 5a087ab26fd..cc0a81a7c29 100644 --- a/test/integration/operator_olm_test.go +++ b/test/integration/operator_olm_test.go @@ -95,27 +95,27 @@ func SingleOperator(t *testing.T) { // Cleanup. defer func() { opcmd.ForceRegistry = true - if err := opcmd.Down(); err != nil { + if err := opcmd.Cleanup(); err != nil { t.Fatal(err) } }() // "Remove operator before deploy" - assert.NoError(t, opcmd.Down()) + assert.NoError(t, opcmd.Cleanup()) // "Remove operator before deploy (force delete registry)" opcmd.ForceRegistry = true - assert.NoError(t, opcmd.Down()) + assert.NoError(t, opcmd.Cleanup()) // "Deploy operator" - assert.NoError(t, opcmd.Up()) + assert.NoError(t, opcmd.Run()) // "Fail to deploy operator after deploy" - assert.Error(t, opcmd.Up()) + assert.Error(t, opcmd.Run()) // "Remove operator after deploy" - assert.NoError(t, opcmd.Down()) + assert.NoError(t, opcmd.Cleanup()) // "Remove operator after removal" - assert.NoError(t, opcmd.Down()) + assert.NoError(t, opcmd.Cleanup()) // "Remove operator after removal (force delete registry)" opcmd.ForceRegistry = true - assert.NoError(t, opcmd.Down()) + assert.NoError(t, opcmd.Cleanup()) } From 8405a1d58f650eb2f1cea7a7d2a56419db2eaa59 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Wed, 15 Jan 2020 13:10:23 -0800 Subject: [PATCH 4/4] fix typos --- CHANGELOG.md | 2 +- cmd/operator-sdk/alpha/cleanup/cmd.go | 1 + doc/cli/operator-sdk_alpha_cleanup.md | 4 ++-- doc/cli/operator-sdk_alpha_run.md | 3 +-- internal/olm/operator/operator.go | 5 ++--- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 224701fef4a..87ff815edad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Added -- Added [`run`](./doc/cli/operator-sdk_alpha_run.md) amd [`cleanup`](./doc/cli/operator-sdk_alpha_cleanup.md) subcommands (under the `alpha` subcommand) to manage deployment/deletion of operators. These commands currently interact with OLM via an in-cluster registry-server created using an operator's on-disk manifests and managed by `operator-sdk`. ([#2402](ttps://github.com/operator-framework/operator-sdk/pull/2402)) +- Added [`run`](./doc/cli/operator-sdk_alpha_run.md) and [`cleanup`](./doc/cli/operator-sdk_alpha_cleanup.md) subcommands (under the `alpha` subcommand) to manage deployment/deletion of operators. These commands currently interact with OLM via an in-cluster registry-server created using an operator's on-disk manifests and managed by `operator-sdk`. ([#2402](ttps://github.com/operator-framework/operator-sdk/pull/2402)) ### Changed diff --git a/cmd/operator-sdk/alpha/cleanup/cmd.go b/cmd/operator-sdk/alpha/cleanup/cmd.go index 9477cea40a3..454be7f8eae 100644 --- a/cmd/operator-sdk/alpha/cleanup/cmd.go +++ b/cmd/operator-sdk/alpha/cleanup/cmd.go @@ -45,5 +45,6 @@ func NewCmd() *cobra.Command { cmd.Flags().BoolVar(&cargs.olm, "olm", true, "The operator to be deleted is managed by OLM in a cluster.") // TODO(estroz): refactor flag setting when new run mode options are added. c.AddToFlagSet(cmd.Flags()) + cmd.Flags().BoolVar(&c.ForceRegistry, "force-registry", false, "Force deletion of the in-cluster registry.") return cmd } diff --git a/doc/cli/operator-sdk_alpha_cleanup.md b/doc/cli/operator-sdk_alpha_cleanup.md index 154fb1f36d1..d36313b0f78 100644 --- a/doc/cli/operator-sdk_alpha_cleanup.md +++ b/doc/cli/operator-sdk_alpha_cleanup.md @@ -13,9 +13,9 @@ operator-sdk alpha cleanup [flags] ### Options ``` - --force-registry Force deletion of the in-cluster registry. This option is a no-op on 'up'. + --force-registry Force deletion of the in-cluster registry. -h, --help help for cleanup - --include strings Path to Kubernetes resource manifests, ex. Role, Subscription. These supplement or override defaults generated by up/down + --include strings Path to Kubernetes resource manifests, ex. Role, Subscription. These supplement or override defaults generated by run/cleanup --install-mode string InstallMode to create OperatorGroup with. Format: InstallModeType=[ns1,ns2[, ...]] --kubeconfig string Path to kubeconfig --manifests string Directory containing package manifest and operator bundles. diff --git a/doc/cli/operator-sdk_alpha_run.md b/doc/cli/operator-sdk_alpha_run.md index e036c9ce082..5a0f58ae393 100644 --- a/doc/cli/operator-sdk_alpha_run.md +++ b/doc/cli/operator-sdk_alpha_run.md @@ -13,9 +13,8 @@ operator-sdk alpha run [flags] ### Options ``` - --force-registry Force deletion of the in-cluster registry. This option is a no-op on 'up'. -h, --help help for run - --include strings Path to Kubernetes resource manifests, ex. Role, Subscription. These supplement or override defaults generated by up/down + --include strings Path to Kubernetes resource manifests, ex. Role, Subscription. These supplement or override defaults generated by run/cleanup --install-mode string InstallMode to create OperatorGroup with. Format: InstallModeType=[ns1,ns2[, ...]] --kubeconfig string Path to kubeconfig --manifests string Directory containing package manifest and operator bundles. diff --git a/internal/olm/operator/operator.go b/internal/olm/operator/operator.go index cfcd0c319f1..664184bb22e 100644 --- a/internal/olm/operator/operator.go +++ b/internal/olm/operator/operator.go @@ -36,7 +36,7 @@ const ( type OLMCmd struct { // nolint:golint // ManifestsDir is a directory containing a package manifest and N bundles // of the operator's CSV and CRD's. OperatorVersion can be set to the - // version of the desired operator version's subdir and Run()/Down() will + // version of the desired operator version's subdir and Run()/Cleanup() will // deploy the operator version in that subdir. ManifestsDir string // OperatorVersion is the version of the operator to deploy. It must be @@ -90,9 +90,8 @@ func (c *OLMCmd) AddToFlagSet(fs *pflag.FlagSet) { fs.StringVar(&c.InstallMode, "install-mode", "", "InstallMode to create OperatorGroup with. Format: "+installModeFormat) fs.StringVar(&c.KubeconfigPath, "kubeconfig", "", "Path to kubeconfig") fs.StringVar(&c.OperatorNamespace, "namespace", "", "Namespace in which to create resources") - fs.StringSliceVar(&c.IncludePaths, "include", nil, "Path to Kubernetes resource manifests, ex. Role, Subscription. These supplement or override defaults generated by up/down") + fs.StringSliceVar(&c.IncludePaths, "include", nil, "Path to Kubernetes resource manifests, ex. Role, Subscription. These supplement or override defaults generated by run/cleanup") fs.DurationVar(&c.Timeout, "timeout", defaultTimeout, "Time to wait for the command to complete before failing") - fs.BoolVar(&c.ForceRegistry, "force-registry", false, "Force deletion of the in-cluster registry. This option is a no-op on 'up'.") } func (c *OLMCmd) validate() error {