Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds extraContainers to integration test elasticsearch #14

Merged
merged 5 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ You can then run `helm search repo zipkin` to see the charts.
| serviceAccount.name | string | `""` | If not set and create is true, a name is generated using the fullname template |
| serviceAccount.psp | bool | `false` | |
| tolerations | list | `[]` | |
| zipkin.storage.elasticsearch.hosts | string | `"hostA hostB"` | |
| zipkin.storage.elasticsearch.index | string | `"fooIndex"` | |
| zipkin.storage.type | string | `"elasticsearch"` | |
| zipkin.selfTracing.enabled | bool | `false` | |
| zipkin.storage.elasticsearch.hosts | string | no default | |
| zipkin.storage.elasticsearch.index | string | `"zipkin"` | |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no good reason for us to have made this mandatory before

| zipkin.storage.type | string | `"mem"` | |

The values are validated using a JSON schema, which contains logic to enforce either:

- `zipkin.storage.type` is set to `mem`
- `zipkin.storage.type` is set to `elasticsearch` *AND* both `z.s.elasticsearch.hosts` and `z.s.elasticsearch.index` is set
- `zipkin.storage.type` is set to `elasticsearch` *AND* `z.s.elasticsearch.hosts` is set
13 changes: 13 additions & 0 deletions charts/zipkin/ci/elasticsearch-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
zipkin:
storage:
type: elasticsearch
elasticsearch:
hosts: http://localhost:9200

# extra containers are in the same pod, so accessible by localhost
extraContainers:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reason this works without any other machinery is that zipkin checks its dependencies and doesn't return OK healthcheck until they are ok.

Hence, it can resolve this as you'll see in the logs.. then the wget tests are safe to run. pretty handy

   Warning  Unhealthy  20s                kubelet            Readiness probe failed: Get "http://10.244.0.7:9411/health": dial tcp 10.244.0.7:9411: connect: connection refused
  Warning  Unhealthy  18s                kubelet            Readiness probe failed: Get "http://10.244.0.7:9411/health": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
  Warning  Unhealthy  11s (x2 over 16s)  kubelet            Readiness probe failed: HTTP probe failed with statuscode: 503

- name: elasticsearch
image: 'ghcr.io/openzipkin/zipkin-elasticsearch8'
ports:
- containerPort: 9200
11 changes: 11 additions & 0 deletions charts/zipkin/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,14 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Add extra containers to the pod spec
*/}}
{{- define "zipkin.extraContainers" -}}
{{- if .Values.extraContainers }}
{{- with .Values.extraContainers }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- end }}
{{- end }}
23 changes: 17 additions & 6 deletions charts/zipkin/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,32 @@ spec:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
env:
{{- if .Values.zipkin.selfTracing.enabled }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conditionally guarding is less cluttered.

you can test like..

$ helm template charts/zipkin --values charts/zipkin/ci/elasticsearch-values.yaml
---
# Source: zipkin/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: release-name-zipkin
  namespace: default
  labels:
    helm.sh/chart: zipkin-0.2.0
    app.kubernetes.io/name: zipkin
    app.kubernetes.io/instance: release-name
    app.kubernetes.io/version: "3.0.6"
    app.kubernetes.io/managed-by: Helm
---
# Source: zipkin/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: release-name-zipkin
  namespace: default
  labels:
    helm.sh/chart: zipkin-0.2.0
    app.kubernetes.io/name: zipkin
    app.kubernetes.io/instance: release-name
    app.kubernetes.io/version: "3.0.6"
    app.kubernetes.io/managed-by: Helm
spec:
  type: ClusterIP
  ports:
    - port: 9411
      targetPort: 9411
      protocol: TCP
      name: http-query
  selector:
    app.kubernetes.io/name: zipkin
    app.kubernetes.io/instance: release-name
---
# Source: zipkin/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: release-name-zipkin
  namespace: default
  labels:
    helm.sh/chart: zipkin-0.2.0
    app.kubernetes.io/name: zipkin
    app.kubernetes.io/instance: release-name
    app.kubernetes.io/version: "3.0.6"
    app.kubernetes.io/managed-by: Helm
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: zipkin
      app.kubernetes.io/instance: release-name
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "false"
      labels:
        app.kubernetes.io/name: zipkin
        app.kubernetes.io/instance: release-name
    spec:
      automountServiceAccountToken: false
      serviceAccountName: release-name-zipkin
      securityContext:
        {}
      containers:
        - name: zipkin
          securityContext:
            readOnlyRootFilesystem: true
            runAsNonRoot: true
            runAsUser: 1000
          image: "openzipkin/zipkin-slim:3.0.6"
          env:
            - name: STORAGE_TYPE
              value: "elasticsearch"
            - name: ES_HOSTS
              value: "http://localhost:9200"
          imagePullPolicy: IfNotPresent
          readinessProbe:
            httpGet:
              path: /health
              port: 9411
            initialDelaySeconds: 5
            periodSeconds: 5
          resources:
            limits:
              cpu: 500m
              memory: 4096Mi
            requests:
              cpu: 100m
              memory: 128Mi
      
        - image: ghcr.io/openzipkin/zipkin-elasticsearch8
          name: elasticsearch
          ports:
          - containerPort: 9200
---
# Source: zipkin/templates/tests/test-connection.yaml
apiVersion: v1
kind: Pod
metadata:
  name: "release-name-zipkin-test-connection"
  labels:
    helm.sh/chart: zipkin-0.2.0
    app.kubernetes.io/name: zipkin
    app.kubernetes.io/instance: release-name
    app.kubernetes.io/version: "3.0.6"
    app.kubernetes.io/managed-by: Helm
  annotations:
    "helm.sh/hook": test
spec:
  containers:
    - name: get-api-services
      image: 'ghcr.io/openzipkin/alpine:3.19.1'
      command: [ '/bin/sh', '-c' ]
      # Get an arbitrary API endpoint using the ClusterIP and service port
      args: [ 'wget -qO ---spider --header "b3: cafebabecafebabe-cafebabecafebabe-1" http://release-name-zipkin:9411/api/v2/services' ]
  restartPolicy: Never

- name: SELF_TRACING_ENABLED
value: "{{ .Values.zipkin.selfTracing.enabled }}"
value: "true"
{{- end }}
- name: STORAGE_TYPE
value: "{{ .Values.zipkin.storage.type }}"
{{- if eq .Values.zipkin.storage.type "elasticsearch" }}
{{- with .Values.zipkin.storage.elasticsearch }}
- name: ES_HOSTS
value: "{{ .hosts }}"
value: {{ .hosts | quote }}
{{- if .index }}
- name: ES_INDEX
value: "{{ .index }}"
value: {{ .index | quote }}
{{- end }}
{{- if .username }}
- name: ES_USERNAME
value: "{{ .username }}"
value: {{ .username | quote }}
{{- end }}
{{- if .password }}
- name: ES_PASSWORD
value: "{{ .password }}"
value: {{ .password | quote }}
{{- end }}
{{- if .sslNoVerify }}
- name: ES_SSL_NO_VERIFY
value: "{{ default false .sslNoVerify }}"
value: "true"
{{- end }}
{{- end }}
{{- end }}
{{- range $key, $value := .Values.zipkin.extraEnv }}
Expand All @@ -79,6 +89,7 @@ spec:
periodSeconds: 5
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- include "zipkin.extraContainers" . | nindent 6 }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know why entirely, but you can't inline the expression. it causes an obscure key not found. I poked around and found otel did the same thing to dodge this, but there wasn't an explicit comment why.

{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
1 change: 1 addition & 0 deletions charts/zipkin/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: v1
kind: Pod
metadata:
Expand Down
21 changes: 17 additions & 4 deletions charts/zipkin/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@
}
}
},
"extraContainers": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": true,
"properties": {
"name": {
"type": "string"
}
},
"required": ["name"]
}
},
"fullnameOverride": {
"type": "string"
},
Expand Down Expand Up @@ -182,7 +195,7 @@
"type": "string"
}
},
"required": ["hosts", "index"]
"required": ["hosts"]
},
"type": {
"enum": ["mem", "elasticsearch"]
Expand All @@ -203,9 +216,9 @@
}
]
},
"extraEnv": {
"type": "object"
}
"extraEnv": {
"type": "object"
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions charts/zipkin/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,6 @@ zipkin:
# index: fooIndex
extraEnv: {}
# JAVA_OPTS: "-Xms128m -Xmx512m -XX:+ExitOnOutOfMemoryError"

# extra containers to add to the same pod
extraContainers: []
Loading