@@ -46,24 +46,24 @@ import (
4646func (d * DryRunner ) dryRun (cmd * cobra.Command , args []string ) error {
4747 cfgPolicy , err := d .readPolicy (cmd )
4848 if err != nil {
49- return err
49+ return fmt . Errorf ( "unable to read input policy: %w" , err )
5050 }
5151
5252 inputObjects , err := d .readInputResources (cmd , args )
5353 if err != nil {
54- return err
54+ return fmt . Errorf ( "unable to read input resources: %w" , err )
5555 }
5656
5757 if err := d .setupLogs (); err != nil {
58- return err
58+ return fmt . Errorf ( "unable to setup the logging configuration: %w" , err )
5959 }
6060
6161 ctx , cancel := context .WithCancel (cmd .Context ())
6262 defer cancel ()
6363
6464 rec , err := d .setupReconciler (ctx , cfgPolicy )
6565 if err != nil {
66- return err
66+ return fmt . Errorf ( "unable to setup the dryrun reconciler: %w" , err )
6767 }
6868
6969 // Apply the user's resources to the fake cluster
@@ -72,7 +72,12 @@ func (d *DryRunner) dryRun(cmd *cobra.Command, args []string) error {
7272
7373 scopedGVR , err := rec .DynamicWatcher .GVKToGVR (gvk )
7474 if err != nil {
75- return err
75+ if errors .Is (depclient .ErrNoVersionedResource , err ) {
76+ return fmt .Errorf ("%w for kind %v: if this is a custom resource, it may need an " +
77+ "entry in the mappings file" , err , gvk .Kind )
78+ }
79+
80+ return fmt .Errorf ("unable to apply an input resource: %w" , err )
7681 }
7782
7883 var resInt dynamic.ResourceInterface
@@ -84,7 +89,7 @@ func (d *DryRunner) dryRun(cmd *cobra.Command, args []string) error {
8489 }
8590
8691 if _ , err := resInt .Create (ctx , obj , metav1.CreateOptions {}); err != nil {
87- return err
92+ return fmt . Errorf ( "unable to apply an input resource: %w" , err )
8893 }
8994 }
9095
@@ -94,16 +99,16 @@ func (d *DryRunner) dryRun(cmd *cobra.Command, args []string) error {
9499 }
95100
96101 if _ , err := rec .Reconcile (ctx , runtime.Request {NamespacedName : cfgPolicyNN }); err != nil {
97- return err
102+ return fmt . Errorf ( "unable to complete the dryrun reconcile: %w" , err )
98103 }
99104
100105 if err := rec .Get (ctx , cfgPolicyNN , cfgPolicy ); err != nil {
101- return err
106+ return fmt . Errorf ( "unable to get the resulting policy state: %w" , err )
102107 }
103108
104109 if d .statusPath != "" {
105110 if err := d .saveStatus (cfgPolicy .Status ); err != nil {
106- return err
111+ return fmt . Errorf ( "unable to save the resulting policy state: %w" , err )
107112 }
108113 }
109114
@@ -112,12 +117,10 @@ func (d *DryRunner) dryRun(cmd *cobra.Command, args []string) error {
112117 }
113118
114119 if err := d .saveOrPrintComplianceMessages (ctx , cmd , rec .Client , cfgPolicy .Namespace ); err != nil {
115- return err
120+ return fmt . Errorf ( "unable to save or print the compliance messages: %w" , err )
116121 }
117122
118123 if cfgPolicy .Status .ComplianceState != policyv1 .Compliant {
119- cmd .SilenceUsage = true
120-
121124 return ErrNonCompliant
122125 }
123126
0 commit comments