Skip to content

Commit 9444948

Browse files
authored
Merge pull request #9 from lablabs/fix_k8s_provider_issues
Add dummy helm chart deployment option
2 parents 7486ab3 + 7e2fd51 commit 9444948

File tree

8 files changed

+187
-23
lines changed

8 files changed

+187
-23
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ Check out these related projects.
2929
## Examples
3030

3131
See [Basic example](examples/basic/README.md) for further information.
32+
33+
## Potential issues with running terraform plan
34+
35+
When deploying with ArgoCD application, Kubernetes terraform provider requires access to Kubernetes cluster API during plan time. This introduces potential issue when you want to deploy the cluster with this addon at the same time, during the same Terraform run.
36+
37+
To overcome this issue, the module deploys the ArgoCD application object using the Helm provider, which does not require API access during plan. If you want to deploy the application using this workaround, you can set the `argo_application_use_helm` variable to `true`.
38+
3239
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
3340
## Requirements
3441

@@ -50,11 +57,13 @@ No modules.
5057
| [aws_iam_policy.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
5158
| [aws_iam_role.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
5259
| [aws_iam_role_policy_attachment.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
60+
| [helm_release.argocd_application](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
5361
| [helm_release.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
54-
| [kubernetes_manifest.this](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest) | resource |
62+
| [kubernetes_manifest.self](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest) | resource |
5563
| [aws_iam_policy_document.cluster_autoscaler](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
5664
| [aws_iam_policy_document.cluster_autoscaler_assume](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
5765
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
66+
| [utils_deep_merge_yaml.argo_application_values](https://registry.terraform.io/providers/cloudposse/utils/latest/docs/data-sources/deep_merge_yaml) | data source |
5867
| [utils_deep_merge_yaml.values](https://registry.terraform.io/providers/cloudposse/utils/latest/docs/data-sources/deep_merge_yaml) | data source |
5968

6069
## Inputs
@@ -65,6 +74,8 @@ No modules.
6574
| <a name="input_cluster_identity_oidc_issuer_arn"></a> [cluster\_identity\_oidc\_issuer\_arn](#input\_cluster\_identity\_oidc\_issuer\_arn) | The OIDC Identity issuer ARN for the cluster that can be used to associate IAM roles with a service account | `string` | n/a | yes |
6675
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | The name of the cluster | `string` | n/a | yes |
6776
| <a name="input_argo_application_enabled"></a> [argo\_application\_enabled](#input\_argo\_application\_enabled) | If set to true, the module will be deployed as ArgoCD application, otherwise it will be deployed as a Helm release | `bool` | `false` | no |
77+
| <a name="input_argo_application_use_helm"></a> [argo\_application\_use\_helm](#input\_argo\_application\_use\_helm) | If set to true, the ArgoCD Application manifest will be deployed using Kubernetes provider as a Helm release. Otherwise it'll be deployed as a Kubernetes manifest. See Readme for more info | `bool` | `false` | no |
78+
| <a name="input_argo_application_values"></a> [argo\_application\_values](#input\_argo\_application\_values) | Value overrides to use when deploying argo application object with helm | `string` | `""` | no |
6879
| <a name="input_argo_destionation_server"></a> [argo\_destionation\_server](#input\_argo\_destionation\_server) | Destination server for ArgoCD Application | `string` | `"https://kubernetes.default.svc"` | no |
6980
| <a name="input_argo_info"></a> [argo\_info](#input\_argo\_info) | ArgoCD info manifest parameter | `list` | <pre>[<br> {<br> "name": "terraform",<br> "value": "true"<br> }<br>]</pre> | no |
7081
| <a name="input_argo_namespace"></a> [argo\_namespace](#input\_argo\_namespace) | Namespace to deploy ArgoCD application CRD to | `string` | `"argo"` | no |

argo.tf

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,55 @@
1-
resource "kubernetes_manifest" "this" {
2-
count = var.argo_application_enabled ? 1 : 0
1+
locals {
2+
argo_application_values = {
3+
"project" : var.argo_project
4+
"source" : {
5+
"repoURL" : var.helm_repo_url
6+
"chart" : var.helm_chart_name
7+
"targetRevision" : var.helm_chart_version
8+
"helm" : {
9+
"releaseName" : var.helm_release_name
10+
"parameters" : [for k, v in var.settings : tomap({ "forceString" : true, "name" : k, "value" : v })]
11+
"values" : data.utils_deep_merge_yaml.values[0].output
12+
}
13+
}
14+
"destination" : {
15+
"server" : var.argo_destionation_server
16+
"namespace" : var.k8s_namespace
17+
}
18+
"syncPolicy" : var.argo_sync_policy
19+
"info" : var.argo_info
20+
}
21+
}
22+
23+
data "utils_deep_merge_yaml" "argo_application_values" {
24+
count = var.enabled && var.argo_application_enabled && var.argo_application_use_helm ? 1 : 0
25+
input = compact([
26+
yamlencode(local.argo_application_values),
27+
var.argo_application_values
28+
])
29+
}
30+
31+
resource "helm_release" "argocd_application" {
32+
count = var.enabled && var.argo_application_enabled && var.argo_application_use_helm ? 1 : 0
33+
34+
chart = "${path.module}/helm/argocd-application"
35+
name = var.helm_release_name
36+
namespace = var.argo_namespace
37+
38+
values = [
39+
data.utils_deep_merge_yaml.argo_application_values[0].output
40+
]
41+
}
42+
43+
44+
resource "kubernetes_manifest" "self" {
45+
count = var.enabled && var.argo_application_enabled && !var.argo_application_use_helm ? 1 : 0
346
manifest = {
447
"apiVersion" = "argoproj.io/v1alpha1"
548
"kind" = "Application"
649
"metadata" = {
750
"name" = var.helm_release_name
851
"namespace" = var.argo_namespace
952
}
10-
"spec" = {
11-
"project" = var.argo_project
12-
"source" = {
13-
"repoURL" = var.helm_repo_url
14-
"chart" = var.helm_chart_name
15-
"targetRevision" = var.helm_chart_version
16-
"helm" = {
17-
"releaseName" = var.helm_release_name
18-
"parameters" = [for k, v in var.settings : tomap({ "forceString" : true, "name" : k, "value" : v })]
19-
"values" = data.utils_deep_merge_yaml.values[0].output
20-
}
21-
}
22-
"destination" = {
23-
"server" = var.argo_destionation_server
24-
"namespace" = var.k8s_namespace
25-
}
26-
"syncPolicy" = var.argo_sync_policy
27-
"info" = var.argo_info
28-
}
53+
"spec" = local.argo_application_values
2954
}
3055
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

helm/argocd-application/Chart.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v2
2+
name: argocd-application
3+
description: Helm wrapper for deploying ArgoCD application object
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 0.1.0
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "argocd_application.name" -}}
5+
{{- default .Chart.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 "argocd_application.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" .Release.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 "argocd_application.chart" -}}
30+
{{- printf "%s" .Chart.Name | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "argocd_application.labels" -}}
37+
helm.sh/chart: {{ include "argocd_application.chart" . }}
38+
{{ include "argocd_application.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 "argocd_application.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "argocd_application.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Application
3+
metadata:
4+
name: {{ include "argocd_application.fullname" . }}
5+
labels:
6+
{{- include "argocd_application.labels" . | nindent 4 }}
7+
spec:
8+
project: {{ .Values.project }}
9+
{{ with .Values.source }}
10+
source:
11+
{{- toYaml . | nindent 4 }}
12+
{{- end }}
13+
{{ with .Values.destination }}
14+
destination:
15+
{{- toYaml . | nindent 4 }}
16+
{{- end }}
17+
{{ with .Values.syncPolicy }}
18+
syncPolicy:
19+
{{- toYaml . | nindent 4 }}
20+
{{- end }}
21+
{{ with .Values.info }}
22+
info:
23+
{{- toYaml . | nindent 4 }}
24+
{{- end }}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nameOverride: ""
2+
fullnameOverride: ""

variables.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,23 @@ variable "argo_namespace" {
9595
description = "Namespace to deploy ArgoCD application CRD to"
9696
}
9797

98-
9998
variable "argo_application_enabled" {
10099
type = bool
101100
default = false
102101
description = "If set to true, the module will be deployed as ArgoCD application, otherwise it will be deployed as a Helm release"
103102
}
104103

104+
variable "argo_application_use_helm" {
105+
type = bool
106+
default = false
107+
description = "If set to true, the ArgoCD Application manifest will be deployed using Kubernetes provider as a Helm release. Otherwise it'll be deployed as a Kubernetes manifest. See Readme for more info"
108+
}
109+
110+
variable "argo_application_values" {
111+
default = ""
112+
description = "Value overrides to use when deploying argo application object with helm"
113+
}
114+
105115
variable "argo_destionation_server" {
106116
type = string
107117
default = "https://kubernetes.default.svc"

0 commit comments

Comments
 (0)