Skip to content

Commit

Permalink
withValues => values. Add an exit case, when there is no values refer…
Browse files Browse the repository at this point in the history
…enced.

* values makes more sense since this flag is present in create, update and install
* Making sure an update call is not made if values is false but there are no values to be deleted or no references to be removed
  • Loading branch information
100mik committed May 16, 2022
1 parent 5f1148f commit cf74205
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions cli/pkg/kctrl/cmd/package/installed/create_or_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type CreateOrUpdateOptions struct {
packageName string
version string
valuesFile string
withValues bool
values bool
serviceAccountName string

install bool
Expand Down Expand Up @@ -88,7 +88,7 @@ func NewCreateCmd(o *CreateOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *
cmd.Flags().StringVarP(&o.packageName, "package", "p", "", "Set package name (required)")
cmd.Flags().StringVar(&o.version, "version", "", "Set package version (required)")
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().StringVar(&o.valuesFile, "values", "", "The path to the configuration values file, optional")

o.WaitFlags.Set(cmd, flagsFactory, &cmdcore.WaitFlagsOpts{
AllowDisableWait: true,
Expand Down Expand Up @@ -128,6 +128,7 @@ func NewInstallCmd(o *CreateOrUpdateOptions, flagsFactory cmdcore.FlagsFactory)
cmd.Flags().StringVar(&o.version, "version", "", "Set package version (required)")
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().StringVar(&o.valuesFile, "values", "", "The path to the configuration values file, optional")

o.WaitFlags.Set(cmd, flagsFactory, &cmdcore.WaitFlagsOpts{
AllowDisableWait: true,
Expand Down Expand Up @@ -165,7 +166,7 @@ func NewUpdateCmd(o *CreateOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *
cmd.Flags().StringVarP(&o.packageName, "package", "p", "", "Name of package install to be updated")
cmd.Flags().StringVar(&o.version, "version", "", "Set package version")
cmd.Flags().StringVar(&o.valuesFile, "values-file", "", "The path to the configuration values file, optional")
cmd.Flags().BoolVar(&o.withValues, "with-values", true, "Add or keep values supplied to package install, optional")
cmd.Flags().BoolVar(&o.values, "values", true, "Add or keep values supplied to package install, optional")
cmd.Flags().BoolVarP(&o.install, "install", "", false, "Install package if the installed package does not exist, optional")

o.WaitFlags.Set(cmd, flagsFactory, &cmdcore.WaitFlagsOpts{
Expand Down Expand Up @@ -307,17 +308,19 @@ func (o CreateOrUpdateOptions) update(client kubernetes.Interface, kcClient kccl
return err
}

if o.valuesFile == "" && !changed && o.withValues {
if o.valuesFile == "" && !changed && o.values {
o.statusUI.PrintMessagef("No changes to package install '%s' in namespace '%s'", o.Name, o.NamespaceFlags.Name)
return nil
}

isSecretCreated, err := o.createOrUpdateValuesSecret(updatedPkgInstall, client)
if err != nil {
o.statusUI.PrintMessagef("", o.Name)
return err
}

isSecretDeleted := false
if !o.withValues && len(updatedPkgInstall.Spec.Values) > 0 {
if !o.values && len(updatedPkgInstall.Spec.Values) > 0 {
isSecretDeleted, err = o.dropValuesSecret(client)
if err != nil {
return err
Expand All @@ -328,8 +331,11 @@ func (o CreateOrUpdateOptions) update(client kubernetes.Interface, kcClient kccl
o.removeValuesSecretReference(updatedPkgInstall)
changed = true
}
} else if !o.withValues && len(updatedPkgInstall.Spec.Values) == 0 {
} else if !o.values && len(updatedPkgInstall.Spec.Values) == 0 {
o.statusUI.PrintMessagef("No values have been supplied to installation '%s' in namespace '%s'", o.Name, o.NamespaceFlags.Name)
if !changed {
return nil
}
}

o.statusUI.PrintMessagef("Updating package install for '%s' in namespace '%s'", o.Name, o.NamespaceFlags.Name)
Expand Down Expand Up @@ -442,7 +448,7 @@ func (o *CreateOrUpdateOptions) createRelatedResources(client kubernetes.Interfa
}
}

if o.valuesFile != "" {
if o.valuesFile != "" && o.values {
o.statusUI.PrintMessagef("Creating secret '%s'", o.createdAnnotations.SecretAnnValue())
if isSecretCreated, err = o.createOrUpdateDataValuesSecret(client); err != nil {
return isServiceAccountCreated, isSecretCreated, err
Expand Down
2 changes: 1 addition & 1 deletion cli/test/e2e/pkgi_values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ foo: bar
})

logger.Section("Dropping consumed values file", func() {
_, err := kappCtrl.RunWithOpts([]string{"package", "installed", "update", "--package-install", pkgiName, "--with-values=false"}, RunOpts{})
_, err := kappCtrl.RunWithOpts([]string{"package", "installed", "update", "--package-install", pkgiName, "--values=false"}, RunOpts{})
require.NoError(t, err)

// Check for owned value secret
Expand Down

0 comments on commit cf74205

Please sign in to comment.