Skip to content

Commit a8b32ed

Browse files
authored
fix: do not use --force with --dry-run (#763)
Signed-off-by: Alexandre Gaudreault <[email protected]>
1 parent 89c110b commit a8b32ed

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
@@ -427,6 +427,10 @@ func (k *kubectlServerSideDiffDryRunApplier) newApplyOptions(ioStreams genericcl
427427
}
428428

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

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

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

@@ -540,7 +552,14 @@ func (k *kubectlResourceOperations) newReplaceOptions(config *rest.Config, f cmd
540552

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

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

0 commit comments

Comments
 (0)