Skip to content
New issue

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

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

Already on GitHub? # to your account

cmd/operator-sdk: run and cleanup commands #2441

Merged
merged 13 commits into from
Jan 21, 2020
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

### Added

- 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](https://github.com/operator-framework/operator-sdk/pull/2402))
- Added the [`cleanup`](./doc/cli/operator-sdk_cleanup.md) subcommand and [`run --olm`](./doc/cli/operator-sdk_run.md) 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](https://github.com/operator-framework/operator-sdk/pull/2402), [#2441](https://github.com/operator-framework/operator-sdk/pull/2441))
- Added [`bundle create`](./doc/cli/operator-sdk_bundle_create.md) which builds, and optionally generates metadata for, [operator bundle images](https://github.com/openshift/enhancements/blob/ec2cf96/enhancements/olm/operator-registry.md). ([#2076](https://github.com/operator-framework/operator-sdk/pull/2076), [#2438](https://github.com/operator-framework/operator-sdk/pull/2438))

### Changed

- Changed error wrapping according to Go version 1.13+ [error handling](https://blog.golang.org/go1.13-errors). ([#2355](https://github.com/operator-framework/operator-sdk/pull/2355))
- Added retry logic to the cleanup function from the e2e test framework in order to allow it to be achieved in the scenarios where temporary network issues are faced. ([#2277](https://github.com/operator-framework/operator-sdk/pull/2277))
- Moved `olm-catalog gen-csv` to the `generate csv` subcommand. ([#2439](https://github.com/operator-framework/operator-sdk/pull/2439))
- `run ansible/helm` are now the hidden commands `exec-entrypoint ansible/helm`. All functionality of each subcommand is the same. ([#2441](https://github.com/operator-framework/operator-sdk/pull/2441))
- `up local` is now [`run --local`](./doc/cli/operator-sdk_run.md). All functionality of this command is the same. ([#2441](https://github.com/operator-framework/operator-sdk/pull/2441))

### Deprecated

Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The following workflow is for a new **Helm** operator:
- Alternatively [podman][podman_tool] `v1.2.0+` or [buildah][buildah_tool] `v1.7+`
- [kubectl][kubectl_tool] version v1.12.0+.
- Access to a Kubernetes v1.12.0+ cluster.
- Optional: [delve](https://github.com/go-delve/delve/tree/master/Documentation/installation) version 1.2.0+ (for `up local --enable-delve`).
- Optional: [delve](https://github.com/go-delve/delve/tree/master/Documentation/installation) version 1.2.0+ (for `run --local --enable-delve`).

## Quick Start

Expand Down Expand Up @@ -134,7 +134,7 @@ $ kubectl delete -f deploy/crds/app.example.com_appservices_crd.yaml
```

**Note:** Follow the steps in the [Getting Started Repository][getting_started] to learn how to develop your Operator projects.

## Command Line Interface

To learn more about the SDK CLI, see the [SDK CLI Reference][sdk_cli_ref], or run `operator-sdk [command] -h`.
Expand Down Expand Up @@ -196,4 +196,3 @@ Operator SDK is under Apache 2.0 license. See the [LICENSE][license_file] file f
[helm_user_guide]:./doc/helm/user-guide.md
[faq]: ./doc/faq.md
[getting_started]: https://github.com/operator-framework/getting-started/blob/master/README.md

50 changes: 0 additions & 50 deletions cmd/operator-sdk/alpha/cleanup/cmd.go

This file was deleted.

6 changes: 1 addition & 5 deletions cmd/operator-sdk/alpha/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
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,10 +28,8 @@ func NewCmd() *cobra.Command {
}

cmd.AddCommand(
olm.NewCmd(),
kubebuilder.NewCmd(),
run.NewCmd(),
cleanup.NewCmd(),
olm.NewCmd(),
)
return cmd
}
49 changes: 0 additions & 49 deletions cmd/operator-sdk/alpha/run/cmd.go

This file was deleted.

93 changes: 93 additions & 0 deletions cmd/operator-sdk/cleanup/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// 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 cleanup

import (
"errors"
"path/filepath"

olmcatalog "github.com/operator-framework/operator-sdk/internal/generate/olm-catalog"
olmoperator "github.com/operator-framework/operator-sdk/internal/olm/operator"
"github.com/operator-framework/operator-sdk/internal/util/projutil"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

type cleanupCmd struct {
// Common options.
kubeconfig string
namespace string

// Cleanup type.
olm bool

// Cleanup type-specific options.
olmArgs olmoperator.OLMCmd
}

// checkCleanupType ensures exactly one cleanup type has been selected.
func (c *cleanupCmd) checkCleanupType() error {
if !c.olm {
return errors.New("exactly one run-type flag must be set: --olm")
}
return nil
}

func NewCmd() *cobra.Command {
c := &cleanupCmd{}
cmd := &cobra.Command{
Use: "cleanup",
Short: "Delete and clean up after a running Operator",
RunE: func(cmd *cobra.Command, args []string) error {
if err := c.checkCleanupType(); err != nil {
return err
}
projutil.MustInProjectRoot()

switch {
case c.olm:
c.olmArgs.KubeconfigPath = c.kubeconfig
c.olmArgs.OperatorNamespace = c.namespace
if c.olmArgs.ManifestsDir == "" {
operatorName := filepath.Base(projutil.MustGetwd())
c.olmArgs.ManifestsDir = filepath.Join(olmcatalog.OLMCatalogDir, operatorName)
}
if err := c.olmArgs.Cleanup(); err != nil {
log.Fatalf("Failed to clean up operator using OLM: %v", err)
}
}
return nil
},
}

// Avoid sorting flags so we can group them according to cleanup type.
cmd.Flags().SortFlags = false

// Shared flags.
cmd.Flags().StringVar(&c.kubeconfig, "kubeconfig", "",
"The file path to kubernetes configuration file. Defaults to location "+
"specified by $KUBECONFIG, or to default file rules if not set")
cmd.Flags().StringVar(&c.namespace, "namespace", "",
"The namespace where the operator watches for changes.")

// 'cleanup --olm' and related flags. Set as default since this is the only
// cleanup type.
cmd.Flags().BoolVar(&c.olm, "olm", true,
"The operator to be cleaned up is managed by OLM in a cluster. "+
"Cannot be set with another cleanup-type flag")
c.olmArgs.AddToFlagSet(cmd.Flags())
return cmd
}
8 changes: 5 additions & 3 deletions cmd/operator-sdk/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@ package cli
import (

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that `run` and `up local` can make use of them.
// to ensure that `exec-entrypoint` and `run` can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/operator-framework/operator-sdk/cmd/operator-sdk/add"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/build"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/bundle"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/cleanup"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/completion"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/execentrypoint"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/migrate"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/new"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/printdeps"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/run"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/scorecard"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/test"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/up"
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/version"
"github.com/operator-framework/operator-sdk/internal/flags"
"github.com/operator-framework/operator-sdk/internal/util/projutil"
Expand Down Expand Up @@ -65,15 +66,16 @@ func GetCLIRoot() *cobra.Command {
root.AddCommand(alpha.NewCmd())
root.AddCommand(build.NewCmd())
root.AddCommand(bundle.NewCmd())
root.AddCommand(cleanup.NewCmd())
root.AddCommand(completion.NewCmd())
root.AddCommand(execentrypoint.NewCmd())
root.AddCommand(generate.NewCmd())
root.AddCommand(migrate.NewCmd())
root.AddCommand(new.NewCmd())
root.AddCommand(printdeps.NewCmd())
root.AddCommand(run.NewCmd())
root.AddCommand(scorecard.NewCmd())
root.AddCommand(test.NewCmd())
root.AddCommand(up.NewCmd())
root.AddCommand(version.NewCmd())

return root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package run
package execentrypoint

import (
"github.com/operator-framework/operator-sdk/pkg/ansible"
Expand All @@ -31,7 +31,7 @@ func newRunAnsibleCmd() *cobra.Command {
Short: "Runs as an ansible operator",
Long: `Runs as an ansible operator. This is intended to be used when running
in a Pod inside a cluster. Developers wanting to run their operator locally
should use "up local" instead.`,
should use "run --local" instead.`,
RunE: func(cmd *cobra.Command, args []string) error {
logf.SetLogger(zap.Logger())

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 The Operator-SDK Authors
// Copyright 2019 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.
Expand All @@ -12,20 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package up
package execentrypoint

import (
"github.com/spf13/cobra"
)
import "github.com/spf13/cobra"

// NewCmd returns a command that contains subcommands to run specific
// operator types.
func NewCmd() *cobra.Command {
upCmd := &cobra.Command{
Use: "up",
Short: "Launches the operator",
Long: `The up command has subcommands that can launch the operator in various ways.
`,
cmd := &cobra.Command{
Use: "exec-entrypoint",
Short: "Runs a generic operator",
Long: `Runs a generic operator. This is intended to be used when running
in a Pod inside a cluster. Developers wanting to run their operator locally
should use "run --local" instead.`,
Hidden: true,
}

upCmd.AddCommand(newLocalCmd())
return upCmd
cmd.AddCommand(
newRunAnsibleCmd(),
newRunHelmCmd(),
)
return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package run
package execentrypoint

import (
"github.com/operator-framework/operator-sdk/pkg/helm"
Expand All @@ -31,7 +31,7 @@ func newRunHelmCmd() *cobra.Command {
Short: "Runs as a helm operator",
Long: `Runs as a helm operator. This is intended to be used when running
in a Pod inside a cluster. Developers wanting to run their operator locally
should use "up local" instead.`,
should use "run --local" instead.`,
RunE: func(cmd *cobra.Command, args []string) error {
logf.SetLogger(zap.Logger())

Expand Down
2 changes: 1 addition & 1 deletion cmd/operator-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"os"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that `run` and `up local` can make use of them.
// to ensure that `exec-entrypoint` and `run` can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/operator-framework/operator-sdk/cmd/operator-sdk/cli"
Expand Down
Loading