Skip to content

Commit

Permalink
Show errors on missing deps (OLM, Istio, cert-manager)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmadigan committed Feb 29, 2024
1 parent 0658b51 commit de3eaaa
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -73,6 +75,14 @@ func installRun(cmd *cobra.Command, args []string) error {
return err
}

// Perform dependency checks right after the Kubernetes client is ready
if err := performDependencyChecks(k8sClient); err != nil {
// If the dependency checks fail, log the error and return it to halt the installation process
logf.Log.Error(err, "Dependency checks failed")
return err
}

// Continue with the rest of the installation process if all dependency checks pass
err = deployKuadrantOperator(k8sClient)
if err != nil {
return err
Expand All @@ -91,13 +101,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 {
Expand Down

0 comments on commit de3eaaa

Please sign in to comment.