Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

✨ enh: adding statuscheck for capd bootstrap #85

Merged
merged 7 commits into from
Mar 15, 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
10 changes: 9 additions & 1 deletion cmd/frigg/bootstrap/capd-controller/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand Down Expand Up @@ -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()

Expand Down
29 changes: 19 additions & 10 deletions cmd/frigg/bootstrap/capd/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
52 changes: 52 additions & 0 deletions cmd/frigg/bootstrap/commons/clusterapi/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/capi_controller/capi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func AddonHelmProviderGen() {
Namespace string `yaml:"namespace"`
}{
Name: "helm",
Namespace: "capi-system",
Namespace: "caaph-system",
},
Spec: struct {
Version string `yaml:"version"`
Expand Down
3 changes: 1 addition & 2 deletions pkg/statuscheck/statuscheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Loading