From 8b10a320884fcb129874580db15f734e97ebd7bf Mon Sep 17 00:00:00 2001 From: Sjors Holtrop Date: Tue, 14 Jan 2025 12:22:21 +0100 Subject: [PATCH 1/4] Improve "flux resume" error message on non-existent object Signed-off-by: Sjors Holtrop --- cmd/flux/resume.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/flux/resume.go b/cmd/flux/resume.go index 5f3c8b8145..3c686064b2 100644 --- a/cmd/flux/resume.go +++ b/cmd/flux/resume.go @@ -151,6 +151,11 @@ func (resume *resumeCommand) getPatchedResumables(ctx context.Context, args []st } processed[arg] = struct{}{} + if resume.list.len() == 0 { + logger.Failuref("%s object '%s' not found in %s namespace", resume.kind, arg, resume.namespace) + continue + } + objs, err := resume.patch(ctx, []client.ListOption{ client.InNamespace(resume.namespace), client.MatchingFields{ @@ -174,11 +179,6 @@ func (resume resumeCommand) patch(ctx context.Context, listOpts []client.ListOpt return nil, err } - if resume.list.len() == 0 { - logger.Failuref("no %s objects found in %s namespace", resume.kind, resume.namespace) - return nil, nil - } - var resumables []resumable for i := 0; i < resume.list.len(); i++ { From 3478fe343dcf1b1a9fa8f6206319cdf9bf4d442d Mon Sep 17 00:00:00 2001 From: Sjors Holtrop Date: Tue, 14 Jan 2025 13:52:51 +0100 Subject: [PATCH 2/4] fix golden file Signed-off-by: Sjors Holtrop --- .../resume_kustomization_from_git_multiple_args_wait.golden | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/flux/testdata/kustomization/resume_kustomization_from_git_multiple_args_wait.golden b/cmd/flux/testdata/kustomization/resume_kustomization_from_git_multiple_args_wait.golden index e07751407b..0cd30e7490 100644 --- a/cmd/flux/testdata/kustomization/resume_kustomization_from_git_multiple_args_wait.golden +++ b/cmd/flux/testdata/kustomization/resume_kustomization_from_git_multiple_args_wait.golden @@ -1,6 +1,6 @@ ► resuming kustomization tkfg in {{ .ns }} namespace ✔ kustomization resumed -✗ no Kustomization objects found in {{ .ns }} namespace +✗ Kustomization object 'tkfg' not found in {{ .ns }} namespace ◎ waiting for Kustomization reconciliation ✔ Kustomization tkfg reconciliation completed ✔ applied revision 6.3.5@sha1:67e2c98a60dc92283531412a9e604dd4bae005a9 From 2e9e8e269054da57ead3446d09607175bfc446b8 Mon Sep 17 00:00:00 2001 From: Sjors Holtrop Date: Tue, 14 Jan 2025 14:29:04 +0100 Subject: [PATCH 3/4] pass args to enable more detailed error message Signed-off-by: Sjors Holtrop --- cmd/flux/resume.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/flux/resume.go b/cmd/flux/resume.go index 3c686064b2..92f9184d41 100644 --- a/cmd/flux/resume.go +++ b/cmd/flux/resume.go @@ -133,7 +133,7 @@ func (resume resumeCommand) run(cmd *cobra.Command, args []string) error { // If the args slice is empty, it patches all resumable objects in the given namespace. func (resume *resumeCommand) getPatchedResumables(ctx context.Context, args []string) ([]resumable, error) { if len(args) < 1 { - objs, err := resume.patch(ctx, []client.ListOption{ + objs, err := resume.patch(ctx, args, []client.ListOption{ client.InNamespace(resume.namespace), }) if err != nil { @@ -151,12 +151,7 @@ func (resume *resumeCommand) getPatchedResumables(ctx context.Context, args []st } processed[arg] = struct{}{} - if resume.list.len() == 0 { - logger.Failuref("%s object '%s' not found in %s namespace", resume.kind, arg, resume.namespace) - continue - } - - objs, err := resume.patch(ctx, []client.ListOption{ + objs, err := resume.patch(ctx, args, []client.ListOption{ client.InNamespace(resume.namespace), client.MatchingFields{ "metadata.name": arg, @@ -174,11 +169,16 @@ func (resume *resumeCommand) getPatchedResumables(ctx context.Context, args []st // Patches resumable objects by setting their status to unsuspended. // Returns a slice of resumables that have been patched and any error encountered during patching. -func (resume resumeCommand) patch(ctx context.Context, listOpts []client.ListOption) ([]resumable, error) { +func (resume resumeCommand) patch(ctx context.Context, args []string, listOpts []client.ListOption) ([]resumable, error) { if err := resume.client.List(ctx, resume.list.asClientList(), listOpts...); err != nil { return nil, err } + if resume.list.len() == 0 { + logger.Failuref("%s object '%s' not found in %s namespace", resume.kind, args[0], resume.namespace) + return nil, nil + } + var resumables []resumable for i := 0; i < resume.list.len(); i++ { From f29bcfb10899d5a32230b2a3dd6a4b4b458750a6 Mon Sep 17 00:00:00 2001 From: Sjors Holtrop Date: Tue, 14 Jan 2025 14:45:34 +0100 Subject: [PATCH 4/4] handle len(args) < 1 case Signed-off-by: Sjors Holtrop --- cmd/flux/resume.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/flux/resume.go b/cmd/flux/resume.go index 92f9184d41..6a622dcb7b 100644 --- a/cmd/flux/resume.go +++ b/cmd/flux/resume.go @@ -175,7 +175,11 @@ func (resume resumeCommand) patch(ctx context.Context, args []string, listOpts [ } if resume.list.len() == 0 { - logger.Failuref("%s object '%s' not found in %s namespace", resume.kind, args[0], resume.namespace) + if len(args) < 1 { + logger.Failuref("no %s objects found in %s namespace", resume.kind, resume.namespace) + } else { + logger.Failuref("%s object '%s' not found in %s namespace", resume.kind, args[0], resume.namespace) + } return nil, nil }