← harnesscd-example-apps

feat: [PLG-3124]: add podinfo appset manifests (#40)

2a22ee7290e67b3b844fff40af60f20a0f3c1695 · Nick Lotz · Jan 3, 2024 20:50

* Create git-generator-files.yaml

* Create config.json

* Create config.json

* Create deployment.yaml

* Create kustomization.yaml

* Create service.yaml

* Update application.yml

* Create environment-dev.yml

* Create environment-prod.yml

* Create github-connector.yml

* Create service.yml

* Create trigger.yml

* Create pipeline.yml

* Update pipeline.yml

+415 −3 · 13 files changed

  • podinfo/apps/podinfo/deployment.yaml +75 −0
  • podinfo/apps/podinfo/kustomization.yaml +5 −0
  • podinfo/apps/podinfo/service.yaml +17 −0
  • podinfo/configs/git-generator-files-discovery /cluster-config/engineering/dev/config.json +10 −0
  • podinfo/configs/git-generator-files-discovery /cluster-config/engineering/prod/config.json +10 −0
  • podinfo/configs/git-generator-files-discovery /git-generator-files.yaml +26 −0
  • podinfo/harness-gitops/application.yml +3 −3
  • podinfo/harness-gitops/environment-dev.yml +8 −0
  • podinfo/harness-gitops/environment-prod.yml +1 −0
  • podinfo/harness-gitops/github-connector.yml +23 −0
  • podinfo/harness-gitops/pipeline.yml +164 −0
  • podinfo/harness-gitops/service.yml +34 −0
  • podinfo/harness-gitops/trigger.yml +39 −0
diff --git a/podinfo/apps/podinfo/deployment.yaml b/podinfo/apps/podinfo/deployment.yaml
new file mode 100644
index 0000000..93f65dc
--- /dev/null
+++ b/podinfo/apps/podinfo/deployment.yaml
@@ -0,0 +1,75 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: podinfo
+spec:
+  minReadySeconds: 3
+  revisionHistoryLimit: 5
+  progressDeadlineSeconds: 60
+  strategy:
+    rollingUpdate:
+      maxUnavailable: 0
+    type: RollingUpdate
+  selector:
+    matchLabels:
+      app: podinfo
+  template:
+    metadata:
+      annotations:
+        prometheus.io/scrape: "true"
+        prometheus.io/port: "9797"
+      labels:
+        app: podinfo
+    spec:
+      containers:
+      - name: podinfod
+        image: ghcr.io/stefanprodan/podinfo:6.5.3
+        imagePullPolicy: IfNotPresent
+        ports:
+        - name: http
+          containerPort: 9898
+          protocol: TCP
+        - name: http-metrics
+          containerPort: 9797
+          protocol: TCP
+        - name: grpc
+          containerPort: 9999
+          protocol: TCP
+        command:
+        - ./podinfo
+        - --port=9898
+        - --port-metrics=9797
+        - --grpc-port=9999
+        - --grpc-service-name=podinfo
+        - --level=info
+        - --random-delay=false
+        - --random-error=false
+        env:
+        - name: PODINFO_UI_COLOR
+          value: "#34577c"
+        livenessProbe:
+          exec:
+            command:
+            - podcli
+            - check
+            - http
+            - localhost:9898/healthz
+          initialDelaySeconds: 5
+          timeoutSeconds: 5
+        readinessProbe:
+          exec:
+            command:
+            - podcli
+            - check
+            - http
+            - localhost:9898/readyz
+          initialDelaySeconds: 5
+          timeoutSeconds: 5
+        resources:
+          limits:
+            cpu: 2000m
+            memory: 512Mi
+          requests:
+            cpu: 100m
+            memory: 64Mi
+            
diff --git a/podinfo/apps/podinfo/kustomization.yaml b/podinfo/apps/podinfo/kustomization.yaml
new file mode 100644
index 0000000..a33121c
--- /dev/null
+++ b/podinfo/apps/podinfo/kustomization.yaml
@@ -0,0 +1,5 @@
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+resources:
+  - deployment.yaml
+  - service.yaml
diff --git a/podinfo/apps/podinfo/service.yaml b/podinfo/apps/podinfo/service.yaml
new file mode 100644
index 0000000..9450823
--- /dev/null
+++ b/podinfo/apps/podinfo/service.yaml
@@ -0,0 +1,17 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: podinfo
+spec:
+  type: ClusterIP
+  selector:
+    app: podinfo
+  ports:
+    - name: http
+      port: 9898
+      protocol: TCP
+      targetPort: http
+    - port: 9999
+      targetPort: grpc
+      protocol: TCP
+      name: grpc
diff --git a/podinfo/configs/git-generator-files-discovery /cluster-config/engineering/dev/config.json b/podinfo/configs/git-generator-files-discovery /cluster-config/engineering/dev/config.json
new file mode 100644
index 0000000..1d5772c
--- /dev/null
+++ b/podinfo/configs/git-generator-files-discovery /cluster-config/engineering/dev/config.json	
@@ -0,0 +1,10 @@
+{
+  "cluster" : {
+    "owner" : "cluster-admin@company.com",
+    "address" : "https://kubernetes.default.svc",
+    "name" : "gitopscluster",
+    "namespace" : "dev"
+  },
+  "asset_id" : "12345678",
+  "aws_account" : "654321"
+}
diff --git a/podinfo/configs/git-generator-files-discovery /cluster-config/engineering/prod/config.json b/podinfo/configs/git-generator-files-discovery /cluster-config/engineering/prod/config.json
new file mode 100644
index 0000000..85b3677
--- /dev/null
+++ b/podinfo/configs/git-generator-files-discovery /cluster-config/engineering/prod/config.json	
@@ -0,0 +1,10 @@
+{
+  "cluster" : {
+    "owner" : "cluster-admin@company.com",
+    "address" : "https://kubernetes.default.svc",
+    "name" : "gitopscluster",
+    "namespace" : "prod"
+  },
+  "asset_id" : "12345678",
+  "aws_account" : "123456"
+}
diff --git a/podinfo/configs/git-generator-files-discovery /git-generator-files.yaml b/podinfo/configs/git-generator-files-discovery /git-generator-files.yaml
new file mode 100644
index 0000000..028a353
--- /dev/null
+++ b/podinfo/configs/git-generator-files-discovery /git-generator-files.yaml	
@@ -0,0 +1,26 @@
+apiVersion: argoproj.io/v1alpha1  
+kind: ApplicationSet  
+metadata:  
+  name: podinfo  
+spec:  
+  generators:  
+    - git:  
+        repoURL: https://github.com/GITHUB_USERNAME/harnesscd-example-apps.git  
+        revision: HEAD  
+        files:  
+        - path: "podinfo/configs/git-generator-files-discovery/cluster-config/**/config.json"  
+  template:  
+    metadata:  
+      name: '{{cluster.namespace}}-podinfo'  
+    spec:  
+      project: YOUR_ARGO_PROJECT_ID  
+      source:  
+        repoURL: https://github.com/YOUR_GITHUB_USERNAME/harness-gitops-workshop.git  
+        targetRevision: HEAD  
+        path: "podinfo/configs/git-generator-files-discovery/apps/podinfo"  
+      destination:  
+        server: '{{cluster.address}}'  
+        namespace: '{{cluster.namespace}}'  
+      syncPolicy:  
+        syncOptions:
+        - CreateNamespace=true
diff --git a/podinfo/harness-gitops/application.yml b/podinfo/harness-gitops/application.yml
index d6d694d..d946e2e 100644
--- a/podinfo/harness-gitops/application.yml
+++ b/podinfo/harness-gitops/application.yml
@@ -11,9 +11,9 @@ gitops:
         harness.io/envRef: ""
     spec:
       source:
-        repoURL: https://github.com/harness-community/harnesscd-example-apps
-        path: podinfo
-        targetRevision: master
+        repoURL: https://github.com/YOUR_GITHUB_USERNAME/harnesscd-example-apps
+        path: podinfo/configs/git-generator-files-discovery
+        targetRevision: main
       destination:
         server: https://kubernetes.default.svc
         namespace: default
diff --git a/podinfo/harness-gitops/environment-dev.yml b/podinfo/harness-gitops/environment-dev.yml
new file mode 100644
index 0000000..066ad1d
--- /dev/null
+++ b/podinfo/harness-gitops/environment-dev.yml
@@ -0,0 +1,8 @@
+environment:
+  name: dev
+  identifier: dev
+  tags: {}
+  type: PreProduction
+  orgIdentifier: default
+  projectIdentifier: default_project
+  variables: []
diff --git a/podinfo/harness-gitops/environment-prod.yml b/podinfo/harness-gitops/environment-prod.yml
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/podinfo/harness-gitops/environment-prod.yml
@@ -0,0 +1 @@
+
diff --git a/podinfo/harness-gitops/github-connector.yml b/podinfo/harness-gitops/github-connector.yml
new file mode 100644
index 0000000..3c91223
--- /dev/null
+++ b/podinfo/harness-gitops/github-connector.yml
@@ -0,0 +1,23 @@
+connector:
+  name: github-connector
+  identifier: githubconnector
+  description: ""
+  accountIdentifier: YOUR_HARNESS_ACCOUNT_ID
+  orgIdentifier: default
+  projectIdentifier: default_project
+  type: Github
+  spec:
+    url: https://github.com/GITHUB_USERNAME/harness-gitops-workshop
+    authentication:
+      type: Http
+      spec:
+        type: UsernameToken
+        spec:
+          username: GITHUB_USERNAME
+          tokenRef: github_pat
+    apiAccess:
+      type: Token
+      spec:
+        tokenRef: github_pat
+    executeOnDelegate: false
+    type: Repo
diff --git a/podinfo/harness-gitops/pipeline.yml b/podinfo/harness-gitops/pipeline.yml
new file mode 100644
index 0000000..d56cf49
--- /dev/null
+++ b/podinfo/harness-gitops/pipeline.yml
@@ -0,0 +1,164 @@
+pipeline:
+  name: cd-gitops-pipeline
+  identifier: cdgitopspipeline
+  projectIdentifier: default_project
+  orgIdentifier: default
+  tags: {}
+  properties:
+    ci:
+      codebase:
+        connectorRef: githubconnector
+        build: <+input>
+  stages:
+    - stage:
+        name: DeployDev
+        identifier: DeployDev
+        description: ""
+        type: Deployment
+        spec:
+          deploymentType: Kubernetes
+          gitOpsEnabled: true
+          service:
+            serviceRef: podinfoservice
+          execution:
+            steps:
+              - step:
+                  type: GitOpsUpdateReleaseRepo
+                  name: Update Release Repo
+                  identifier: updateReleaseRepo
+                  timeout: 10m
+                  spec:
+                    variables:
+                      - name: cluster.name
+                        type: String
+                        value: <+input>
+                      - name: cluster.owner
+                        type: String
+                        value: <+input>
+                      - name: cluster.address
+                        type: String
+                        value: <+input>
+                      - name: cluster.namespace
+                        type: String
+                        value: <+input>
+                      - name: asset_id
+                        type: String
+                        value: <+input>
+                      - name: aws_account
+                        type: String
+                        value: <+input>
+              - step:
+                  type: MergePR
+                  name: Merge PR
+                  identifier: mergePR
+                  spec:
+                    deleteSourceBranch: true
+                  timeout: 10m
+              - step:
+                  type: GitOpsFetchLinkedApps
+                  name: Fetch Linked Apps
+                  identifier: fetchLinkedApps
+                  timeout: 10m
+                  spec: {}
+            rollbackSteps: []
+          environment:
+            environmentRef: dev
+            deployToAll: false
+            gitOpsClusters:
+              - identifier: gitopscluster
+        tags: {}
+        failureStrategies:
+          - onFailure:
+              errors:
+                - AllErrors
+              action:
+                type: StageRollback
+    - stage:
+        name: ApprovePromoteProd
+        identifier: ApprovePromoteProd
+        description: ""
+        type: Approval
+        spec:
+          execution:
+            steps:
+              - step:
+                  name: ApprovePromoteProd
+                  identifier: ApprovePromoteProd
+                  type: HarnessApproval
+                  timeout: 1d
+                  spec:
+                    approvalMessage: |-
+                      Please review the following information
+                      and approve the pipeline progression
+                    includePipelineExecutionHistory: true
+                    approvers:
+                      minimumCount: 1
+                      disallowPipelineExecutor: false
+                      userGroups:
+                        - account._account_all_users
+                    isAutoRejectEnabled: false
+                    approverInputs: []
+        tags: {}
+    - stage:
+        name: DeployProd
+        identifier: DeployProd
+        description: ""
+        type: Deployment
+        spec:
+          deploymentType: Kubernetes
+          gitOpsEnabled: true
+          service:
+            serviceRef: podinfoservice
+          execution:
+            steps:
+              - step:
+                  type: GitOpsUpdateReleaseRepo
+                  name: Update Release Repo
+                  identifier: updateReleaseRepo
+                  timeout: 10m
+                  spec:
+                    variables:
+                      - name: cluster.name
+                        type: String
+                        value: <+input>
+                      - name: cluster.owner
+                        type: String
+                        value: <+input>
+                      - name: cluster.address
+                        type: String
+                        value: <+input>
+                      - name: cluster.namespace
+                        type: String
+                        value: <+input>
+                      - name: asset_id
+                        type: String
+                        value: <+input>
+                      - name: aws_account
+                        type: String
+                        value: <+input>
+              - step:
+                  type: MergePR
+                  name: Merge PR
+                  identifier: mergePR
+                  spec:
+                    deleteSourceBranch: true
+                  timeout: 10m
+              - step:
+                  type: GitOpsFetchLinkedApps
+                  name: Fetch Linked Apps
+                  identifier: fetchLinkedApps
+                  timeout: 10m
+                  spec: {}
+            rollbackSteps: []
+          environment:
+            environmentRef: prod
+            deployToAll: false
+            gitOpsClusters:
+              - identifier: gitopscluster
+        tags: {}
+        failureStrategies:
+          - onFailure:
+              errors:
+                - AllErrors
+              action:
+                type: StageRollback
diff --git a/podinfo/harness-gitops/service.yml b/podinfo/harness-gitops/service.yml
new file mode 100644
index 0000000..4513c56
--- /dev/null
+++ b/podinfo/harness-gitops/service.yml
@@ -0,0 +1,34 @@
+service:
+  name: podinfoservice
+  identifier: podinfoservice
+  orgIdentifier: default
+  projectIdentifier: default_project
+  serviceDefinition:
+    spec:
+      manifests:
+        - manifest:
+            identifier: configjson
+            type: ReleaseRepo
+            spec:
+              store:
+                type: Github
+                spec:
+                  connectorRef: githubconnector
+                  gitFetchType: Branch
+                  paths:
+                    - podinfo/configs/git-generator-files-discovery/cluster-config/engineering/<+env.name>/config.json
+                  branch: main
+        - manifest:
+            identifier: podinfodeployment
+            type: DeploymentRepo
+            spec:
+              store:
+                type: Github
+                spec:
+                  connectorRef: githubconnector
+                  gitFetchType: Branch
+                  paths:
+                    - podinfo/configs/git-generator-files-discovery/git-generator-files.yaml
+                  branch: main
+    type: Kubernetes
+  gitOpsEnabled: true
diff --git a/podinfo/harness-gitops/trigger.yml b/podinfo/harness-gitops/trigger.yml
new file mode 100644
index 0000000..694a0ac
--- /dev/null
+++ b/podinfo/harness-gitops/trigger.yml
@@ -0,0 +1,39 @@
+trigger:
+  name: gitopstrigger
+  identifier: gitopstrigger
+  enabled: true
+  encryptedWebhookSecretIdentifier: ""
+  description: ""
+  tags: {}
+  orgIdentifier: default
+  stagesToExecute: []
+  projectIdentifier: default_project
+  pipelineIdentifier: cdgitopspipeline
+  source:
+    type: Webhook
+    spec:
+      type: Github
+      spec:
+        type: Push
+        spec:
+          connectorRef: githubconnector
+          autoAbortPreviousExecutions: false
+          payloadConditions:
+            - key: changedFiles
+              operator: NotIn
+              value: podinfo/configs/git-generator-files-discovery/
+            - key: targetBranch
+              operator: Equals
+              value: main
+          headerConditions: []
+          actions: []
+  inputYaml: |
+    pipeline:
+      identifier: cdgitopspipeline
+      properties:
+        ci:
+          codebase:
+            build:
+              type: branch
+              spec:
+                branch: <+trigger.branch>