Skip to content

Commit

Permalink
up/down -> run/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
estroz committed Jan 14, 2020
1 parent 7807c8b commit eb6f89a
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 65 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions cmd/operator-sdk/alpha/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -30,6 +32,8 @@ func NewCmd() *cobra.Command {
cmd.AddCommand(
olm.NewCmd(),
kubebuilder.NewCmd(),
run.NewCmd(),
cleanup.NewCmd(),
)
return cmd
}
4 changes: 1 addition & 3 deletions cmd/operator-sdk/alpha/olm/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion doc/cli/operator-sdk_alpha.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
@@ -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

6 changes: 2 additions & 4 deletions doc/cli/operator-sdk_alpha_olm.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

2 changes: 1 addition & 1 deletion doc/cli/operator-sdk_alpha_olm_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion doc/cli/operator-sdk_alpha_olm_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion doc/cli/operator-sdk_alpha_olm_uninstall.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
@@ -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

4 changes: 2 additions & 2 deletions internal/olm/operator/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions internal/olm/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
16 changes: 8 additions & 8 deletions test/integration/operator_olm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit eb6f89a

Please sign in to comment.