Skip to content

Commit 04221ff

Browse files
authored
Merge pull request #2265 from yue9944882/gh-action-crd-generation
CRD generate gh-action workflow
2 parents adea6cf + 4082c57 commit 04221ff

File tree

2 files changed

+80
-15
lines changed

2 files changed

+80
-15
lines changed

.github/workflows/generate-crd.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CRD Java Model Generate
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
crds:
6+
type: string
7+
required: true
8+
description: 'Comma-separated paths to CRD yaml sources, can be either HTTP url or local file path.'
9+
generatingJavaPackage:
10+
type: string
11+
required: true
12+
description: 'The package name of the generated java project.'
13+
crdApiGroupPrefix:
14+
type: string
15+
required: false
16+
description: 'The prefix of the target CRDs api group to generate. (Optional)'
17+
18+
env:
19+
IMAGE_NAME: ghcr.io/kubernetes-client/java/crd-model-gen
20+
IMAGE_TAG: v1.0.6
21+
GEN_DIR: crd-gen
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
generate:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v3
32+
- name: Run CRD Model Generation
33+
run: |
34+
read CRD_SRC_ARGS < <(echo '${{ github.event.inputs.crds }}' | perl -ne 'print join " ", map {"-u $_"} split /,/')
35+
test -z ${{ github.event.inputs.crdApiGroupPrefix }} || export CRD_API_GROUP_ARGS="-n ${{ github.event.inputs.crdApiGroupPrefix }}"
36+
echo "CRD Src Args: ${CRD_SRC_ARGS}"
37+
echo "CRD Api Group Prefix Args: ${CRD_API_GROUP_ARGS}"
38+
mkdir -p ${GEN_DIR}
39+
docker run \
40+
--rm \
41+
-v /var/run/docker.sock:/var/run/docker.sock \
42+
-v "$(pwd)":"$(pwd)" \
43+
--network host \
44+
${IMAGE_NAME}:${IMAGE_TAG} \
45+
/generate.sh \
46+
${CRD_SRC_ARGS} \
47+
${CRD_API_GROUP_ARGS} \
48+
-p ${{ github.event.inputs.generatingJavaPackage }} \
49+
-o "$(pwd)/${GEN_DIR}"
50+
ls -lh ${GEN_DIR}
51+
- uses: actions/upload-artifact@v3
52+
with:
53+
name: generated-java-crd-model
54+
path: |
55+
${{ env.GEN_DIR }}

docs/generate-model-from-third-party-resources.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,36 @@ Alternatively, without this automatic code-generation process, you can always ma
55
models for CRDs by implementing [KubernetesObject](https://github.com/kubernetes-client/java/blob/master/kubernetes/src/main/java/io/kubernetes/client/common/KubernetesObject.java)
66
and [KubernetesListObject](https://github.com/kubernetes-client/java/blob/master/kubernetes/src/main/java/io/kubernetes/client/common/KubernetesListObject.java) interfaces.
77

8-
### Setup Environment
8+
## Remote Generate via Github Action
99

10-
__Note__: You can skip this section by replacing image prefix `docker.pkg.github.com/kubernetes-client/java/..`
11-
to `ghcr.io/yue9944882/..` which is a mirror repository allows anonymous access. `docker.pkg.github.com/kubernetes-client/java/..`
12-
will require docker-login due to `kubernetes-client` permission limit.
10+
### 1. Fork Upstream Repo
1311

14-
1. Make there's an active docker daemon service working on your host, run `docker ps` to check it if
15-
it's correctly setup.
12+
Fork the repository [kubernetes-client/java](https://github.com/kubernetes-client/java)
13+
so that you can run the github action ["CRD Java Model Generate"](./.github/workflows/generate-crd.yml)
14+
in your forked repo. (Running github action job manually requires "collaborator" access to the repo).
1615

17-
2. Generating your access token in [https://github.com/settings/tokens](https://github.com/settings/tokens)
18-
and grants it package-read privilege. And save your token into a local file `~/TOKEN.txt`.
16+
Alternatively, you can also copy-paste the above github action definition to your repo to run it.
1917

20-
3. Login to github docker registry by running:
18+
### 2. Execute Github Action
19+
20+
Go to the repo home page, then click __"Actions"__. Find the job "CRD Java Model Generate"
21+
under __"Workflows"__ and then run it. The workflow will help convert your CRD yaml manifests to
22+
zip-archived java sources which is downloadable after it finishes.
23+
24+
### 3. Download the Generated Sources
25+
26+
Go to the __"Summary"__ page of the workflow execution, you can find the archived java sources at
27+
the bottom of the page. Just click it to download.
28+
29+
## Generate in Local Environment
30+
31+
### 1. Pull Image
2132

2233
```bash
23-
# TODO: replace USERNAME w/ your github alias
24-
cat ~/TOKEN.txt | docker login https://docker.pkg.github.com -u USERNAME --password-stdin
34+
docker pull ghcr.io/kubernetes-client/java/crd-model-gen:v1.0.6
2535
```
2636

27-
### Code-generator Image
37+
### 2. Run Code-generator Image
2838

2939
##### Usage
3040

@@ -57,7 +67,7 @@ docker run \
5767
-v "$(pwd)":"$(pwd)" \
5868
-ti \
5969
--network host \
60-
docker.pkg.github.com/kubernetes-client/java/crd-model-gen:v1.0.6 \
70+
ghcr.io/kubernetes-client/java/crd-model-gen:v1.0.6 \
6171
/generate.sh \
6272
-u https://gist.githubusercontent.com/yue9944882/266fee8e95c2f15a93778263633e72ed/raw/be12c13379eeed13d2532cb65da61fffb19ee3e7/crontab-crd.yaml \
6373
-n com.example.stable \
@@ -88,7 +98,7 @@ docker run \
8898
-v "$(pwd)":"$(pwd)" \
8999
-ti \
90100
--network host \
91-
docker.pkg.github.com/kubernetes-client/java/crd-model-gen:v1.0.6 \
101+
ghcr.io/kubernetes-client/java/crd-model-gen:v1.0.6 \
92102
/generate.sh \
93103
-u $LOCAL_MANIFEST_FILE \
94104
-n com.example.stable \
@@ -97,7 +107,7 @@ docker run \
97107
```
98108

99109

100-
### Manipulate the generated models
110+
## Manipulate the generated models
101111

102112
After generation you will see bunch of generated model sources under the `/tmp/java`:
103113

0 commit comments

Comments
 (0)