-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
cmd/operator-sdk: OLM integration alpha run/cleanup
CLI
#2402
Changes from 4 commits
27a3735
664af43
7807c8b
eb6f89a
8405a1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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 ( | ||
olmoperator "github.com/operator-framework/operator-sdk/internal/olm/operator" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type cleanupArgs struct { | ||
olm bool | ||
} | ||
|
||
func NewCmd() *cobra.Command { | ||
cargs := &cleanupArgs{} | ||
c := &olmoperator.OLMCmd{} | ||
cmd := &cobra.Command{ | ||
Use: "cleanup", | ||
Short: "Delete and clean up after a running Operator", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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 run | ||
|
||
import ( | ||
olmoperator "github.com/operator-framework/operator-sdk/internal/olm/operator" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type runArgs struct { | ||
olm bool | ||
} | ||
|
||
func NewCmd() *cobra.Command { | ||
cargs := &runArgs{} | ||
c := &olmoperator.OLMCmd{} | ||
cmd := &cobra.Command{ | ||
Use: "run", | ||
Short: "Run an Operator in a variety of environments", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## operator-sdk alpha cleanup | ||
|
||
Delete and clean up after a running Operator | ||
|
||
### Synopsis | ||
|
||
Delete and clean up after a running Operator | ||
|
||
``` | ||
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 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](operator-sdk_alpha.md) - Run an alpha subcommand | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,31 @@ | ||||||
## operator-sdk alpha run | ||||||
|
||||||
Run an Operator in a variety of environments | ||||||
|
||||||
### Synopsis | ||||||
|
||||||
Run an Operator in a variety of environments | ||||||
|
||||||
``` | ||||||
operator-sdk alpha run [flags] | ||||||
``` | ||||||
|
||||||
### Options | ||||||
|
||||||
``` | ||||||
--force-registry Force deletion of the in-cluster registry. This option is a no-op on 'up'. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious about this: Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This flag should be specific to |
||||||
-h, --help help for run | ||||||
--include strings Path to Kubernetes resource manifests, ex. Role, Subscription. These supplement or override defaults generated by up/down | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
--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](operator-sdk_alpha.md) - Run an alpha subcommand | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// 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) | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.