Skip to content

Commit 1ee5d73

Browse files
committed
feat(ci): Refine release process and improve deployment configuration
This commit introduces a number of improvements to the CI/CD pipeline and the operator's deployment configuration. Key changes include: - Upgrading the Go version to 1.24 in the CI workflows. - Enhancing the release process with better version calculation and tag handling. - Renaming RBAC resources for clarity and consistency. - Adding support for custom webhook certificates, allowing for more flexible deployments. - Updating kustomize configurations to enable webhooks and cert-manager.
1 parent 501d46f commit 1ee5d73

File tree

15 files changed

+216
-142
lines changed

15 files changed

+216
-142
lines changed

.github/workflows/branch-pipeline.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Set up Go
1515
uses: actions/setup-go@v5
1616
with:
17-
go-version: '1.23'
17+
go-version: '1.24'
1818

1919
- name: Check out code
2020
uses: actions/checkout@v5
@@ -41,11 +41,13 @@ jobs:
4141
steps:
4242
- name: Check out code
4343
uses: actions/checkout@v5
44+
with:
45+
fetch-depth: 0
4446

45-
- name: Check for [skip ci] in commit messages or PR title
47+
- name: Check for [skip ci] in commit message
4648
id: check_skip_ci
4749
run: |
48-
if [[ "${{ github.event.head_commit.message }}" =~ \[skip\ ci\] ]] || [[ "${{ github.event.pull_request.title }}" =~ \[skip\ ci\] ]]; then
50+
if [[ "${{ github.event.head_commit.message }}" =~ \[skip\ ci\] ]]; then
4951
echo "CI skip detected, exiting."
5052
exit 0
5153
fi
@@ -59,18 +61,20 @@ jobs:
5961
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
6062
VERSION="${BRANCH_NAME#release-}"
6163
TS=$(date '+%m%d%H%M')
62-
LARGEST_TAG=$(git tag --merged $BRANCH_NAME --sort=-v:refname | grep $VERSION | head -n 1)
64+
# Get the latest tag matching the release version, looking at all tags now
65+
LARGEST_TAG=$(git tag --sort=-v:refname | grep "^v${VERSION}\\.$" | head -n 1)
6366
if [ -z "$LARGEST_TAG" ]; then
6467
# No existing tag found, use version from branch name with .0 patch version
6568
TAG_NAME="v${VERSION}.0-rc.${TS}.${GITHUB_SHA::7}"
6669
else
67-
# Extract and increment patch version from existing tag
70+
# Extract and increment patch version from existing tag.
71+
# This regex handles both final tags (v1.2.3) and pre-release tags (v1.2.3-rc1)
6872
if [[ $LARGEST_TAG =~ ^v?([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
6973
MAJOR=${BASH_REMATCH[1]}
7074
MINOR=${BASH_REMATCH[2]}
7175
PATCH=${BASH_REMATCH[3]}
7276
NEW_PATCH=$((PATCH + 1))
73-
TAG_NAME="v${MAJOR}.${MINOR}.${NEW_PATCH}-rc.${ts}.${GITHUB_SHA::7}"
77+
TAG_NAME="v${MAJOR}.${MINOR}.${NEW_PATCH}-rc.${TS}.${GITHUB_SHA::7}"
7478
else
7579
# Fallback if tag format is unexpected
7680
TAG_NAME="${LARGEST_TAG}-rc.${TS}.${GITHUB_SHA::7}"

.github/workflows/pr-pipeline.yaml

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Set up Go
1414
uses: actions/setup-go@v5
1515
with:
16-
go-version: '1.23'
16+
go-version: '1.24'
1717

1818
- name: Check out code
1919
uses: actions/checkout@v5
@@ -42,12 +42,53 @@ jobs:
4242
steps:
4343
- name: Check out code
4444
uses: actions/checkout@v5
45+
with:
46+
fetch-depth: 0
4547

4648
- name: Read version from file
4749
id: get_version
4850
run: |
49-
ls -la
50-
echo "VERSION=$(cat version)" >> $GITHUB_ENV
51+
# 1. Fetch all tags
52+
git fetch --tags --force
53+
54+
# 2. Get the latest tag name
55+
latest_tag=$(git tag --sort=-v:refname | head -n 1)
56+
57+
# 3. Handle case where no tags exist
58+
if [ -z "$latest_tag" ]; then
59+
new_tag="v0.1.0"
60+
else
61+
echo "Latest tag found: $latest_tag"
62+
63+
# 4. Remove 'v' prefix for processing
64+
if [[ $latest_tag == v* ]]; then
65+
prefix="v"
66+
version="${latest_tag#v}"
67+
else
68+
prefix=""
69+
version="$latest_tag"
70+
fi
71+
72+
# 5. Split version into parts
73+
IFS='.' read -r major minor patch <<< "$version"
74+
75+
# ----------------------------------------------------------- #
76+
# NEW: Default missing minor/patch versions to 0 for robustness
77+
minor=${minor:-0}
78+
patch=${patch:-0}
79+
# ----------------------------------------------------------- #
80+
81+
# 6. Increment the patch version
82+
patch=$((patch + 1))
83+
84+
# 7. Assemble the new tag
85+
new_tag="${prefix}${major}.${minor}.${patch}"
86+
fi
87+
88+
echo "Calculated new tag: $new_tag"
89+
90+
# 8. Set the new tag as a GitHub Action output
91+
echo "VERSION=$new_tag" >> "$GITHUB_ENV"
5192
5293
- name: Get branch name
5394
id: get_branch
@@ -58,7 +99,7 @@ jobs:
5899
BRANCH_NAME=${GITHUB_REF#refs/heads/}
59100
fi
60101
# Replace special characters with hyphens, remove trailing hyphens, and convert to lowercase
61-
SANITIZED_BRANCH_NAME=$(echo "$BRANCH_NAME" | tr -cs '[:alnum:]' '-' | sed 's/-*$//' | tr '[:upper:]' '[:lower:]')
102+
SANITIZED_BRANCH_NAME=$(echo "$BRANCH_NAME" | tr -cs '[:alnum:]' '-' | sed 's/[-_]//g' | tr '[:upper:]' '[:lower:]')
62103
echo "BRANCH_NAME=$SANITIZED_BRANCH_NAME" >> $GITHUB_ENV
63104
64105
- name: Get short commit SHA
@@ -87,6 +128,6 @@ jobs:
87128
file: ./Dockerfile
88129
context: .
89130
push: true
90-
tags: ghcr.io/${{ github.repository }}:${{ env.VERSION }}-${{ env.BRANCH_NAME }}-${{ env.COMMIT_SHA }}
131+
tags: ghcr.io/${{ github.repository }}:${{ env.VERSION }}-${{ env.BRANCH_NAME }}.g${{ env.COMMIT_SHA }}
91132
platforms: linux/amd64,linux/arm64
92-
133+
linux/arm64

.github/workflows/release-pipeline.yaml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@ name: release-pipeline
33
on:
44
push:
55
tags:
6-
- '*'
6+
- 'v*'
77

88
jobs:
99
build:
1010
name: Build and push Docker image
1111
runs-on: ubuntu-latest
12+
env:
13+
RELEASE_VERSION: ${{ github.ref_name }}
14+
1215
steps:
1316
- name: Check out code
1417
uses: actions/checkout@v5
1518

16-
- name: Get the current tag
17-
run: |
18-
TAG=$(git describe --tags --abbrev=0)
19-
echo "TAG=$TAG" >> $GITHUB_ENV
20-
2119
- name: Set up QEMU
2220
uses: docker/setup-qemu-action@v3
2321

@@ -47,6 +45,6 @@ jobs:
4745
context: .
4846
push: true
4947
tags: |
50-
${{ vars.DOCKER_USERNAME }}/valkey-operator:${{ env.TAG }}
51-
ghcr.io/alauda/valkey-operator:${{ env.TAG }}
48+
${{ vars.DOCKER_USERNAME }}/valkey-operator:${{ env.RELEASE_VERSION }}
49+
ghcr.io/${{ github.repository_owner }}/valkey-operator:${{ env.RELEASE_VERSION }}
5250
platforms: linux/amd64,linux/arm64

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ help: ## Display this help.
105105

106106
.PHONY: manifests
107107
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
108-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
108+
$(CONTROLLER_GEN) rbac:roleName=valkey-operator-manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
109109

110110
.PHONY: generate
111111
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.

cmd/main.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func init() {
8181

8282
func main() {
8383
var metricsAddr string
84+
var webhookCertPath, webhookCertName, webhookCertKey string
8485
var enableLeaderElection bool
8586
var probeAddr string
8687
var secureMetrics bool
@@ -94,6 +95,9 @@ func main() {
9495
"Enabling this will ensure there is only one active controller manager.")
9596
flag.BoolVar(&secureMetrics, "metrics-secure", true,
9697
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
98+
flag.StringVar(&webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.")
99+
flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.")
100+
flag.StringVar(&webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.")
97101
flag.BoolVar(&enableHTTP2, "enable-http2", false,
98102
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
99103
opts := zap.Options{
@@ -120,10 +124,22 @@ func main() {
120124
if !enableHTTP2 {
121125
tlsOpts = append(tlsOpts, disableHTTP2)
122126
}
127+
// Initial webhook TLS options
128+
webhookTLSOpts := tlsOpts
129+
webhookServerOptions := webhook.Options{
130+
TLSOpts: webhookTLSOpts,
131+
}
123132

124-
webhookServer := webhook.NewServer(webhook.Options{
125-
TLSOpts: tlsOpts,
126-
})
133+
if len(webhookCertPath) > 0 {
134+
setupLog.Info("Initializing webhook certificate watcher using provided certificates",
135+
"webhook-cert-path", webhookCertPath, "webhook-cert-name", webhookCertName, "webhook-cert-key", webhookCertKey)
136+
137+
webhookServerOptions.CertDir = webhookCertPath
138+
webhookServerOptions.CertName = webhookCertName
139+
webhookServerOptions.KeyName = webhookCertKey
140+
}
141+
142+
webhookServer := webhook.NewServer(webhookServerOptions)
127143

128144
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
129145
// More info:

config/crd/kustomization.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ resources:
1616

1717
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
1818
# patches here are for enabling the CA injection for each CRD
19-
#- path: patches/cainjection_in_failovers.yaml
20-
#- path: patches/cainjection_in_clusters.yaml
21-
#- path: patches/cainjection_in_sentinels.yaml
22-
#- path: patches/cainjection_in_rds_valkeys.yaml
23-
#- path: patches/cainjection_in_users.yaml
19+
# - path: patches/cainjection_in_failovers.yaml
20+
# - path: patches/cainjection_in_clusters.yaml
21+
# - path: patches/cainjection_in_sentinels.yaml
22+
# - path: patches/cainjection_in_rds_valkeys.yaml
23+
# - path: patches/cainjection_in_users.yaml
2424
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
2525

2626
# [WEBHOOK] To enable webhook, uncomment the following section
2727
# the following config is for teaching kustomize how to do kustomization for CRDs.
2828

2929
#configurations:
30-
#- kustomizeconfig.yaml
30+
# - kustomizeconfig.yaml

0 commit comments

Comments
 (0)