Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
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
111 changes: 111 additions & 0 deletions .github/workflows/test-wandb-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Test operator-wandb Chart

on:
pull_request:
paths:
- charts/operator-wandb/**
- test-configs/wandb-base/**

jobs:
snapshots:
name: Snapshot testing
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Helm
uses: azure/[email protected]
with:
version: v3.17.0
- name: Helm snapshot build and test
run: |
pushd ./charts/operator-wandb/
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add stakater https://stakater.github.io/stakater-charts
helm repo add prometheus https://prometheus-community.github.io/helm-charts
popd
helm plugin install https://github.com/origranot/helm-cascade
helm plugin install https://github.com/jlandowner/helm-chartsnap
./snapshots.sh build
./snapshots.sh run
# currently this action always tries to install helm, so dont use it for now
- name: Chart Snapshots
if: ${{ !always() }}
uses: jlandowner/helm-chartsnap-action@v1
id: chartsnap
with:
chart: charts/wandb-base/
values: test-configs/wandb-base/

test:
name: Test Chart
strategy:
fail-fast: false
matrix:
k8s-version: ["v1.32.2", "v1.31.6", "v1.30.10"]
configuration:
[
env-values-example
env-precedence-container
env-precedence-sizing
env-precedence-chart-env
env-precedence-chart-legacy
env-precedence-global-env
env-precedence-global-legacy
]
runs-on: ubuntu-latest
environment: Helm Charts
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/[email protected]
with:
version: v3.17.0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Set up chart-testing
uses: helm/[email protected]
with:
version: v3.12.0

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --config ct.yaml)
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
fi
- name: Create kind cluster
uses: helm/[email protected]
with:
version: v0.27.0
cluster_name: chart-testing-${{ matrix.k8s-version }}-${{ matrix.configuration }}
node_image: kindest/node:${{ matrix.k8s-version }}
if: env.ACT || steps.list-changed.outputs.changed == 'true'

- name: Apply user defined secrets
run: |
if [[ -d test-configs/additional-resources/${{matrix.configuration}} ]]; then
kubectl --context kind-chart-testing-${{ matrix.k8s-version }}-${{ matrix.configuration }} apply -f test-configs/additional-resources/${{matrix.configuration}}
else
echo "No additional resources to be applied for ${{matrix.configuration}}"
fi
if: env.ACT || steps.list-changed.outputs.changed == 'true'

- name: Run chart-testing (install)
if: env.ACT || steps.list-changed.outputs.changed == 'true'
run: |
ct install --namespace default \
--charts ./charts/wandb-base \
--config ct.yaml \
--helm-extra-args '--kube-context kind-chart-testing-${{ matrix.k8s-version }}-${{ matrix.configuration }} --timeout 600s' \
--helm-extra-set-args '--values test-configs/wandb-base/${{ matrix.configuration }}.yaml'
67 changes: 66 additions & 1 deletion charts/wandb-base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Environment variables can be defined at multiple levels, with the following prec
5. Global environment variables (`global.env`)
6. Legacy global environment variables (`global.extraEnv`)

Example:
#### Examples Of `env` at different levels

```yaml
# Global environment variables (lowest precedence)
Expand All @@ -52,6 +52,71 @@ containers:

In this example, the `LOG_LEVEL` for the `app` container would be set to `trace`.

#### Examples of different `env` values:
At any of the difference env levels shown above the following patterns are allowed.

[k8s ref envvar](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#envvar-v1-core)
[k8s ref valueFrom](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.34/#envvarsource-v1-core)

Basic Key/Value
```yaml
env:
EXAMPLE: "100"
```

```yaml
env:
EXAMPLE_ALT:
value: "200"
```

Reference a configmap
```yaml
env:
EXAMPLE_FROM_CONFIGMAP:
valueFrom:
configMapKeyRef:
name: "my-configmap"
key: "configmap-key"
```

Reference a secret
```yaml
env:
EXAMPLE_FROM_SECRET:
valueFrom:
secretKeyRef:
name: "my-secret"
key: "secret-key"
```

Reference k8s data (fieldRef)
Selects a field of the pod: supports `metadata.name`, `metadata.namespace`, `metadata.labels['<KEY>']`, `metadata.annotations['<KEY>']`, `spec.nodeName`, `spec.serviceAccountName`, `status.hostIP`, `status.podIP`, `status.podIPs`
```yaml
env:
EXAMPLE_FROM_FIELD_REF:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
# practical example
DD_AGENT_HOST:
valueFrom:
fieldRef:
fieldPath: status.hostIP
```

Reference k8s data (resourceFieldRef)
Selects a resource of the container: only resources limits and requests (`limits.cpu`, `limits.memory`, `limits.ephemeral-storage`, `requests.cpu`, `requests.memory` and `requests.ephemeral-storage`) are currently supported.
```yaml
env:
EXAMPLE_FROM_RESOURCE_FIELD_REF:
valueFrom:
resourceFieldRef:
resource: limits.memory
```

#### Examples of `envFrom` to set groups of env vars at once

Additionally, environment variables can be sourced from ConfigMaps and Secrets using the `envFrom` field:

```yaml
Expand Down
51 changes: 51 additions & 0 deletions charts/wandb-base/templates/tests/test-jobs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{- if and .Values.test.enabled (eq .Values.kind "Job") }}
{{- range $jobName, $job := .Values.jobs }}
{{- $job := mergeOverwrite (dict "enabled" true) $job}}
{{- if $job.enabled }}
---
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "wandb-base.fullname" $ }}-test-job-{{ $jobName }}"
labels:
{{- include "wandb-base.labels" $ | nindent 4 }}
annotations:
"helm.sh/hook": test
"helm.sh/hook-weight": "1"
spec:
containers:
- name: job-test
image: bitnami/kubectl:latest
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid floating tag for kubectl image; pin or parameterize.

latest is non-reproducible and risky. Pin to a version (ideally matching cluster) or expose via Values.

Apply (example pin; adjust as needed):

-      image: bitnami/kubectl:latest
+      image: bitnami/kubectl:1.31.6

Or parameterize:

-      image: bitnami/kubectl:latest
+      image: {{ default "bitnami/kubectl:1.31.6" .Values.test.kubectlImage }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
image: bitnami/kubectl:latest
image: {{ default "bitnami/kubectl:1.31.6" .Values.test.kubectlImage }}
🤖 Prompt for AI Agents
In charts/wandb-base/templates/tests/test-jobs.yaml around line 19, the
container image is using the floating tag "bitnami/kubectl:latest"; change this
to a fixed version or make it configurable via values. Replace
"bitnami/kubectl:latest" with a pinned tag (e.g., "bitnami/kubectl:<version>")
or use a Helm template reference that reads from values.yaml (e.g., {{
.Values.testJob.kubectlImage }}), then add an entry in values.yaml
(testJob.kubectlImage) with the chosen pinned image so deployments become
reproducible and configurable.

command: ['/bin/sh']
args:
- -c
- |
set -e
echo "Testing job: {{ printf "%s-%s" $.Release.Name $jobName }}"
# Wait for the job to exist
echo "Waiting for job to be created..."
kubectl wait --for=condition=Ready job/{{ printf "%s-%s" $.Release.Name $jobName }} --timeout=300s || true
# Wait for the job to complete successfully
echo "Waiting for job to complete successfully..."
kubectl wait --for=condition=complete job/{{ printf "%s-%s" $.Release.Name $jobName }} --timeout=600s
# Verify the job completed successfully (not failed)
echo "Verifying job completed successfully..."
JOB_STATUS=$(kubectl get job {{ printf "%s-%s" $.Release.Name $jobName }} -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}')
if [ "$JOB_STATUS" != "True" ]; then
echo "Job did not complete successfully. Current status:"
kubectl describe job {{ printf "%s-%s" $.Release.Name $jobName }}
exit 1
fi
echo "Job {{ printf "%s-%s" $.Release.Name $jobName }} completed successfully!"
# Optional: Show job logs for debugging
echo "Job logs:"
kubectl logs job/{{ printf "%s-%s" $.Release.Name $jobName }} --tail=50 || echo "No logs available"
restartPolicy: Never
{{- end }}
{{- end }}
{{- end }}
41 changes: 22 additions & 19 deletions snapshots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ EOF
}

function main() {
local chart="operator-wandb"
local charts=("wandb-base" "operator-wandb")
local values_dir="test-configs"

if [ $# -eq 0 ]; then
Expand All @@ -39,24 +39,27 @@ function main() {
fi

local func="$1"
case "$func" in
build)
echo "Building operator-wandb"
helm cascade build "./charts/$chart"
;;
update)
echo "Updating operator-wandb snapshots"
helm chartsnap -c "./charts/$chart" -u -f "./$values_dir/$chart"
;;
run)
echo "Checking snapshot tests"
helm chartsnap -c "./charts/$chart" -f "./$values_dir/$chart"
;;
*)
usage
exit 1
;;
esac

for chart in "${charts[@]}"; do
case "$func" in
build)
echo "Building operator-wandb"
helm cascade build "./charts/$chart"
;;
update)
echo "Updating operator-wandb snapshots"
helm chartsnap -c "./charts/$chart" -u -f "./$values_dir/$chart"
;;
run)
echo "Checking snapshot tests"
helm chartsnap -c "./charts/$chart" -f "./$values_dir/$chart"
;;
*)
usage
exit 1
;;
esac
done
}

main "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: my-configmap
data:
configmap-key: "test"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Secret
metadata:
name: my-secret
stringData:
secret-key: "test"
4 changes: 4 additions & 0 deletions test-configs/wandb-base/.chartsnap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dynamicFields:
- jsonPath:
- /metadata/labels/helm.sh~1chart
value: '###CHART_VERSION###'
Loading
Loading