Skip to content

Commit

Permalink
Merge pull request #1267 from yue9944882/codegen-abort-on-failure
Browse files Browse the repository at this point in the history
Codegen should abort upon hitting any error
  • Loading branch information
k8s-ci-robot authored Sep 15, 2020
2 parents 069c6c5 + a44b189 commit d780a9b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,29 @@ jobs:
-B \
-De2e.skip=false \
-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
codegen:
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
name: CRD Java Models Code Generation
steps:
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: kubernetes-client/java/crd-model-gen
tags: gh-action-tmp
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: docker.pkg.github.com
workdir: client-java-contrib
no_push: true
- name: Run Code-gen for Cert-Manager
working-directory: ${{ github.workspace }}/client-java-contrib/cert-manager
run: IMAGE_TAG=gh-action-tmp ./update.sh
- name: Run Code-gen for Prometheus-Operator
working-directory: ${{ github.workspace }}/client-java-contrib/prometheus-operator
run: IMAGE_TAG=gh-action-tmp ./update.sh

6 changes: 4 additions & 2 deletions client-java-contrib/cert-manager/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
# This script generates the model classes from a released version of cert-manager CRDs
# under src/main/java/io/cert/manager/models.

IMAGE_NAME=${IMAGE_NAME:docker.pkg.github.com/kubernetes-client/java/crd-model-gen}
IMAGE_TAG=${IMAGE_TAG:v1.0.2}

# a crdgen container is run in a way that:
# 1. it has access to the docker daemon on the host so that it is able to create sibling container on the host
# 2. it runs on the host network so that it is able to communicate with the KinD cluster it launched on the host
docker run \
--rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$(pwd)":"$(pwd)" \
-ti \
--network host \
docker.pkg.github.com/kubernetes-client/java/crd-model-gen:v1.0.1 \
${IMAGE_NAME}:${IMAGE_TAG} \
/generate.sh \
-u https://github.com/jetstack/cert-manager/releases/download/v0.16.1/cert-manager.crds.yaml \
-n io.cert-manager \
Expand Down
8 changes: 7 additions & 1 deletion client-java-contrib/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ while getopts 'u:n:p:o:' flag; do
esac
done

set -e

# create a KinD cluster on the host
kind create cluster

# install CRDs to the KinD cluster and dump the swagger spec
for url in "${CRD_URLS[@]}"; do
kubectl apply -f "$url"
if [[ ! -z $url ]]; then
kubectl apply -f "$url"
fi
done

sleep 5
Expand All @@ -58,10 +62,12 @@ kubectl get crd -o name \
do
if [[ $(kubectl get $L -o jsonpath='{.status.conditions[?(@.type=="NonStructuralSchema")].status}') == "True" ]]; then
echo "$L failed publishing openapi schema because it's attached non-structral-schema condition."
kind delete cluster
exit 1
fi
if [[ $(kubectl get $L -o jsonpath='{.spec.preserveUnknownFields}') == "true" ]]; then
echo "$L failed publishing openapi schema because it explicitly disabled unknown fields pruning."
kind delete cluster
exit 1
fi
echo "$L successfully installed"
Expand Down
6 changes: 4 additions & 2 deletions client-java-contrib/prometheus-operator/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
# This script generates the model classes from a released version of cert-manager CRDs
# under src/main/java/io/cert/manager/models.

IMAGE_NAME=${IMAGE_NAME:docker.pkg.github.com/kubernetes-client/java/crd-model-gen}
IMAGE_TAG=${IMAGE_TAG:v1.0.2}

# a crdgen container is run in a way that:
# 1. it has access to the docker daemon on the host so that it is able to create sibling container on the host
# 2. it runs on the host network so that it is able to communicate with the KinD cluster it launched on the host
docker run \
--rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$(pwd)":"$(pwd)" \
-ti \
--network host \
docker.pkg.github.com/kubernetes-client/java/crd-model-gen:v1.0.1 \
${IMAGE_NAME}:${IMAGE_TAG} \
/generate.sh \
-u https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.38.1/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagers.yaml \
-u https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.38.1/example/prometheus-operator-crd/monitoring.coreos.com_thanosrulers.yaml \
Expand Down
4 changes: 2 additions & 2 deletions docs/generate-model-from-third-party-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ docker run \
-v "$(pwd)":"$(pwd)" \
-ti \
--network host \
docker.pkg.github.com/kubernetes-client/java/crd-model-gen:v1.0.1 \
docker.pkg.github.com/kubernetes-client/java/crd-model-gen:v1.0.2 \
/generate.sh \
-u https://gist.githubusercontent.com/yue9944882/266fee8e95c2f15a93778263633e72ed/raw/be12c13379eeed13d2532cb65da61fffb19ee3e7/crontab-crd.yaml \
-n com.example.stable \
Expand Down Expand Up @@ -84,7 +84,7 @@ docker run \
-v "$(pwd)":"$(pwd)" \
-ti \
--network host \
docker.pkg.github.com/kubernetes-client/java/crd-model-gen:v1.0.1 \
docker.pkg.github.com/kubernetes-client/java/crd-model-gen:v1.0.2 \
/generate.sh \
-u $LOCAL_MANIFEST_FILE \
-n com.example.stable \
Expand Down

0 comments on commit d780a9b

Please sign in to comment.