diff --git a/pkg/cmd/annotate/annotate.go b/pkg/cmd/annotate/annotate.go index 70cf71f50..1b78cecbb 100644 --- a/pkg/cmd/annotate/annotate.go +++ b/pkg/cmd/annotate/annotate.go @@ -48,11 +48,9 @@ import ( // the logic itself easy to unit test type AnnotateFlags struct { // Common user flags - All bool - AllNamespaces bool - + All bool + AllNamespaces bool DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier FieldManager string FieldSelector string resource.FilenameOptions @@ -84,7 +82,6 @@ type AnnotateOptions struct { builder *resource.Builder dryRunStrategy cmdutil.DryRunStrategy - dryRunVerifier *resource.QueryParamVerifier enforceNamespace bool fieldSelector string @@ -219,13 +216,6 @@ func (flags *AnnotateFlags) ToOptions(f cmdutil.Factory, cmd *cobra.Command, arg return nil, err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return nil, err - } - - options.dryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) - cmdutil.PrintFlagsWithDryRunStrategy(flags.PrintFlags, options.dryRunStrategy) printer, err := flags.PrintFlags.ToPrinter() if err != nil { @@ -340,11 +330,6 @@ func (o AnnotateOptions) RunAnnotate() error { outputObj = obj } else { mapping := info.ResourceMapping() - if o.dryRunStrategy == cmdutil.DryRunServer { - if err := o.dryRunVerifier.HasSupport(mapping.GroupVersionKind); err != nil { - return err - } - } name, namespace := info.Name, info.Namespace if len(o.resourceVersion) != 0 { diff --git a/pkg/cmd/apply/apply.go b/pkg/cmd/apply/apply.go index e951194a2..2997e8735 100644 --- a/pkg/cmd/apply/apply.go +++ b/pkg/cmd/apply/apply.go @@ -91,7 +91,6 @@ type ApplyOptions struct { FieldManager string Selector string DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier FieldValidationVerifier *resource.QueryParamVerifier Prune bool PruneResources []prune.Resource @@ -256,7 +255,6 @@ func (flags *ApplyFlags) ToOptions(cmd *cobra.Command, baseName string, args []s return nil, err } - dryRunVerifier := resource.NewQueryParamVerifier(dynamicClient, flags.Factory.OpenAPIGetter(), resource.QueryParamDryRun) fieldValidationVerifier := resource.NewQueryParamVerifier(dynamicClient, flags.Factory.OpenAPIGetter(), resource.QueryParamFieldValidation) fieldManager := GetApplyFieldManagerFlag(cmd, serverSideApply) @@ -326,7 +324,6 @@ func (flags *ApplyFlags) ToOptions(cmd *cobra.Command, baseName string, args []s FieldManager: fieldManager, Selector: flags.Selector, DryRunStrategy: dryRunStrategy, - DryRunVerifier: dryRunVerifier, Prune: flags.Prune, PruneResources: flags.PruneResources, All: flags.All, @@ -502,16 +499,6 @@ func (o *ApplyOptions) applyOneObject(info *resource.Info) error { WithFieldManager(o.FieldManager). WithFieldValidation(o.ValidationDirective) - if o.DryRunStrategy == cmdutil.DryRunServer { - // Ensure the APIServer supports server-side dry-run for the resource, - // otherwise fail early. - // For APIServers that don't support server-side dry-run will persist - // changes. - if err := o.DryRunVerifier.HasSupport(info.Mapping.GroupVersionKind); err != nil { - return err - } - } - if o.ServerSideApply { // Send the full object to be applied on the server side. data, err := runtime.Encode(unstructured.UnstructuredJSONScheme, info.Object) diff --git a/pkg/cmd/apply/apply_set_last_applied.go b/pkg/cmd/apply/apply_set_last_applied.go index 86b49f490..9bb4d9327 100644 --- a/pkg/cmd/apply/apply_set_last_applied.go +++ b/pkg/cmd/apply/apply_set_last_applied.go @@ -50,7 +50,6 @@ type SetLastAppliedOptions struct { namespace string enforceNamespace bool dryRunStrategy cmdutil.DryRunStrategy - dryRunVerifier *resource.QueryParamVerifier shortOutput bool output string patchBufferList []PatchBuffer @@ -124,11 +123,6 @@ func (o *SetLastAppliedOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.dryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) o.output = cmdutil.GetFlagString(cmd, "output") o.shortOutput = o.output == "name" @@ -208,11 +202,6 @@ func (o *SetLastAppliedOptions) RunSetLastApplied() error { if err != nil { return err } - if o.dryRunStrategy == cmdutil.DryRunServer { - if err := o.dryRunVerifier.HasSupport(mapping.GroupVersionKind); err != nil { - return err - } - } helper := resource. NewHelper(client, mapping). DryRun(o.dryRunStrategy == cmdutil.DryRunServer) diff --git a/pkg/cmd/autoscale/autoscale.go b/pkg/cmd/autoscale/autoscale.go index 0523ed8f7..78b7a5343 100644 --- a/pkg/cmd/autoscale/autoscale.go +++ b/pkg/cmd/autoscale/autoscale.go @@ -74,7 +74,6 @@ type AutoscaleOptions struct { enforceNamespace bool namespace string dryRunStrategy cmdutil.DryRunStrategy - dryRunVerifier *resource.QueryParamVerifier builder *resource.Builder fieldManager string @@ -138,15 +137,10 @@ func (o *AutoscaleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } discoveryClient, err := f.ToDiscoveryClient() if err != nil { return err } - o.dryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) o.createAnnotation = cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag) o.builder = f.NewBuilder() o.scaleKindResolver = scale.NewDiscoveryScaleKindResolver(discoveryClient) @@ -242,9 +236,6 @@ func (o *AutoscaleOptions) Run() error { createOptions.FieldManager = o.fieldManager } if o.dryRunStrategy == cmdutil.DryRunServer { - if err := o.dryRunVerifier.HasSupport(hpa.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } actualHPA, err := o.HPAClient.HorizontalPodAutoscalers(o.namespace).Create(context.TODO(), hpa, createOptions) diff --git a/pkg/cmd/create/create.go b/pkg/cmd/create/create.go index 76dcb8de0..e304dfbbf 100644 --- a/pkg/cmd/create/create.go +++ b/pkg/cmd/create/create.go @@ -52,7 +52,6 @@ type CreateOptions struct { RecordFlags *genericclioptions.RecordFlags DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier FieldValidationVerifier *resource.QueryParamVerifier ValidationDirective string @@ -210,7 +209,6 @@ func (o *CreateOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []s if err != nil { return err } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) o.FieldValidationVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamFieldValidation) o.ValidationDirective, err = cmdutil.GetValidationDirective(cmd) @@ -284,11 +282,6 @@ func (o *CreateOptions) RunCreate(f cmdutil.Factory, cmd *cobra.Command) error { } if o.DryRunStrategy != cmdutil.DryRunClient { - if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(info.Mapping.GroupVersionKind); err != nil { - return cmdutil.AddSourceToErr("creating", info.Source, err) - } - } obj, err := resource. NewHelper(info.Client, info.Mapping). DryRun(o.DryRunStrategy == cmdutil.DryRunServer). @@ -359,7 +352,6 @@ type CreateSubcommandOptions struct { // StructuredGenerator is the resource generator for the object being created StructuredGenerator generate.StructuredGenerator DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier CreateAnnotation bool FieldManager string ValidationDirective string @@ -396,11 +388,6 @@ func (o *CreateSubcommandOptions) Complete(f cmdutil.Factory, cmd *cobra.Command if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) o.CreateAnnotation = cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) @@ -471,9 +458,6 @@ func (o *CreateSubcommandOptions) Run() error { createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(mapping.GroupVersionKind); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } actualObject, err := o.DynamicClient.Resource(mapping.Resource).Namespace(o.Namespace).Create(context.TODO(), asUnstructured, createOptions) diff --git a/pkg/cmd/create/create_clusterrole.go b/pkg/cmd/create/create_clusterrole.go index 052f89b04..7f9951b4e 100644 --- a/pkg/cmd/create/create_clusterrole.go +++ b/pkg/cmd/create/create_clusterrole.go @@ -215,9 +215,6 @@ func (c *CreateClusterRoleOptions) RunCreateRole() error { } createOptions.FieldValidation = c.ValidationDirective if c.DryRunStrategy == cmdutil.DryRunServer { - if err := c.DryRunVerifier.HasSupport(clusterRole.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } clusterRole, err = c.Client.ClusterRoles().Create(context.TODO(), clusterRole, createOptions) diff --git a/pkg/cmd/create/create_clusterrolebinding.go b/pkg/cmd/create/create_clusterrolebinding.go index 8114bda00..697cb2702 100644 --- a/pkg/cmd/create/create_clusterrolebinding.go +++ b/pkg/cmd/create/create_clusterrolebinding.go @@ -27,7 +27,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" rbacclientv1 "k8s.io/client-go/kubernetes/typed/rbac/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -61,7 +60,6 @@ type ClusterRoleBindingOptions struct { Client rbacclientv1.RbacV1Interface DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string genericclioptions.IOStreams @@ -136,11 +134,6 @@ func (o *ClusterRoleBindingOptions) Complete(f cmdutil.Factory, cmd *cobra.Comma if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) printer, err := o.PrintFlags.ToPrinter() @@ -176,9 +169,6 @@ func (o *ClusterRoleBindingOptions) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(clusterRoleBinding.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } var err error diff --git a/pkg/cmd/create/create_configmap.go b/pkg/cmd/create/create_configmap.go index 899d275a1..fac1f6760 100644 --- a/pkg/cmd/create/create_configmap.go +++ b/pkg/cmd/create/create_configmap.go @@ -31,7 +31,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" corev1client "k8s.io/client-go/kubernetes/typed/core/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -97,7 +96,6 @@ type ConfigMapOptions struct { Client corev1client.CoreV1Interface DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string genericclioptions.IOStreams @@ -169,17 +167,6 @@ func (o *ConfigMapOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - discoveryClient, err := f.ToDiscoveryClient() - if err != nil { - return err - } - - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, discoveryClient, resource.QueryParamDryRun) - o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace() if err != nil { return err @@ -229,9 +216,6 @@ func (o *ConfigMapOptions) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(configMap.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } configMap, err = o.Client.ConfigMaps(o.Namespace).Create(context.TODO(), configMap, createOptions) diff --git a/pkg/cmd/create/create_cronjob.go b/pkg/cmd/create/create_cronjob.go index 09039fd90..9e9af1415 100644 --- a/pkg/cmd/create/create_cronjob.go +++ b/pkg/cmd/create/create_cronjob.go @@ -64,7 +64,6 @@ type CreateCronJobOptions struct { EnforceNamespace bool Client batchv1client.BatchV1Interface DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string Builder *resource.Builder FieldManager string @@ -147,11 +146,6 @@ func (o *CreateCronJobOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, a if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) printer, err := o.PrintFlags.ToPrinter() if err != nil { @@ -183,9 +177,6 @@ func (o *CreateCronJobOptions) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(cronJob.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } var err error diff --git a/pkg/cmd/create/create_deployment.go b/pkg/cmd/create/create_deployment.go index 85664b8ca..54d1e9eca 100644 --- a/pkg/cmd/create/create_deployment.go +++ b/pkg/cmd/create/create_deployment.go @@ -29,7 +29,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" utilrand "k8s.io/apimachinery/pkg/util/rand" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" appsv1client "k8s.io/client-go/kubernetes/typed/apps/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -74,7 +73,6 @@ type CreateDeploymentOptions struct { Client appsv1client.AppsV1Interface DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string genericclioptions.IOStreams @@ -153,11 +151,6 @@ func (o *CreateDeploymentOptions) Complete(f cmdutil.Factory, cmd *cobra.Command if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) printer, err := o.PrintFlags.ToPrinter() @@ -199,9 +192,6 @@ func (o *CreateDeploymentOptions) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(deploy.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } var err error diff --git a/pkg/cmd/create/create_ingress.go b/pkg/cmd/create/create_ingress.go index b3e2e3408..ab1f75c12 100644 --- a/pkg/cmd/create/create_ingress.go +++ b/pkg/cmd/create/create_ingress.go @@ -29,7 +29,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" networkingv1client "k8s.io/client-go/kubernetes/typed/networking/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -118,7 +117,6 @@ type CreateIngressOptions struct { Client networkingv1client.NetworkingV1Interface DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string FieldManager string @@ -195,11 +193,6 @@ func (o *CreateIngressOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, a if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) printer, err := o.PrintFlags.ToPrinter() @@ -259,9 +252,6 @@ func (o *CreateIngressOptions) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(ingress.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } var err error diff --git a/pkg/cmd/create/create_job.go b/pkg/cmd/create/create_job.go index 9cf432760..4d8f86ff1 100644 --- a/pkg/cmd/create/create_job.go +++ b/pkg/cmd/create/create_job.go @@ -66,7 +66,6 @@ type CreateJobOptions struct { EnforceNamespace bool Client batchv1client.BatchV1Interface DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string Builder *resource.Builder FieldManager string @@ -142,11 +141,6 @@ func (o *CreateJobOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) printer, err := o.PrintFlags.ToPrinter() if err != nil { @@ -215,9 +209,6 @@ func (o *CreateJobOptions) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(job.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } var err error diff --git a/pkg/cmd/create/create_namespace.go b/pkg/cmd/create/create_namespace.go index fc77e5a2f..0c757e6b4 100644 --- a/pkg/cmd/create/create_namespace.go +++ b/pkg/cmd/create/create_namespace.go @@ -25,7 +25,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/cli-runtime/pkg/resource" coreclient "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/kubectl/pkg/scheme" "k8s.io/kubectl/pkg/util" @@ -53,7 +52,6 @@ type NamespaceOptions struct { Name string DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string CreateAnnotation bool FieldManager string @@ -123,15 +121,6 @@ func (o *NamespaceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - discoveryClient, err := f.ToDiscoveryClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, discoveryClient, resource.QueryParamDryRun) o.CreateAnnotation = cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) printer, err := o.PrintFlags.ToPrinter() @@ -160,9 +149,6 @@ func (o *NamespaceOptions) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(namespace.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } var err error diff --git a/pkg/cmd/create/create_pdb.go b/pkg/cmd/create/create_pdb.go index 59156d3d5..f06d899c2 100644 --- a/pkg/cmd/create/create_pdb.go +++ b/pkg/cmd/create/create_pdb.go @@ -28,7 +28,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" policyv1client "k8s.io/client-go/kubernetes/typed/policy/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -71,7 +70,6 @@ type PodDisruptionBudgetOpts struct { Client *policyv1client.PolicyV1Client DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string genericclioptions.IOStreams @@ -139,15 +137,6 @@ func (o *PodDisruptionBudgetOpts) Complete(f cmdutil.Factory, cmd *cobra.Command if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - discoveryClient, err := f.ToDiscoveryClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, discoveryClient, resource.QueryParamDryRun) o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace() if err != nil { @@ -224,9 +213,6 @@ func (o *PodDisruptionBudgetOpts) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(podDisruptionBudget.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } podDisruptionBudget, err = o.Client.PodDisruptionBudgets(o.Namespace).Create(context.TODO(), podDisruptionBudget, createOptions) diff --git a/pkg/cmd/create/create_priorityclass.go b/pkg/cmd/create/create_priorityclass.go index 982aad43d..c3827f932 100644 --- a/pkg/cmd/create/create_priorityclass.go +++ b/pkg/cmd/create/create_priorityclass.go @@ -27,7 +27,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" schedulingv1client "k8s.io/client-go/kubernetes/typed/scheduling/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -66,7 +65,6 @@ type PriorityClassOptions struct { Client *schedulingv1client.SchedulingV1Client DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string genericclioptions.IOStreams @@ -135,11 +133,6 @@ func (o *PriorityClassOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, a if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) printer, err := o.PrintFlags.ToPrinter() @@ -176,9 +169,6 @@ func (o *PriorityClassOptions) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(priorityClass.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } var err error diff --git a/pkg/cmd/create/create_quota.go b/pkg/cmd/create/create_quota.go index f3cfa644f..5d643944d 100644 --- a/pkg/cmd/create/create_quota.go +++ b/pkg/cmd/create/create_quota.go @@ -28,7 +28,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" coreclient "k8s.io/client-go/kubernetes/typed/core/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -67,7 +66,6 @@ type QuotaOpts struct { Client *coreclient.CoreV1Client DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string genericclioptions.IOStreams @@ -133,11 +131,6 @@ func (o *QuotaOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args []strin if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace() if err != nil { @@ -189,9 +182,6 @@ func (o *QuotaOpts) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(resourceQuota.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } resourceQuota, err = o.Client.ResourceQuotas(o.Namespace).Create(context.TODO(), resourceQuota, createOptions) diff --git a/pkg/cmd/create/create_role.go b/pkg/cmd/create/create_role.go index 0f2985a01..c55ba4cd9 100644 --- a/pkg/cmd/create/create_role.go +++ b/pkg/cmd/create/create_role.go @@ -30,7 +30,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" clientgorbacv1 "k8s.io/client-go/kubernetes/typed/rbac/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -139,7 +138,6 @@ type CreateRoleOptions struct { ResourceNames []string DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string OutputFormat string Namespace string @@ -257,11 +255,6 @@ func (o *CreateRoleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) o.OutputFormat = cmdutil.GetFlagString(cmd, "output") o.CreateAnnotation = cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag) @@ -384,9 +377,6 @@ func (o *CreateRoleOptions) RunCreateRole() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(role.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } role, err = o.Client.Roles(o.Namespace).Create(context.TODO(), role, createOptions) diff --git a/pkg/cmd/create/create_rolebinding.go b/pkg/cmd/create/create_rolebinding.go index 06b9ad5bc..7ab22650c 100644 --- a/pkg/cmd/create/create_rolebinding.go +++ b/pkg/cmd/create/create_rolebinding.go @@ -27,7 +27,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" rbacclientv1 "k8s.io/client-go/kubernetes/typed/rbac/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -63,7 +62,6 @@ type RoleBindingOptions struct { Client rbacclientv1.RbacV1Interface DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string genericclioptions.IOStreams @@ -137,11 +135,6 @@ func (o *RoleBindingOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, arg if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) printer, err := o.PrintFlags.ToPrinter() if err != nil { @@ -183,9 +176,6 @@ func (o *RoleBindingOptions) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(roleBinding.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } roleBinding, err = o.Client.RoleBindings(o.Namespace).Create(context.TODO(), roleBinding, createOptions) diff --git a/pkg/cmd/create/create_secret.go b/pkg/cmd/create/create_secret.go index c3fab63d3..3c936da23 100644 --- a/pkg/cmd/create/create_secret.go +++ b/pkg/cmd/create/create_secret.go @@ -30,7 +30,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" corev1client "k8s.io/client-go/kubernetes/typed/core/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -113,7 +112,6 @@ type CreateSecretOptions struct { Client corev1client.CoreV1Interface DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string genericclioptions.IOStreams @@ -185,18 +183,6 @@ func (o *CreateSecretOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, ar return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - - discoveryClient, err := f.ToDiscoveryClient() - if err != nil { - return err - } - - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, discoveryClient, resource.QueryParamDryRun) - o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace() if err != nil { return err @@ -249,10 +235,6 @@ func (o *CreateSecretOptions) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - err := o.DryRunVerifier.HasSupport(secret.GroupVersionKind()) - if err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } secret, err = o.Client.Secrets(o.Namespace).Create(context.TODO(), secret, createOptions) diff --git a/pkg/cmd/create/create_secret_docker.go b/pkg/cmd/create/create_secret_docker.go index c2269966f..07f44e28f 100644 --- a/pkg/cmd/create/create_secret_docker.go +++ b/pkg/cmd/create/create_secret_docker.go @@ -27,7 +27,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" corev1client "k8s.io/client-go/kubernetes/typed/core/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -110,7 +109,6 @@ type CreateSecretDockerRegistryOptions struct { Client corev1client.CoreV1Interface DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string genericclioptions.IOStreams @@ -185,18 +183,6 @@ func (o *CreateSecretDockerRegistryOptions) Complete(f cmdutil.Factory, cmd *cob return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - - discoveryClient, err := f.ToDiscoveryClient() - if err != nil { - return err - } - - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, discoveryClient, resource.QueryParamDryRun) - o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace() if err != nil { return err @@ -249,10 +235,6 @@ func (o *CreateSecretDockerRegistryOptions) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - err := o.DryRunVerifier.HasSupport(secretDockerRegistry.GroupVersionKind()) - if err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } secretDockerRegistry, err = o.Client.Secrets(o.Namespace).Create(context.TODO(), secretDockerRegistry, createOptions) diff --git a/pkg/cmd/create/create_secret_tls.go b/pkg/cmd/create/create_secret_tls.go index 85776d89d..c405cbd4f 100644 --- a/pkg/cmd/create/create_secret_tls.go +++ b/pkg/cmd/create/create_secret_tls.go @@ -27,7 +27,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" corev1client "k8s.io/client-go/kubernetes/typed/core/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -71,7 +70,6 @@ type CreateSecretTLSOptions struct { Client corev1client.CoreV1Interface DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string genericclioptions.IOStreams @@ -142,18 +140,6 @@ func (o *CreateSecretTLSOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - - discoveryClient, err := f.ToDiscoveryClient() - if err != nil { - return err - } - - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, discoveryClient, resource.QueryParamDryRun) - o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace() if err != nil { return err @@ -206,10 +192,6 @@ func (o *CreateSecretTLSOptions) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - err := o.DryRunVerifier.HasSupport(secretTLS.GroupVersionKind()) - if err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } secretTLS, err = o.Client.Secrets(o.Namespace).Create(context.TODO(), secretTLS, createOptions) diff --git a/pkg/cmd/create/create_service.go b/pkg/cmd/create/create_service.go index d1313405a..84863b347 100644 --- a/pkg/cmd/create/create_service.go +++ b/pkg/cmd/create/create_service.go @@ -30,7 +30,6 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/validation" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" corev1client "k8s.io/client-go/kubernetes/typed/core/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -76,7 +75,6 @@ type ServiceOptions struct { Client corev1client.CoreV1Interface DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string genericclioptions.IOStreams } @@ -116,11 +114,6 @@ func (o *ServiceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [] if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) printer, err := o.PrintFlags.ToPrinter() diff --git a/pkg/cmd/create/create_serviceaccount.go b/pkg/cmd/create/create_serviceaccount.go index 36488df32..892ea4b95 100644 --- a/pkg/cmd/create/create_serviceaccount.go +++ b/pkg/cmd/create/create_serviceaccount.go @@ -27,7 +27,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/cli-runtime/pkg/resource" coreclient "k8s.io/client-go/kubernetes/typed/core/v1" cmdutil "k8s.io/kubectl/pkg/cmd/util" "k8s.io/kubectl/pkg/scheme" @@ -53,7 +52,6 @@ type ServiceAccountOpts struct { // Name of resource being created Name string DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string CreateAnnotation bool FieldManager string @@ -125,11 +123,6 @@ func (o *ServiceAccountOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, arg if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace() if err != nil { @@ -181,9 +174,6 @@ func (o *ServiceAccountOpts) Run() error { } createOptions.FieldValidation = o.ValidationDirective if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(serviceAccount.GroupVersionKind()); err != nil { - return err - } createOptions.DryRun = []string{metav1.DryRunAll} } serviceAccount, err = o.Client.ServiceAccounts(o.Namespace).Create(context.TODO(), serviceAccount, createOptions) diff --git a/pkg/cmd/delete/delete.go b/pkg/cmd/delete/delete.go index 2c1887e6a..15e6e4109 100644 --- a/pkg/cmd/delete/delete.go +++ b/pkg/cmd/delete/delete.go @@ -125,7 +125,6 @@ type DeleteOptions struct { Timeout time.Duration DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier Output string @@ -196,11 +195,6 @@ func (o *DeleteOptions) Complete(f cmdutil.Factory, args []string, cmd *cobra.Co if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) if len(o.Raw) == 0 { r := f.NewBuilder(). @@ -328,11 +322,6 @@ func (o *DeleteOptions) DeleteResult(r *resource.Result) error { } return nil } - if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(info.Mapping.GroupVersionKind); err != nil { - return err - } - } response, err := o.deleteResource(info, options) if err != nil { return err diff --git a/pkg/cmd/diff/diff.go b/pkg/cmd/diff/diff.go index a6541ca66..dcf172f59 100644 --- a/pkg/cmd/diff/diff.go +++ b/pkg/cmd/diff/diff.go @@ -110,7 +110,6 @@ type DiffOptions struct { Selector string OpenAPISchema openapi.Resources DynamicClient dynamic.Interface - DryRunVerifier *resource.QueryParamVerifier CmdNamespace string EnforceNamespace bool Builder *resource.Builder @@ -645,8 +644,6 @@ func (o *DiffOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []str return err } - o.DryRunVerifier = resource.NewQueryParamVerifier(o.DynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) - o.CmdNamespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace() if err != nil { return err @@ -697,10 +694,6 @@ func (o *DiffOptions) Run() error { return err } - if err := o.DryRunVerifier.HasSupport(info.Mapping.GroupVersionKind); err != nil { - return err - } - local := info.Object.DeepCopyObject() for i := 1; i <= maxRetries; i++ { if err = info.Get(); err != nil { diff --git a/pkg/cmd/drain/drain.go b/pkg/cmd/drain/drain.go index afa55c57d..755bd23cd 100644 --- a/pkg/cmd/drain/drain.go +++ b/pkg/cmd/drain/drain.go @@ -224,11 +224,6 @@ func (o *DrainCmdOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [ if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.drainer.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) if o.drainer.Client, err = f.KubernetesClientSet(); err != nil { return err @@ -400,12 +395,6 @@ func (o *DrainCmdOptions) RunCordonOrUncordon(desired bool) error { printObj(nodeInfo.Object, o.Out) } else { if o.drainer.DryRunStrategy != cmdutil.DryRunClient { - if o.drainer.DryRunStrategy == cmdutil.DryRunServer { - if err := o.drainer.DryRunVerifier.HasSupport(gvk); err != nil { - printError(err) - continue - } - } err, patchErr := c.PatchOrReplace(o.drainer.Client, o.drainer.DryRunStrategy == cmdutil.DryRunServer) if patchErr != nil { printError(patchErr) diff --git a/pkg/cmd/expose/expose.go b/pkg/cmd/expose/expose.go index 9ce97d323..5ee33c806 100644 --- a/pkg/cmd/expose/expose.go +++ b/pkg/cmd/expose/expose.go @@ -115,7 +115,6 @@ type ExposeServiceOptions struct { ClusterIP string DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier EnforceNamespace bool fieldManager string @@ -201,11 +200,6 @@ func (o *ExposeServiceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) e if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) printer, err := o.PrintFlags.ToPrinter() @@ -360,11 +354,6 @@ func (o *ExposeServiceOptions) RunExpose(cmd *cobra.Command, args []string) erro if err != nil { return err } - if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(objMapping.GroupVersionKind); err != nil { - return err - } - } // Serialize the object with the annotation applied. client, err := o.ClientForMapping(objMapping) if err != nil { diff --git a/pkg/cmd/label/label.go b/pkg/cmd/label/label.go index f5f48fcb5..098f8038d 100644 --- a/pkg/cmd/label/label.go +++ b/pkg/cmd/label/label.go @@ -83,7 +83,6 @@ type LabelOptions struct { enforceNamespace bool builder *resource.Builder unstructuredClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error) - dryRunVerifier *resource.QueryParamVerifier // Common shared fields genericclioptions.IOStreams @@ -181,11 +180,6 @@ func (o *LabelOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.dryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) o.ToPrinter = func(operation string) (printers.ResourcePrinter, error) { o.PrintFlags.NamePrintFlags.Operation = operation @@ -343,11 +337,6 @@ func (o *LabelOptions) RunLabel() error { } mapping := info.ResourceMapping() - if o.dryRunStrategy == cmdutil.DryRunServer { - if err := o.dryRunVerifier.HasSupport(mapping.GroupVersionKind); err != nil { - return err - } - } client, err := o.unstructuredClientForMapping(mapping) if err != nil { return err diff --git a/pkg/cmd/patch/patch.go b/pkg/cmd/patch/patch.go index b048caf00..7c892540d 100644 --- a/pkg/cmd/patch/patch.go +++ b/pkg/cmd/patch/patch.go @@ -68,7 +68,6 @@ type PatchOptions struct { namespace string enforceNamespace bool dryRunStrategy cmdutil.DryRunStrategy - dryRunVerifier *resource.QueryParamVerifier outputFormat string args []string builder *resource.Builder @@ -177,11 +176,6 @@ func (o *PatchOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st o.args = args o.builder = f.NewBuilder() o.unstructuredClientForMapping = f.UnstructuredClientForMapping - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.dryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) return nil } @@ -257,11 +251,6 @@ func (o *PatchOptions) RunPatch() error { if !o.Local && o.dryRunStrategy != cmdutil.DryRunClient { mapping := info.ResourceMapping() - if o.dryRunStrategy == cmdutil.DryRunServer { - if err := o.dryRunVerifier.HasSupport(mapping.GroupVersionKind); err != nil { - return err - } - } client, err := o.unstructuredClientForMapping(mapping) if err != nil { return err diff --git a/pkg/cmd/replace/replace.go b/pkg/cmd/replace/replace.go index ee1e55b23..b82552d51 100644 --- a/pkg/cmd/replace/replace.go +++ b/pkg/cmd/replace/replace.go @@ -77,7 +77,6 @@ type ReplaceOptions struct { DeleteOptions *delete.DeleteOptions DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier FieldValidationVerifier *resource.QueryParamVerifier validationDirective string @@ -165,7 +164,6 @@ func (o *ReplaceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [] if err != nil { return err } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) o.FieldValidationVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamFieldValidation) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) @@ -303,11 +301,6 @@ func (o *ReplaceOptions) Run(f cmdutil.Factory) error { if o.DryRunStrategy == cmdutil.DryRunClient { return o.PrintObj(info.Object) } - if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(info.Mapping.GroupVersionKind); err != nil { - return err - } - } // Serialize the object with the annotation applied. obj, err := resource. diff --git a/pkg/cmd/rollout/rollout_undo.go b/pkg/cmd/rollout/rollout_undo.go index 5723e1f7d..97d974240 100644 --- a/pkg/cmd/rollout/rollout_undo.go +++ b/pkg/cmd/rollout/rollout_undo.go @@ -41,7 +41,6 @@ type UndoOptions struct { Builder func() *resource.Builder ToRevision int64 DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier Resources []string Namespace string LabelSelector string @@ -113,11 +112,6 @@ func (o *UndoOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []str if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) if o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace(); err != nil { return err @@ -167,11 +161,6 @@ func (o *UndoOptions) RunUndo() error { return err } - if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(info.Mapping.GroupVersionKind); err != nil { - return err - } - } result, err := rollbacker.Rollback(info.Object, nil, o.ToRevision, o.DryRunStrategy) if err != nil { return err diff --git a/pkg/cmd/run/run.go b/pkg/cmd/run/run.go index 42154493c..70f432c61 100644 --- a/pkg/cmd/run/run.go +++ b/pkg/cmd/run/run.go @@ -109,7 +109,6 @@ type RunOptions struct { DeleteOptions *cmddelete.DeleteOptions DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier PrintObj func(runtime.Object) error Recorder genericclioptions.Recorder @@ -227,7 +226,6 @@ func (o *RunOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error { if err != nil { return err } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) attachFlag := cmd.Flags().Lookup("attach") if !attachFlag.Changed && o.Interactive { @@ -651,11 +649,6 @@ func (o *RunOptions) createGeneratedObject(f cmdutil.Factory, cmd *cobra.Command if err != nil { return nil, err } - if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(mapping.GroupVersionKind); err != nil { - return nil, err - } - } actualObj, err = resource. NewHelper(client, mapping). DryRun(o.DryRunStrategy == cmdutil.DryRunServer). diff --git a/pkg/cmd/scale/scale.go b/pkg/cmd/scale/scale.go index 9529aeef8..37f7a85e5 100644 --- a/pkg/cmd/scale/scale.go +++ b/pkg/cmd/scale/scale.go @@ -87,7 +87,6 @@ type ScaleOptions struct { unstructuredClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error) parent string dryRunStrategy cmdutil.DryRunStrategy - dryRunVerifier *resource.QueryParamVerifier genericclioptions.IOStreams } @@ -156,12 +155,6 @@ func (o *ScaleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st } o.PrintObj = printer.PrintObj - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.dryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) - o.namespace, o.enforceNamespace, err = f.ToRawKubeConfigLoader().Namespace() if err != nil { return err diff --git a/pkg/cmd/set/set_env.go b/pkg/cmd/set/set_env.go index 78da2e553..ace8082b6 100644 --- a/pkg/cmd/set/set_env.go +++ b/pkg/cmd/set/set_env.go @@ -123,7 +123,6 @@ type EnvOptions struct { resources []string output string dryRunStrategy cmdutil.DryRunStrategy - dryRunVerifier *resource.QueryParamVerifier builder func() *resource.Builder updatePodSpecForObject polymorphichelpers.UpdatePodSpecForObjectFunc namespace string @@ -231,11 +230,6 @@ func (o *EnvOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.dryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.dryRunStrategy) printer, err := o.PrintFlags.ToPrinter() @@ -521,13 +515,6 @@ func (o *EnvOptions) RunEnv() error { continue } - if o.dryRunStrategy == cmdutil.DryRunServer { - if err := o.dryRunVerifier.HasSupport(info.Mapping.GroupVersionKind); err != nil { - allErrs = append(allErrs, err) - continue - } - } - actual, err := resource. NewHelper(info.Client, info.Mapping). DryRun(o.dryRunStrategy == cmdutil.DryRunServer). diff --git a/pkg/cmd/set/set_image.go b/pkg/cmd/set/set_image.go index b3bbb311a..87fefa411 100644 --- a/pkg/cmd/set/set_image.go +++ b/pkg/cmd/set/set_image.go @@ -47,7 +47,6 @@ type SetImageOptions struct { Infos []*resource.Info Selector string DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier All bool Output string Local bool @@ -154,11 +153,7 @@ func (o *SetImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [ if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) + o.Output = cmdutil.GetFlagString(cmd, "output") o.ResolveImage = ImageResolver @@ -284,11 +279,6 @@ func (o *SetImageOptions) Run() error { continue } - if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(info.Mapping.GroupVersionKind); err != nil { - return err - } - } // patch the change actual, err := resource. NewHelper(info.Client, info.Mapping). diff --git a/pkg/cmd/set/set_resources.go b/pkg/cmd/set/set_resources.go index cb70c0fdd..75e530a41 100644 --- a/pkg/cmd/set/set_resources.go +++ b/pkg/cmd/set/set_resources.go @@ -86,7 +86,6 @@ type SetResourcesOptions struct { UpdatePodSpecForObject polymorphichelpers.UpdatePodSpecForObjectFunc Resources []string - DryRunVerifier *resource.QueryParamVerifier genericclioptions.IOStreams } @@ -157,11 +156,6 @@ func (o *SetResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, ar if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) printer, err := o.PrintFlags.ToPrinter() @@ -288,13 +282,6 @@ func (o *SetResourcesOptions) Run() error { continue } - if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(info.Mapping.GroupVersionKind); err != nil { - allErrs = append(allErrs, fmt.Errorf("failed to patch resources update to pod template %v", err)) - continue - } - } - actual, err := resource. NewHelper(info.Client, info.Mapping). DryRun(o.DryRunStrategy == cmdutil.DryRunServer). diff --git a/pkg/cmd/set/set_selector.go b/pkg/cmd/set/set_selector.go index 7fbd21228..b89addf4d 100644 --- a/pkg/cmd/set/set_selector.go +++ b/pkg/cmd/set/set_selector.go @@ -45,7 +45,6 @@ type SetSelectorOptions struct { PrintFlags *genericclioptions.PrintFlags RecordFlags *genericclioptions.RecordFlags dryRunStrategy cmdutil.DryRunStrategy - dryRunVerifier *resource.QueryParamVerifier fieldManager string // set by args @@ -136,11 +135,6 @@ func (o *SetSelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, arg if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.dryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) o.resources, o.selector, err = getResourcesAndSelector(args) if err != nil { @@ -216,11 +210,6 @@ func (o *SetSelectorOptions) RunSelector() error { if !o.WriteToServer { return o.PrintObj(info.Object, o.Out) } - if o.dryRunStrategy == cmdutil.DryRunServer { - if err := o.dryRunVerifier.HasSupport(info.Mapping.GroupVersionKind); err != nil { - return err - } - } actual, err := resource. NewHelper(info.Client, info.Mapping). diff --git a/pkg/cmd/set/set_serviceaccount.go b/pkg/cmd/set/set_serviceaccount.go index 8f534002a..297a55736 100644 --- a/pkg/cmd/set/set_serviceaccount.go +++ b/pkg/cmd/set/set_serviceaccount.go @@ -63,7 +63,6 @@ type SetServiceAccountOptions struct { fileNameOptions resource.FilenameOptions dryRunStrategy cmdutil.DryRunStrategy - dryRunVerifier *resource.QueryParamVerifier shortOutput bool all bool output string @@ -138,11 +137,6 @@ func (o *SetServiceAccountOptions) Complete(f cmdutil.Factory, cmd *cobra.Comman if o.local && o.dryRunStrategy == cmdutil.DryRunServer { return fmt.Errorf("cannot specify --local and --dry-run=server - did you mean --dry-run=client?") } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.dryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) o.output = cmdutil.GetFlagString(cmd, "output") o.updatePodSpecForObject = polymorphichelpers.UpdatePodSpecForObjectFn @@ -210,12 +204,6 @@ func (o *SetServiceAccountOptions) Run() error { } continue } - if o.dryRunStrategy == cmdutil.DryRunServer { - if err := o.dryRunVerifier.HasSupport(info.Mapping.GroupVersionKind); err != nil { - patchErrs = append(patchErrs, err) - continue - } - } actual, err := resource. NewHelper(info.Client, info.Mapping). DryRun(o.dryRunStrategy == cmdutil.DryRunServer). diff --git a/pkg/cmd/set/set_subject.go b/pkg/cmd/set/set_subject.go index 6dea1eb4c..c67fc927e 100644 --- a/pkg/cmd/set/set_subject.go +++ b/pkg/cmd/set/set_subject.go @@ -66,7 +66,6 @@ type SubjectOptions struct { Output string All bool DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier Local bool fieldManager string @@ -128,11 +127,6 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [] if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) printer, err := o.PrintFlags.ToPrinter() @@ -270,12 +264,6 @@ func (o *SubjectOptions) Run(fn updateSubjects) error { continue } - if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(info.Mapping.GroupVersionKind); err != nil { - allErrs = append(allErrs, err) - continue - } - } actual, err := resource. NewHelper(info.Client, info.Mapping). DryRun(o.DryRunStrategy == cmdutil.DryRunServer). diff --git a/pkg/cmd/taint/taint.go b/pkg/cmd/taint/taint.go index 1004ae88b..eab09551b 100644 --- a/pkg/cmd/taint/taint.go +++ b/pkg/cmd/taint/taint.go @@ -48,7 +48,6 @@ type TaintOptions struct { ToPrinter func(string) (printers.ResourcePrinter, error) DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier ValidationDirective string resources []string @@ -144,11 +143,6 @@ func (o *TaintOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st if err != nil { return err } - dynamicClient, err := f.DynamicClient() - if err != nil { - return err - } - o.DryRunVerifier = resource.NewQueryParamVerifier(dynamicClient, f.OpenAPIGetter(), resource.QueryParamDryRun) cmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy) o.ValidationDirective, err = cmdutil.GetValidationDirective(cmd) @@ -332,11 +326,6 @@ func (o TaintOptions) RunTaint() error { } mapping := info.ResourceMapping() - if o.DryRunStrategy == cmdutil.DryRunServer { - if err := o.DryRunVerifier.HasSupport(mapping.GroupVersionKind); err != nil { - return err - } - } client, err := o.ClientForMapping(mapping) if err != nil { return err diff --git a/pkg/drain/drain.go b/pkg/drain/drain.go index b36692eb4..ccb4c8b46 100644 --- a/pkg/drain/drain.go +++ b/pkg/drain/drain.go @@ -83,7 +83,6 @@ type Helper struct { ErrOut io.Writer DryRunStrategy cmdutil.DryRunStrategy - DryRunVerifier *resource.QueryParamVerifier // OnPodDeletedOrEvicted is called when a pod is evicted/deleted; for printing progress output OnPodDeletedOrEvicted func(pod *corev1.Pod, usingEviction bool) @@ -135,22 +134,11 @@ func (d *Helper) makeDeleteOptions() metav1.DeleteOptions { // DeletePod will delete the given pod, or return an error if it couldn't func (d *Helper) DeletePod(pod corev1.Pod) error { - if d.DryRunStrategy == cmdutil.DryRunServer { - if err := d.DryRunVerifier.HasSupport(pod.GroupVersionKind()); err != nil { - return err - } - } return d.Client.CoreV1().Pods(pod.Namespace).Delete(d.getContext(), pod.Name, d.makeDeleteOptions()) } // EvictPod will evict the given pod, or return an error if it couldn't func (d *Helper) EvictPod(pod corev1.Pod, evictionGroupVersion schema.GroupVersion) error { - if d.DryRunStrategy == cmdutil.DryRunServer { - if err := d.DryRunVerifier.HasSupport(pod.GroupVersionKind()); err != nil { - return err - } - } - delOpts := d.makeDeleteOptions() switch evictionGroupVersion {