Skip to content

Commit 6af41ad

Browse files
Merge pull request #132 from clobrano/automate-community-bundle-0
Automate community bundle creation
2 parents d320cba + 34feda6 commit 6af41ad

File tree

5 files changed

+203
-53
lines changed

5 files changed

+203
-53
lines changed

.github/workflows/post-submit.yaml

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,26 @@ permissions:
1111
pull-requests: read
1212

1313
jobs:
14-
push-images:
15-
name: Build and push images to quay.io/medik8s
14+
push_to_registry:
15+
name: Build and push unversioned images to quay.io/medik8s
1616
runs-on: ubuntu-22.04
1717
steps:
1818
- name: Checkout code
19-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
2020
with:
2121
fetch-depth: 0
2222

23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version-file: go.mod
27+
2328
- name: Log in to Quay.io
24-
uses: docker/login-action@v2
29+
uses: docker/login-action@v3
2530
with:
2631
username: ${{ secrets.QUAY_USERNAME }}
2732
password: ${{ secrets.QUAY_PASSWORD }}
2833
registry: quay.io
2934

30-
- name: Build and push CSV 0.0.1 + latest images for PR merges to main
31-
if: ${{ github.ref_type != 'tag' }}
35+
- name: Build and push CSV version 0.0.1 with latest images
3236
run: export IMAGE_REGISTRY=quay.io/medik8s && make container-build-and-push-community
33-
34-
- name: Build and push versioned CSV and images for tags
35-
if: ${{ github.ref_type == 'tag' }}
36-
# remove leading 'v' from tag!
37-
run: export VERSION=$(echo $GITHUB_REF_NAME | sed 's/v//') && make container-build-and-push-community
38-
39-
- name: Create release with manifests
40-
if: ${{ github.ref_type == 'tag' }}
41-
# https://github.com/marketplace/actions/github-release-create-update-and-upload-assets
42-
uses: meeDamian/[email protected]
43-
with:
44-
token: ${{ secrets.GITHUB_TOKEN }}
45-
draft: true
46-
body: |
47-
# Node Maintenance Operator ${{ github.ref_name }}
48-
49-
## Notable Changes
50-
51-
* TODO
52-
53-
## Release Artifacts
54-
55-
### Images
56-
* Operator: quay.io/medik8s/node-maintenance-operator:${{ github.ref_name }}
57-
* Bundle: quay.io/medik8s/node-maintenance-operator-bundle:${{ github.ref_name }}
58-
* Catalog aka Index: quay.io/medik8s/node-maintenance-operator-catalog:${{ github.ref_name }}
59-
60-
### Source code and OLM manifests
61-
Please find the source code and the OLM manifests in the `Assets` section below.
62-
gzip: folders
63-
files: >
64-
Manifests:bundle/

.github/workflows/release.yaml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Release
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
operation:
6+
description: "The operation to perform."
7+
required: true
8+
type: choice
9+
default: "build_and_push_images"
10+
options:
11+
- build_and_push_images
12+
- create_okd_release_pr
13+
- create_k8s_release_pr
14+
version:
15+
description: "The version to release, without the leading `v`"
16+
required: true
17+
previous_version:
18+
description: "The previous version, used for the CVS's `replaces` field, without the leading `v`"
19+
required: true
20+
ocp_version:
21+
description: "The target OCP version for the release (mandatory for create_okd_release_pr option)"
22+
required: false
23+
24+
permissions:
25+
contents: write
26+
27+
jobs:
28+
push_to_registry:
29+
if: ${{ inputs.operation == 'build_and_push_images' }}
30+
name: Build and push versioned images to quay.io/medik8s
31+
runs-on: ubuntu-22.04
32+
env:
33+
VERSION: ${{ inputs.version }}
34+
PREVIOUS_VERSION: ${{ inputs.previous_version }}
35+
OCP_VERSION: ${{ inputs.ocp_version }}
36+
steps:
37+
- name: Log inputs
38+
run: |
39+
echo "Building version: ${VERSION},"
40+
echo "which replaces version: ${PREVIOUS_VERSION}."
41+
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
with:
45+
fetch-depth: 0
46+
47+
- name: Set up Go
48+
uses: actions/setup-go@v5
49+
with:
50+
go-version-file: go.mod
51+
52+
- name: Log in to Quay.io
53+
uses: docker/login-action@v3
54+
with:
55+
username: ${{ secrets.QUAY_USERNAME }}
56+
password: ${{ secrets.QUAY_PASSWORD }}
57+
registry: quay.io
58+
59+
- name: Build and push versioned CSV and images
60+
run: VERSION=$VERSION PREVIOUS_VERSION=$PREVIOUS_VERSION make container-build-community container-push
61+
62+
- name: Create release with manifests, for tags
63+
# https://github.com/marketplace/actions/github-release-create-update-and-upload-assets
64+
uses: meeDamian/[email protected]
65+
with:
66+
tag: v${{ inputs.version }}
67+
token: ${{ secrets.GITHUB_TOKEN }}
68+
draft: true
69+
body: |
70+
# Node Maintenance Operator ${{ inputs.version }}
71+
72+
## Notable Changes
73+
74+
* TODO
75+
76+
## Release Artifacts
77+
78+
### Images
79+
* Operator: quay.io/medik8s/node-maintenance-operator:v${{ inputs.version }}
80+
* Bundle: quay.io/medik8s/node-maintenance-operator-bundle:v${{ inputs.version }}
81+
* Catalog aka Index: quay.io/medik8s/node-maintenance-operator-catalog:v${{ inputs.version }}
82+
83+
### Source code and OLM manifests
84+
Please find the source code and the OLM manifests in the `Assets` section below.
85+
gzip: folders
86+
files: >
87+
Manifests:bundle/
88+
89+
create_k8s_release_pr:
90+
if: inputs.operation == 'create_k8s_release_pr'
91+
uses: medik8s/.github/.github/workflows/release_community_bundle_parametric.yaml@main
92+
secrets: inherit
93+
with:
94+
version: ${{ inputs.version }}
95+
previous_version: ${{ inputs.previous_version }}
96+
community: 'K8S'
97+
make_targets: "bundle-community-k8s"
98+
create_okd_release_pr:
99+
if: inputs.operation == 'create_okd_release_pr'
100+
uses: medik8s/.github/.github/workflows/release_community_bundle_parametric.yaml@main
101+
secrets: inherit
102+
with:
103+
version: ${{ inputs.version }}
104+
previous_version: ${{ inputs.previous_version }}
105+
ocp_version: ${{ inputs.ocp_version }}
106+
community: 'OKD'
107+
make_targets: "bundle-community-okd"

Makefile

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ GO_VERSION = 1.20
2020
ENVTEST_K8S_VERSION = 1.28
2121
# See https://github.com/slintes/sort-imports/releases for the last version
2222
SORT_IMPORTS_VERSION = v0.2.1
23+
# OCP Version: for OKD bundle community
24+
OCP_VERSION ?= 4.12
25+
# update for major version updates to YQ_VERSION! see https://github.com/mikefarah/yq
26+
# NOTE: v4.42.1 is the latest supporting go 1.20
27+
YQ_API_VERSION = v4
28+
YQ_VERSION = v4.42.1
2329

2430
# IMAGE_REGISTRY used to indicate the registery/group for the operator, bundle and catalog
2531
IMAGE_REGISTRY ?= quay.io/medik8s
@@ -209,32 +215,64 @@ bundle-cleanup: operator-sdk ## Remove bundle installed via bundle-run
209215
## Some addition to bundle creation in the bundle
210216
DEFAULT_ICON_BASE64 := $(shell base64 --wrap=0 ./config/assets/nmo_blue_icon.png)
211217
export ICON_BASE64 ?= ${DEFAULT_ICON_BASE64}
212-
export BUNDLE_CSV ?= "./bundle/manifests/$(OPERATOR_NAME).clusterserviceversion.yaml"
218+
export CSV ?= "./bundle/manifests/$(OPERATOR_NAME).clusterserviceversion.yaml"
213219

214220
.PHONY: bundle-update
215-
bundle-update: verify-previous-version ## Update CSV fields and validate the bundle directory
216-
sed -r -i "s|containerImage: .*|containerImage: $(IMG)|;" ${BUNDLE_CSV}
217-
sed -r -i "s|createdAt: .*|createdAt: `date '+%Y-%m-%d %T'`|;" ${BUNDLE_CSV}
218-
sed -r -i "s|replaces: .*|replaces: $(OPERATOR_NAME).v${PREVIOUS_VERSION}|;" ${BUNDLE_CSV}
219-
sed -r -i "s|base64data:.*|base64data: ${ICON_BASE64}|;" ${BUNDLE_CSV}
221+
bundle-update: ## Update CSV fields and validate the bundle directory
222+
sed -r -i "s|containerImage: .*|containerImage: $(IMG)|;" ${CSV}
223+
sed -r -i "s|createdAt: .*|createdAt: `date '+%Y-%m-%d %T'`|;" ${CSV}
224+
sed -r -i "s|base64data:.*|base64data: ${ICON_BASE64}|;" ${CSV}
220225
$(MAKE) bundle-validate
221226

222-
.PHONY: verify-previous-version
223-
verify-previous-version: ## Verifies that PREVIOUS_VERSION variable is set
224-
@if [ $(VERSION) != $(DEFAULT_VERSION) ] && [ $(VERSION) != $(CI_VERSION) ] && [ $(PREVIOUS_VERSION) = $(DEFAULT_VERSION) ]; then \
225-
echo "Error: PREVIOUS_VERSION must be set for the selected VERSION"; \
226-
exit 1; \
227+
.PHONY: add-replaces-field
228+
add-replaces-field: ## Add replaces field to the CSV
229+
# add replaces field when building versioned bundle
230+
@if [ $(VERSION) != $(DEFAULT_VERSION) ]; then \
231+
if [ $(PREVIOUS_VERSION) == $(DEFAULT_VERSION) ]; then \
232+
echo "Error: PREVIOUS_VERSION must be set for versioned builds"; \
233+
exit 1; \
234+
elif [ $(shell ./hack/semver_cmp.sh $(VERSION) $(PREVIOUS_VERSION)) != 1 ]; then \
235+
echo "Error: VERSION ($(VERSION)) must be greater than PREVIOUS_VERSION ($(PREVIOUS_VERSION))"; \
236+
exit 1; \
237+
else \
238+
# preferring sed here, in order to have "replaces" near "version" \
239+
sed -r -i "/ version: $(VERSION)/ a\ replaces: $(OPERATOR_NAME).v$(PREVIOUS_VERSION)" ${CSV}; \
240+
fi \
227241
fi
228242

229243
.PHONY: bundle-reset-date
230244
bundle-reset-date: ## Reset bundle's createdAt
231-
sed -r -i "s|createdAt: .*|createdAt: \"\"|;" ${BUNDLE_CSV}
245+
sed -r -i "s|createdAt: .*|createdAt: \"\"|;" ${CSV}
232246

233247
.PHONY: bundle-community
234-
bundle-community: bundle-k8s ## Update displayName, and description fields in the bundle's CSV
235-
sed -r -i "s|displayName: Node Maintenance Operator|displayName: Node Maintenance Operator - Community Edition |;" ${BUNDLE_CSV}
248+
bundle-community: ## Update displayName, and description fields in the bundle's CSV
249+
sed -r -i "s|displayName: Node Maintenance Operator|displayName: Node Maintenance Operator - Community Edition |;" ${CSV}
236250
$(MAKE) bundle-update
237251

252+
253+
.PHONY: bundle-community-k8s
254+
bundle-community-k8s: bundle-k8s bundle-community ## Generate bundle manifests and metadata customized to Red Hat community release
255+
256+
.PHONY: bundle-community-okd
257+
bundle-community-okd: bundle bundle-community ## Generate bundle manifests and metadata customized to Red Hat community release
258+
$(MAKE) add-replaces-field
259+
$(MAKE) add-ocp-annotations
260+
echo -e "\n # Annotations for OCP\n com.redhat.openshift.versions: \"v${OCP_VERSION}\"" >> bundle/metadata/annotations.yaml
261+
262+
263+
.PHONY: add-ocp-annotations
264+
add-ocp-annotations: yq ## Add OCP annotations
265+
$(YQ) -i '.metadata.annotations."operators.openshift.io/valid-subscription" = "[\"OpenShift Kubernetes Engine\", \"OpenShift Container Platform\", \"OpenShift Platform Plus\"]"' ${CSV}
266+
# new infrastructure annotations see https://docs.engineering.redhat.com/display/CFC/Best_Practices#Best_Practices-(New)RequiredInfrastructureAnnotations
267+
$(YQ) -i '.metadata.annotations."features.operators.openshift.io/disconnected" = "true"' ${CSV}
268+
$(YQ) -i '.metadata.annotations."features.operators.openshift.io/fips-compliant" = "false"' ${CSV}
269+
$(YQ) -i '.metadata.annotations."features.operators.openshift.io/proxy-aware" = "false"' ${CSV}
270+
$(YQ) -i '.metadata.annotations."features.operators.openshift.io/tls-profiles" = "false"' ${CSV}
271+
$(YQ) -i '.metadata.annotations."features.operators.openshift.io/token-auth-aws" = "false"' ${CSV}
272+
$(YQ) -i '.metadata.annotations."features.operators.openshift.io/token-auth-azure" = "false"' ${CSV}
273+
$(YQ) -i '.metadata.annotations."features.operators.openshift.io/token-auth-gcp" = "false"' ${CSV}
274+
275+
238276
##@ Build
239277

240278
.PHONY: build
@@ -291,6 +329,7 @@ GINKGO_DIR ?= $(LOCALBIN)/ginkgo
291329
OPM_DIR = $(LOCALBIN)/opm
292330
OPERATOR_SDK_DIR ?= $(LOCALBIN)/operator-sdk
293331
SORT_IMPORTS_DIR ?= $(LOCALBIN)/sort-imports
332+
YQ_DIR ?= $(LOCALBIN)/yq
294333

295334
## Specific Tool Binaries
296335
KUSTOMIZE = $(KUSTOMIZE_DIR)/$(KUSTOMIZE_VERSION)/kustomize
@@ -301,6 +340,7 @@ GINKGO = $(GINKGO_DIR)/$(GINKGO_VERSION)/ginkgo
301340
OPM = $(OPM_DIR)/$(OPM_VERSION)/opm
302341
OPERATOR_SDK = $(OPERATOR_SDK_DIR)/$(OPERATOR_SDK_VERSION)/operator-sdk
303342
SORT_IMPORTS = $(SORT_IMPORTS_DIR)/$(SORT_IMPORTS_VERSION)/sort-imports
343+
YQ = $(YQ_DIR)/$(YQ_API_VERSION)-$(YQ_VERSION)/yq
304344

305345
.PHONY: kustomize
306346
kustomize: ## Download kustomize locally if necessary.
@@ -326,6 +366,10 @@ ginkgo: ## Download ginkgo locally if necessary.
326366
sort-imports: ## Download sort-imports locally if necessary.
327367
$(call go-install-tool,$(SORT_IMPORTS),$(SORT_IMPORTS_DIR),github.com/slintes/sort-imports@$(SORT_IMPORTS_VERSION))
328368

369+
.PHONY: yq
370+
yq: ## Download yq locally if necessary.
371+
$(call go-install-tool,$(YQ),$(YQ_DIR), github.com/mikefarah/yq/$(YQ_API_VERSION)@$(YQ_VERSION))
372+
329373
# go-install-tool will delete old package $2, then 'go install' any package $3 to $1.
330374
define go-install-tool
331375
@[ -f $(1) ]|| { \

config/manifests/bases/node-maintenance-operator.clusterserviceversion.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,4 @@ spec:
101101
provider:
102102
name: Medik8s
103103
url: https://github.com/medik8s
104-
replaces: node-maintenance-operator.v0.0.1
105104
version: 0.0.0

hack/semver_cmp.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
# -*- coding: UTF-8 -*-
3+
## Compare two semantic version numbers.
4+
## semver_cmp.sh VER1 VER2 is equivalent to test if "VER1 >= VER2"
5+
## Usage:
6+
## - semver_cmp.sh 1.2.3 1.2.4 ## -1 VER1 is < than VER2
7+
## - semver_cmp.sh 1.2.4 1.2.4 ## 0 VER1 is == to VER2
8+
## - semver_cmp.sh 1.2.5 1.2.4 ## 1 VER1 is > than VER2
9+
## other tests
10+
## - semver_cmp.sh 1.2 1.2.4 ## -1
11+
## - semver_cmp.sh 1.2 1.2 ## 0
12+
## - semver_cmp.sh 1.3 1.2.9 ## 1
13+
14+
if [ "$#" -ne 2 ]; then
15+
echo "Illegal number of parameters"
16+
exit 1
17+
fi
18+
19+
if [ "$1" = "$2" ]; then
20+
echo 0
21+
else
22+
# sort the input and check if it is sorted (quietly).
23+
# `sort` will exit successfully if the given file is already sorted, and exit with status 1 otherwise.
24+
# Since we already excluded that the two versions are equal, if the input is sorted,
25+
# it means the first argument is less than the second one.
26+
# https://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html#sort-invocation
27+
printf "%s\n%s\n" "$1" "$2" | sort --version-sort --check=quiet && echo -1 || echo 1
28+
fi

0 commit comments

Comments
 (0)