Skip to content

Commit 2e8bdb9

Browse files
authored
refactor ci for 'run only once' (#1162)
Signed-off-by: apedriza <[email protected]>
1 parent d95129c commit 2e8bdb9

File tree

6 files changed

+134
-74
lines changed

6 files changed

+134
-74
lines changed

.github/workflows/capi-smoke-tests.yml

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ jobs:
2424
with:
2525
go-version-file: go.mod
2626

27-
- name: Create image bundle
28-
run: |
29-
make release
30-
make k0smotron-image-bundle.tar
27+
- name: Download image bundle
28+
uses: actions/download-artifact@v4
29+
with:
30+
name: k0smotron-image-bundle
3131

32-
- name: Create kind network with IPv4 only
32+
- name: Load k0smotron image bundle
3333
run: |
34-
docker network create kind --opt com.docker.network.bridge.enable_ip_masquerade=true
35-
34+
docker load -i k0smotron-image-bundle.tar
3635
3736
- name: Download kind
3837
uses: supplypike/setup-bin@v4
@@ -62,32 +61,29 @@ jobs:
6261
version: v1.4.3
6362
uri: https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.4.3/clusterctl-linux-amd64
6463

65-
- name: Prepare cluster api components
66-
run: |
67-
make bootstrap-components.yaml control-plane-components.yaml infrastructure-components.yaml
68-
mkdir -p v0.0.0 k0sproject-k0smotron/control-plane-k0sproject-k0smotron/ k0sproject-k0smotron/bootstrap-k0sproject-k0smotron/ k0sproject-k0smotron/infrastructure-k0sproject-k0smotron/
69-
70-
mv bootstrap-components.yaml v0.0.0
71-
mv control-plane-components.yaml v0.0.0
72-
mv infrastructure-components.yaml v0.0.0
73-
mv ./hack/capi-ci/metadata.yaml v0.0.0
74-
75-
cp -r v0.0.0 k0sproject-k0smotron/bootstrap-k0sproject-k0smotron/
76-
cp -r v0.0.0 k0sproject-k0smotron/control-plane-k0sproject-k0smotron/
77-
cp -r v0.0.0 k0sproject-k0smotron/infrastructure-k0sproject-k0smotron/
78-
sed -e 's#%pwd%#'`pwd`'#g' ./hack/capi-ci/config.yaml > config.yaml
64+
- name: Download cluster-api components
65+
uses: actions/download-artifact@v4
66+
with:
67+
name: cluster-api-components
68+
path: .
7969

8070
- name: Install cluster api components
8171
env:
8272
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8373
run: |
84-
CLUSTER_TOPOLOGY=true clusterctl init --control-plane k0sproject-k0smotron --bootstrap k0sproject-k0smotron --infrastructure k0sproject-k0smotron,docker --config config.yaml
74+
export CLUSTERCTL_REPOSITORY_PATH="$GITHUB_WORKSPACE"
75+
CLUSTER_TOPOLOGY=true clusterctl init --control-plane k0sproject-k0smotron --bootstrap k0sproject-k0smotron --infrastructure k0sproject-k0smotron,docker --config ./hack/capi-ci/config.yaml
8576
kubectl wait --for=condition=available -n cert-manager deployment/cert-manager-webhook --timeout=300s
8677
8778
- name: Install PVC provider
8879
run: |
8980
kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.24/deploy/local-path-storage.yaml
9081
82+
- name: Download install manifest for k0smotron
83+
uses: actions/download-artifact@v4
84+
with:
85+
name: install-yaml
86+
9187
- name: Run inttest for CAPI with docker provider
9288
run: |
9389
kind get kubeconfig > kind.conf

.github/workflows/go.yml

Lines changed: 103 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,23 @@ name: Go build
22

33
on:
44
push:
5-
branches:
5+
branches: &protected_branches
66
- main
77
- release-*
8-
paths-ignore:
8+
paths-ignore: &common_ignores
99
- 'config/**'
1010
- 'docs/**'
1111
- 'mkdocs.yml'
1212
- '**.md'
1313
- LICENSE
1414
- '**.svg'
1515
pull_request:
16-
branches:
17-
- main
18-
- release-*
19-
paths-ignore:
20-
- 'config/**'
21-
- 'docs/**'
22-
- 'mkdocs.yml'
23-
- '**.md'
24-
- LICENSE
25-
- '**.svg'
16+
branches: *protected_branches
17+
paths-ignore: *common_ignores
2618

2719
jobs:
2820
build:
29-
name: Build
21+
name: Build artifacts
3022
runs-on: ubuntu-latest
3123
steps:
3224
- name: Check out code into the Go module directory
@@ -43,33 +35,58 @@ jobs:
4335
- name: Build
4436
run: |
4537
make build
38+
39+
- name: Upload manager binary
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: manager-binary
43+
path: bin/manager
4644

47-
- name: Build image
45+
- name: Build image bundle
4846
run: |
49-
make docker-build
47+
# Build Docker image and create image bundle
48+
make k0smotron-image-bundle.tar
5049
51-
generate-sbom:
52-
name: "Build :: SBOM"
53-
needs: [ build ]
50+
- name: Upload image bundle
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: k0smotron-image-bundle
54+
path: k0smotron-image-bundle.tar
5455

55-
runs-on: ubuntu-22.04
56+
- name: Build cluster api components
57+
run: |
58+
make bootstrap-components.yaml control-plane-components.yaml infrastructure-components.yaml
59+
mkdir -p v0.0.0 k0sproject-k0smotron/control-plane-k0sproject-k0smotron/ k0sproject-k0smotron/bootstrap-k0sproject-k0smotron/ k0sproject-k0smotron/infrastructure-k0sproject-k0smotron/
5660
57-
steps:
58-
- name: Check out code into the Go module directory
59-
uses: actions/checkout@v4
61+
mv bootstrap-components.yaml v0.0.0
62+
mv control-plane-components.yaml v0.0.0
63+
mv infrastructure-components.yaml v0.0.0
64+
mv ./hack/capi-ci/metadata.yaml v0.0.0
6065
61-
- name: Generate SBOM
66+
cp -r v0.0.0 k0sproject-k0smotron/bootstrap-k0sproject-k0smotron/
67+
cp -r v0.0.0 k0sproject-k0smotron/control-plane-k0sproject-k0smotron/
68+
cp -r v0.0.0 k0sproject-k0smotron/infrastructure-k0sproject-k0smotron/
69+
70+
- name: Upload cluster api components
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: cluster-api-components
74+
path: |
75+
config.yaml
76+
k0sproject-k0smotron/
77+
78+
- name: Generate install yaml
6279
run: |
63-
mkdir -p sbom && chmod 777 sbom
64-
make sbom/spdx.json
80+
make release
6581
66-
- uses: actions/upload-artifact@v4
82+
- name: Upload install yaml
83+
uses: actions/upload-artifact@v4
6784
with:
68-
name: spdx.json
69-
path: sbom/spdx.json
85+
name: install-yaml
86+
path: install.yaml
7087

7188
unittest:
72-
name: Unit test
89+
name: Unit & Integration tests
7390
needs: build
7491
runs-on: ubuntu-latest
7592

@@ -86,6 +103,37 @@ jobs:
86103
run: |
87104
make test
88105
106+
generate-sbom:
107+
name: "Build :: SBOM"
108+
needs: [ build ]
109+
110+
runs-on: ubuntu-22.04
111+
112+
steps:
113+
- name: Check out code into the Go module directory
114+
uses: actions/checkout@v4
115+
116+
- name: Download manager binary
117+
uses: actions/download-artifact@v4
118+
with:
119+
name: manager-binary
120+
path: bin
121+
122+
- name: Prepare embedded binary for SBOM
123+
run: |
124+
mkdir -p embedded-bins/staging/linux/bin
125+
cp bin/manager embedded-bins/staging/linux/bin/manager
126+
127+
- name: Generate SBOM
128+
run: |
129+
mkdir -p sbom && chmod 777 sbom
130+
make sbom/spdx.json
131+
132+
- uses: actions/upload-artifact@v4
133+
with:
134+
name: spdx.json
135+
path: sbom/spdx.json
136+
89137
smoketest:
90138
name: Smoke test
91139
needs: build
@@ -115,10 +163,19 @@ jobs:
115163
with:
116164
go-version-file: go.mod
117165

118-
- name: Create image bundle
166+
- name: Download image bundle
167+
uses: actions/download-artifact@v4
168+
with:
169+
name: k0smotron-image-bundle
170+
171+
- name: Download install manifest for k0smotron
172+
uses: actions/download-artifact@v4
173+
with:
174+
name: install-yaml
175+
176+
- name: Load k0smotron image bundle
119177
run: |
120-
make release
121-
make k0smotron-image-bundle.tar
178+
docker load -i k0smotron-image-bundle.tar
122179
123180
- name: Run inttest
124181
run: |
@@ -198,11 +255,24 @@ jobs:
198255
with:
199256
go-version-file: go.mod
200257

258+
- name: Download image bundle
259+
uses: actions/download-artifact@v4
260+
with:
261+
name: k0smotron-image-bundle
262+
263+
- name: Load k0smotron image bundle
264+
run: |
265+
docker load -i k0smotron-image-bundle.tar
266+
267+
- name: Download install manifest
268+
uses: actions/download-artifact@v4
269+
with:
270+
name: install-yaml
271+
201272
- name: Run e2e test
202273
run: |
203274
export TEST_NAME=Test$(echo "${{ matrix.e2e-suite }}" | awk -F'-' '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)}1' OFS='')
204275
echo "Running E2E tests with TEST_NAME=$TEST_NAME"
205-
make release
206276
make e2e TEST_NAME="$TEST_NAME"
207277
208278
- name: Archive artifacts

.github/workflows/lint.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
name: Go lint
2+
23
on:
34
push:
4-
branches:
5+
branches: &protected_branches
56
- main
67
- release-*
7-
paths-ignore:
8+
paths-ignore: &common_ignores
89
- 'docs/**'
910
- 'examples/**'
1011
- '**.md'
1112
- '**.svg'
1213
- '.github/workflows/publish-docs.yml'
1314
- 'mkdocs.yml'
1415
pull_request:
15-
branches:
16-
- main
17-
- release-*
18-
paths-ignore:
19-
- 'docs/**'
20-
- 'examples/**'
21-
- '**.md'
22-
- '**.svg'
23-
- '.github/workflows/publish-docs.yml'
24-
- 'mkdocs.yml'
16+
branches: *protected_branches
17+
paths-ignore: *common_ignores
2518

2619
jobs:
2720
lint:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
install.yaml
33
bootstrap-components.yaml
44
control-plane-components.yaml
5+
infrastructure-components.yaml
56

67
# Binaries for programs and plugins
78
*.exe

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ vet: ## Run go vet against code.
108108
go vet $(GO_PKGS)
109109

110110
.PHONY: test
111-
test: manifests generate fmt vet envtest ## Run tests.
111+
test: $(ENVTEST)
112112
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $(GO_TEST_DIRS) -coverprofile cover.out
113113

114114
DOCKER_TEMPLATES := e2e/data/infrastructure-docker
@@ -121,7 +121,7 @@ generate-e2e-templates-main: $(KUSTOMIZE)
121121
$(KUSTOMIZE) build $(DOCKER_TEMPLATES)/main/cluster-template-webhook-k0s-not-compatible --load-restrictor LoadRestrictionsNone > $(DOCKER_TEMPLATES)/main/cluster-template-webhook-k0s-not-compatible.yaml
122122
$(KUSTOMIZE) build $(DOCKER_TEMPLATES)/main/cluster-template-machinedeployment --load-restrictor LoadRestrictionsNone > $(DOCKER_TEMPLATES)/main/cluster-template-machinedeployment.yaml
123123

124-
e2e: k0smotron-image-bundle.tar install.yaml kustomize generate-e2e-templates-main
124+
e2e: generate-e2e-templates-main
125125
set +x;
126126
PATH="${LOCALBIN}:${PATH}" go test -v -tags e2e -run '$(TEST_NAME)' ./e2e \
127127
-artifacts-folder="$(ARTIFACTS)" \
@@ -132,7 +132,7 @@ e2e: k0smotron-image-bundle.tar install.yaml kustomize generate-e2e-templates-ma
132132
##@ Build
133133

134134
.PHONY: build
135-
build: manifests generate fmt vet ## Build manager binary.
135+
build:
136136
go build -o bin/manager cmd/main.go
137137

138138
.PHONY: run
@@ -143,7 +143,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
143143
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
144144
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
145145
.PHONY: docker-build
146-
docker-build: test ## Build docker image with the manager.
146+
docker-build:
147147
docker build \
148148
-t ${IMG} \
149149
--build-arg BUILD_IMG=golang:$(GO_VERSION) \

hack/capi-ci/config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
providers:
22
- name: "k0sproject-k0smotron"
3-
url: "file://%pwd%/k0sproject-k0smotron/bootstrap-k0sproject-k0smotron/v0.0.0/bootstrap-components.yaml"
3+
url: "file://${CLUSTERCTL_REPOSITORY_PATH}/k0sproject-k0smotron/bootstrap-k0sproject-k0smotron/v0.0.0/bootstrap-components.yaml"
44
type: "BootstrapProvider"
55
- name: "k0sproject-k0smotron"
6-
url: "file://%pwd%/k0sproject-k0smotron/control-plane-k0sproject-k0smotron/v0.0.0/control-plane-components.yaml"
6+
url: "file://${CLUSTERCTL_REPOSITORY_PATH}/k0sproject-k0smotron/control-plane-k0sproject-k0smotron/v0.0.0/control-plane-components.yaml"
77
type: "ControlPlaneProvider"
88
- name: "k0sproject-k0smotron"
9-
url: "file://%pwd%/k0sproject-k0smotron/infrastructure-k0sproject-k0smotron/v0.0.0/infrastructure-components.yaml"
9+
url: "file://${CLUSTERCTL_REPOSITORY_PATH}/k0sproject-k0smotron/infrastructure-k0sproject-k0smotron/v0.0.0/infrastructure-components.yaml"
1010
type: "InfrastructureProvider"

0 commit comments

Comments
 (0)