diff --git a/examples/observability/assets/podtatohead-deployment-evaluation/.gitignore b/examples/observability/assets/podtatohead-deployment-evaluation/.gitignore new file mode 100644 index 00000000000..2a082b43fec --- /dev/null +++ b/examples/observability/assets/podtatohead-deployment-evaluation/.gitignore @@ -0,0 +1 @@ +/slack-secret.yaml diff --git a/examples/observability/assets/podtatohead-deployment-evaluation/README.md b/examples/observability/assets/podtatohead-deployment-evaluation/README.md new file mode 100644 index 00000000000..e4c147d758a --- /dev/null +++ b/examples/observability/assets/podtatohead-deployment-evaluation/README.md @@ -0,0 +1,5 @@ +### Create Secret for Slack here + +``` +kubectl create secret generic slack-notification --from-literal=SECURE_DATA='{"slack_hook":"","text":"Deployed PodTatoHead Application"}' -n podtato-kubectl -oyaml --dry-run > slack-secret.yaml +``` diff --git a/examples/observability/assets/podtatohead-deployment-evaluation/app.yaml b/examples/observability/assets/podtatohead-deployment-evaluation/app.yaml new file mode 100644 index 00000000000..0911bdcdb7e --- /dev/null +++ b/examples/observability/assets/podtatohead-deployment-evaluation/app.yaml @@ -0,0 +1,24 @@ +apiVersion: lifecycle.keptn.sh/v1alpha1 +kind: KeptnApp +metadata: + name: podtato-head + namespace: podtato-kubectl +spec: + version: "1.3" + workloads: + - name: podtato-head-left-arm + version: 0.1.0 + - name: podtato-head-left-leg + version: 0.1.0 + - name: podtato-head-entry + version: 0.1.0 + - name: podtato-head-right-arm + version: 0.1.0 + - name: podtato-head-left-arm + version: 0.1.0 + - name: podtato-head-hat + version: 0.1.0 + postDeploymentTasks: + - post-deployment-hello + preDeploymentEvaluations: #Comment out this two lines if you do not have a prometheus installation + - my-prometheus-definition diff --git a/examples/observability/assets/podtatohead-deployment-evaluation/check_entry.yaml b/examples/observability/assets/podtatohead-deployment-evaluation/check_entry.yaml new file mode 100644 index 00000000000..958540ec070 --- /dev/null +++ b/examples/observability/assets/podtatohead-deployment-evaluation/check_entry.yaml @@ -0,0 +1,12 @@ +apiVersion: lifecycle.keptn.sh/v1alpha1 +kind: KeptnTaskDefinition +metadata: + name: check-entry-service + namespace: podtato-kubectl +spec: + function: + httpRef: + url: https://raw.githubusercontent.com/keptn-sandbox/lifecycle-controller/main/functions-runtime/samples/ts/http.ts + parameters: + map: + url: http://podtato-head-entry.podtato-kubectl.svc.cluster.local:9000 diff --git a/examples/observability/assets/podtatohead-deployment-evaluation/keptnevaluationdefinition.yaml b/examples/observability/assets/podtatohead-deployment-evaluation/keptnevaluationdefinition.yaml new file mode 100644 index 00000000000..20fbe29379c --- /dev/null +++ b/examples/observability/assets/podtatohead-deployment-evaluation/keptnevaluationdefinition.yaml @@ -0,0 +1,15 @@ +apiVersion: lifecycle.keptn.sh/v1alpha1 +kind: KeptnEvaluationDefinition +metadata: + name: my-prometheus-definition + namespace: podtato-kubectl +spec: + source: prometheus + objectives: + - name: query-1 + query: "sum(prometheus_engine_query_duration_seconds_count)" + evaluationTarget: ">10" #string: can only be starting with < or > + - name: query-2 + query: "sum(kube_pod_container_resource_limits{resource='mem'}) - sum(kube_node_status_capacity{resource='mem'})" + evaluationTarget: "<100000000000000000" #string: can only be starting with < or > + diff --git a/examples/observability/assets/podtatohead-deployment-evaluation/keptnevaluationprovider.yaml b/examples/observability/assets/podtatohead-deployment-evaluation/keptnevaluationprovider.yaml new file mode 100644 index 00000000000..53c72c2c42e --- /dev/null +++ b/examples/observability/assets/podtatohead-deployment-evaluation/keptnevaluationprovider.yaml @@ -0,0 +1,8 @@ +apiVersion: lifecycle.keptn.sh/v1alpha1 +kind: KeptnEvaluationProvider +metadata: + name: prometheus + namespace: podtato-kubectl +spec: + targetServer: "http://prometheus-k8s.monitoring.svc.cluster.local:9090" #string + secretName: prometheusLoginCredentials #secret name, optional diff --git a/examples/observability/assets/podtatohead-deployment-evaluation/manifest.yaml b/examples/observability/assets/podtatohead-deployment-evaluation/manifest.yaml new file mode 100644 index 00000000000..cf6c15a2d26 --- /dev/null +++ b/examples/observability/assets/podtatohead-deployment-evaluation/manifest.yaml @@ -0,0 +1,306 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: podtato-kubectl + annotations: + keptn.sh/lifecycle-controller: "enabled" +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podtato-head-entry + namespace: podtato-kubectl + labels: + app: podtato-head +spec: + selector: + matchLabels: + component: podtato-head-entry + template: + metadata: + labels: + component: podtato-head-entry + annotations: + keptn.sh/app: podtato-head + keptn.sh/workload: podtato-head-entry + keptn.sh/version: 0.1.0 + keptn.sh/post-deployment-tasks: post-deployment-hello + spec: + terminationGracePeriodSeconds: 5 + initContainers: + - name: init-myservice + image: busybox:1.28 + command: ['sh', '-c', 'sleep 30'] + containers: + - name: server + image: ghcr.io/podtato-head/entry:latest + imagePullPolicy: Always + ports: + - containerPort: 9000 + env: + - name: PODTATO_PORT + value: "9000" +--- +apiVersion: v1 +kind: Service +metadata: + name: podtato-head-entry + namespace: podtato-kubectl + labels: + app: podtato-head +spec: + selector: + component: podtato-head-entry + ports: + - name: http + port: 9000 + protocol: TCP + targetPort: 9000 + type: LoadBalancer + # change to NodePort if no LoadBalancer controller is available + # type: NodePort +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podtato-head-hat + namespace: podtato-kubectl + labels: + app: podtato-head +spec: + selector: + matchLabels: + component: podtato-head-hat + template: + metadata: + labels: + component: podtato-head-hat + keptn.sh/pre-deployment-tasks: check-entry-service + annotations: + keptn.sh/app: podtato-head + keptn.sh/workload: podtato-head-hat + keptn.sh/version: 0.1.0 + spec: + terminationGracePeriodSeconds: 5 + containers: + - name: server + image: ghcr.io/podtato-head/hat:latest + imagePullPolicy: Always + ports: + - containerPort: 9000 + env: + - name: PODTATO_PORT + value: "9000" +--- +apiVersion: v1 +kind: Service +metadata: + name: podtato-head-hat + namespace: podtato-kubectl + labels: + app: podtato-head +spec: + selector: + component: podtato-head-hat + ports: + - name: http + port: 9001 + protocol: TCP + targetPort: 9000 + type: ClusterIP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podtato-head-left-leg + namespace: podtato-kubectl + labels: + app: podtato-head +spec: + selector: + matchLabels: + component: podtato-head-left-leg + template: + metadata: + labels: + component: podtato-head-left-leg + annotations: + keptn.sh/app: podtato-head + keptn.sh/workload: podtato-head-left-leg + keptn.sh/version: 0.1.0 + keptn.sh/pre-deployment-tasks: check-entry-service + spec: + terminationGracePeriodSeconds: 5 + containers: + - name: server + image: ghcr.io/podtato-head/left-leg:latest + imagePullPolicy: Always + ports: + - containerPort: 9000 + env: + - name: PODTATO_PORT + value: "9000" +--- +apiVersion: v1 +kind: Service +metadata: + name: podtato-head-left-leg + namespace: podtato-kubectl + labels: + app: podtato-head +spec: + selector: + component: podtato-head-left-leg + ports: + - name: http + port: 9002 + protocol: TCP + targetPort: 9000 + type: ClusterIP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podtato-head-left-arm + namespace: podtato-kubectl + labels: + app: podtato-head +spec: + selector: + matchLabels: + component: podtato-head-left-arm + template: + metadata: + labels: + component: podtato-head-left-arm + annotations: + keptn.sh/app: podtato-head + keptn.sh/workload: podtato-head-left-arm + keptn.sh/version: 0.1.0 + keptn.sh/pre-deployment-tasks: check-entry-service + spec: + terminationGracePeriodSeconds: 5 + containers: + - name: server + image: ghcr.io/podtato-head/left-arm:latest + imagePullPolicy: Always + ports: + - containerPort: 9000 + env: + - name: PODTATO_PORT + value: "9000" +--- +apiVersion: v1 +kind: Service +metadata: + name: podtato-head-left-arm + namespace: podtato-kubectl + labels: + app: podtato-head +spec: + selector: + component: podtato-head-left-arm + ports: + - name: http + port: 9003 + protocol: TCP + targetPort: 9000 + type: ClusterIP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podtato-head-right-leg + namespace: podtato-kubectl + labels: + app: podtato-head +spec: + selector: + matchLabels: + component: podtato-head-right-leg + template: + metadata: + labels: + component: podtato-head-right-leg + annotations: + keptn.sh/app: podtato-head + keptn.sh/workload: podtato-head-right-leg + keptn.sh/version: 0.1.0 + keptn.sh/pre-deployment-tasks: check-entry-service + spec: + terminationGracePeriodSeconds: 5 + containers: + - name: server + image: ghcr.io/podtato-head/right-leg:latest + imagePullPolicy: Always + ports: + - containerPort: 9000 + env: + - name: PODTATO_PORT + value: "9000" +--- +apiVersion: v1 +kind: Service +metadata: + name: podtato-head-right-leg + namespace: podtato-kubectl + labels: + app: podtato-head +spec: + selector: + component: podtato-head-right-leg + ports: + - name: http + port: 9004 + protocol: TCP + targetPort: 9000 + type: ClusterIP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podtato-head-right-arm + namespace: podtato-kubectl + labels: + app: podtato-head +spec: + selector: + matchLabels: + component: podtato-head-right-arm + template: + metadata: + labels: + component: podtato-head-right-arm + annotations: + keptn.sh/app: podtato-head + keptn.sh/workload: podtato-head-right-arm + keptn.sh/version: 0.1.0 + keptn.sh/pre-deployment-tasks: check-entry-service + spec: + terminationGracePeriodSeconds: 5 + containers: + - name: server + image: ghcr.io/podtato-head/right-arm:latest + imagePullPolicy: Always + ports: + - containerPort: 9000 + env: + - name: PODTATO_PORT + value: "9000" +--- +apiVersion: v1 +kind: Service +metadata: + name: podtato-head-right-arm + namespace: podtato-kubectl + labels: + app: podtato-head +spec: + selector: + component: podtato-head-right-arm + ports: + - name: http + port: 9005 + protocol: TCP + targetPort: 9000 + type: ClusterIP diff --git a/examples/observability/assets/podtatohead-deployment-evaluation/post-deployment-tasks.yaml b/examples/observability/assets/podtatohead-deployment-evaluation/post-deployment-tasks.yaml new file mode 100644 index 00000000000..1628d22b3d9 --- /dev/null +++ b/examples/observability/assets/podtatohead-deployment-evaluation/post-deployment-tasks.yaml @@ -0,0 +1,44 @@ +apiVersion: lifecycle.keptn.sh/v1alpha1 +kind: KeptnTaskDefinition +metadata: + name: post-deployment-hello + namespace: podtato-kubectl +spec: + function: + inline: + code: | + let text = Deno.env.get("SECURE_DATA"); + let context = Deno.env.get("CONTEXT"); + let data; + let body; + let contextdata; + + if (text != undefined) { + data = JSON.parse(text); + } + + if (context != undefined) { + contextdata = JSON.parse(context); + } + + if (contextdata.objectType == "Application") { + body = `{ + "text": "Application ${contextdata.appName}, Version ${contextdata.appVersion} has been deployed" + }` + } + + if (contextdata.objectType == "Workload") { + body = `{ + "text": "Workload ${contextdata.workloadName}, Version ${contextdata.workloadVersion} in App ${contextdata.appName} has been deployed" + }` + } + + console.log(body) + let resp = await fetch("https://hooks.slack.com/services/" + data.slack_hook, { + method: "POST", + body, + }); + + console.log(resp) + secureParameters: + secret: slack-notification