Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
106 changes: 106 additions & 0 deletions .github/workflows/test-wandb-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
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:
[
]
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)
# env:
# LICENSE: ${{ secrets.LICENSE }}
# if: env.ACT || steps.list-changed.outputs.changed == 'true'
# run: |
# ct install --namespace default \
# --charts ./charts/operator-wandb \
# --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/operator-wandb/${{ matrix.configuration }}.yaml --set=license=$LICENSE'
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
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###'
107 changes: 107 additions & 0 deletions test-configs/wandb-base/__snapshots__/env-precedence-chart-env.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# chartsnap: snapshot_version=v3
---
# Source: wandb-base/templates/pdb.yaml
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: chartsnap-wandb-base
labels:
helm.sh/chart: '###CHART_VERSION###'
app.kubernetes.io/name: wandb-base
app.kubernetes.io/instance: chartsnap
app.kubernetes.io/managed-by: Helm
spec:
selector:
matchExpressions:
- key: batch.kubernetes.io/job-name
operator: DoesNotExist
matchLabels:
app.kubernetes.io/name: wandb-base
app.kubernetes.io/instance: chartsnap
maxUnavailable: 1
---
# Source: wandb-base/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: chartsnap-wandb-base
labels:
helm.sh/chart: '###CHART_VERSION###'
app.kubernetes.io/name: wandb-base
app.kubernetes.io/instance: chartsnap
app.kubernetes.io/managed-by: Helm
automountServiceAccountToken: true
---
# Source: wandb-base/templates/job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: chartsnap-test
labels:
helm.sh/chart: '###CHART_VERSION###'
app.kubernetes.io/name: wandb-base
app.kubernetes.io/instance: chartsnap
app.kubernetes.io/managed-by: Helm
spec:
template:
metadata:
labels:
helm.sh/chart: wandb-base-0.11.0
app.kubernetes.io/name: wandb-base
app.kubernetes.io/instance: chartsnap
app.kubernetes.io/managed-by: Helm
spec:
containers:
- name: example
command:
- /bin/bash
args:
- -c
- |
echo "EXAMPLE=$EXAMPLE"
EXPECTED="400"
if [ "$EXAMPLE" = "$EXPECTED" ]; then
echo "Value is $EXPECTED"
exit 0
else
echo "Value is NOT $EXPECTED"
exit 1
fi
envFrom:
env:
- name: EXAMPLE
value: "400"
securityContext:
allowPrivilegeEscalation: false
capabilities:
add: []
drop: []
privileged: false
readOnlyRootFilesystem: false
image: "debian:12-slim"
imagePullPolicy:
restartPolicy: Never
serviceAccountName: chartsnap-wandb-base
securityContext:
fsGroup: 0
fsGroupChangePolicy: OnRootMismatch
runAsGroup: 0
runAsNonRoot: true
runAsUser: 999
seccompProfile:
type: RuntimeDefault
topologySpreadConstraints:
- labelSelector:
matchLabels:
app.kubernetes.io/instance: chartsnap
app.kubernetes.io/name: wandb-base
maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
- labelSelector:
matchLabels:
app.kubernetes.io/instance: chartsnap
app.kubernetes.io/name: wandb-base
maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
Loading
Loading