Skip to content

Commit

Permalink
Remove options that can be manipulated downstream
Browse files Browse the repository at this point in the history
Signed-off-by: Soumik Majumder <[email protected]>
  • Loading branch information
100mik committed Jan 24, 2024
1 parent 6247224 commit bfbb83f
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 46 deletions.
1 change: 0 additions & 1 deletion cli/pkg/kctrl/cmd/app/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func NewDeleteCmd(o *DeleteOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Co
AllowDisableWait: true,
DefaultInterval: 1 * time.Second,
DefaultTimeout: 5 * time.Minute,
WaitByDefault: true,
})

return cmd
Expand Down
1 change: 0 additions & 1 deletion cli/pkg/kctrl/cmd/app/kick.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func NewKickCmd(o *KickOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Comman
AllowDisableWait: true,
DefaultInterval: 1 * time.Second,
DefaultTimeout: 5 * time.Minute,
WaitByDefault: true,
})

return cmd
Expand Down
13 changes: 0 additions & 13 deletions cli/pkg/kctrl/cmd/core/config_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ type ConfigFactoryImpl struct {

qps float32
burst int

defaultKubeconfigOverridePath string
defaultKubeconfigOverrideContext string
}

var _ ConfigFactory = &ConfigFactoryImpl{}
Expand All @@ -52,11 +49,6 @@ func (f *ConfigFactoryImpl) ConfigureYAMLResolver(resolverFunc func() (string, e
f.yamlResolverFunc = resolverFunc
}

func (f *ConfigFactoryImpl) ConfigureKubeconfigOverrides(defaultKubeconfigOverridePath string, defaultKubeconfigOverrideContext string) {
f.defaultKubeconfigOverridePath = defaultKubeconfigOverridePath
f.defaultKubeconfigOverrideContext = defaultKubeconfigOverrideContext
}

func (f *ConfigFactoryImpl) ConfigureClient(qps float32, burst int) {
f.qps = qps
f.burst = burst
Expand Down Expand Up @@ -131,11 +123,6 @@ func (f *ConfigFactoryImpl) clientConfig() (bool, clientcmd.ClientConfig, error)
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
overrides := &clientcmd.ConfigOverrides{}

if len(path) == 0 && len(context) == 0 && f.defaultKubeconfigOverrideContext != "" && f.defaultKubeconfigOverridePath != "" {
path = f.defaultKubeconfigOverridePath
context = f.defaultKubeconfigOverrideContext
}

if len(path) > 0 {
loadingRules.ExplicitPath = path
}
Expand Down
7 changes: 1 addition & 6 deletions cli/pkg/kctrl/cmd/core/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ type PackageCommandTreeOpts struct {
Color bool
JSON bool

DefaultKubeconfigOverridePath string
DefaultKubeconfigOverrideContext string

DefaultServiceAcccountName string
WaitByDefault bool
AllowSharedNamespaces bool
AlwaysAllowTogglingWait bool
}

type Example struct {
Expand Down
4 changes: 2 additions & 2 deletions cli/pkg/kctrl/cmd/core/secure_namespace_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type SecureNamespaceFlags struct {
AllowedSharedNamespaces bool
}

func (s *SecureNamespaceFlags) Set(cmd *cobra.Command, defaultVal bool) {
cmd.Flags().BoolVar(&s.AllowedSharedNamespaces, "dangerous-allow-use-of-shared-namespace", defaultVal, "Allow use of shared namespaces")
func (s *SecureNamespaceFlags) Set(cmd *cobra.Command) {
cmd.Flags().BoolVar(&s.AllowedSharedNamespaces, "dangerous-allow-use-of-shared-namespace", false, "Allow use of shared namespaces")
}

func (s *SecureNamespaceFlags) CheckForDisallowedSharedNamespaces(namespace string) error {
Expand Down
7 changes: 3 additions & 4 deletions cli/pkg/kctrl/cmd/core/wait_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ type WaitFlagsOpts struct {
AllowDisableWait bool
DefaultInterval time.Duration
DefaultTimeout time.Duration
WaitByDefault bool
}

func (f *WaitFlags) Set(cmd *cobra.Command, flagsFactory FlagsFactory, opts *WaitFlagsOpts) {
if opts.AllowDisableWait || !opts.WaitByDefault {
cmd.Flags().BoolVar(&f.Enabled, "wait", opts.WaitByDefault, "Wait for reconciliation to complete")
if opts.AllowDisableWait {
cmd.Flags().BoolVar(&f.Enabled, "wait", true, "Wait for reconciliation to complete")
}
f.Enabled = opts.WaitByDefault
f.Enabled = true
cmd.Flags().DurationVar(&f.CheckInterval, "wait-check-interval", opts.DefaultInterval, "Amount of time to sleep between checks while waiting")
cmd.Flags().DurationVar(&f.Timeout, "wait-timeout", opts.DefaultTimeout, "Maximum amount of time to wait in wait phase")
}
3 changes: 1 addition & 2 deletions cli/pkg/kctrl/cmd/kctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewKctrlCmd(o *KctrlOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Comm
cmdcore.RestOfCommandsHelpGroup,
}))

pkgOpts := cmdcore.PackageCommandTreeOpts{BinaryName: "kctrl", Color: true, JSON: true, WaitByDefault: true}
pkgOpts := cmdcore.PackageCommandTreeOpts{BinaryName: "kctrl", Color: true, JSON: true}

setGlobalFlags(o, cmd, flagsFactory, pkgOpts)

Expand Down Expand Up @@ -227,7 +227,6 @@ func AttachGlobalFlags(o *KctrlOptions, cmd *cobra.Command, flagsFactory cmdcore

func AttachKctrlPackageCommandTree(cmd *cobra.Command, confUI *ui.ConfUI, opts cmdcore.PackageCommandTreeOpts) {
configFactory := cmdcore.NewConfigFactoryImpl()
configFactory.ConfigureKubeconfigOverrides(opts.DefaultKubeconfigOverridePath, opts.DefaultKubeconfigOverrideContext)
depsFactory := cmdcore.NewDepsFactoryImpl(configFactory, confUI)
options := NewKctrlOptions(confUI, configFactory, depsFactory)
flagsFactory := cmdcore.NewFlagsFactory(configFactory, depsFactory)
Expand Down
13 changes: 5 additions & 8 deletions cli/pkg/kctrl/cmd/package/installed/create_or_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewCreateCmd(o *CreateOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *
cmdcore.PackageManagementCommandsHelpGroup.Key: cmdcore.PackageManagementCommandsHelpGroup.Value},
}
o.NamespaceFlags.SetWithPackageCommandTreeOpts(cmd, flagsFactory, o.pkgCmdTreeOpts)
o.SecureNamespaceFlags.Set(cmd, o.pkgCmdTreeOpts.AllowSharedNamespaces)
o.SecureNamespaceFlags.Set(cmd)

if !o.pkgCmdTreeOpts.PositionalArgs {
cmd.Flags().StringVarP(&o.Name, "package-install", "i", "", "Set installed package name (required)")
Expand All @@ -99,7 +99,7 @@ func NewCreateCmd(o *CreateOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *

cmd.Flags().StringVarP(&o.packageName, "package", "p", "", "Set package name (required)")
cmd.Flags().StringVarP(&o.version, "version", "v", "", "Set package version (required)")
cmd.Flags().StringVar(&o.serviceAccountName, "service-account-name", o.pkgCmdTreeOpts.DefaultServiceAcccountName, "Name of an existing service account used to install underlying package contents, optional")
cmd.Flags().StringVar(&o.serviceAccountName, "service-account-name", "", "Name of an existing service account used to install underlying package contents, optional")
cmd.Flags().StringVar(&o.valuesFile, "values-file", "", "The path to the configuration values file, optional")
cmd.Flags().BoolVar(&o.values, "values", true, "Add or keep values supplied to package install, optional")
cmd.Flags().BoolVar(&o.DryRun, "dry-run", false, "Print YAML for resources being applied to the cluster without applying them, optional")
Expand All @@ -108,7 +108,6 @@ func NewCreateCmd(o *CreateOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *
AllowDisableWait: true,
DefaultInterval: 1 * time.Second,
DefaultTimeout: 30 * time.Minute,
WaitByDefault: o.pkgCmdTreeOpts.WaitByDefault,
})
o.YttOverlayFlags.Set(cmd)

Expand All @@ -135,7 +134,7 @@ func NewInstallCmd(o *CreateOrUpdateOptions, flagsFactory cmdcore.FlagsFactory)
cmdcore.PackageManagementCommandsHelpGroup.Key: cmdcore.PackageManagementCommandsHelpGroup.Value},
}
o.NamespaceFlags.SetWithPackageCommandTreeOpts(cmd, flagsFactory, o.pkgCmdTreeOpts)
o.SecureNamespaceFlags.Set(cmd, o.pkgCmdTreeOpts.AllowSharedNamespaces)
o.SecureNamespaceFlags.Set(cmd)

if !o.pkgCmdTreeOpts.PositionalArgs {
cmd.Flags().StringVarP(&o.Name, "package-install", "i", "", "Set installed package name (required)")
Expand All @@ -146,7 +145,7 @@ func NewInstallCmd(o *CreateOrUpdateOptions, flagsFactory cmdcore.FlagsFactory)

cmd.Flags().StringVarP(&o.packageName, "package", "p", "", "Set package name (required)")
cmd.Flags().StringVarP(&o.version, "version", "v", "", "Set package version (required)")
cmd.Flags().StringVar(&o.serviceAccountName, "service-account-name", o.pkgCmdTreeOpts.DefaultServiceAcccountName, "Name of an existing service account used to install underlying package contents, optional")
cmd.Flags().StringVar(&o.serviceAccountName, "service-account-name", "", "Name of an existing service account used to install underlying package contents, optional")
cmd.Flags().StringVar(&o.valuesFile, "values-file", "", "The path to the configuration values file, optional")
cmd.Flags().BoolVar(&o.values, "values", true, "Add or keep values supplied to package install, optional")
cmd.Flags().BoolVar(&o.DryRun, "dry-run", false, "Print YAML for resources being applied to the cluster without applying them, optional")
Expand All @@ -155,7 +154,6 @@ func NewInstallCmd(o *CreateOrUpdateOptions, flagsFactory cmdcore.FlagsFactory)
AllowDisableWait: true,
DefaultInterval: 1 * time.Second,
DefaultTimeout: 30 * time.Minute,
WaitByDefault: o.pkgCmdTreeOpts.WaitByDefault,
})
o.YttOverlayFlags.Set(cmd)

Expand All @@ -181,7 +179,7 @@ func NewUpdateCmd(o *CreateOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *
cmdcore.PackageManagementCommandsHelpGroup.Key: cmdcore.PackageManagementCommandsHelpGroup.Value},
}
o.NamespaceFlags.SetWithPackageCommandTreeOpts(cmd, flagsFactory, o.pkgCmdTreeOpts)
o.SecureNamespaceFlags.Set(cmd, o.pkgCmdTreeOpts.AllowSharedNamespaces)
o.SecureNamespaceFlags.Set(cmd)

if !o.pkgCmdTreeOpts.PositionalArgs {
cmd.Flags().StringVarP(&o.Name, "package-install", "i", "", "Set installed package name")
Expand All @@ -199,7 +197,6 @@ func NewUpdateCmd(o *CreateOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *
AllowDisableWait: true,
DefaultInterval: 1 * time.Second,
DefaultTimeout: 30 * time.Minute,
WaitByDefault: o.pkgCmdTreeOpts.WaitByDefault,
})
o.YttOverlayFlags.Set(cmd)

Expand Down
3 changes: 1 addition & 2 deletions cli/pkg/kctrl/cmd/package/installed/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ func NewDeleteCmd(o *DeleteOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Co
}

o.WaitFlags.Set(cmd, flagsFactory, &cmdcore.WaitFlagsOpts{
AllowDisableWait: false,
AllowDisableWait: false || o.pkgCmdTreeOpts.AlwaysAllowTogglingWait,
DefaultInterval: 1 * time.Second,
DefaultTimeout: 5 * time.Minute,
WaitByDefault: o.pkgCmdTreeOpts.WaitByDefault,
})

return cmd
Expand Down
1 change: 0 additions & 1 deletion cli/pkg/kctrl/cmd/package/installed/pause_or_kick.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func NewKickCmd(o *PauseOrKickOptions, flagsFactory cmdcore.FlagsFactory) *cobra
AllowDisableWait: true,
DefaultInterval: 2 * time.Second,
DefaultTimeout: 5 * time.Minute,
WaitByDefault: o.pkgCmdTreeOpts.WaitByDefault,
})

return cmd
Expand Down
6 changes: 2 additions & 4 deletions cli/pkg/kctrl/cmd/package/repository/add_or_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewAddCmd(o *AddOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *cobra.
}

o.NamespaceFlags.SetWithPackageCommandTreeOpts(cmd, flagsFactory, o.pkgCmdTreeOpts)
o.SecureNamespaceFlags.Set(cmd, o.pkgCmdTreeOpts.AllowSharedNamespaces)
o.SecureNamespaceFlags.Set(cmd)

if !o.pkgCmdTreeOpts.PositionalArgs {
cmd.Flags().StringVarP(&o.Name, "repository", "r", "", "Set package repository name (required)")
Expand All @@ -84,7 +84,6 @@ func NewAddCmd(o *AddOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *cobra.
AllowDisableWait: true,
DefaultInterval: 1 * time.Second,
DefaultTimeout: 5 * time.Minute,
WaitByDefault: o.pkgCmdTreeOpts.WaitByDefault,
})

o.CreateRepository = true
Expand All @@ -107,7 +106,7 @@ func NewUpdateCmd(o *AddOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *cob
}

o.NamespaceFlags.SetWithPackageCommandTreeOpts(cmd, flagsFactory, o.pkgCmdTreeOpts)
o.SecureNamespaceFlags.Set(cmd, o.pkgCmdTreeOpts.AllowSharedNamespaces)
o.SecureNamespaceFlags.Set(cmd)

if !o.pkgCmdTreeOpts.PositionalArgs {
cmd.Flags().StringVarP(&o.Name, "repository", "r", "", "Set package repository name (required)")
Expand All @@ -122,7 +121,6 @@ func NewUpdateCmd(o *AddOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *cob
AllowDisableWait: true,
DefaultInterval: 1 * time.Second,
DefaultTimeout: 5 * time.Minute,
WaitByDefault: o.pkgCmdTreeOpts.WaitByDefault,
})

return cmd
Expand Down
1 change: 0 additions & 1 deletion cli/pkg/kctrl/cmd/package/repository/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func NewDeleteCmd(o *DeleteOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Co
AllowDisableWait: true,
DefaultInterval: 1 * time.Second,
DefaultTimeout: 5 * time.Minute,
WaitByDefault: o.pkgCmdTreeOpts.WaitByDefault,
})

return cmd
Expand Down
1 change: 0 additions & 1 deletion cli/pkg/kctrl/cmd/package/repository/kick.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func NewKickCmd(o *KickOptions, flagsFactory cmdcore.FlagsFactory) *cobra.Comman
AllowDisableWait: true,
DefaultInterval: 1 * time.Second,
DefaultTimeout: 5 * time.Minute,
WaitByDefault: o.pkgCmdTreeOpts.WaitByDefault,
})

return cmd
Expand Down

0 comments on commit bfbb83f

Please sign in to comment.