Skip to content

Commit

Permalink
Various CI improvements (kubeflow#1418)
Browse files Browse the repository at this point in the history
This change renames the github workflows to be clearer about their purpose, and adds a set of tests which
aim to force developers to increment the appVersion if they have changed anything with the spark-operator docker container
or the chart version if they have updated the chart.

Signed-off-by: Tom Hellier <[email protected]>
  • Loading branch information
TomHellier authored Dec 3, 2021
1 parent d04160e commit ba16242
Show file tree
Hide file tree
Showing 14 changed files with 732 additions and 454 deletions.
141 changes: 116 additions & 25 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,36 @@ on:
- master

jobs:
build:

build-api-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
with:
fetch-depth: "0"

- name: The API should not change once published
run: |
if ! git diff --quiet origin/master -- pkg/apis/sparkoperator.k8s.io/v1beta1; then
echo "sparkoperator.k8s.io/v1beta1 api has changed"
false
fi
if ! git diff --quiet origin/master -- pkg/apis/sparkoperator.k8s.io/v1beta2; then
echo "sparkoperator.k8s.io/v1beta2 api has changed"
false
fi
- name: The API documentation hasn't changed
run: |
make build-api-docs
if ! git diff --quiet -- docs/api-docs.md; then
echo "Need to re-run 'make build-api-docs' and commit the changes"
git diff -- docs/api-docs.md;
false
fi
build-sparkctl:
runs-on: ubuntu-latest
steps:
- name: Set up Go
Expand All @@ -21,22 +50,15 @@ jobs:
- name: Checkout source code
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: fmt check
run: make fmt-check
fetch-depth: "0"

- name: unit tests
run: make test
- name: build sparkctl
run: |
make all
it:
build-spark-operator:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v2
with:
Expand All @@ -45,32 +67,75 @@ jobs:
- name: Checkout source code
uses: actions/checkout@v2
with:
fetch-depth: 2
fetch-depth: "0"

- name: Run gofmt check
run: make fmt-check

- name: Run static analysis
run: make static-analysis

- name: Run unit tests
run: make unit-test

- name: Build Spark-Operator Docker Image
run: |
tag=$(git describe --tags --dirty)_v3.1.1
docker build -t gcr.io/spark-operator/spark-operator:${tag} .
docker build -t gcr.io/spark-operator/spark-operator:local .
DOCKER_TAG=$(cat charts/spark-operator-chart/Chart.yaml | grep "appVersion: .*" | cut -c13-)
docker build -t gcr.io/spark-operator/spark-operator:${DOCKER_TAG} .
- name: Check changes in resources used in docker file
run: |
DOCKERFILE_RESOURCES=$(cat Dockerfile | grep -P -o "COPY [a-zA-Z0-9].*? " | cut -c6-)
for resource in $DOCKERFILE_RESOURCES; do
# If the resource is different
if ! git diff --quiet origin/master -- $resource; then
## And the appVersion hasn't been updated
if ! git diff --quiet charts/spark-operator-chart/Chart.yaml | grep +appVersion; then
echo "resource used in gcr.io/spark-operator/spark-operator has changed in $resource, need to update the appVersion in charts/spark-operator-chart/Chart.yaml"
git diff origin/master -- $resource;
echo "failing the build... " && false
fi
fi
done
build-helm-chart:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
with:
fetch-depth: "0"

- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.4.0
version: v3.7.1

- uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Produce the helm documentation
run: |
make helm-docs
if ! git diff --quiet -- charts/spark-operator-chart/README.md; then
echo "Need to re-run 'make helm-docs' and commit the changes"
false
fi
- name: Set up chart-testing
uses: helm/[email protected]

- name: Print ct version information and List files
run: ct version && ls -lh
- name: Print chart-testing version information
run: ct version

- name: Run chart-testing (lint)
run: ct lint

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed)
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
fi
- name: Detect CRDs drift between chart and manifest
run: make detect-crds-drift

Expand All @@ -84,13 +149,39 @@ jobs:

- name: Run chart-testing (install)
run: |
tag=$(git describe --tags --dirty)_v3.1.1
docker build -t gcr.io/spark-operator/spark-operator:local .
minikube image load gcr.io/spark-operator/spark-operator:local
ct install
integration-test:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15

- name: Checkout source code
uses: actions/checkout@v2
with:
fetch-depth: "0"

- name: setup minikube
uses: manusa/[email protected]
with:
minikube version: "v1.24.0"
kubernetes version: "v1.20.8"
start args: --memory 6g --cpus=2 --addons ingress
github token: ${{ inputs.github-token }}

- name: Build local spark-operator docker image for minikube testing
run: |
docker build -t gcr.io/spark-operator/spark-operator:local .
minikube image load gcr.io/spark-operator/spark-operator:local
# The integration tests are currently broken see: https://github.com/GoogleCloudPlatform/spark-on-k8s-operator/issues/1416
# - name: Run chart-testing (integration test)
# run: make it-test
# run: make integation-test

- name: Setup tmate session
if: failure()
Expand Down
45 changes: 10 additions & 35 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
fetch-depth: "0"

- name: Configure Git
run: |
Expand All @@ -22,11 +22,11 @@ jobs:
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.4.0
version: v3.7.1

- uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.10

# TODO: Maintainer of repository to follow:
# https://github.com/docker/login-action#google-container-registry-gcr to add credentials so
Expand All @@ -38,42 +38,17 @@ jobs:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build Spark-Operator Docker Image
- name: Release Spark-Operator Docker Image
run: |
tag=$(git describe --tags --dirty)_v3.1.1
docker build -t gcr.io/spark-operator/spark-operator:${tag} .
docker build -t gcr.io/spark-operator/spark-operator:local .
DOCKER_TAG=$(cat charts/spark-operator-chart/Chart.yaml | grep "appVersion: .*" | cut -c13-)
docker build -t gcr.io/spark-operator/spark-operator:${DOCKER_TAG} .
echo "Ideally, we'd release the docker container at this point, but the maintainer of this repo needs to approve..."
echo "docker push gcr.io/spark-operator/spark-operator:${tag}"
- name: Set up chart-testing
uses: helm/[email protected]

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed)
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
if ! docker pull docker pull gcr.io/spark-operator/spark-operator:${DOCKER_TAG}; then
echo "docker push gcr.io/spark-operator/spark-operator:${DOCKER_TAG}"
git tag $DOCKER_TAG
git push origin $DOCKER_TAG
fi
- name: Run chart-testing (lint)
run: ct lint

- name: setup minikube
uses: manusa/[email protected]
with:
minikube version: "v1.24.0"
kubernetes version: "v1.20.8"
start args: --memory 6g --cpus=2 --addons ingress
github token: ${{ inputs.github-token }}

- name: Run chart-testing (install)
run: |
tag=$(git describe --tags --dirty)_v3.1.1
minikube image load gcr.io/spark-operator/spark-operator:local
ct install
- name: Run chart-releaser
uses: helm/[email protected]
env:
Expand Down
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ all: clean-sparkctl build-sparkctl install-sparkctl
build-sparkctl:
[ ! -f "sparkctl/sparkctl-darwin-amd64" ] || [ ! -f "sparkctl/sparkctl-linux-amd64" ] && \
echo building using $(BUILDER) && \
docker run -it -w $(SPARK_OPERATOR_GOPATH) \
docker run -w $(SPARK_OPERATOR_GOPATH) \
-v $$(pwd):$(SPARK_OPERATOR_GOPATH) $(BUILDER) sh -c \
"apk add --no-cache bash git && \
cd sparkctl && \
Expand All @@ -36,14 +36,16 @@ install-sparkctl: | sparkctl/sparkctl-darwin-amd64 sparkctl/sparkctl-linux-amd64
fi

build-api-docs:
hack/api-ref-docs \
-config hack/api-docs-config.json \
-api-dir github.com/GoogleCloudPlatform/spark-on-k8s-operator/pkg/apis/sparkoperator.k8s.io/v1beta2 \
-template-dir hack/api-docs-template \
-out-file docs/api-docs.md
docker build -t temp-api-ref-docs hack/api-docs
docker run -v $$(pwd):/repo/ temp-api-ref-docs \
sh -c "cd /repo/ && /go/gen-crd-api-reference-docs/gen-crd-api-reference-docs \
-config /repo/hack/api-docs/api-docs-config.json \
-api-dir github.com/GoogleCloudPlatform/spark-on-k8s-operator/pkg/apis/sparkoperator.k8s.io/v1beta2 \
-template-dir /repo/hack/api-docs/api-docs-template \
-out-file /repo/docs/api-docs.md"

helm-docs:
helm-docs -c ./charts
docker run --rm --volume "$(pwd):/helm-docs" -u "$(id -u)" jnorwood/helm-docs:latest

fmt-check: clean
@echo "running fmt check"; cd "$(dirname $0)"; \
Expand All @@ -63,16 +65,15 @@ clean:
go clean -cache -testcache -r -x ./... 2>&1 >/dev/null
-rm -rf _output

test: clean
unit-test: clean
@echo "running unit tests"
go test -v ./... -covermode=atomic


it-test: clean
integration-test: clean
@echo "running unit tests"
go test -v ./test/e2e/ --kubeconfig "$(HOME)/.kube/config" --operator-image=gcr.io/spark-operator/spark-operator:local

vet:
static-analysis:
@echo "running go vet"
# echo "Building using $(BUILDER)"
# go vet ./...
Expand Down
4 changes: 2 additions & 2 deletions charts/spark-operator-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v2
name: spark-operator
description: A Helm chart for Spark on Kubernetes operator
version: 1.1.15
appVersion: v1beta2-1.3.1-3.1.1
version: 1.1.16
appVersion: v1beta2-1.3.2-3.1.1
keywords:
- spark
home: https://github.com/GoogleCloudPlatform/spark-on-k8s-operator
Expand Down
10 changes: 5 additions & 5 deletions charts/spark-operator-chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ All charts linted successfully
| fullnameOverride | string | `""` | String to override release name |
| image.pullPolicy | string | `"IfNotPresent"` | Image pull policy |
| image.repository | string | `"gcr.io/spark-operator/spark-operator"` | Image repository |
| image.tag | string | `""` | Overrides the image tag whose default is the chart appVersion. |
| image.tag | string | `""` | if set, override the image tag whose default is the chart appVersion. |
| imagePullSecrets | list | `[]` | Image pull secrets |
| uiService.enable | bool | `""` | Enable UI service creation for Spark application |
| ingressUrlFormat | string | `""` | Ingress URL format. Requires the UI service to be enabled by setting `uiService.enable` to true. |
| istio.enabled | bool | `false` | When using `istio`, spark jobs need to run without a sidecar to properly terminate |
| labelSelectorFilter | string | `""` | A comma-separated list of key=value, or key labels to filter resources during watch and list based on the specified labels. |
Expand All @@ -114,7 +113,7 @@ All charts linted successfully
| rbac.createRole | bool | `true` | Create and use RBAC `Role` resources |
| replicaCount | int | `1` | Desired number of pods, leaderElection will be enabled if this is greater than 1 |
| resourceQuotaEnforcement.enable | bool | `false` | Whether to enable the ResourceQuota enforcement for SparkApplication resources. Requires the webhook to be enabled by setting `webhook.enable` to true. Ref: https://github.com/GoogleCloudPlatform/spark-on-k8s-operator/blob/master/docs/user-guide.md#enabling-resource-quota-enforcement. |
| resources | object | `{}` | Pod resource requests and limits |
| resources | object | `{}` | Pod resource requests and limits Note, that each job submission will spawn a JVM within the Spark Operator Pod using "/usr/local/openjdk-11/bin/java -Xmx128m". Kubernetes may kill these Java processes at will to enforce resource limits. When that happens, you will see the following error: 'failed to run spark-submit for SparkApplication [...]: signal: killed' - when this happens, you may want to increase memory limits. |
| resyncInterval | int | `30` | Operator resync interval. Note that the operator will respond to events (e.g. create, update) unrelated to this setting |
| securityContext | object | `{}` | Operator container security context |
| serviceAccounts.spark.annotations | object | `{}` | Optional annotations for the spark service account |
Expand All @@ -125,12 +124,13 @@ All charts linted successfully
| serviceAccounts.sparkoperator.name | string | `""` | Optional name for the operator service account |
| sparkJobNamespace | string | `""` | Set this if running spark jobs in a different namespace than the operator |
| tolerations | list | `[]` | List of node taints to tolerate |
| webhook.initAnnotations | object | `{"helm.sh/hook":"pre-install, pre-upgrade","helm.sh/hook-weight":"50"}` | The annotations applied to init job, required to restore certs deleted by the cleanup job during upgrade |
| uiService.enable | bool | `true` | Enable UI service creation for Spark application |
| webhook.cleanupAnnotations | object | `{"helm.sh/hook":"pre-delete, pre-upgrade","helm.sh/hook-delete-policy":"hook-succeeded"}` | The annotations applied to the cleanup job, required for helm lifecycle hooks |
| webhook.enable | bool | `false` | Enable webhook server |
| webhook.initAnnotations | object | `{"helm.sh/hook":"pre-install, pre-upgrade","helm.sh/hook-weight":"50"}` | The annotations applied to init job, required to restore certs deleted by the cleanup job during upgrade |
| webhook.namespaceSelector | string | `""` | The webhook server will only operate on namespaces with this label, specified in the form key1=value1,key2=value2. Empty string (default) will operate on all namespaces |
| webhook.port | int | `8080` | Webhook service port |
| webhook.timeout | int | `30` | Webhook timeout in seconds |
| webhook.timeout | int | `30` | |

## Maintainers

Expand Down
Loading

0 comments on commit ba16242

Please sign in to comment.