From f1a19c436276125c41ae3cc9c3a9413a003e4dcf Mon Sep 17 00:00:00 2001 From: Jason Madigan Date: Wed, 28 Feb 2024 17:19:53 +0000 Subject: [PATCH] Show errors on missing deps (OLM, Istio, cert-manager) --- cmd/install.go | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/cmd/install.go b/cmd/install.go index c36eaa0..653cd41 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -15,6 +15,8 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/kubernetes/scheme" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + kuadrantoperator "github.com/kuadrant/kuadrant-operator/api/v1beta1" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/config" @@ -30,7 +32,7 @@ var ( ) const ( - KUADRANT_OPERATOR_VERSION string = "v0.4.1" + KUADRANT_OPERATOR_VERSION string = "v0.6.1" ) func installCommand() *cobra.Command { @@ -73,6 +75,11 @@ func installRun(cmd *cobra.Command, args []string) error { return err } + if err := performDependencyChecks(k8sClient); err != nil { + logf.Log.Error(err, "Dependency checks failed") + return err + } + err = deployKuadrantOperator(k8sClient) if err != nil { return err @@ -91,13 +98,46 @@ func installRun(cmd *cobra.Command, args []string) error { return nil } +func checkCRDExistence(k8sClient client.Client, crdName, documentationURL string) error { + crd := &apiextensionsv1.CustomResourceDefinition{} + err := k8sClient.Get(context.Background(), types.NamespacedName{Name: crdName}, crd) + if err != nil { + logf.Log.Info(fmt.Sprintf("CRD %s not found. Please visit %s for installation instructions.", crdName, documentationURL)) + return fmt.Errorf("dependency CRD %s is not installed. Please follow the installation guide at %s", crdName, documentationURL) + } + return nil +} + +func performDependencyChecks(k8sClient client.Client) error { + var dependencyErrors []error + + // Perform each check and collect errors + if err := checkCRDExistence(k8sClient, "gateways.networking.istio.io", "https://istio.io/latest/docs/setup/additional-setup/getting-started/"); err != nil { + dependencyErrors = append(dependencyErrors, err) + } + if err := checkCRDExistence(k8sClient, "gatewayclasses.gateway.networking.k8s.io", "https://gateway-api.sigs.k8s.io/guides/#installing-gateway-api"); err != nil { + dependencyErrors = append(dependencyErrors, err) + } + if err := checkCRDExistence(k8sClient, "certificates.cert-manager.io", "https://cert-manager.io/docs/installation/"); err != nil { + dependencyErrors = append(dependencyErrors, err) + } + + // If any errors were collected, return an aggregated error + if len(dependencyErrors) > 0 { + return fmt.Errorf("dependency checks failed: %+v", dependencyErrors) + } + + // If no errors were collected, return nil to indicate success + return nil +} + func waitForDeployments(k8sClient client.Client) error { retryInterval := time.Second * 5 - timeout := time.Minute * 2 + timeout := time.Minute * 3 deploymentKeys := []types.NamespacedName{ types.NamespacedName{Name: "authorino", Namespace: installNamespace}, - types.NamespacedName{Name: "limitador", Namespace: installNamespace}, + types.NamespacedName{Name: "limitador-limitador", Namespace: installNamespace}, } for _, key := range deploymentKeys {