Skip to content

Commit

Permalink
--drop-values-file => --with-values
Browse files Browse the repository at this point in the history
  • Loading branch information
100mik committed May 16, 2022
1 parent ba4cd69 commit 5f1148f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 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
dropValuesFile bool
withValues bool
serviceAccountName string

install bool
Expand Down Expand Up @@ -149,6 +149,8 @@ func NewUpdateCmd(o *CreateOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *
},
cmdcore.Example{"Update package install with new values file",
[]string{"package", "installed", "update", "-i", "cert-man", "--values-file", "values.yml"}},
cmdcore.Example{"Update package install to stop consuming supplied values",
[]string{"package", "installed", "update", "-i", "cert-man", "--with-values", "false"}},
}.Description("-i", o.pkgCmdTreeOpts),
}
o.NamespaceFlags.SetWithPackageCommandTreeOpts(cmd, flagsFactory, o.pkgCmdTreeOpts)
Expand All @@ -163,7 +165,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.dropValuesFile, "drop-values-file", false, "Drop values file and remove reference from installation if values are not supplied, optional")
cmd.Flags().BoolVar(&o.withValues, "with-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 @@ -271,8 +273,6 @@ func (o *CreateOrUpdateOptions) RunUpdate(args []string) error {
}

o.createdAnnotations = NewCreatedResourceAnnotations(o.Name, o.NamespaceFlags.Name)

o.statusUI.PrintMessagef("Getting package install for '%s'", o.Name)
pkgInstall, err := kcClient.PackagingV1alpha1().PackageInstalls(o.NamespaceFlags.Name).Get(
context.Background(), o.Name, metav1.GetOptions{},
)
Expand Down Expand Up @@ -307,8 +307,8 @@ func (o CreateOrUpdateOptions) update(client kubernetes.Interface, kcClient kccl
return err
}

if o.valuesFile == "" && !changed && !o.dropValuesFile {
return err
if o.valuesFile == "" && !changed && o.withValues {
return nil
}

isSecretCreated, err := o.createOrUpdateValuesSecret(updatedPkgInstall, client)
Expand All @@ -317,7 +317,7 @@ func (o CreateOrUpdateOptions) update(client kubernetes.Interface, kcClient kccl
}

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

o.statusUI.PrintMessagef("Updating package install for '%s' in namespace '%s'", o.Name, o.NamespaceFlags.Name)
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, "--drop-values-file"}, RunOpts{})
_, err := kappCtrl.RunWithOpts([]string{"package", "installed", "update", "--package-install", pkgiName, "--with-values=false"}, RunOpts{})
require.NoError(t, err)

// Check for owned value secret
Expand Down

0 comments on commit 5f1148f

Please sign in to comment.