Repository: iter8-tools/iter8
Pull request #1218 (2022-04-11 16:33:32)

readiness chart changes
Chart changes to support addition of readiness task.  Addresses issue https://github.com/iter8-tools/iter8/issues/1222

Signed-off-by: Michael Kalantar <kalantar@us.ibm.com>


Patch:
diff --git a/charts/iter8lib/templates/_task-grpc.tpl b/charts/iter8lib/templates/_task-grpc.tpl
index b7c698c1..76501941 100644
--- a/charts/iter8lib/templates/_task-grpc.tpl
+++ b/charts/iter8lib/templates/_task-grpc.tpl
@@ -1,12 +1,12 @@
-{{- define "task.grpc" -}}
-{{/* Validate values */}}
+{{- define "task.grpc" }}
+{{- /* Validate values */ -}}
 {{- if not .Values.host }}
 {{- fail "Please set a value for the host parameter." }}
 {{- end }}
 {{- if not .Values.call }}
 {{- fail "Please set a value for the call parameter." }}
 {{- end }}
-{{/* Perform the various setup steps before the main task */}}
+{{- /* Perform the various setup steps before the main task */ -}}
 {{- $vals := mustDeepCopy .Values }}
 {{- if $vals.protoURL }}
 # task: download proto file from URL
diff --git a/charts/iter8lib/templates/_task-http.tpl b/charts/iter8lib/templates/_task-http.tpl
index 8f94e7b3..af9d762b 100644
--- a/charts/iter8lib/templates/_task-http.tpl
+++ b/charts/iter8lib/templates/_task-http.tpl
@@ -1,9 +1,9 @@
 {{- define "task.http" -}}
-{{/* Validate values */}}
+{{- /* Validate values */ -}}
 {{- if not .Values.url }}
   {{- fail "Please set a value for the url parameter." }}
 {{- end }}
-{{/* Perform the various setup steps before the main task */}}
+{{- /* Perform the various setup steps before the main task */ -}}
 {{- $vals := mustDeepCopy .Values }}
 {{- if $vals.percentiles }}
   {{- $percentiles := list }}
diff --git a/charts/iter8lib/templates/_task.ready.tpl b/charts/iter8lib/templates/_task.ready.tpl
new file mode 100644
index 00000000..8154d039
--- /dev/null
+++ b/charts/iter8lib/templates/_task.ready.tpl
@@ -0,0 +1,51 @@
+{{- define "task.ready.tn" }}
+{{- /* Optional timeout from .Values.ready.timeout */ -}}
+{{- if .Values.ready }}
+{{- if .Values.ready.timeout }}
+timeout: {{ .Values.ready.timeout }}
+{{- end }}
+{{- end }}
+{{- /* Optional timeout from .Values.ready.namespace (non-Kubernetes experiment) or .Release.Namespace (Kubernetes experiment) */ -}}
+{{ $namespace := "" }}
+{{- if .Values.ready }}
+{{- if .Values.ready.namespace }}
+{{ $namespace = .Values.ready.namespace }}
+{{- end }}
+{{- end }}
+{{- if .Release.Namespace }}
+{{ $namespace = .Release.Namespace }}
+{{- end }}
+{{- /* if one of .Values.ready.namespace or .Release.Namespace */ -}}
+{{- if $namespace }}
+namespace: {{ $namespace }}
+{{- end }}
+{{ end }}
+
+{{- define "task.ready" }}
+{{- /* If user has specified a check for readiesss of a Kubernetes Service */ -}}
+{{- if .Values.ready }}
+{{- if .Values.ready.service }}
+# task: determine if Kubernetes Service exists
+- task: k8s-object-ready
+  with:
+    name: {{ .Values.ready.service }}
+    version: v1
+    resource: services
+{{- include "task.ready.tn" . | indent 4 }}
+{{ end }}
+{{- end }}
+{{- /* If user has specified a check for readiesss of a Kubernetes Deployment */ -}}
+{{- if .Values.ready }}
+{{- if .Values.ready.deploy }}
+# task: determine if Kubernetes Deployment is Available
+- task: k8s-object-ready
+  with:
+    name: {{ .Values.ready.deploy }}
+    group: apps
+    version: v1
+    resource: deployments
+    condition: Available
+{{- include "task.ready.tn" . | indent 4 }}
+{{ end }}
+{{- end }}
+{{- end }}
\ No newline at end of file
diff --git a/charts/iter8lib/values.yaml b/charts/iter8lib/values.yaml
index 914f5e69..32be927b 100644
--- a/charts/iter8lib/values.yaml
+++ b/charts/iter8lib/values.yaml
@@ -9,4 +9,4 @@ majorMinor: v0.10
 ### To disable the job manifest, uncomment the next two lines and delete the line after that.
 ### disable
 ###   job: true
-disable: {}
\ No newline at end of file
+disable: {}


Test patch:
diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml
index 5e599a5a..02c5b965 100644
--- a/.github/workflows/tests.yaml
+++ b/.github/workflows/tests.yaml
@@ -182,6 +182,29 @@ jobs:
         iter8 k report
         iter8 k delete
 
+  readiness:
+    runs-on: ubuntu-latest
+    steps:
+    - name: Start kind cluster
+      uses: helm/kind-action@v1.2.0
+      with:
+        wait: 300s
+    - name: Check out code into the Go module directory
+      uses: actions/checkout@v2
+    - name: deploy resources to cluster
+      run: |
+        kubectl apply -f testdata/manifests/readiness.yaml
+    - name: Install Iter8
+      uses: iter8-tools/iter8@v0.10
+    - name: launch load-test-http with readiness checks
+      run: |
+        iter8 launch -c load-test-http --noDownload \
+        --set ready.deploy="test-deployment" \
+        --set url="https://httpbin.org/get"
+    - name: assert experiment completed without failures
+      run: |
+        iter8 assert -c completed -c nofailure
+
   static-check:
     runs-on: ubuntu-latest
     steps:
diff --git a/charts/load-test-grpc/templates/_experiment.tpl b/charts/load-test-grpc/templates/_experiment.tpl
index 8ddd903e..90dadaae 100644
--- a/charts/load-test-grpc/templates/_experiment.tpl
+++ b/charts/load-test-grpc/templates/_experiment.tpl
@@ -1,4 +1,5 @@
-{{ define "experiment" -}}
+{{- define "experiment" -}}
+{{- include "task.ready" . -}}
 {{- include "task.grpc" . -}}
 {{- include "task.assess" . -}}
-{{ end }}
\ No newline at end of file
+{{- end }}
\ No newline at end of file
diff --git a/charts/load-test-http/templates/_experiment.tpl b/charts/load-test-http/templates/_experiment.tpl
index 9c1f40ee..ce726970 100644
--- a/charts/load-test-http/templates/_experiment.tpl
+++ b/charts/load-test-http/templates/_experiment.tpl
@@ -1,4 +1,5 @@
-{{ define "experiment" -}}
-{{- include "task.http" . }}
-{{- include "task.assess" . }}
-{{ end }}
\ No newline at end of file
+{{- define "experiment" -}}
+{{- include "task.ready" . -}}
+{{- include "task.http" . -}}
+{{- include "task.assess" . -}}
+{{- end }}
\ No newline at end of file
diff --git a/testdata/manifests/readiness.yaml b/testdata/manifests/readiness.yaml
new file mode 100644
index 00000000..b57ebc87
--- /dev/null
+++ b/testdata/manifests/readiness.yaml
@@ -0,0 +1,18 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: test-deployment
+spec:
+  replicas: 2
+  selector:
+    matchLabels:
+      app: curl
+  template:
+    metadata:
+      labels:
+        app: curl
+    spec:
+      containers:
+      - name: curl
+        image: curlimages/curl
+        command: ["/bin/sleep","infinity"]