From f6c14c939d9484fc13dd3c25ccbeeb65f545fc29 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Wed, 8 Jun 2022 17:36:16 +0300 Subject: [PATCH] Add CRDs to `flux check` command Verify that the Flux CRDs are registered on the cluster and print their version. Signed-off-by: Stefan Prodan --- cmd/flux/check.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/cmd/flux/check.go b/cmd/flux/check.go index 5ad70f9b..05b69e14 100644 --- a/cmd/flux/check.go +++ b/cmd/flux/check.go @@ -24,6 +24,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/spf13/cobra" v1 "k8s.io/api/apps/v1" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/client-go/kubernetes" "sigs.k8s.io/controller-runtime/pkg/client" @@ -95,9 +96,16 @@ func runCheckCmd(cmd *cobra.Command, args []string) error { if !componentsCheck() { checkFailed = true } + + logger.Actionf("checking crds") + if !crdsCheck() { + checkFailed = true + } + if checkFailed { os.Exit(1) } + logger.Successf("all checks passed") return nil } @@ -205,3 +213,28 @@ func componentsCheck() bool { } return ok } + +func crdsCheck() bool { + ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout) + defer cancel() + + kubeClient, err := utils.KubeClient(kubeconfigArgs, kubeclientOptions) + if err != nil { + return false + } + + ok := true + selector := client.MatchingLabels{manifestgen.PartOfLabelKey: manifestgen.PartOfLabelValue} + var list apiextensionsv1.CustomResourceDefinitionList + if err := kubeClient.List(ctx, &list, client.InNamespace(*kubeconfigArgs.Namespace), selector); err == nil { + for _, crd := range list.Items { + if len(crd.Status.StoredVersions) > 0 { + logger.Successf(crd.Name + "/" + crd.Status.StoredVersions[0]) + } else { + ok = false + logger.Failuref("no stored versions for %s", crd.Name) + } + } + } + return ok +}