diff --git a/apps/README.md b/apps/README.md new file mode 100644 index 0000000..a7ef689 --- /dev/null +++ b/apps/README.md @@ -0,0 +1,27 @@ +# Apps +This directory contains all of the applications you installed by using: +```bash +argocd-autopilot app create --app -p +``` + +## Application Types +> If you don't specify the application `--type` argocd-autopilot will try to clone the source repository and infer the application type [automatically](https://argoproj.github.io/argo-cd/user-guide/tool_detection/#tool-detection) + +* ### Directory application + Such an application references a specific directory at a given repo URL, path and revision. It will be persisted in the GitOps Repository as a single file at `apps///config.json`. + #### Example: + ```bash + argocd-autopilot app create dir-example --app github.com/argoproj-labs/argocd-autopilot/examples/demo-dir/ -p --type dir + ``` + +* ### Kustomize application + A Kustomize application will have exactly one: `apps//base/kustomization.yaml` file, and one or more `apps//overlays//` folders. + + The `apps//base/kustomization.yaml` file is created the first time you create the application. The `apps//overlays//` folder is created for each project you install this application on. So all overlays of the same application are using the same base `kustomization.yaml`. + #### Example: + Try running the following command: + ```bash + argocd-autopilot app create hello-world --app github.com/argoproj-labs/argocd-autopilot/examples/demo-app/ -p --type kustomize + ``` + +###### * If you did not create a project yet take a look at: [creating a project](https://argocd-autopilot.readthedocs.io/en/stable/Getting-Started/#add-a-project-and-an-application). \ No newline at end of file diff --git a/apps/my-app/base/kustomization.yaml b/apps/my-app/base/kustomization.yaml new file mode 100644 index 0000000..233de2b --- /dev/null +++ b/apps/my-app/base/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - github.com/argoproj-labs/argocd-autopilot/examples/demo-app/ \ No newline at end of file diff --git a/apps/my-app/overlays/k3s-cluster/config.json b/apps/my-app/overlays/k3s-cluster/config.json new file mode 100644 index 0000000..f221d7c --- /dev/null +++ b/apps/my-app/overlays/k3s-cluster/config.json @@ -0,0 +1,11 @@ +{ + "appName": "my-app", + "userGivenName": "my-app", + "destNamespace": "default", + "destServer": "https://kubernetes.default.svc", + "srcPath": "apps/my-app/overlays/k3s-cluster", + "srcRepoURL": "https://github.com/3dwardch3ng/home-cluster-ops.git", + "srcTargetRevision": "", + "labels": null, + "annotations": null +} \ No newline at end of file diff --git a/apps/my-app/overlays/k3s-cluster/kustomization.yaml b/apps/my-app/overlays/k3s-cluster/kustomization.yaml new file mode 100644 index 0000000..a227ac4 --- /dev/null +++ b/apps/my-app/overlays/k3s-cluster/kustomization.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../../base \ No newline at end of file diff --git a/appsets/k3s-cluster-appset.yaml b/appsets/k3s-cluster-appset.yaml deleted file mode 100644 index de6f7df..0000000 --- a/appsets/k3s-cluster-appset.yaml +++ /dev/null @@ -1,39 +0,0 @@ -apiVersion: argoproj.io/v1alpha1 -kind: ApplicationSet -metadata: - name: k3s-cluster-appset - namespace: argocd -spec: - goTemplate: true - goTemplateOptions: ["missingkey=error"] - generators: - - git: - repoURL: https://github.com/3dwardch3ng/home-cluster-ops.git - revision: HEAD - directories: - - path: apps/*/envs/k3s-cluster - template: - metadata: - name: '{{index .path.segments 1}}-{{index .path.segments 3}}' - spec: - # The project the application belongs to. - project: home-cluster-ops - - # Source of the application manifests - source: - repoURL: https://github.com/3dwardch3ng/home-cluster-ops.git - targetRevision: HEAD - path: '{{.path.path}}' - - # Destination cluster and namespace to deploy the application - destination: - server: https://kubernetes.default.svc - namespace: '{{index .path.segments 1}}-{{index .path.segments 3}}' - - # Sync policy - syncPolicy: - syncOptions: - - CreateNamespace=true - automated: # automated sync by default retries failed attempts 5 times with following delays between attempts ( 5s, 10s, 20s, 40s, 80s ); retry controlled using `retry` field. - prune: true # Specifies if resources should be pruned during auto-syncing ( false by default ). - selfHeal: true # Specifies if partial app sync should be executed when resources are changed only in target Kubernetes cluster and no git change detected ( false by default ). \ No newline at end of file diff --git a/bootstrap/argo-cd.yaml b/bootstrap/argo-cd.yaml new file mode 100644 index 0000000..a2e38bd --- /dev/null +++ b/bootstrap/argo-cd.yaml @@ -0,0 +1,38 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + creationTimestamp: null + labels: + app.kubernetes.io/managed-by: argocd-autopilot + app.kubernetes.io/name: argo-cd + name: argo-cd + namespace: argocd +spec: + destination: + namespace: argocd + server: https://kubernetes.default.svc + ignoreDifferences: + - group: argoproj.io + jsonPointers: + - /status + kind: Application + project: default + source: + path: bootstrap/argo-cd + repoURL: https://github.com/3dwardch3ng/home-cluster-ops.git + syncPolicy: + automated: + allowEmpty: true + prune: true + selfHeal: true + syncOptions: + - allowEmpty=true +status: + health: {} + summary: {} + sync: + comparedTo: + destination: {} + source: + repoURL: "" + status: "" \ No newline at end of file diff --git a/bootstrap/argo-cd/kustomization.yaml b/bootstrap/argo-cd/kustomization.yaml new file mode 100644 index 0000000..6df5a48 --- /dev/null +++ b/bootstrap/argo-cd/kustomization.yaml @@ -0,0 +1,17 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +configMapGenerator: + - behavior: merge + literals: + - | + repository.credentials=- passwordSecret: + key: git_token + name: autopilot-secret + url: https://github.com/ + usernameSecret: + key: git_username + name: autopilot-secret + name: argocd-cm +kind: Kustomization +namespace: argocd +resources: + - github.com/argoproj-labs/argocd-autopilot/manifests/base?ref=v0.4.12 \ No newline at end of file diff --git a/bootstrap/cluster-resources.yaml b/bootstrap/cluster-resources.yaml new file mode 100644 index 0000000..4d93d10 --- /dev/null +++ b/bootstrap/cluster-resources.yaml @@ -0,0 +1,49 @@ +apiVersion: argoproj.io/v1alpha1 +kind: ApplicationSet +metadata: + annotations: + argocd.argoproj.io/sync-wave: "0" + creationTimestamp: null + name: cluster-resources + namespace: argocd +spec: + generators: + - git: + files: + - path: bootstrap/cluster-resources/*.json + repoURL: https://github.com/3dwardch3ng/home-cluster-ops.git + requeueAfterSeconds: 20 + revision: "" + template: + metadata: {} + spec: + destination: {} + project: "" + source: + repoURL: "" + syncPolicy: + preserveResourcesOnDeletion: true + template: + metadata: + labels: + app.kubernetes.io/managed-by: argocd-autopilot + app.kubernetes.io/name: cluster-resources-{{name}} + name: cluster-resources-{{name}} + namespace: argocd + spec: + destination: + server: '{{server}}' + ignoreDifferences: + - group: argoproj.io + jsonPointers: + - /status + kind: Application + project: default + source: + path: bootstrap/cluster-resources/{{name}} + repoURL: https://github.com/3dwardch3ng/home-cluster-ops.git + syncPolicy: + automated: + allowEmpty: true + selfHeal: true +status: {} \ No newline at end of file diff --git a/bootstrap/cluster-resources/in-cluster.json b/bootstrap/cluster-resources/in-cluster.json new file mode 100644 index 0000000..259083a --- /dev/null +++ b/bootstrap/cluster-resources/in-cluster.json @@ -0,0 +1 @@ +{"name":"in-cluster","server":"https://kubernetes.default.svc"} \ No newline at end of file diff --git a/bootstrap/cluster-resources/in-cluster/README.md b/bootstrap/cluster-resources/in-cluster/README.md new file mode 100644 index 0000000..279f224 --- /dev/null +++ b/bootstrap/cluster-resources/in-cluster/README.md @@ -0,0 +1,3 @@ +# Cluster Resources +This directory contains all cluster resources that should be applied to cluster: `in-cluster`. +For example `Namespace` resources that are shared by multiple applications on the same namespace. \ No newline at end of file diff --git a/bootstrap/cluster-resources/in-cluster/argocd-ns.yaml b/bootstrap/cluster-resources/in-cluster/argocd-ns.yaml new file mode 100644 index 0000000..b16706d --- /dev/null +++ b/bootstrap/cluster-resources/in-cluster/argocd-ns.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Namespace +metadata: + annotations: + argocd.argoproj.io/sync-options: Prune=false + creationTimestamp: null + name: argocd +spec: {} +status: {} \ No newline at end of file diff --git a/bootstrap/root.yaml b/bootstrap/root.yaml new file mode 100644 index 0000000..a5802a6 --- /dev/null +++ b/bootstrap/root.yaml @@ -0,0 +1,40 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + creationTimestamp: null + finalizers: + - resources-finalizer.argocd.argoproj.io + labels: + app.kubernetes.io/managed-by: argocd-autopilot + app.kubernetes.io/name: root + name: root + namespace: argocd +spec: + destination: + namespace: argocd + server: https://kubernetes.default.svc + ignoreDifferences: + - group: argoproj.io + jsonPointers: + - /status + kind: Application + project: default + source: + path: projects + repoURL: https://github.com/3dwardch3ng/home-cluster-ops.git + syncPolicy: + automated: + allowEmpty: true + prune: true + selfHeal: true + syncOptions: + - allowEmpty=true +status: + health: {} + summary: {} + sync: + comparedTo: + destination: {} + source: + repoURL: "" + status: "" \ No newline at end of file diff --git a/projects/k3s-cluster.yaml b/projects/k3s-cluster.yaml new file mode 100644 index 0000000..4ec7b75 --- /dev/null +++ b/projects/k3s-cluster.yaml @@ -0,0 +1,94 @@ +apiVersion: argoproj.io/v1alpha1 +kind: AppProject +metadata: + annotations: + argocd-autopilot.argoproj-labs.io/default-dest-server: https://kubernetes.default.svc + argocd.argoproj.io/sync-options: PruneLast=true + argocd.argoproj.io/sync-wave: "-2" + creationTimestamp: null + name: k3s-cluster + namespace: argocd +spec: + clusterResourceWhitelist: + - group: '*' + kind: '*' + description: k3s-cluster project + destinations: + - namespace: '*' + server: '*' + namespaceResourceWhitelist: + - group: '*' + kind: '*' + sourceRepos: + - '*' +status: {} +--- +apiVersion: argoproj.io/v1alpha1 +kind: ApplicationSet +metadata: + annotations: + argocd.argoproj.io/sync-wave: "0" + creationTimestamp: null + name: k3s-cluster + namespace: argocd +spec: + generators: + - git: + files: + - path: apps/**/k3s-cluster/config.json + repoURL: V + requeueAfterSeconds: 20 + revision: "" + template: + metadata: {} + spec: + destination: {} + project: "" + source: + repoURL: "" + - git: + files: + - path: apps/**/k3s-cluster/config_dir.json + repoURL: https://github.com/3dwardch3ng/home-cluster-ops.git + requeueAfterSeconds: 20 + revision: "" + template: + metadata: {} + spec: + destination: {} + project: "" + source: + directory: + exclude: '{{ exclude }}' + include: '{{ include }}' + jsonnet: {} + recurse: true + repoURL: "" + syncPolicy: {} + template: + metadata: + labels: + app.kubernetes.io/managed-by: argocd-autopilot + app.kubernetes.io/name: '{{ appName }}' + name: k3s-cluster-{{ userGivenName }} + namespace: argocd + spec: + destination: + namespace: '{{ destNamespace }}' + server: '{{ destServer }}' + ignoreDifferences: + - group: argoproj.io + jsonPointers: + - /status + kind: Application + project: k3s-cluster + source: + path: '{{ srcPath }}' + repoURL: '{{ srcRepoURL }}' + targetRevision: '{{ srcTargetRevision }}' + syncPolicy: + automated: + allowEmpty: true + prune: true + selfHeal: true +status: {} \ No newline at end of file diff --git a/root-argocd-app.yaml b/root-argocd-app.yaml deleted file mode 100644 index 9432611..0000000 --- a/root-argocd-app.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: argoproj.io/v1alpha1 -kind: Application -metadata: - name: all-apps - namespace: argocd -spec: - project: home-cluster-ops - source: - repoURL: https://github.com/3dwardch3ng/home-cluster-ops.git - targetRevision: HEAD - path: appsets - destination: - server: https://kubernetes.default.svc - namespace: argocd - syncPolicy: - syncOptions: - - CreateNamespace=true - automated: - prune: true - selfHeal: true \ No newline at end of file diff --git a/scripts/3.bootstrap-argocd.sh b/scripts/3.bootstrap-argocd.sh new file mode 100644 index 0000000..92d3a7a --- /dev/null +++ b/scripts/3.bootstrap-argocd.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +argocd-autopilot repo bootstrap --app https://github.com/argoproj-labs/argocd-autopilot/manifests/ha \ No newline at end of file