From 8cf38af57c57e27f9a430b265ed38af6c3fdb310 Mon Sep 17 00:00:00 2001 From: Alexandre Gaudreault Date: Mon, 18 Aug 2025 19:56:37 -0400 Subject: [PATCH] validate resource opts Signed-off-by: Alexandre Gaudreault --- pkg/utils/kube/resource_ops.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/pkg/utils/kube/resource_ops.go b/pkg/utils/kube/resource_ops.go index 316045a70..b110153f0 100644 --- a/pkg/utils/kube/resource_ops.go +++ b/pkg/utils/kube/resource_ops.go @@ -427,6 +427,10 @@ func (k *kubectlServerSideDiffDryRunApplier) newApplyOptions(ioStreams genericcl } o.ForceConflicts = true + + if err := o.Validate(); err != nil { + return nil, fmt.Errorf("error validating options: %w", err) + } return o, nil } @@ -456,6 +460,10 @@ func (k *kubectlResourceOperations) newApplyOptions(ioStreams genericclioptions. if serverSideApply { o.ForceConflicts = true } + + if err := o.Validate(); err != nil { + return nil, fmt.Errorf("error validating options: %w", err) + } return o, nil } @@ -490,6 +498,10 @@ func (k *kubectlResourceOperations) newCreateOptions(ioStreams genericclioptions return printer.PrintObj(obj, o.Out) } o.FilenameOptions.Filenames = []string{fileName} + + if err := o.Validate(); err != nil { + return nil, fmt.Errorf("error validating options: %w", err) + } return o, nil } @@ -540,7 +552,14 @@ func (k *kubectlResourceOperations) newReplaceOptions(config *rest.Config, f cmd o.DeleteOptions.Filenames = []string{fileName} o.Namespace = namespace - o.DeleteOptions.ForceDeletion = force + + if dryRunStrategy == cmdutil.DryRunNone { + o.DeleteOptions.ForceDeletion = force + } + + if err := o.Validate(); err != nil { + return nil, fmt.Errorf("error validating options: %w", err) + } return o, nil } @@ -570,6 +589,10 @@ func newReconcileOptions(f cmdutil.Factory, kubeClient *kubernetes.Clientset, fi return nil, err } o.PrintObject = printer.PrintObj + + if err := o.Validate(); err != nil { + return nil, fmt.Errorf("error validating options: %w", err) + } return o, nil }