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
* Update flag descriptions
  • Loading branch information
100mik committed May 24, 2022
1 parent bbbe9a6 commit 2f690c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 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 @@ -89,6 +89,7 @@ func NewCreateCmd(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().BoolVar(&o.values, "values", true, "Add or keep values supplied to package install, optional")

o.WaitFlags.Set(cmd, flagsFactory, &cmdcore.WaitFlagsOpts{
AllowDisableWait: true,
Expand Down Expand Up @@ -128,6 +129,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().BoolVar(&o.values, "values", true, "Add or keep values supplied to package install, optional")

o.WaitFlags.Set(cmd, flagsFactory, &cmdcore.WaitFlagsOpts{
AllowDisableWait: true,
Expand Down Expand Up @@ -165,7 +167,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")

o.WaitFlags.Set(cmd, flagsFactory, &cmdcore.WaitFlagsOpts{
AllowDisableWait: true,
Expand Down Expand Up @@ -265,7 +267,7 @@ func (o *CreateOrUpdateOptions) RunUpdate(args []string) error {
return fmt.Errorf("Expected package install to be non-empty")
}

if len(o.version) == 0 && len(o.valuesFile) == 0 {
if len(o.version) == 0 && len(o.valuesFile) == 0 && o.values {
return fmt.Errorf("Expected either package version or values file to update the package")
}

Expand Down Expand Up @@ -301,17 +303,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 @@ -322,8 +326,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 @@ -436,7 +443,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 2f690c8

Please sign in to comment.