[Backport release-1.5] Fix: check definition of addon whether is conflict (#4502)

* fix checksemver

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

override defs

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

add tests

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
(cherry picked from commit 226b4d390f)

* add test and fix some special cases

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

fix checkdiff

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

fix flags

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
(cherry picked from commit 910d411e99)

* fix comments

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
(cherry picked from commit fefca7d9e2)

* small fix

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
(cherry picked from commit 04c5ec8a7e)

Co-authored-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
This commit is contained in:
github-actions[bot]
2022-07-29 16:47:43 +08:00
committed by GitHub
co-authored by 楚岳
parent acf923dd10
commit fafa18e8db
6 changed files with 252 additions and 20 deletions
+10
View File
@@ -77,6 +77,8 @@ var verboseStatus bool
var skipValidate bool
var overrideDefs bool
// NewAddonCommand create `addon` command
func NewAddonCommand(c common.Args, order string, ioStreams cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
@@ -203,6 +205,7 @@ func NewAddonEnableCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Com
cmd.Flags().StringVarP(&addonVersion, "version", "v", "", "specify the addon version to enable")
cmd.Flags().StringVarP(&addonClusters, types.ClustersArg, "c", "", "specify the runtime-clusters to enable")
cmd.Flags().BoolVarP(&skipValidate, "skip-version-validating", "s", false, "skip validating system version requirement")
cmd.Flags().BoolVarP(&overrideDefs, "override-definitions", "", false, "override existing definitions if conflict with those contained in this addon")
return cmd
}
@@ -323,6 +326,7 @@ non-empty new arg
}
cmd.Flags().StringVarP(&addonVersion, "version", "v", "", "specify the addon version to upgrade")
cmd.Flags().BoolVarP(&skipValidate, "skip-version-validating", "s", false, "skip validating system version requirement")
cmd.Flags().BoolVarP(&overrideDefs, "override-definitions", "", false, "override existing definitions if conflict with those contained in this addon")
return cmd
}
@@ -535,6 +539,9 @@ func enableAddon(ctx context.Context, k8sClient client.Client, dc *discovery.Dis
if skipValidate {
opts = append(opts, pkgaddon.SkipValidateVersion)
}
if overrideDefs {
opts = append(opts, pkgaddon.OverrideDefinitions)
}
err = pkgaddon.EnableAddon(ctx, name, version, k8sClient, dc, apply.NewAPIApplicator(k8sClient), config, registry, args, nil, opts...)
if errors.Is(err, pkgaddon.ErrNotExist) {
continue
@@ -570,6 +577,9 @@ func enableAddonByLocal(ctx context.Context, name string, dir string, k8sClient
if skipValidate {
opts = append(opts, pkgaddon.SkipValidateVersion)
}
if overrideDefs {
opts = append(opts, pkgaddon.OverrideDefinitions)
}
if err := pkgaddon.EnableAddonByLocalDir(ctx, name, dir, k8sClient, dc, apply.NewAPIApplicator(k8sClient), config, args, opts...); err != nil {
return err
}