Skip to content

Commit c1d17aa

Browse files
committed
fix: simplified dryRun input
1 parent 4e1ef50 commit c1d17aa

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

gateway/resolver/arguments.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,3 @@ func validateSortBy(items []unstructured.Unstructured, fieldPath string) error {
170170

171171
return nil
172172
}
173-
174-
func getDryRunArg(args map[string]interface{}, key string, required bool) ([]string, error) {
175-
val, exists := args[key]
176-
if !exists {
177-
if required {
178-
err := errors.New("missing required argument: " + key)
179-
log.Error().Err(err).Msg(key + " argument is required")
180-
return nil, err
181-
}
182-
return nil, nil
183-
}
184-
185-
dryRun, ok := val.(bool)
186-
if !ok {
187-
err := errors.New("invalid type for dryRun argument: expected boolean")
188-
log.Error().Err(err).Msg("dryRun argument must be a boolean")
189-
return nil, err
190-
}
191-
192-
if dryRun {
193-
return []string{"All"}, nil
194-
}
195-
return nil, nil
196-
}

gateway/resolver/resolver.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,14 @@ func (r *Service) CreateItem(gvk schema.GroupVersionKind, scope v1.ResourceScope
237237
return nil, errors.New("object metadata.name is required")
238238
}
239239

240-
dryRun, err := getDryRunArg(p.Args, DryRunArg, false)
240+
dryRunBool, err := getBoolArg(p.Args, DryRunArg, false)
241241
if err != nil {
242242
return nil, err
243243
}
244+
dryRun := []string{}
245+
if dryRunBool {
246+
dryRun = []string{"All"}
247+
}
244248

245249
if err := r.runtimeClient.Create(ctx, obj, &client.CreateOptions{DryRun: dryRun}); err != nil {
246250
log.Error().Err(err).Msg("Failed to create object")
@@ -292,10 +296,14 @@ func (r *Service) UpdateItem(gvk schema.GroupVersionKind, scope v1.ResourceScope
292296
return nil, err
293297
}
294298

295-
dryRun, err := getDryRunArg(p.Args, DryRunArg, false)
299+
dryRunBool, err := getBoolArg(p.Args, DryRunArg, false)
296300
if err != nil {
297301
return nil, err
298302
}
303+
dryRun := []string{}
304+
if dryRunBool {
305+
dryRun = []string{"All"}
306+
}
299307

300308
// Apply the merge patch to the existing object
301309
patch := client.RawPatch(types.MergePatchType, patchData)
@@ -335,10 +343,14 @@ func (r *Service) DeleteItem(gvk schema.GroupVersionKind, scope v1.ResourceScope
335343
obj.SetNamespace(namespace)
336344
}
337345

338-
dryRun, err := getDryRunArg(p.Args, DryRunArg, false)
346+
dryRunBool, err := getBoolArg(p.Args, DryRunArg, false)
339347
if err != nil {
340348
return nil, err
341349
}
350+
dryRun := []string{}
351+
if dryRunBool {
352+
dryRun = []string{"All"}
353+
}
342354

343355
if err := r.runtimeClient.Delete(ctx, obj, &client.DeleteOptions{DryRun: dryRun}); err != nil {
344356
log.Error().Err(err).Msg("Failed to delete object")

0 commit comments

Comments
 (0)