Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks to kuadrantctl install - error handling for missing deps. #54

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ env-setup:
$(MAKE) olm-install
$(MAKE) gateway-api-install
$(MAKE) istio-install
$(MAKE) cert-manager-install
$(MAKE) deploy-gateway

## local-setup: Sets up Kind cluster with GatewayAPI manifests and istio GW, nothing Kuadrant. Build and install kuadrantctl binary
Expand Down
44 changes: 42 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,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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@david-martin david-martin Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it stands, the dependency error instructs to 'Please follow the installation guide at..'
If that is and always will be the same as what other docs (like on docs.kuadrant.io) will say, then that seems like a good dev exp as it brings them closer to the solution quicker than having to parse through the prerequisites section of guide that may have multiple prerequisites.

If however it may be different, like specifying a specific version or a specific way of installing, then linking to docs.kuadrant.io is the safest as that is something actively being maintained and tested with each release

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your point about getting people to the right information, sooner. I think these looks are generic/non-versioned enough to be quite stable.

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
5 changes: 5 additions & 0 deletions make/cert-manager.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##@ Install cert-manager, a tool to help manage the TLS certificates.

.PHONY: cert-manager-install
cert-manager-install:
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.3/cert-manager.yaml
Loading