diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 8e33febce6..f8e9912e0e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -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 @@ -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: diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 1e52d35f1d..4601be7a55 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -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 diff --git a/.gitignore b/.gitignore index d9edebaba2..cb902a2338 100644 --- a/.gitignore +++ b/.gitignore @@ -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* diff --git a/argocd/app-of-apps/Chart.yaml b/argocd/app-of-apps/Chart.yaml new file mode 100644 index 0000000000..21cfe49977 --- /dev/null +++ b/argocd/app-of-apps/Chart.yaml @@ -0,0 +1,4 @@ +--- +apiVersion: "v2" +name: "app-of-apps" +version: "0" diff --git a/argocd/app-of-apps/templates/apps.yaml b/argocd/app-of-apps/templates/apps.yaml new file mode 100644 index 0000000000..6817725529 --- /dev/null +++ b/argocd/app-of-apps/templates/apps.yaml @@ -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 diff --git a/argocd/app-of-apps/values.yaml b/argocd/app-of-apps/values.yaml new file mode 100644 index 0000000000..ec6a7ca8a6 --- /dev/null +++ b/argocd/app-of-apps/values.yaml @@ -0,0 +1,7 @@ +--- +spec: + destination: + server: https://kubernetes.default.svc + source: + repoURL: ... + targetRevision: HEAD diff --git a/examples/k3s-docker-demo-app/terraform/main.tf b/examples/k3s-docker-demo-app/terraform/main.tf index 5ee00547f4..48ae163323 100644 --- a/examples/k3s-docker-demo-app/terraform/main.tf +++ b/examples/k3s-docker-demo-app/terraform/main.tf @@ -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" { @@ -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" = <=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "demo-app.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} diff --git a/tests/k3s-docker-demo-app/argocd/demo-app/templates/secretproviderclass.yaml b/tests/k3s-docker-demo-app/argocd/demo-app/templates/secretproviderclass.yaml new file mode 100644 index 0000000000..afe73ec138 --- /dev/null +++ b/tests/k3s-docker-demo-app/argocd/demo-app/templates/secretproviderclass.yaml @@ -0,0 +1,23 @@ +--- +apiVersion: secrets-store.csi.x-k8s.io/v1alpha1 +kind: SecretProviderClass +metadata: + name: vault-demo-app +spec: + provider: vault + parameters: + roleName: "demo-app" + vaultAddress: "http://vault-internal.vault.svc:8200" + vaultSkipTLSVerify: "true" + objects: | + array: + - | + objectPath: "/demo-app" + objectName: "foo" + objectVersion: "" + secretObjects: + - data: + - key: foo + objectName: demo-app + secretName: demo-app-secrets-store-csi-secret + type: Opaque diff --git a/tests/k3s-docker-demo-app/argocd/demo-app/templates/service.yaml b/tests/k3s-docker-demo-app/argocd/demo-app/templates/service.yaml new file mode 100644 index 0000000000..87706e7175 --- /dev/null +++ b/tests/k3s-docker-demo-app/argocd/demo-app/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "demo-app.fullname" . }} + labels: + {{- include "demo-app.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "demo-app.selectorLabels" . | nindent 4 }} diff --git a/tests/k3s-docker-demo-app/argocd/demo-app/templates/serviceaccount.yaml b/tests/k3s-docker-demo-app/argocd/demo-app/templates/serviceaccount.yaml new file mode 100644 index 0000000000..073bf3f6ef --- /dev/null +++ b/tests/k3s-docker-demo-app/argocd/demo-app/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "demo-app.serviceAccountName" . }} + labels: + {{- include "demo-app.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/tests/k3s-docker-demo-app/argocd/demo-app/templates/tests/test-connection.yaml b/tests/k3s-docker-demo-app/argocd/demo-app/templates/tests/test-connection.yaml new file mode 100644 index 0000000000..01382a2612 --- /dev/null +++ b/tests/k3s-docker-demo-app/argocd/demo-app/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "demo-app.fullname" . }}-test-connection" + labels: + {{- include "demo-app.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "demo-app.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/tests/k3s-docker-demo-app/argocd/demo-app/values.yaml b/tests/k3s-docker-demo-app/argocd/demo-app/values.yaml new file mode 100644 index 0000000000..898c60165d --- /dev/null +++ b/tests/k3s-docker-demo-app/argocd/demo-app/values.yaml @@ -0,0 +1,82 @@ +# Default values for demo-app. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: paulbouwer/hello-kubernetes + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "1.8" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: + vault.hashicorp.com/agent-inject: "true" + vault.hashicorp.com/agent-inject-secret-demo-app: /secret/demo-app + vault.hashicorp.com/role: demo-app + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/tests/k3s-docker-demo-app/argocd/project-apps/Chart.yaml b/tests/k3s-docker-demo-app/argocd/project-apps/Chart.yaml new file mode 100644 index 0000000000..f60a09292b --- /dev/null +++ b/tests/k3s-docker-demo-app/argocd/project-apps/Chart.yaml @@ -0,0 +1,4 @@ +--- +apiVersion: "v2" +name: "project-apps" +version: "0" diff --git a/tests/k3s-docker-demo-app/argocd/project-apps/templates/demo-app.yaml b/tests/k3s-docker-demo-app/argocd/project-apps/templates/demo-app.yaml new file mode 100644 index 0000000000..d92d6ca21f --- /dev/null +++ b/tests/k3s-docker-demo-app/argocd/project-apps/templates/demo-app.yaml @@ -0,0 +1,38 @@ +--- +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: demo-app + namespace: argocd +spec: + project: default + source: + path: examples/k3s-docker-demo-app/argocd/demo-app + repoURL: {{ .Values.spec.source.repoURL }} + targetRevision: {{ .Values.spec.source.targetRevision }} + helm: + values: | + ingress: + enabled: true + annotations: + cert-manager.io/cluster-issuer: selfsigned-issuer + traefik.ingress.kubernetes.io/router.entrypoints: websecure + traefik.ingress.kubernetes.io/router.tls: "true" + hosts: + - host: demo-app.apps.{{ .Values.baseDomain }} + paths: + - / + tls: + - secretName: demo-app-secret + hosts: + - demo-app.apps.{{ .Values.baseDomain }} + autoscaling: + enabled: true + minReplicas: 2 + maxReplicas: 3 + destination: + namespace: demo-app + server: {{ .Values.spec.destination.server }} + syncPolicy: + automated: + selfHeal: true diff --git a/tests/k3s-docker-demo-app/argocd/project-apps/values.yaml b/tests/k3s-docker-demo-app/argocd/project-apps/values.yaml new file mode 100644 index 0000000000..ec6a7ca8a6 --- /dev/null +++ b/tests/k3s-docker-demo-app/argocd/project-apps/values.yaml @@ -0,0 +1,7 @@ +--- +spec: + destination: + server: https://kubernetes.default.svc + source: + repoURL: ... + targetRevision: HEAD diff --git a/tests/k3s-docker-demo-app/terraform/main.tf b/tests/k3s-docker-demo-app/terraform/main.tf new file mode 100644 index 0000000000..0fdac533d3 --- /dev/null +++ b/tests/k3s-docker-demo-app/terraform/main.tf @@ -0,0 +1,100 @@ +locals { + base_domain = module.cluster.base_domain + kubernetes_host = module.cluster.kubernetes_host + kubernetes_username = module.cluster.kubernetes_username + kubernetes_password = module.cluster.kubernetes_password + kubernetes_cluster_ca_certificate = module.cluster.kubernetes_cluster_ca_certificate + kubernetes_vault_auth_backend_path = module.cluster.kubernetes_vault_auth_backend_path +} + +module "cluster" { + source = "../../../modules/k3s-docker" + + cluster_name = terraform.workspace + node_count = 1 + + repo_url = var.repo_url + target_revision = var.target_revision +} + +provider "helm" { + kubernetes { + insecure = true + host = local.kubernetes_host + username = local.kubernetes_username + password = local.kubernetes_password + load_config_file = false + } +} + +provider "vault" { + address = format("https://vault.apps.%s", local.base_domain) + token = "root" + skip_tls_verify = true +} + +resource "helm_release" "project_apps" { + name = "project-apps" + chart = "${path.module}/../argocd/project-apps" + namespace = "argocd" + dependency_update = true + create_namespace = true + + values = [ + <