Skip to content

Commit

Permalink
Don't use kubernetes-alpha provider (fixes camptocamp#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanevet committed Nov 4, 2020
1 parent 66433db commit 2eff070
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 121 deletions.
4 changes: 4 additions & 0 deletions argocd/app-of-apps/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
apiVersion: "v2"
name: "app-of-apps"
version: "0"
25 changes: 25 additions & 0 deletions argocd/app-of-apps/templates/apps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
annotations:
argocd.argoproj.io/sync-wave: "5"
name: apps
namespace: argocd
labels:
argocd.argoproj.io/instance: apps
spec:
project: default
source:
path: argocd/apps
repoURL: {{ .Values.spec.source.repoURL }}
targetRevision: {{ .Values.spec.source.targetRevision }}
helm:
values: |
{{ toYaml .Values | nindent 8 }}
destination:
namespace: default
server: {{ .Values.spec.destination.server }}
syncPolicy:
automated:
selfHeal: true
7 changes: 7 additions & 0 deletions argocd/app-of-apps/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
spec:
destination:
server: https://kubernetes.default.svc
source:
repoURL: ...
targetRevision: HEAD
63 changes: 15 additions & 48 deletions examples/k3s-docker-demo-app/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
repo_url = "https://github.com/camptocamp/camptocamp-devops-stack.git"
target_revision = "HEAD"
repo_url = "https://github.com/mcanevet/camptocamp-devops-stack.git"
target_revision = "no_kubernetes_alpha"

base_domain = module.cluster.base_domain
kubernetes_host = module.cluster.kubernetes_host
Expand All @@ -11,7 +11,7 @@ locals {
}

module "cluster" {
source = "git::https://github.com/camptocamp/camptocamp-devops-stack.git//modules/k3s-docker?ref=HEAD"
source = "../../../modules/k3s-docker"

cluster_name = terraform.workspace
node_count = 1
Expand All @@ -20,40 +20,21 @@ module "cluster" {
target_revision = local.target_revision
}

provider "kubernetes-alpha" {
host = local.kubernetes_host
username = local.kubernetes_username
password = local.kubernetes_password
cluster_ca_certificate = local.kubernetes_cluster_ca_certificate
}

provider "vault" {
address = format("https://vault.apps.%s", local.base_domain)
token = "root"
skip_tls_verify = true
}

resource "kubernetes_manifest" "project_apps" {
provider = kubernetes-alpha
resource "helm_release" "project_apps" {
name = "project-apps"
chart = "${path.module}/../argocd/project-apps"
namespace = "argocd"
dependency_update = true
create_namespace = true

manifest = {
"apiVersion" = "argoproj.io/v1alpha1"
"kind" = "Application"
"metadata" = {
"name" = "project-apps"
"namespace" = "argocd"
"annotations" = {
"argocd.argoproj.io/sync-wave" = "15"
}
}
"spec" = {
"project" = "default"
"source" = {
"path" = "examples/k3s-docker-demo-app/argocd/project-apps"
"repoURL" = local.repo_url
"targetRevision" = local.target_revision
"helm" = {
"values" = <<EOT
values = [
<<EOT
---
spec:
source:
Expand All @@ -62,25 +43,11 @@ spec:
baseDomain: ${local.base_domain}
EOT
}
}
"destination" = {
"namespace" = "default"
"server" = "https://kubernetes.default.svc"
}
"syncPolicy" = {
"automated" = {
"selfHeal" = true
}
}
}
}
]

lifecycle {
ignore_changes = [
object,
]
}
depends_on = [
module.cluster,
]
}

resource "random_password" "superdupersecret" {
Expand Down
75 changes: 18 additions & 57 deletions modules/k3s-docker/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

locals {
base_domain = format("%s.nip.io", replace(module.cluster.ingress_ip_address, ".", "-"))
context = yamldecode(module.cluster.kubeconfig)
Expand All @@ -18,20 +17,6 @@ provider "helm" {
}
}

provider "kubernetes" {
host = local.kubernetes_host
username = local.kubernetes_username
password = local.kubernetes_password
cluster_ca_certificate = local.kubernetes_cluster_ca_certificate
}

provider "kubernetes-alpha" {
host = local.kubernetes_host
username = local.kubernetes_username
password = local.kubernetes_password
cluster_ca_certificate = local.kubernetes_cluster_ca_certificate
}

provider "vault" {
address = format("https://vault.apps.%s", local.base_domain)
token = "root"
Expand Down Expand Up @@ -83,48 +68,24 @@ server:
]
}

resource "kubernetes_manifest" "app_of_apps" {
provider = kubernetes-alpha

manifest = {
"apiVersion" = "argoproj.io/v1alpha1"
"kind" = "Application"
"metadata" = {
"name" = "apps"
"namespace" = "argocd"
"annotations" = {
"argocd.argoproj.io/sync-wave" = "5"
}
}
"spec" = {
"project" = "default"
"source" = {
"path" = "argocd/apps"
"repoURL" = var.repo_url
"targetRevision" = var.target_revision
"helm" = {
"parameters" = var.app_of_apps_parameters
"values" = templatefile("${path.module}/values.tmpl.yaml",
{
cluster_name = var.cluster_name,
base_domain = local.base_domain,
repo_url = var.repo_url,
target_revision = var.target_revision,
}
)
}
}
"destination" = {
"namespace" = "default"
"server" = "https://kubernetes.default.svc"
}
"syncPolicy" = {
"automated" = {
"selfHeal" = true
}
resource "helm_release" "app_of_apps" {
name = "app-of-apps"
chart = "${path.module}/../../argocd/app-of-apps"
namespace = "argocd"
dependency_update = true
create_namespace = true

values = [
templatefile("${path.module}/values.tmpl.yaml",
{
cluster_name = var.cluster_name,
base_domain = local.base_domain,
repo_url = var.repo_url,
target_revision = var.target_revision,
}
}
}
),
var.app_of_apps_values_overrides,
]

depends_on = [
helm_release.argocd,
Expand All @@ -133,7 +94,7 @@ resource "kubernetes_manifest" "app_of_apps" {

resource "null_resource" "wait_for_vault" {
depends_on = [
kubernetes_manifest.app_of_apps,
helm_release.app_of_apps,
]

provisioner "local-exec" {
Expand Down
12 changes: 4 additions & 8 deletions modules/k3s-docker/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ variable "target_revision" {
type = string
}

variable "app_of_apps_parameters" {
description = "App of apps parameters overrides."
type = list(object({
name = string
value = string
forceString = bool
}))
default = []
variable "app_of_apps_values_overrides" {
description = "App of apps values overrides."
type = string
default = ""
}
8 changes: 0 additions & 8 deletions modules/k3s-docker/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ terraform {
source = "hashicorp/null"
version = "3.0.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "1.13.2"
}
kubernetes-alpha = {
source = "hashicorp/kubernetes-alpha"
version = "0.2.1"
}
vault = {
source = "hashicorp/vault"
version = "2.15.0"
Expand Down

0 comments on commit 2eff070

Please sign in to comment.