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 f083513
Show file tree
Hide file tree
Showing 28 changed files with 683 additions and 127 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: examples/k3s-docker-demo-app
working-directory: tests/k3s-docker-demo-app
steps:
- uses: actions/checkout@v2
- name: Deploy cluster
Expand All @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: examples/k3s-docker-demo-app
working-directory: tests/k3s-docker-demo-app
steps:
- uses: actions/checkout@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: examples/k3s-docker-demo-app
working-directory: tests/k3s-docker-demo-app
steps:
- uses: actions/checkout@v2
- name: Deploy cluster
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ package-lock.json
examples/*/terraform/dev.log
examples/*/terraform/kubeconfig.yaml
examples/*/terraform/terraform.tfstate*
tests/*/terraform/dev.log
tests/*/terraform/kubeconfig.yaml
tests/*/terraform/terraform.tfstate*
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"
23 changes: 23 additions & 0 deletions argocd/app-of-apps/templates/apps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
annotations:
argocd.argoproj.io/sync-wave: "5"
name: apps
namespace: argocd
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
65 changes: 21 additions & 44 deletions examples/k3s-docker-demo-app/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ 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 "helm" {
kubernetes {
insecure = true
host = local.kubernetes_host
username = local.kubernetes_username
password = local.kubernetes_password
load_config_file = false
}
}

provider "vault" {
Expand All @@ -33,27 +36,15 @@ provider "vault" {
skip_tls_verify = true
}

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

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
resource "helm_release" "project_apps" {
name = "project-apps"
chart = "${path.module}/../argocd/project-apps"
namespace = "argocd"
dependency_update = true
create_namespace = true

values = [
<<EOT
---
spec:
source:
Expand All @@ -62,25 +53,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
7 changes: 0 additions & 7 deletions scripts/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ cd terraform || exit
terraform init -upgrade
terraform workspace select "$CLUSTER_NAME" || terraform workspace new "$CLUSTER_NAME"
terraform init -upgrade
terraform apply --auto-approve \
-target module.cluster.module.cluster \
-target module.cluster.helm_release.argocd \
-target module.cluster.module.iam_assumable_role_cert_manager \
-target module.cluster.aws_cognito_user_pool_client.client \
-target module.cluster.random_password.oauth2_cookie_secret
terraform apply --auto-approve -target module.cluster.kubernetes_manifest.app_of_apps
terraform apply --auto-approve -target module.cluster.null_resource.wait_for_vault
terraform apply --auto-approve
terraform plan --detailed-exitcode
Expand Down
28 changes: 28 additions & 0 deletions tests/k3s-docker-demo-app/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CLUSTER_NAME := default

ifneq ($(CI_PROJECT_URL),)
TF_VAR_repo_url = $(CI_PROJECT_URL)
TF_VAR_target_revision = $(CI_COMMIT_REF_NAME)
else
ifneq ($(GITHUB_SERVER_URL),)
TF_VAR_repo_url = "$(GITHUB_SERVER_URL)/$(GITHUB_REPOSITORY).git"
TF_VAR_target_revision = $(shell echo $(GITHUB_REF) | rev | cut -f1 -d/ | rev)
else
REMOTE := $(shell git status -sb|sed -Ene's@.. ([^\.]*)\.\.\.([^/]*)/(.*)@\2@p')
TF_VAR_target_revision := $(shell git status -sb|sed -Ene's@.. ([^\.]*)\.\.\.([^/]*)/(.*)@\3@p'|cut -f1 -d' ')
REMOTE_URL := $(shell git remote get-url $(REMOTE))
ifeq ($(findstring "https",$(REMOTE_URL)),)
TF_VAR_repo_url = "https://github.com/$(shell echo $(REMOTE_URL) | sed -Ene's|[email protected]:([^/]*)/(.*).git|\1/\2|p').git"
else
TF_VAR_repo_url = $(REMOTE_URL)
endif
endif
endif

.PHONY: provision clean

provision: terraform/*.tf
CLUSTER_NAME=$(CLUSTER_NAME) TF_VAR_repo_url=$(TF_VAR_repo_url) TF_VAR_target_revision=$(TF_VAR_target_revision) ../../scripts/provision.sh

clean:
CLUSTER_NAME=$(CLUSTER_NAME) TF_VAR_repo_url=$(TF_VAR_repo_url) TF_VAR_target_revision=$(TF_VAR_target_revision) ../../scripts/destroy.sh
23 changes: 23 additions & 0 deletions tests/k3s-docker-demo-app/argocd/demo-app/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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/
23 changes: 23 additions & 0 deletions tests/k3s-docker-demo-app/argocd/demo-app/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: demo-app
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: "1.8"
Loading

0 comments on commit f083513

Please sign in to comment.