remove PruneWhitelist, use prune-allowlist instead

Signed-off-by: yulng <wei.yang@daocloud.io>
Signed-off-by: Paco Xu <paco.xu@daocloud.io>
This commit is contained in:
yulng 2023-07-05 11:38:20 +08:00 committed by Paco Xu
parent ae185414f4
commit 06679402e7
12 changed files with 24 additions and 31 deletions

View File

@ -50,7 +50,6 @@ import (
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/openapi"
"k8s.io/kubectl/pkg/util/prune"
"k8s.io/kubectl/pkg/util/slice"
"k8s.io/kubectl/pkg/util/templates"
"k8s.io/kubectl/pkg/validation"
)
@ -73,8 +72,6 @@ type ApplyFlags struct {
Overwrite bool
OpenAPIPatch bool
// DEPRECATED: Use PruneAllowlist instead
PruneWhitelist []string // TODO: Remove this in kubectl 1.28 or later
PruneAllowlist []string
genericiooptions.IOStreams
@ -235,8 +232,7 @@ func (flags *ApplyFlags) AddFlags(cmd *cobra.Command) {
cmdutil.AddServerSideApplyFlags(cmd)
cmdutil.AddFieldManagerFlagVar(cmd, &flags.FieldManager, FieldManagerClientSideApply)
cmdutil.AddLabelSelectorFlagVar(cmd, &flags.Selector)
cmdutil.AddPruningFlags(cmd, &flags.Prune, &flags.PruneAllowlist, &flags.PruneWhitelist, &flags.All, &flags.ApplySetRef)
cmdutil.AddPruningFlags(cmd, &flags.Prune, &flags.PruneAllowlist, &flags.All, &flags.ApplySetRef)
cmd.Flags().BoolVar(&flags.Overwrite, "overwrite", flags.Overwrite, "Automatically resolve conflicts between the modified and live configuration by using values from the modified configuration")
cmd.Flags().BoolVar(&flags.OpenAPIPatch, "openapi-patch", flags.OpenAPIPatch, "If true, use openapi to calculate diff when the openapi presents and the resource can be found in the openapi spec. Otherwise, fall back to use baked-in types.")
}
@ -335,8 +331,7 @@ func (flags *ApplyFlags) ToOptions(f cmdutil.Factory, cmd *cobra.Command, baseNa
applySet = NewApplySet(parent, tooling, mapper, restClient)
}
if flags.Prune {
pruneAllowlist := slice.ToSet(flags.PruneAllowlist, flags.PruneWhitelist)
flags.PruneResources, err = prune.ParseResources(mapper, pruneAllowlist)
flags.PruneResources, err = prune.ParseResources(mapper, flags.PruneAllowlist)
if err != nil {
return nil, err
}

View File

@ -166,7 +166,7 @@ func NewCmdDiff(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Co
})
usage := "contains the configuration to diff"
cmd.Flags().StringArray("prune-allowlist", []string{}, "Overwrite the default whitelist with <group/version/kind> for --prune")
cmd.Flags().StringArray("prune-allowlist", []string{}, "Overwrite the default allowlist with <group/version/kind> for --prune")
cmd.Flags().Bool("prune", false, "Include resources that would be deleted by pruning. Can be used with -l and default shows all resources would be pruned")
cmd.Flags().BoolVar(&options.ShowManagedFields, "show-managed-fields", options.ShowManagedFields, "If true, include managed fields in the diff.")
cmd.Flags().IntVar(&options.Concurrency, "concurrency", 1, "Number of objects to process in parallel when diffing against the live version. Larger number = faster, but more memory, I/O and CPU over that shorter period of time.")

View File

@ -523,11 +523,9 @@ func AddLabelSelectorFlagVar(cmd *cobra.Command, p *string) {
cmd.Flags().StringVarP(p, "selector", "l", *p, "Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2). Matching objects must satisfy all of the specified label constraints.")
}
func AddPruningFlags(cmd *cobra.Command, prune *bool, pruneAllowlist *[]string, pruneWhitelist *[]string, all *bool, applySetRef *string) {
func AddPruningFlags(cmd *cobra.Command, prune *bool, pruneAllowlist *[]string, all *bool, applySetRef *string) {
// Flags associated with the original allowlist-based alpha
cmd.Flags().StringArrayVar(pruneAllowlist, "prune-allowlist", *pruneAllowlist, "Overwrite the default allowlist with <group/version/kind> for --prune")
cmd.Flags().StringArrayVar(pruneWhitelist, "prune-whitelist", *pruneWhitelist, "Overwrite the default whitelist with <group/version/kind> for --prune") // TODO: Remove this in kubectl 1.28 or later
_ = cmd.Flags().MarkDeprecated("prune-whitelist", "Use --prune-allowlist instead.")
cmd.Flags().BoolVar(all, "all", *all, "Select all resources in the namespace of the specified resource types.")
// Flags associated with the new ApplySet-based alpha

View File

@ -736,7 +736,7 @@ msgstr "kubectl kontrolliert den Kubernetes-Cluster-Manager"
#~ "\n"
#~ "\t\t# Apply the configuration in manifest.yaml and delete all the other "
#~ "configmaps that are not in the file.\n"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/"
#~ "v1/ConfigMap"
#~ msgstr ""
#~ "\n"
@ -754,7 +754,7 @@ msgstr "kubectl kontrolliert den Kubernetes-Cluster-Manager"
#~ "\n"
#~ "\t\t# Wende die Konfiguration im manifest.yaml an und lösche alle "
#~ "ConfigMaps, die nicht in der Datei sind.\n"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/"
#~ "v1/ConfigMap"
#, c-format

View File

@ -260,7 +260,7 @@ msgid ""
"\n"
"\t\t# Apply the configuration in manifest.yaml and delete all the other "
"config maps that are not in the file\n"
"\t\tkubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/v1/"
"\t\tkubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/v1/"
"ConfigMap"
msgstr ""
"\n"
@ -282,7 +282,7 @@ msgstr ""
"\n"
"\t\t# Apply the configuration in manifest.yaml and delete all the other "
"config maps that are not in the file\n"
"\t\tkubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/v1/"
"\t\tkubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/v1/"
"ConfigMap"
#: staging/src/k8s.io/kubectl/pkg/cmd/autoscale/autoscale.go:48

View File

@ -260,7 +260,7 @@ msgid ""
"\n"
"\t\t# Apply the configuration in manifest.yaml and delete all the other "
"config maps that are not in the file\n"
"\t\tkubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/v1/"
"\t\tkubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/v1/"
"ConfigMap"
msgstr ""
"\n"
@ -282,7 +282,7 @@ msgstr ""
"\n"
"\t\t# Apply the configuration in manifest.yaml and delete all the other "
"config maps that are not in the file\n"
"\t\tkubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/v1/"
"\t\tkubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/v1/"
"ConfigMap"
#: staging/src/k8s.io/kubectl/pkg/cmd/autoscale/autoscale.go:48

View File

@ -815,7 +815,7 @@ msgstr "Kubectl controlla il gestore cluster di Kubernetes"
#~ "\n"
#~ "\t\t# Apply the configuration in manifest.yaml and delete all the other "
#~ "configmaps that are not in the file.\n"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/"
#~ "v1/ConfigMap"
#~ msgstr ""
#~ "\n"
@ -833,7 +833,7 @@ msgstr "Kubectl controlla il gestore cluster di Kubernetes"
#~ "\n"
#~ "\t\t# Applica la configurazione manifest.yaml ed elimina tutti gli altri "
#~ "configmaps non presenti nel file.\n"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/"
#~ "v1/ConfigMap"
#, c-format

View File

@ -891,7 +891,7 @@ msgstr "kubectl controls the Kubernetes cluster manager"
#~ "\n"
#~ "\t\t# Apply the configuration in manifest.yaml and delete all the other "
#~ "configmaps that are not in the file.\n"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/"
#~ "v1/ConfigMap"
#~ msgstr ""
#~ "\n"
@ -909,7 +909,7 @@ msgstr "kubectl controls the Kubernetes cluster manager"
#~ "\n"
#~ "\t\t# Apply the configuration in manifest.yaml and delete all the other "
#~ "configmaps that are not in the file.\n"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/"
#~ "v1/ConfigMap"
#, c-format

View File

@ -814,7 +814,7 @@ msgstr "kubectl controla o gerenciador de cluster do Kubernetes"
#~ "\n"
#~ "\t\t# Apply the configuration in manifest.yaml and delete all the other "
#~ "configmaps that are not in the file.\n"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/"
#~ "v1/ConfigMap"
#~ msgstr ""
#~ "\n"
@ -832,7 +832,7 @@ msgstr "kubectl controla o gerenciador de cluster do Kubernetes"
#~ "\n"
#~ "\t\t# Aplica a configuração do manifest.yaml e remove todos os outros "
#~ "configmaps que não estão no arquivo.\n"
#~ "\t\tkubectl apply —prune -f manifest.yaml —all —prune-whitelist=core/v1/"
#~ "\t\tkubectl apply —prune -f manifest.yaml —all —prune-allowlist=core/v1/"
#~ "ConfigMap"
#, c-format

View File

@ -854,7 +854,7 @@ msgstr "kubectl 控制 Kubernetes 集群管理器"
#~ "\n"
#~ "\t\t# Apply the configuration in manifest.yaml and delete all the other "
#~ "configmaps that are not in the file.\n"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/v1/"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/v1/"
#~ "ConfigMap"
#~ msgstr ""
#~ "\n"
@ -870,7 +870,7 @@ msgstr "kubectl 控制 Kubernetes 集群管理器"
#~ "\t\tkubectl apply --prune -f manifest.yaml -l app=nginx\n"
#~ "\n"
#~ "\t\t# 应用 manifest.yaml 的配置并删除所有不在这个文件中的 ConfigMaps。\n"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/v1/"
#~ "\t\tkubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/v1/"
#~ "ConfigMap"
#, c-format

View File

@ -231,18 +231,18 @@ __EOF__
kube::test::get_object_assert pods "{{range.items}}{{${id_field:?}}}:{{end}}" ''
kubectl delete pvc b-pvc 2>&1 "${kube_flags[@]:?}"
## kubectl apply --prune --prune-whitelist
## kubectl apply --prune --prune-allowlist
# Pre-Condition: no POD exists
kube::test::get_object_assert pods "{{range.items}}{{${id_field:?}}}:{{end}}" ''
# apply pod a
kubectl apply --prune -l prune-group=true -f hack/testdata/prune/a.yaml "${kube_flags[@]:?}"
# check right pod exists
kube::test::get_object_assert 'pods a' "{{${id_field:?}}}" 'a'
# apply svc and don't prune pod a by overwriting whitelist
kubectl apply --prune -l prune-group=true -f hack/testdata/prune/svc.yaml --prune-whitelist core/v1/Service 2>&1 "${kube_flags[@]:?}"
# apply svc and don't prune pod a by overwriting allowlist
kubectl apply --prune -l prune-group=true -f hack/testdata/prune/svc.yaml --prune-allowlist core/v1/Service 2>&1 "${kube_flags[@]:?}"
kube::test::get_object_assert 'service prune-svc' "{{${id_field:?}}}" 'prune-svc'
kube::test::get_object_assert 'pods a' "{{${id_field:?}}}" 'a'
# apply svc and prune pod a with default whitelist
# apply svc and prune pod a with default allowlist
kubectl apply --prune -l prune-group=true -f hack/testdata/prune/svc.yaml 2>&1 "${kube_flags[@]:?}"
kube::test::get_object_assert 'service prune-svc' "{{${id_field:?}}}" 'prune-svc'
kube::test::get_object_assert pods "{{range.items}}{{${id_field:?}}}:{{end}}" ''

View File

@ -500,13 +500,13 @@ run_non_native_resource_tests() {
kube::test::get_object_assert bars "{{range.items}}{{$id_field}}:{{end}}" ''
# apply --prune on foo.yaml that has foo/test
kubectl apply --prune -l pruneGroup=true -f hack/testdata/CRD/foo.yaml "${kube_flags[@]}" --prune-whitelist=company.com/v1/Foo --prune-whitelist=company.com/v1/Bar
kubectl apply --prune -l pruneGroup=true -f hack/testdata/CRD/foo.yaml "${kube_flags[@]}" --prune-allowlist=company.com/v1/Foo --prune-allowlist=company.com/v1/Bar
# check right crds exist
kube::test::get_object_assert foos "{{range.items}}{{$id_field}}:{{end}}" 'test:'
kube::test::get_object_assert bars "{{range.items}}{{$id_field}}:{{end}}" ''
# apply --prune on bar.yaml that has bar/test
kubectl apply --prune -l pruneGroup=true -f hack/testdata/CRD/bar.yaml "${kube_flags[@]}" --prune-whitelist=company.com/v1/Foo --prune-whitelist=company.com/v1/Bar
kubectl apply --prune -l pruneGroup=true -f hack/testdata/CRD/bar.yaml "${kube_flags[@]}" --prune-allowlist=company.com/v1/Foo --prune-allowlist=company.com/v1/Bar
# check right crds exist
kube::test::wait_object_assert foos "{{range.items}}{{$id_field}}:{{end}}" ''
kube::test::get_object_assert bars "{{range.items}}{{$id_field}}:{{end}}" 'test:'