diff --git a/cmd/frigg/bootstrap/capd-controller/cluster/cluster.go b/cmd/frigg/bootstrap/capd-controller/cluster/cluster.go index 6c907f0..32633df 100644 --- a/cmd/frigg/bootstrap/capd-controller/cluster/cluster.go +++ b/cmd/frigg/bootstrap/capd-controller/cluster/cluster.go @@ -201,8 +201,10 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole) error { reporender.FullStage() // Creating Namespaces + println(color.GreenString("Creating Namespaces..")) clusterapi.CreateCapiNs() clusterapi.CreateCapdNs() + clusterapi.CreateCaaphNs() clusterapi.CreateKubeadmBootstrapNs() clusterapi.CreateKubeAdmControlPlaneNs() @@ -219,7 +221,7 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole) error { statuscheck.ConditionCheckCapiOperator() // Installs capi components on the bootstrap cluster. - println(color.YellowString("Applying ClusterAPI Controller")) + println(color.YellowString("Applying ClusterAPI Controllers")) clusterapi.ApplyCoreProvider() clusterapi.ApplyBootstrapProv() clusterapi.ApplyControlPlaneProv() @@ -265,29 +267,35 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole) error { clusterapi.CreateArgoNSMgmt() clusterapi.CreateCapiNsMgmt() clusterapi.CreateCapdNsMgmt() + clusterapi.CreateCaaphNsMgmt() clusterapi.CreateKubeadmBootstrapNsMgmt() clusterapi.CreateKubeAdmControlPlaneNsMgmt() // Installing CertManager + println(color.GreenString("Installation of Cert-Manager and waiting for the 'Ready' conditions..")) clusterapi.ApplyCertManagerMgmt() // Checks the conditions for all cert-manager related deployments statuscheck.ConditionsCertManagersMgmt() // Installing ClusterAPI Operator + println(color.GreenString("Installation of the ClusterAPI Operator and waiting for the 'Ready' conditions..")) clusterapi.ApplyCapiOperatorMgmt() // Checks for all conditions of the clusterapi controller deployment statuscheck.ConditionCheckCapiOperatorMgmt() // Installs capi components on the mgmt cluster. + println(color.GreenString("Installation of the ClusterAPI Providers and waiting for the 'Ready' conditions..")) clusterapi.ApplyCoreProviderMgmt() clusterapi.ApplyBootstrapProvMgmt() clusterapi.ApplyControlPlaneProvMgmt() statuscheck.ConditionsCapiControllersMgmt() //clusterapi.ApplyDockerInfraProvMgmt() + println(color.GreenString("Installation of the ClusterAPI Provider CAPD and waiting for the 'Ready' conditions..")) clusterapi.ClusterAPIMgmt() statuscheck.ConditionsCapdControllersMgmt() + println(color.GreenString("Installation of the ClusterAPI Helm Provider and waiting for the 'Ready' conditions..")) clusterapi.ApplyAddonHelmProvMgmt() statuscheck.ConditionsCaaphControllersMgmt() diff --git a/cmd/frigg/bootstrap/capd/cluster/cluster.go b/cmd/frigg/bootstrap/capd/cluster/cluster.go index aaa511c..3fe8683 100644 --- a/cmd/frigg/bootstrap/capd/cluster/cluster.go +++ b/cmd/frigg/bootstrap/capd/cluster/cluster.go @@ -17,6 +17,7 @@ import ( "github.com/PatrickLaabs/frigg/pkg/kubeconfig" "github.com/PatrickLaabs/frigg/pkg/postbootstrap" "github.com/PatrickLaabs/frigg/pkg/sshkey" + "github.com/PatrickLaabs/frigg/pkg/statuscheck" "github.com/PatrickLaabs/frigg/pkg/tmpl/clusterctlconfig" "github.com/PatrickLaabs/frigg/pkg/tmpl/helmchartsproxies" "github.com/PatrickLaabs/frigg/pkg/tmpl/kindconfig" @@ -155,7 +156,6 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole) error { helmchartsproxies.MgmtArgoApps() // Generates a manifest for the management cluster, named frigg-mgmt-cluster - wait.Wait(10 * time.Second) mgmtmanifestgen.Gen() provider := cluster.NewProvider( @@ -187,13 +187,15 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole) error { reporender.FullStage() // Installs capi components on the bootstrap cluster. - // clustername is bootstrapcluster - wait.Wait(10 * time.Second) + println(color.GreenString("Applying ClusterAPI and Cert-Manager Components and waiting for the 'Ready' condition..")) clusterapi.ClusterAPI() + statuscheck.ConditionsCertManagers() + statuscheck.ConditionsCapiControllers() + statuscheck.ConditionsCapdControllers() + statuscheck.ConditionsCaaphControllers() // Installs a CNI solution helm chart proxy to the bootstrapcluster // This is needed, to make the worker nodes ready and complete the bootstrap deployment - wait.Wait(10 * time.Second) cnibootstrap.Installation() // Applies the frigg-mgmt-cluster manifest to the bootstrap cluster @@ -216,22 +218,29 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole) error { fmt.Printf("Error on modification of mgmt clusters kubeconfig: %v\n", err) } - // Installs the capi components to the frigg-mgmt-cluster - // This part may take a while. - wait.Wait(60 * time.Second) - clusterapi.ClusterAPIMgmt() + println(color.GreenString("Waiting for 'Ready' conditions for Tigera, CoreDNS and CNI..")) + statuscheck.ConditionTigerOperatorMgmt() + statuscheck.ConditionCoreDnsMgmt() + statuscheck.ConditionsCni() // Creates the argo namespace on the Mgmt Cluster clusterapi.CreateArgoNSMgmt() - //wait.Wait(5 * time.Second) + // Installs the capi components to the frigg-mgmt-cluster + // This part may take a while. + println(color.GreenString("Installation of ClusterAPI Componentes and waiting for the 'Ready' condition..")) + clusterapi.ClusterAPIMgmt() + statuscheck.ConditionsCertManagersMgmt() + statuscheck.ConditionsCapiControllersMgmt() + statuscheck.ConditionsCapdControllersMgmt() + statuscheck.ConditionsCaaphControllersMgmt() + // Github Token Secret deployment clusterapi.ApplyGithubSecretMgmt() // ArgoCD Default Login Secret deployment clusterapi.ApplyArgoSecretMgmt() // Installs the HelmChartProxies onto the mgmt-cluster - wait.Wait(10 * time.Second) argocdWorkload.Installation() cni.Installation() mgmtArgocdApps.Installation() diff --git a/cmd/frigg/bootstrap/commons/clusterapi/apply.go b/cmd/frigg/bootstrap/commons/clusterapi/apply.go index 0be53db..bb28c6e 100644 --- a/cmd/frigg/bootstrap/commons/clusterapi/apply.go +++ b/cmd/frigg/bootstrap/commons/clusterapi/apply.go @@ -256,6 +256,32 @@ func CreateCapdNs() { } } +func CreateCaaphNs() { + homedir, err := os.UserHomeDir() + if err != nil { + println(color.RedString("Error on accessing the working directory: %v\n", err)) + return + } + + friggDir := filepath.Join(homedir, vars.FriggDirName) + friggToolsDir := filepath.Join(friggDir, vars.FriggTools) + kubectlPath := filepath.Join(friggToolsDir, "kubectl") + + kubeconfigFlagPath := filepath.Join(friggDir, vars.BootstrapkubeconfigName) + + cmd := exec.Command(kubectlPath, "--kubeconfig", + kubeconfigFlagPath, "create", "namespace", "caaph-system", + ) + + // Capture the output of the command + output, err := cmd.CombinedOutput() + if err != nil { + println(color.RedString("Error running kubectl: %v\n", err)) + println(color.YellowString(string(output))) + return + } +} + func CreateKubeadmBootstrapNs() { homedir, err := os.UserHomeDir() if err != nil { @@ -552,6 +578,32 @@ func CreateCapdNsMgmt() { } } +func CreateCaaphNsMgmt() { + homedir, err := os.UserHomeDir() + if err != nil { + println(color.RedString("Error on accessing the working directory: %v\n", err)) + return + } + + friggDir := filepath.Join(homedir, vars.FriggDirName) + friggToolsDir := filepath.Join(friggDir, vars.FriggTools) + kubectlPath := filepath.Join(friggToolsDir, "kubectl") + + kubeconfigFlagPath := filepath.Join(friggDir, vars.ManagementKubeconfigName) + + cmd := exec.Command(kubectlPath, "--kubeconfig", + kubeconfigFlagPath, "create", "namespace", "caaph-system", + ) + + // Capture the output of the command + output, err := cmd.CombinedOutput() + if err != nil { + println(color.RedString("Error running kubectl: %v\n", err)) + println(color.YellowString(string(output))) + return + } +} + func CreateKubeadmBootstrapNsMgmt() { homedir, err := os.UserHomeDir() if err != nil { diff --git a/pkg/capi_controller/capi_controller.go b/pkg/capi_controller/capi_controller.go index 8ccd9f6..b31fa65 100644 --- a/pkg/capi_controller/capi_controller.go +++ b/pkg/capi_controller/capi_controller.go @@ -308,7 +308,7 @@ func AddonHelmProviderGen() { Namespace string `yaml:"namespace"` }{ Name: "helm", - Namespace: "capi-system", + Namespace: "caaph-system", }, Spec: struct { Version string `yaml:"version"` diff --git a/pkg/statuscheck/statuscheck.go b/pkg/statuscheck/statuscheck.go index f626007..27e1977 100644 --- a/pkg/statuscheck/statuscheck.go +++ b/pkg/statuscheck/statuscheck.go @@ -190,7 +190,6 @@ func checkCapiControllers(kubeconfigFlagPath string, deployments map[string][]st panic(err.Error()) } - //namespace := "capi-system" allAvailable := true for namespace, namespaceDeployments := range deployments { for _, deployment := range namespaceDeployments { @@ -355,7 +354,7 @@ func checkCaaphControllers(kubeconfigFlagPath string, deployments []string, read panic(err.Error()) } - namespace := "capi-system" + namespace := "caaph-system" allAvailable := true for _, deployment := range deployments { available, _ := checkDeploymentCondition(clientset, namespace, deployment)