From 6f139934a674b4db1909562b15a40e8b6b59240b Mon Sep 17 00:00:00 2001 From: Ellis Tarn Date: Tue, 8 Mar 2022 13:02:15 -0800 Subject: [PATCH] Refactored chart implementation for readability (#141) --- substrate/demo/apply.sh | 4 +- substrate/demo/delete.sh | 2 +- .../substrate/cluster/addons/operators.go | 71 ++++++++++++++----- 3 files changed, 55 insertions(+), 22 deletions(-) diff --git a/substrate/demo/apply.sh b/substrate/demo/apply.sh index ee4fcf31..2c0744cb 100755 --- a/substrate/demo/apply.sh +++ b/substrate/demo/apply.sh @@ -12,9 +12,9 @@ clusterctl init --infrastructure aws --kubeconfig bootstrap.kubeconfig # Create Cluster kubectl apply --kubeconfig bootstrap.kubeconfig -f ./substrate.yaml kubectl get cluster substrate -w --kubeconfig bootstrap.kubeconfig - -# Pivot Cluster clusterctl get kubeconfig substrate --kubeconfig bootstrap.kubeconfig >substrate.kubeconfig kubectl apply -f https://docs.projectcalico.org/v3.21/manifests/calico.yaml --kubeconfig substrate.kubeconfig + +# Pivot Cluster clusterctl init --infrastructure aws --kubeconfig substrate.kubeconfig clusterctl move --kubeconfig bootstrap.kubeconfig --to-kubeconfig substrate.kubeconfig diff --git a/substrate/demo/delete.sh b/substrate/demo/delete.sh index ba0c9b25..19c3451c 100755 --- a/substrate/demo/delete.sh +++ b/substrate/demo/delete.sh @@ -2,5 +2,5 @@ # Delete Cluster clusterctl move --kubeconfig ./substrate.kubeconfig --to-kubeconfig ./bootstrap.kubeconfig -kubectl delete --kubeconfig bootstrap.kubeconfig -f ./substrate.yaml +kubectl delete --kubeconfig bootstrap.kubeconfig -f ./substrate.yaml || true kind delete cluster --name bootstrap diff --git a/substrate/pkg/controller/substrate/cluster/addons/operators.go b/substrate/pkg/controller/substrate/cluster/addons/operators.go index 7d16610e..2ee5336a 100644 --- a/substrate/pkg/controller/substrate/cluster/addons/operators.go +++ b/substrate/pkg/controller/substrate/cluster/addons/operators.go @@ -21,6 +21,7 @@ import ( "github.com/awslabs/kit/substrate/pkg/apis/v1alpha1" "github.com/awslabs/kit/substrate/pkg/controller/substrate/cluster" "github.com/awslabs/kit/substrate/pkg/utils/discovery" + "github.com/awslabs/kit/substrate/pkg/utils/json" "go.uber.org/multierr" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart/loader" @@ -34,17 +35,11 @@ import ( type HelmCharts struct { } -const ( - kitOperatorChart = "https://github.com/awslabs/kubernetes-iteration-toolkit/releases/download/kit-operator-0.0.5/kit-operator-0.0.5.tgz" - karpenterChart = "https://charts.karpenter.sh/karpenter-0.5.5.tgz" - awsVPCCNIChart = "https://aws.github.io/eks-charts/aws-vpc-cni-1.1.13.tgz" - awsEBSCSIDriverChart = "https://github.com/kubernetes-sigs/aws-ebs-csi-driver/releases/download/helm-chart-aws-ebs-csi-driver-2.6.3/aws-ebs-csi-driver-2.6.3.tgz" - awsLBControllerChart = "https://aws.github.io/eks-charts/aws-load-balancer-controller-1.4.0.tgz" -) - type chart struct { - location, namespace, name string - values map[string]interface{} + namespace string + name string + location string + values json.Value } func (h *HelmCharts) Create(ctx context.Context, substrate *v1alpha1.Substrate) (reconcile.Result, error) { @@ -52,15 +47,53 @@ func (h *HelmCharts) Create(ctx context.Context, substrate *v1alpha1.Substrate) return reconcile.Result{Requeue: true}, nil } charts := []*chart{ - {awsVPCCNIChart, "kube-system", "aws-vpc-cni", nil}, - {kitOperatorChart, "kit", "kit-operator", nil}, - {karpenterChart, "karpenter", "karpenter", map[string]interface{}{ - "controller": map[string]interface{}{ - "clusterName": substrate.Name, "clusterEndpoint": fmt.Sprintf("https://%s:8443", *substrate.Status.Cluster.Address), - "resources": map[string]interface{}{"requests": map[string]interface{}{"cpu": "100m"}}}, - "aws": map[string]interface{}{"defaultInstanceProfile": discovery.Name(substrate, cluster.TenantControlPlaneNodeRole)}}}, - {awsEBSCSIDriverChart, "kube-system", "aws-ebs-csi-driver", map[string]interface{}{"controller": map[string]interface{}{"replicaCount": "1"}}}, - {awsLBControllerChart, "kube-system", "aws-load-balancer-controller", map[string]interface{}{"clusterName": substrate.Name, "replicaCount": "1"}}, + { + namespace: "kube-system", + name: "aws-vpc-cni", + location: "https://aws.github.io/eks-charts/aws-vpc-cni-1.1.13.tgz", + }, + { + namespace: "kit", + name: "kit-operator", + location: "https://github.com/awslabs/kubernetes-iteration-toolkit/releases/download/kit-operator-0.0.5/kit-operator-0.0.5.tgz", + }, + { + namespace: "karpenter", + name: "karpenter", + location: "https://charts.karpenter.sh/karpenter-0.5.5.tgz", + values: json.Value{ + "controller": json.Value{ + "clusterName": substrate.Name, "clusterEndpoint": fmt.Sprintf("https://%s:8443", *substrate.Status.Cluster.Address), + "resources": json.Value{ + "requests": json.Value{ + "cpu": "100m", + }, + }, + }, + "aws": json.Value{ + "defaultInstanceProfile": discovery.Name(substrate, cluster.TenantControlPlaneNodeRole), + }, + }, + }, + { + namespace: "kube-system", + name: "aws-ebs-csi-driver", + location: "https://github.com/kubernetes-sigs/aws-ebs-csi-driver/releases/download/helm-chart-aws-ebs-csi-driver-2.6.3/aws-ebs-csi-driver-2.6.3.tgz", + values: json.Value{ + "controller": json.Value{ + "replicaCount": "1", + }, + }, + }, + { + namespace: "kube-system", + name: "aws-load-balancer-controller", + location: "https://aws.github.io/eks-charts/aws-load-balancer-controller-1.4.0.tgz", + values: json.Value{ + "clusterName": substrate.Name, + "replicaCount": "1", + }, + }, } errs := make([]error, len(charts)) workqueue.ParallelizeUntil(ctx, len(charts), len(charts), func(i int) {