Skip to content

Commit 46cf8c9

Browse files
chore: Terraform charts (#316)
* Jules was unable to complete the task in time. Please review the work done so far and provide feedback for Jules to continue. * Here's a summary of the initial creation of Helm charts for multiple Kubernetes flavors: I've set up the initial structure for Helm charts that will help you provision various Kubernetes distributions (GKE, AKS, RKE-Rancher, OpenShift, Tanzu, K3s) using FluxCD's Terraform controller. Here are the key changes I made: - I created new chart directories by copying the existing 'eks-auto-mode' chart. - I performed initial updates to 'Chart.yaml' for each new flavor with distinct names and descriptions (e.g., 'terraform-gke-auto-cluster'). - I developed placeholder 'values.yaml' and 'values.schema.json' files for each chart, outlining common configurable parameters specific to each Kubernetes platform. These serve as a starting point and assume corresponding Terraform modules. - I modified 'templates/terraform.yaml' in each chart to: - Point 'spec.path' to an assumed Terraform module location (e.g., './terraform/gke-auto-mode'). - Update 'spec.vars' to align with the new 'values.yaml' parameters for each flavor. - Adjusted 'secretRef.name' for Terraform runner pod credentials to be more platform-specific (e.g., 'tf-gcp-creds'). The Terraform integration relies on the assumption that the actual Terraform modules for each Kubernetes flavor either exist or will be made available in the 'devtron-labs/utilities' Git repository under the specified paths. Based on your feedback, here's what I'll work on next: - I will rename chart directories and internal chart names to remove the "-auto-mode" suffix (e.g., 'charts/gke', 'terraform-gke-cluster'). - I will conduct a thorough review and update of all descriptions within 'Chart.yaml', 'values.yaml', and 'values.schema.json' for each chart to ensure accuracy and platform-specificity. - I will refine 'values.yaml' files to clearly denote all required inputs from you with comments or more descriptive placeholders. - I will create 'NOTES.txt' and 'README.md' files for each new chart. * Jules was unable to complete the task in time. Please review the work done so far and provide feedback for Jules to continue. * charts to provision clusters --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 3f5097c commit 46cf8c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2017
-0
lines changed

charts/aks/Chart.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
appVersion: 0.0.1
3+
description: Helm chart to provision an AKS cluster using Terraform with Flux.
4+
name: terraform-aks-cluster
5+
type: application
6+
version: 0.0.1

charts/aks/templates/NOTES.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Your {{ .Chart.Name }} Helm chart for provisioning a {{ .Values.name | default .Release.Name }} AKS cluster has been deployed.
2+
3+
The actual cluster provisioning is managed by the FluxCD Terraform controller using the configuration from the 'devtron-labs/utilities' Git repository.
4+
5+
1. Check the status of the GitRepository source:
6+
kubectl get gitrepositories -n flux-system {{ .Release.Name }} -o wide
7+
8+
2. Check the status of the Terraform custom resource:
9+
kubectl get terraforms -n flux-system {{ .Release.Name }} -o wide
10+
kubectl describe terraforms -n flux-system {{ .Release.Name }}
11+
12+
(Look for conditions and events. Provisioning an AKS cluster can take several minutes.)
13+
14+
3. Important Reminders from your values.yaml:
15+
Please ensure you have correctly filled out all mandatory 'TODO' items in your values.yaml, such as:
16+
- Azure 'resource_group_name', 'dns_prefix', and 'service_principal_client_id'.
17+
- Ensure the 'service_principal_client_secret' is correctly provided via the '{{ .Release.Name }}-spn-secret' Kubernetes secret (or as configured).
18+
- Appropriate 'resource_tags' (e.g., cost_center).
19+
- Ensure Azure credentials are correctly configured in the 'tf-azure-creds' secret in the flux-system namespace.
20+
21+
If these are not correctly set, the Terraform provisioning will likely fail.
22+
23+
4. Cluster Outputs:
24+
Once the Terraform execution is complete and successful, any defined outputs will be written to a Kubernetes Secret:
25+
Name: {{ .Release.Name }}-outputs
26+
Namespace: flux-system
27+
28+
You can inspect the secret using:
29+
kubectl get secret -n flux-system {{ .Release.Name }}-outputs -o yaml
30+
31+
The specific content of the secret depends on the outputs defined in the Terraform module at {{ .Values.path }}.
32+
33+
Thank you for using the {{ .Chart.Name }} chart!

charts/aks/templates/_helpers.tpl

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "terraform.name" -}}
5+
{{- default .Release.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "terraform.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "terraform.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "terraform.labels" -}}
37+
helm.sh/chart: {{ include "terraform.chart" . }}
38+
{{ include "terraform.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "terraform.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "terraform.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "terraform.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "terraform.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
63+
64+
{{/* vim: set filetype=mustache: */}}
65+
{{/*
66+
Expand the name of the chart.
67+
*/}}
68+
{{- define ".Chart.Name .name" -}}
69+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
70+
{{- end -}}
71+
72+
{{/*
73+
Create a default fully qualified app name.
74+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
75+
If release name contains chart name it will be used as a full name.
76+
*/}}
77+
{{- define ".Chart.Name .fullname" -}}
78+
{{- if .Values.fullnameOverride -}}
79+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
80+
{{- else -}}
81+
{{- $name := default .Chart.Name .Values.nameOverride -}}
82+
{{- if contains $name .Release.Name -}}
83+
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
84+
{{- else -}}
85+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
86+
{{- end -}}
87+
{{- end -}}
88+
{{- end -}}
89+
90+
{{/*
91+
Create chart name and version as used by the chart label.
92+
*/}}
93+
{{- define ".Chart.Name .chart" -}}
94+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
95+
{{- end -}}
96+
97+
{{- define ".Chart.Name .color" -}}
98+
{{- $active0 := (index .Values.server.deployment 0).enabled -}}
99+
{{/*
100+
{{- $active1 := (index .Values.server.deployment 1).enabled -}}
101+
*/}}
102+
{{- $active1 := include "safeenabledcheck" . -}}
103+
{{- $active := and $active0 $active1 -}}
104+
{{- $active -}}
105+
{{- end -}}

charts/aks/templates/gitrepo.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: source.toolkit.fluxcd.io/v1
2+
kind: GitRepository
3+
metadata:
4+
name: {{ $.Release.Name }}
5+
namespace: flux-system
6+
spec:
7+
interval: 30s
8+
ref:
9+
branch: main
10+
timeout: 61s
11+
url: https://github.com/devtron-labs/utilities.git

charts/aks/templates/terraform.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
apiVersion: infra.contrib.fluxcd.io/v1alpha2
2+
kind: Terraform
3+
metadata:
4+
name: {{ $.Release.Name }}
5+
namespace: flux-system
6+
spec:
7+
path: {{ default "./terraform/aks" .Values.path }} # Updated path for AKS
8+
approvePlan: {{ default "auto" .Values.approvePlan }}
9+
interval: 1m
10+
storeReadablePlan: human
11+
enableInventory: true
12+
destroyResourcesOnDeletion: {{ default false .Values.destroyResourcesOnDeletion }}
13+
alwaysCleanupRunnerPod: {{ default false .Values.alwaysCleanupRunnerPod }}
14+
force: {{ default false .Values.force }}
15+
sourceRef:
16+
kind: GitRepository
17+
name: {{ $.Release.Name }}
18+
namespace: flux-system
19+
writeOutputsToSecret:
20+
name: {{ $.Release.Name }}-outputs
21+
vars:
22+
- name: name
23+
value: {{ .Values.name | quote }}
24+
- name: resource_group_name
25+
value: {{ .Values.resource_group_name | quote }}
26+
- name: region
27+
value: {{ .Values.region | quote }}
28+
- name: cluster_version # Or kubernetes_version depending on TF module for AKS
29+
value: {{ .Values.cluster_version | quote }}
30+
- name: dns_prefix
31+
value: {{ .Values.dns_prefix | quote }}
32+
- name: agent_pool_name
33+
value: {{ .Values.agent_pool_name | quote }}
34+
- name: agent_vm_size
35+
value: {{ .Values.agent_vm_size | quote }}
36+
- name: agent_count
37+
value: {{ .Values.agent_count }} # Typically a number
38+
39+
{{- if .Values.service_principal_client_id }}
40+
- name: service_principal_client_id
41+
value: {{ .Values.service_principal_client_id | quote }}
42+
{{- end }}
43+
44+
{{- if .Values.service_principal_client_secret }}
45+
- name: service_principal_client_secret
46+
valueFrom: # Assuming this might be sensitive and stored in a K8s secret
47+
secretKeyRef:
48+
name: {{ $.Release.Name }}-spn-secret # Example, or directly use .Values if not sensitive
49+
key: client_secret
50+
# Alternatively, if provided directly in values.yaml and not sensitive:
51+
# value: {{ .Values.service_principal_client_secret | quote }}
52+
{{- end }}
53+
54+
{{- if .Values.resource_tags }}
55+
- name: resource_tags
56+
value:
57+
{{ toYaml .Values.resource_tags | nindent 8 }}
58+
{{- end }}
59+
60+
runnerPodTemplate:
61+
spec:
62+
{{- if $.Values.affinity }}
63+
affinity:
64+
{{ toYaml .Values.affinity.values | indent 8 }}
65+
{{- end }}
66+
{{- if .Values.tolerations }}
67+
tolerations:
68+
{{ toYaml .Values.tolerations | indent 8 }}
69+
{{- end }}
70+
envFrom:
71+
- secretRef:
72+
name: tf-azure-creds # Updated for Azure credentials

charts/aks/values.schema.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "AKS Cluster Configuration Values",
4+
"description": "Values for configuring an Azure Kubernetes Service (AKS) cluster provisioned via Terraform and Flux.",
5+
"type": "object",
6+
"required": [
7+
"name",
8+
"resource_group_name",
9+
"region",
10+
"cluster_version",
11+
"dns_prefix"
12+
],
13+
"properties": {
14+
"name": {
15+
"type": "string",
16+
"description": "Name of the AKS cluster."
17+
},
18+
"resource_group_name": {
19+
"type": "string",
20+
"description": "Azure Resource Group name for the AKS cluster. TODO: You must update this."
21+
},
22+
"region": {
23+
"type": "string",
24+
"description": "Azure region for the AKS cluster (e.g., 'East US')."
25+
},
26+
"cluster_version": {
27+
"type": "string",
28+
"description": "Desired AKS Kubernetes version (e.g., '1.28'). Check Azure documentation for available versions."
29+
},
30+
"dns_prefix": {
31+
"type": "string",
32+
"description": "Unique DNS prefix for the AKS cluster, part of its FQDN. TODO: You must provide a globally unique value."
33+
},
34+
"agent_pool_name": {
35+
"type": "string",
36+
"description": "Name for the default agent (node) pool.",
37+
"default": "agentpool"
38+
},
39+
"agent_vm_size": {
40+
"type": "string",
41+
"description": "VM size for the AKS agent nodes (e.g., 'Standard_DS2_v2').",
42+
"default": "Standard_DS2_v2"
43+
},
44+
"agent_count": {
45+
"type": "integer",
46+
"description": "Number of nodes in the default agent pool.",
47+
"default": 1,
48+
"minimum": 1
49+
},
50+
"resource_tags": {
51+
"type": "object",
52+
"description": "Custom tags to apply to Azure resources. It's recommended to define a 'cost_center' tag.",
53+
"properties": {
54+
"team": { "type": "string", "default": "Devops_Team" },
55+
"environment": { "type": "string", "default": "non-production" }
56+
},
57+
"additionalProperties": { "type": "string" }
58+
}
59+
}
60+
}

charts/aks/values.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# values.yaml for AKS cluster provisioning
2+
3+
# -- Name of the AKS cluster
4+
name: "example-aks-cluster"
5+
# -- Azure Resource Group name for the AKS cluster.
6+
# TODO: Replace with your desired Resource Group name. Ensure it exists or will be created by Terraform if configured.
7+
resource_group_name: "rg-myaks-cluster"
8+
# -- Azure region for the AKS cluster (e.g., 'East US', 'West Europe').
9+
region: "East US"
10+
# -- Desired AKS version (e.g., '1.28'). Check Azure documentation for available versions.
11+
cluster_version: "1.28"
12+
# -- Unique DNS prefix for the AKS cluster. This will be part of the FQDN.
13+
# TODO: Replace with a globally unique DNS prefix.
14+
dns_prefix: "myuniqueakscluster"
15+
# -- Name for the default agent (node) pool.
16+
agent_pool_name: "agentpool"
17+
# -- VM size for the AKS agent nodes (e.g., 'Standard_DS2_v2').
18+
agent_vm_size: "Standard_DS2_v2"
19+
# -- Number of nodes in the default agent pool.
20+
agent_count: 1
21+
22+
# -- Tags to apply to Azure resources created for the cluster.
23+
resource_tags:
24+
team: "Devops_Team"
25+
environment: "non-production"

charts/gke/Chart.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
appVersion: 0.0.1
3+
description: Helm chart to provision a GKE cluster using Terraform with Flux.
4+
name: terraform-gke-cluster
5+
type: application
6+
version: 0.0.1

charts/gke/templates/NOTES.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Your {{ .Chart.Name }} Helm chart for provisioning a {{ .Values.name | default .Release.Name }} GKE cluster has been deployed.
2+
3+
The actual cluster provisioning is managed by the FluxCD Terraform controller using the configuration from the 'devtron-labs/utilities' Git repository.
4+
5+
1. Check the status of the GitRepository source:
6+
kubectl get gitrepositories -n flux-system {{ .Release.Name }} -o wide
7+
8+
2. Check the status of the Terraform custom resource:
9+
kubectl get terraforms -n flux-system {{ .Release.Name }} -o wide
10+
kubectl describe terraforms -n flux-system {{ .Release.Name }}
11+
12+
(Look for conditions and events. Provisioning a GKE cluster can take several minutes.)
13+
14+
3. Important Reminders from your values.yaml:
15+
Please ensure you have correctly filled out all mandatory 'TODO' items in your values.yaml, such as:
16+
- GCP 'project_id'.
17+
- Appropriate 'resource_tags' (e.g., cost_center).
18+
- Ensure GCP credentials are correctly configured in the 'tf-gcp-creds' secret in the flux-system namespace for the Terraform runner pod.
19+
20+
If these are not correctly set, the Terraform provisioning will likely fail.
21+
22+
4. Cluster Outputs:
23+
Once the Terraform execution is complete and successful, any defined outputs (like Kubeconfig, cluster endpoint, etc., depending on the underlying Terraform module at {{ .Values.path }}) will be written to a Kubernetes Secret:
24+
Name: {{ .Release.Name }}-outputs
25+
Namespace: flux-system
26+
27+
You can inspect the secret using:
28+
kubectl get secret -n flux-system {{ .Release.Name }}-outputs -o yaml
29+
30+
The specific content of the secret depends on the outputs defined in the Terraform module.
31+
32+
Thank you for using the {{ .Chart.Name }} chart!

0 commit comments

Comments
 (0)