-
Notifications
You must be signed in to change notification settings - Fork 108
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
luwangVMW
wants to merge
1
commit into
carvel-dev:develop
Choose a base branch
from
luwangVMW:option_update_package_name
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,8 @@ type CreateOrUpdateOptions struct { | |
values bool | ||
serviceAccountName string | ||
|
||
rename bool | ||
|
||
install bool | ||
|
||
DryRun bool | ||
|
@@ -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") | ||
|
||
o.WaitFlags.Set(cmd, flagsFactory, &cmdcore.WaitFlagsOpts{ | ||
AllowDisableWait: true, | ||
|
@@ -767,13 +770,18 @@ func (o *CreateOrUpdateOptions) preparePackageInstallForUpdate(pkgInstall *kcpkg | |
return nil, fmt.Errorf("Failed to update package '%s' as no existing package reference/version was found in the package install", o.Name) | ||
} | ||
|
||
// if o.rename is true, we allow changing the package name in the package installed update operation. | ||
// 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
|
||
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 | ||
} else { | ||
updatedPkgInstall.Spec.PackageRef.RefName = o.packageName | ||
} | ||
o.packageName = updatedPkgInstall.Spec.PackageRef.RefName | ||
|
||
// If o.Version is provided by the user (via --version flag), set the version in PackageInstall to this version | ||
// Otherwise if o.Version is not provided, fill it from the installed package spec | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
orrename-package
?