Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option --allow-change-package-name in the package installed update operation #1671

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

luwangVMW
Copy link

Add option allow-change-package-name in the package installed update operation

this option allows user to change the package name for the packageinstalled CR

What this PR does / why we need it:

We need to change the package name for the installed package. However the current code blocks it .

Which issue(s) this PR fixes:

Fixes #1651

Does this PR introduce a user-facing change?

this option --allow-change-package-name allows user to change the package name when calling package installed update operation

Additional Notes for your reviewer:

Review Checklist:
  • Follows the developer guidelines
  • Relevant tests are added or updated
  • Relevant docs in this repo added or updated
  • Relevant carvel.dev docs added or updated in a separate PR and there's
    a link to that PR
  • Code is at least as readable and maintainable as it was before this
    change

Additional documentation e.g., Proposal, usage docs, etc.:


…operation

this option allows user to change the package name for the packageinstalled CR

Signed-off-by: luwang <[email protected]>
Copy link

@AkbaraliShaikh AkbaraliShaikh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR,

Have the changes in the PR been tested?

// If o.PackageName is provided by the user (via --package flag), verify that the package name in PackageInstall matches it.
// This will prevent the users from accidentally overwriting an installed package with another package content due to choosing a pre-existing name for the package isntall.
// Otherwise if o.PackageName is not provided, fill it from the installed package spec
if o.packageName != "" && updatedPkgInstall.Spec.PackageRef.RefName != o.packageName {
return nil, fmt.Errorf("Installed package '%s' is already associated with package '%s'", o.Name, updatedPkgInstall.Spec.PackageRef.RefName)
if !o.rename {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
could you please reverse the if condition?

if o.rename {
    updatedPkgInstall.Spec.PackageRef.RefName = o.packageName
} else {
    if o.packageName != "" && updatedPkgInstall.Spec.PackageRef.RefName != o.packageName {
        return nil, fmt.Errorf("Installed package '%s' is already associated with package '%s'", o.Name, updatedPkgInstall.Spec.PackageRef.RefName)
    }
    o.packageName = updatedPkgInstall.Spec.PackageRef.RefName
}

@@ -195,6 +197,7 @@ func NewUpdateCmd(o *CreateOrUpdateOptions, flagsFactory cmdcore.FlagsFactory) *
cmd.Flags().StringVarP(&o.version, "version", "v", "", "Set package version")
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.rename, "allow-change-package-name", false, "Allow to use different package name, optional")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the flag name to allow-package-name-change or rename-package ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

to support --allow-change-package-name (or similar) in the kctrl pacakge installed update command
2 participants