Skip to content

Commit d13ca35

Browse files
authored
fix: do not use --force with --dry-run (#764)
Signed-off-by: Alexandre Gaudreault <[email protected]>
1 parent 093aef0 commit d13ca35

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

pkg/utils/kube/resource_ops.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ func (k *kubectlServerSideDiffDryRunApplier) newApplyOptions(ioStreams genericcl
428428
}
429429

430430
o.ForceConflicts = true
431+
432+
if err := o.Validate(); err != nil {
433+
return nil, fmt.Errorf("error validating options: %w", err)
434+
}
431435
return o, nil
432436
}
433437

@@ -457,6 +461,10 @@ func (k *kubectlResourceOperations) newApplyOptions(ioStreams genericclioptions.
457461
if serverSideApply {
458462
o.ForceConflicts = true
459463
}
464+
465+
if err := o.Validate(); err != nil {
466+
return nil, fmt.Errorf("error validating options: %w", err)
467+
}
460468
return o, nil
461469
}
462470

@@ -491,6 +499,10 @@ func (k *kubectlResourceOperations) newCreateOptions(ioStreams genericclioptions
491499
return printer.PrintObj(obj, o.Out)
492500
}
493501
o.FilenameOptions.Filenames = []string{fileName}
502+
503+
if err := o.Validate(); err != nil {
504+
return nil, fmt.Errorf("error validating options: %w", err)
505+
}
494506
return o, nil
495507
}
496508

@@ -541,7 +553,14 @@ func (k *kubectlResourceOperations) newReplaceOptions(config *rest.Config, f cmd
541553

542554
o.DeleteOptions.Filenames = []string{fileName}
543555
o.Namespace = namespace
544-
o.DeleteOptions.ForceDeletion = force
556+
557+
if dryRunStrategy == cmdutil.DryRunNone {
558+
o.DeleteOptions.ForceDeletion = force
559+
}
560+
561+
if err := o.Validate(); err != nil {
562+
return nil, fmt.Errorf("error validating options: %w", err)
563+
}
545564
return o, nil
546565
}
547566

@@ -571,6 +590,10 @@ func newReconcileOptions(f cmdutil.Factory, kubeClient *kubernetes.Clientset, fi
571590
return nil, fmt.Errorf("error configuring printer: %w", err)
572591
}
573592
o.PrintObject = printer.PrintObj
593+
594+
if err := o.Validate(); err != nil {
595+
return nil, fmt.Errorf("error validating options: %w", err)
596+
}
574597
return o, nil
575598
}
576599

0 commit comments

Comments
 (0)