Skip to content

Commit

Permalink
feat: squash of capi working branch commits
Browse files Browse the repository at this point in the history
  • Loading branch information
davidspek committed Sep 5, 2023
1 parent a30cdc9 commit 982a6c2
Show file tree
Hide file tree
Showing 103 changed files with 8,692 additions and 16 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/cluster-chart-unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: cluster-chart-unit-test

on:
push:
branches: [ main ]
paths:
- 'bootstrap/helm/cluster-api-cluster/**'
pull_request:
branches: [ main ]
paths:
- 'bootstrap/helm/cluster-api-cluster/**'
jobs:
helm-unit-test:
runs-on: ubuntu-latest
permissions:
contents: 'read'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: install helm
uses: azure/setup-helm@v3
with:
version: v3.12.3
- name: install helm unit test
run: helm plugin install https://github.com/helm-unittest/helm-unittest.git
- name: run helm unit test
run: helm unittest ./bootstrap/helm/cluster-api-cluster
24 changes: 24 additions & 0 deletions bootstrap/helm/cluster-api-cluster/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
tests/
6 changes: 6 additions & 0 deletions bootstrap/helm/cluster-api-cluster/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: cluster-api-cluster
description: A Helm chart for Kubernetes
type: application
version: 0.1.40
appVersion: "1.16.0"
3 changes: 3 additions & 0 deletions bootstrap/helm/cluster-api-cluster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Cluster API Cluster

A helm chart that deploys a cluster using the Cluster-API project
7 changes: 7 additions & 0 deletions bootstrap/helm/cluster-api-cluster/deps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: plural.sh/v1alpha1
kind: Dependencies
metadata:
application: true
description: installs a cluster using cluster-api
spec:
dependencies: []
237 changes: 237 additions & 0 deletions bootstrap/helm/cluster-api-cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "cluster-api-cluster.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "cluster-api-cluster.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "cluster-api-cluster.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "cluster-api-cluster.labels" -}}
helm.sh/chart: {{ include "cluster-api-cluster.chart" . }}
{{ include "cluster-api-cluster.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "cluster-api-cluster.selectorLabels" -}}
app.kubernetes.io/name: {{ include "cluster-api-cluster.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "cluster-api-cluster.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "cluster-api-cluster.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Creates the Kubernetes version for the cluster
# TODO: this should actually be used to sanatize the `.Values.cluster.kubernetesVersion` value to what the providers support instead of defining these static versions
*/}}
{{- define "cluster.kubernetesVersion" -}}
{{- if .Values.cluster.kubernetesVersion -}}
{{ .Values.cluster.kubernetesVersion }}
{{- else if eq .Values.provider "aws" -}}
v1.24
{{- else if eq .Values.provider "azure" -}}
v1.25.11
{{- else if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}}
1.24.14-gke.2700
{{- else if eq .Values.provider "kind" -}}
v1.25.11
{{- end }}
{{- end }}

{{/*
Create the kind for the infrastructureRef for the cluster
*/}}
{{- define "cluster.infrastructure.kind" -}}
{{- if and (eq .Values.provider "aws") (eq .Values.type "managed") -}}
AWSManagedCluster
{{- end }}
{{- if and (eq .Values.provider "azure") (eq .Values.type "managed") -}}
AzureManagedCluster
{{- end }}
{{- if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}}
GCPManagedCluster
{{- end }}
{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}}
DockerCluster
{{- end }}
{{- end }}

{{/*
Create the apiVersion for the infrastructureRef for the cluster
*/}}
{{- define "cluster.infrastructure.apiVersion" -}}
{{- if and (eq .Values.provider "aws") (eq .Values.type "managed") -}}
infrastructure.cluster.x-k8s.io/v1beta2
{{- end }}
{{- if and (eq .Values.provider "azure") (eq .Values.type "managed") -}}
infrastructure.cluster.x-k8s.io/v1beta1
{{- end }}
{{- if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}}
infrastructure.cluster.x-k8s.io/v1beta1
{{- end }}
{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}}
infrastructure.cluster.x-k8s.io/v1beta1
{{- end }}
{{- end }}

{{/*
Create the kind for the controlPlaneRef for the cluster
*/}}
{{- define "cluster.controlPlane.kind" -}}
{{- if and (eq .Values.provider "aws") (eq .Values.type "managed") -}}
AWSManagedControlPlane
{{- end }}
{{- if and (eq .Values.provider "azure") (eq .Values.type "managed") -}}
AzureManagedControlPlane
{{- end }}
{{- if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}}
GCPManagedControlPlane
{{- end }}
{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}}
KubeadmControlPlane
{{- end }}
{{- end }}

{{/*
Create the apiVersion for the controlPlaneRef for the cluster
*/}}
{{- define "cluster.controlPlane.apiVersion" -}}
{{- if and (eq .Values.provider "aws") (eq .Values.type "managed") -}}
controlplane.cluster.x-k8s.io/v1beta2
{{- end }}
{{- if and (eq .Values.provider "azure") (eq .Values.type "managed") -}}
infrastructure.cluster.x-k8s.io/v1beta1
{{- end }}
{{- if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}}
infrastructure.cluster.x-k8s.io/v1beta1
{{- end }}
{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}}
controlplane.cluster.x-k8s.io/v1beta1
{{- end }}
{{- end }}

{{/*
Create the kind for the infrastructureRef for the worker MachinePools
*/}}
{{- define "workers.infrastructure.kind" -}}
{{- if and (eq .Values.provider "aws") (eq .Values.type "managed") -}}
AWSManagedMachinePool
{{- end }}
{{- if and (eq .Values.provider "azure") (eq .Values.type "managed") -}}
AzureManagedMachinePool
{{- end }}
{{- if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}}
GCPManagedMachinePool
{{- end }}
{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}}
DockerMachinePool
{{- end }}
{{- end }}

{{/*
Create the apiVersion for the infrastructureRef for the worker MachinePools
*/}}
{{- define "workers.infrastructure.apiVersion" -}}
{{- if and (eq .Values.provider "aws") (eq .Values.type "managed") -}}
infrastructure.cluster.x-k8s.io/v1beta2
{{- end }}
{{- if and (eq .Values.provider "azure") (eq .Values.type "managed") -}}
infrastructure.cluster.x-k8s.io/v1beta1
{{- end }}
{{- if and (eq .Values.provider "gcp") (eq .Values.type "managed") -}}
infrastructure.cluster.x-k8s.io/v1beta1
{{- end }}
{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}}
infrastructure.cluster.x-k8s.io/v1beta1
{{- end }}
{{- end }}

{{/*
Create the configRef for the worker MachinePools
*/}}
{{- define "workers.configref" -}}
{{- if and (eq .Values.provider "kind") (eq .Values.type "managed") -}}
configRef:
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KubeadmConfig
name: worker-mp-config
{{- end }}
{{- end }}

{{/*
Create a MachinePool for the given values
ctx = . context
name = the name of the MachinePool resource
values = the values for this specific MachinePool resource
defaultVals = the default values for the MachinePool resource
*/}}
{{- define "workers.machinePool" -}}
{{- $replicas := (.values | default dict).replicas | default .defaultVals.replicas }}
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachinePool
metadata:
name: {{ .name }}
annotations:
helm.sh/resource-policy: keep
spec:
clusterName: {{ .ctx.Values.cluster.name }}
replicas: {{ $replicas }}
template:
spec:
{{- if or (eq .ctx.Values.provider "gcp") (eq .ctx.Values.provider "azure") (eq .ctx.Values.provider "kind") }}
version: {{ .values.kubernetesVersion | default (include "cluster.kubernetesVersion" .ctx) }}
{{- end }}
clusterName: {{ .ctx.Values.cluster.name }}
bootstrap:
{{- if or (eq .ctx.Values.provider "gcp") (eq .ctx.Values.provider "azure") (eq .ctx.Values.provider "aws") }}
dataSecretName: ""
{{- end }}
{{- if eq .ctx.Values.provider "kind" }}
{{- include "workers.configref" .ctx | nindent 8 }}
{{- end }}
infrastructureRef:
name: {{ .name }}
apiVersion: {{ include "workers.infrastructure.apiVersion" .ctx }}
kind: {{ include "workers.infrastructure.kind" .ctx }}
{{- end }}
Loading

0 comments on commit 982a6c2

Please sign in to comment.