Skip to content

Commit

Permalink
Refactored chart implementation for readability (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellistarn authored Mar 8, 2022
1 parent d880424 commit 6f13993
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
4 changes: 2 additions & 2 deletions substrate/demo/apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion substrate/demo/delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
71 changes: 52 additions & 19 deletions substrate/pkg/controller/substrate/cluster/addons/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -34,33 +35,65 @@ 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) {
if !substrate.IsReady() {
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) {
Expand Down

0 comments on commit 6f13993

Please sign in to comment.