Skip to content

Commit

Permalink
EVEREST-1769 | [CLI] unify behavior of provisioning DB namespaces bet…
Browse files Browse the repository at this point in the history
…ween CLI and Helm (#948)

Signed-off-by: Mayank Shah <[email protected]>
  • Loading branch information
mayankshah1607 authored Dec 20, 2024
1 parent f0f73dd commit d7539ab
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cli-tests/tests/flow/namespaces.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test.describe('Everest CLI install', async () => {

await test.step('run everest install (no database namespace))', async () => {
const out = await cli.everestExecSkipWizard(
`install`,
`install --skip-db-namespace`,
);

await out.assertSuccess();
Expand Down
26 changes: 18 additions & 8 deletions commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ func newInstallCmd(l *zap.SugaredLogger) *cobra.Command {
}
c.CLIOptions.BindViperFlags()

if c.SkipDBNamespace {
if cmd.Flags().Lookup(cli.FlagNamespaces).Changed {
l.Errorf("cannot set both --%s and --%s", cli.FlagInstallSkipDBNamespace, cli.FlagNamespaces)
os.Exit(1)
}
c.Namespaces = ""
}

enableLogging := viper.GetBool("verbose") || viper.GetBool("json")
c.Pretty = !enableLogging

Expand All @@ -71,13 +79,14 @@ func newInstallCmd(l *zap.SugaredLogger) *cobra.Command {
}

func initInstallFlags(cmd *cobra.Command) {
cmd.Flags().String(cli.FlagNamespaces, "", "Comma-separated namespaces list Percona Everest can manage")
cmd.Flags().String(cli.FlagNamespaces, install.DefaultDBNamespaceName, "Comma-separated namespaces list Percona Everest can manage")
cmd.Flags().Bool(cli.FlagSkipWizard, false, "Skip installation wizard")
cmd.Flags().String(cli.FlagVersionMetadataURL, "https://check.percona.com", "URL to retrieve version metadata information from")
cmd.Flags().String(cli.FlagVersion, "", "Everest version to install. By default the latest version is installed")
cmd.Flags().Bool(cli.FlagDisableTelemetry, false, "Disable telemetry")
cmd.Flags().MarkHidden(cli.FlagDisableTelemetry) //nolint:errcheck,gosec
cmd.Flags().Bool(cli.FlagSkipEnvDetection, false, "Skip detecting Kubernetes environment where Everest is installed")
cmd.Flags().Bool(cli.FlagInstallSkipDBNamespace, false, "Skip creating a database namespace with install")

cmd.Flags().String(helm.FlagChartDir, "", "Path to the chart directory. If not set, the chart will be downloaded from the repository")
cmd.Flags().MarkHidden(helm.FlagChartDir) //nolint:errcheck,gosec
Expand All @@ -93,13 +102,14 @@ func initInstallFlags(cmd *cobra.Command) {
func initInstallViperFlags(cmd *cobra.Command) {
viper.BindPFlag(cli.FlagSkipWizard, cmd.Flags().Lookup(cli.FlagSkipWizard)) //nolint:errcheck,gosec

viper.BindEnv(cli.FlagKubeconfig) //nolint:errcheck,gosec
viper.BindPFlag(cli.FlagKubeconfig, cmd.Flags().Lookup(cli.FlagKubeconfig)) //nolint:errcheck,gosec
viper.BindPFlag(cli.FlagNamespaces, cmd.Flags().Lookup(cli.FlagNamespaces)) //nolint:errcheck,gosec
viper.BindPFlag(cli.FlagVersionMetadataURL, cmd.Flags().Lookup(cli.FlagVersionMetadataURL)) //nolint:errcheck,gosec
viper.BindPFlag(cli.FlagVersion, cmd.Flags().Lookup(cli.FlagVersion)) //nolint:errcheck,gosec
viper.BindPFlag(cli.FlagDisableTelemetry, cmd.Flags().Lookup(cli.FlagDisableTelemetry)) //nolint:errcheck,gosec
viper.BindPFlag(cli.FlagSkipEnvDetection, cmd.Flags().Lookup(cli.FlagSkipEnvDetection)) //nolint:errcheck,gosec
viper.BindEnv(cli.FlagKubeconfig) //nolint:errcheck,gosec
viper.BindPFlag(cli.FlagKubeconfig, cmd.Flags().Lookup(cli.FlagKubeconfig)) //nolint:errcheck,gosec
viper.BindPFlag(cli.FlagNamespaces, cmd.Flags().Lookup(cli.FlagNamespaces)) //nolint:errcheck,gosec
viper.BindPFlag(cli.FlagVersionMetadataURL, cmd.Flags().Lookup(cli.FlagVersionMetadataURL)) //nolint:errcheck,gosec
viper.BindPFlag(cli.FlagVersion, cmd.Flags().Lookup(cli.FlagVersion)) //nolint:errcheck,gosec
viper.BindPFlag(cli.FlagDisableTelemetry, cmd.Flags().Lookup(cli.FlagDisableTelemetry)) //nolint:errcheck,gosec
viper.BindPFlag(cli.FlagSkipEnvDetection, cmd.Flags().Lookup(cli.FlagSkipEnvDetection)) //nolint:errcheck,gosec
viper.BindPFlag(cli.FlagInstallSkipDBNamespace, cmd.Flags().Lookup(cli.FlagInstallSkipDBNamespace)) //nolint:errcheck,gosec

viper.BindPFlag(helm.FlagChartDir, cmd.Flags().Lookup(helm.FlagChartDir)) //nolint:errcheck,gosec
viper.BindPFlag(helm.FlagRepository, cmd.Flags().Lookup(helm.FlagRepository)) //nolint:errcheck,gosec
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
github.com/operator-framework/api v0.27.0
github.com/operator-framework/operator-lifecycle-manager v0.27.0
github.com/percona/everest-operator v0.6.0-dev1.0.20241203113640-8dd4a9d32733
github.com/percona/percona-helm-charts/charts/everest v0.0.0-20241218102153-1844495296a6
github.com/percona/percona-helm-charts/charts/everest v0.0.0-20241220051605-6fa7cc9f3bd5
github.com/rodaine/table v1.3.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.18.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2218,8 +2218,8 @@ github.com/percona/everest-operator v0.6.0-dev1.0.20241203113640-8dd4a9d32733 h1
github.com/percona/everest-operator v0.6.0-dev1.0.20241203113640-8dd4a9d32733/go.mod h1:FTKcDBn/1BHKNDnocKBAWH2mG3BYyD6yLXtoS58o1BM=
github.com/percona/percona-backup-mongodb v1.8.1-0.20241002124601-957ac501f939 h1:OggdqSzqe9pO3A4GaRlrLwZXS3zEQ84O4+7Jm9cg74s=
github.com/percona/percona-backup-mongodb v1.8.1-0.20241002124601-957ac501f939/go.mod h1:KhIlTT4wR2mIkMvDtEFerr9zaADJorL7UThSztzxBaY=
github.com/percona/percona-helm-charts/charts/everest v0.0.0-20241218102153-1844495296a6 h1:MFtysQifbF9aXKXsO/s6IBP1Z+I7BfyPmcabmriaS/I=
github.com/percona/percona-helm-charts/charts/everest v0.0.0-20241218102153-1844495296a6/go.mod h1:j5Ci48Azwb4Xs4XvZQNfleWCn2uyiZywazklxNH1ut4=
github.com/percona/percona-helm-charts/charts/everest v0.0.0-20241220051605-6fa7cc9f3bd5 h1:qmHod+E+zP82Y7hAkXS/AdCNYOvzmCoRepxypYehIC4=
github.com/percona/percona-helm-charts/charts/everest v0.0.0-20241220051605-6fa7cc9f3bd5/go.mod h1:j5Ci48Azwb4Xs4XvZQNfleWCn2uyiZywazklxNH1ut4=
github.com/percona/percona-postgresql-operator v0.0.0-20241007204305-35d61aa5aebd h1:9RCUfPUxbdXuL/247r77DJmRSowDzA2xzZC9FpuLuUw=
github.com/percona/percona-postgresql-operator v0.0.0-20241007204305-35d61aa5aebd/go.mod h1:ICbLstSO4zhYo+SFSciIWO9rLHQg29GJ1335L0tfhR0=
github.com/percona/percona-server-mongodb-operator v1.18.0 h1:inRWonCOTacD++D/tvyFXVUqKx7f2OQzz8w1NyT3cAI=
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ const (
FlagDisableTelemetry = "disable-telemetry"
// FlagTakeNamespaceOwnership is the name of the take-ownership flag.
FlagTakeNamespaceOwnership = "take-ownership"
// FlagInstallSkipDBNamespace is the name of the skip-db-namespace flag.
FlagInstallSkipDBNamespace = "skip-db-namespace"
)
11 changes: 10 additions & 1 deletion pkg/cli/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const (
backoffInterval = 5 * time.Second

postInstallMessage = "Everest has been successfully installed!"

// DefaultDBNamespaceName is the name of the default DB namespace during installation.
DefaultDBNamespaceName = "everest"
)

// Install implements the main logic for commands.
Expand Down Expand Up @@ -83,6 +86,8 @@ type Config struct {
SkipEnvDetection bool `mapstructure:"skip-env-detection"`
// If set, we will print the pretty output.
Pretty bool
// SkipDBNamespace is set if the installation should skip provisioning database.
SkipDBNamespace bool `mapstructure:"skip-db-namespace"`

helm.CLIOptions
namespaces.NamespaceAddConfig `mapstructure:",squash"`
Expand Down Expand Up @@ -168,11 +173,15 @@ func (o *Install) Run(ctx context.Context) error {
}

func (o *Install) installDBNamespacesStep(ctx context.Context) (*steps.Step, error) {
askNamespaces := !o.cmd.Flags().Lookup(cli.FlagNamespaces).Changed
askNamespaces := !(o.cmd.Flags().Lookup(cli.FlagNamespaces).Changed || o.config.SkipDBNamespace)
askOperators := !(o.cmd.Flags().Lookup(cli.FlagOperatorMongoDB).Changed ||
o.cmd.Flags().Lookup(cli.FlagOperatorPostgresql).Changed ||
o.cmd.Flags().Lookup(cli.FlagOperatorXtraDBCluster).Changed)

if askNamespaces {
o.config.Namespaces = DefaultDBNamespaceName
}

if err := o.config.Populate(ctx, askNamespaces, askOperators); err != nil {
// not specifying a namespace in this context is allowed.
if errors.Is(err, namespaces.ErrNSEmpty) {
Expand Down

0 comments on commit d7539ab

Please sign in to comment.