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 f1a19c4
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 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 All @@ -30,7 +32,7 @@ var (
)

const (
KUADRANT_OPERATOR_VERSION string = "v0.4.1"
KUADRANT_OPERATOR_VERSION string = "v0.6.1"
)

func installCommand() *cobra.Command {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit f1a19c4

Please sign in to comment.