From 443e5b5539c0d99b14acf7ec2c215a3b573c3be9 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Thu, 9 Jun 2022 09:27:27 +0300 Subject: [PATCH] Fail check if no controllers or crds are found Signed-off-by: Stefan Prodan --- cmd/flux/check.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/flux/check.go b/cmd/flux/check.go index 05b69e14..cf43654a 100644 --- a/cmd/flux/check.go +++ b/cmd/flux/check.go @@ -103,6 +103,7 @@ func runCheckCmd(cmd *cobra.Command, args []string) error { } if checkFailed { + logger.Failuref("check failed") os.Exit(1) } @@ -199,7 +200,14 @@ func componentsCheck() bool { ok := true selector := client.MatchingLabels{manifestgen.PartOfLabelKey: manifestgen.PartOfLabelValue} var list v1.DeploymentList - if err := kubeClient.List(ctx, &list, client.InNamespace(*kubeconfigArgs.Namespace), selector); err == nil { + ns := *kubeconfigArgs.Namespace + if err := kubeClient.List(ctx, &list, client.InNamespace(ns), selector); err == nil { + if len(list.Items) == 0 { + logger.Failuref("no controllers found in the '%s' namespace with the label selector '%s=%s'", + ns, manifestgen.PartOfLabelKey, manifestgen.PartOfLabelValue) + return false + } + for _, d := range list.Items { if ref, err := buildComponentObjectRefs(d.Name); err == nil { if err := statusChecker.Assess(ref...); err != nil { @@ -227,6 +235,12 @@ func crdsCheck() bool { selector := client.MatchingLabels{manifestgen.PartOfLabelKey: manifestgen.PartOfLabelValue} var list apiextensionsv1.CustomResourceDefinitionList if err := kubeClient.List(ctx, &list, client.InNamespace(*kubeconfigArgs.Namespace), selector); err == nil { + if len(list.Items) == 0 { + logger.Failuref("no crds found with the label selector '%s=%s'", + manifestgen.PartOfLabelKey, manifestgen.PartOfLabelValue) + return false + } + for _, crd := range list.Items { if len(crd.Status.StoredVersions) > 0 { logger.Successf(crd.Name + "/" + crd.Status.StoredVersions[0])