Skip to content

Commit d1b0c25

Browse files
committed
network regex validation for powervscluster
1 parent 2a3745e commit d1b0c25

File tree

89 files changed

+14175
-2676
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+14175
-2676
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
name: Cluster API version update
3+
about: Create an issue to track tasks for a Cluster API version update
4+
title: Bump cluster-api to v<>
5+
6+
---
7+
8+
/area provider/ibmcloud
9+
10+
## Tasks for Cluster API major version update
11+
12+
Update cluster-api version
13+
- [ ] [go.mod](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/go.mod)
14+
- [ ] [hack/tools/go.mod](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/hack/tools/go.mod)
15+
- [ ] [E2E config files](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/tree/main/test/e2e/config)
16+
- [ ] [test/e2e/data/metadata.yaml](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/test/e2e/data/shared/metadata.yaml)
17+
- [ ] run `make generate` to update the CRDs
18+
19+
20+
Update Kubernetes version
21+
- [ ] [go.mod](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/go.mod)
22+
- [ ] [Kubebuilder version](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/Makefile#L84)
23+
- [ ] [scripts](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/fetch_ext_bins.sh#L29)
24+
25+
26+
If Go version is bumped, update it in the following files
27+
- [ ] [go.mod](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/go.mod)
28+
- [ ] [hack/tools/go.mod](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/hack/tools/go.mod)
29+
- [ ] [ .golangci.yaml](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/.golangci.yml)
30+
- [ ] [hack/ensure-go.sh](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/hack/ensure-go.sh)
31+
- [ ] [netlify.toml](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/netlify.toml)
32+
- [ ] [Makefile](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/Makefile#L66)
33+
- [ ] [hack/ccm/Makefile](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/hack/ccm/Makefile#L16)
34+
- [ ] [Update gcb-docker-gcloud image](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/cloudbuild.yaml#L7)
35+
36+
Previous PR: https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/pull/2069
37+
38+
## Tasks for Cluster API minor version update
39+
40+
Update cluster-api version
41+
- [ ] [go.mod](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/go.mod)
42+
- [ ] [hack/tools/go.mod](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/hack/tools/go.mod)
43+
- [ ] [E2E config files](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/tree/main/test/e2e/config)
44+
45+
46+
**Notes**:
47+
* With every Cluster API release, update the version in the last two CAPIBM release branches also.
48+
* Update the e2e CI to use machine images with corresponding kubernetes version with every Cluster API major version release and update the e2e files accordingly.

.github/ISSUE_TEMPLATE/release.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: Release tracker
3+
about: Create an issue to track tasks for a Cluster API version update
4+
title: Release tracker for v<>
5+
6+
---
7+
8+
/area provider/ibmcloud
9+
10+
**Tasks:**
11+
12+
After every CAPIBM major version release:
13+
- [ ] Update Infrastructure Provider version in [metadata.yaml](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/metadata.yaml) and [e2e test config files](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/tree/main/test/e2e/config)
14+
- [ ] [Update release branch versions for weekly security scan](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/.github/workflows/weekly-security-scan.yaml#L16)
15+
- [ ] [Update release support data in docs](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/docs/book/src/developer/release-support-guidelines.md)
16+
- [ ] [Update docs with reference to latest release](https://github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/blob/main/README.md#compatibility-with-cluster-api-and-kubernetes-versions)
17+
- [ ] Update and add documentation link for new release branch in Netlify
18+
- [ ] Add new presubmit job for latest release kubernetes/test-infra for CAPIBM jobs
19+
- [ ] Bump machine images in CI to use relevent Kubernetes version
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: YamlLint
2+
on: [push, pull_request]
3+
jobs:
4+
yamllint:
5+
runs-on: ubuntu-24.04
6+
steps:
7+
- uses: actions/checkout@v4
8+
- name: Run yamllint make target
9+
run: make yamllint

.github/workflows/weekly-security-scan.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
branch: [ main, release-0.8, release-0.7 ]
16+
branch: [ main, release-0.9, release-0.8 ]
1717
name: Trivy
18-
runs-on: ubuntu-latest
18+
runs-on: ubuntu-24.04
1919
steps:
2020
- name: Check out code
2121
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v4.1.7

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ vendor/sigs.k8s.io/cluster-api/docs/book/*.json
4141
# release
4242
_artifacts/
4343
out/
44+
45+
#ide settings
46+
.vscode/

.yamllint

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
extends: default
2+
3+
ignore:
4+
- config # Skip autogenerated config dir from liniting
5+
6+
rules:
7+
# Rules to control the number of spaces around operators
8+
braces:
9+
min-spaces-inside: 0 # No spaces required inside braces
10+
max-spaces-inside: 1 # Maximum one space inside braces
11+
brackets:
12+
min-spaces-inside: 0
13+
max-spaces-inside: 1
14+
colons:
15+
max-spaces-before: 0
16+
max-spaces-after: 1
17+
commas:
18+
max-spaces-before: 0
19+
max-spaces-after: 1
20+
hyphens:
21+
max-spaces-after: 1
22+
23+
# Rules to control indentation
24+
indentation:
25+
spaces: consistent # Spaces should be consistently used for indentation
26+
indent-sequences: whatever # Either indenting or not indenting individual block sequences is OK
27+
comments-indentation: enable # Comments should be indented the same as the content
28+
29+
# Rules to control lines
30+
line-length:
31+
max: 200 # Maximum 150 characters per line
32+
allow-non-breakable-words: true # Allow long words without breaks
33+
allow-non-breakable-inline-mappings: true # Allow long inline mappings without breaks
34+
empty-lines:
35+
max: 2 # Maximum two consecutive empty lines allowed
36+
trailing-spaces: enable # Ensure no trailing spaces at the end of lines
37+
38+
# Other rules
39+
comments:
40+
min-spaces-from-content: 1 # At least one space required between content and comment
41+
key-duplicates: enable # Ensure no duplicate keys in mappings
42+
truthy:
43+
allowed-values: ['true', 'false', 'on', 'off'] # Allow only these values for boolean scalars

Makefile

+7-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ RELEASE_DIR := out
6363
OUTPUT_TYPE ?= type=registry
6464

6565
# Go
66-
GO_VERSION ?=1.22.8
66+
GO_VERSION ?=1.22.10
6767
GO_CONTAINER_IMAGE ?= golang:$(GO_VERSION)
6868

6969
# kind
@@ -81,7 +81,7 @@ PULL_POLICY ?= Always
8181
# Set build time variables including version details
8282
LDFLAGS := $(shell ./hack/version.sh)
8383

84-
KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.29.3
84+
KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.30.0
8585

8686
# main controller
8787
CORE_IMAGE_NAME ?= cluster-api-ibmcloud-controller
@@ -546,6 +546,11 @@ else
546546
echo "Versions are different across Makefiles. Please ensure to keep them uniform."
547547
endif
548548

549+
550+
.PHONY: yamllint
551+
yamllint:
552+
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/data cytopia/yamllint:latest /data --config-file /data/.yamllint --no-warnings
553+
549554
## --------------------------------------
550555
## Cleanup / Verification
551556
## --------------------------------------

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ This provider's versions are compatible with the following versions of Cluster A
4949
|:----------------------------------------|:---------------:|:--------------:|
5050
| CAPIBM v1alpha4 (v0.1.x) || |
5151
| CAPIBM v1beta1 (v0.2.x, v0.3.x) | ||
52-
| CAPIBM v1beta2 (v0.[4-8].x, main) | ||
52+
| CAPIBM v1beta2 (v0.[4-9].x, main) | ||
5353

5454

5555
(See [Kubernetes support matrix][cluster-api-supported-v] of Cluster API versions).

api/v1beta1/ibmpowervsmachine_types.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222

2323
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
24-
"sigs.k8s.io/cluster-api/errors"
2524
)
2625

2726
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
@@ -142,7 +141,7 @@ type IBMPowerVSMachineStatus struct {
142141
// can be added as events to the Machine object and/or logged in the
143142
// controller's output.
144143
// +optional
145-
FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"`
144+
FailureReason *string `json:"failureReason,omitempty"`
146145

147146
// FailureMessage will be set in the event that there is a terminal problem
148147
// reconciling the Machine and will contain a more verbose string suitable

api/v1beta1/zz_generated.conversion.go

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/zz_generated.deepcopy.go

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/common.go

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta2
1818

1919
import (
20+
"regexp"
2021
"strconv"
2122

2223
"k8s.io/apimachinery/pkg/util/intstr"
@@ -42,16 +43,24 @@ func validateIBMPowerVSResourceReference(res IBMPowerVSResourceReference, resTyp
4243
if res.ID != nil && res.Name != nil {
4344
return false, field.Invalid(field.NewPath("spec", resType), res, "Only one of "+resType+" - ID or Name may be specified")
4445
}
46+
4547
return true, nil
4648
}
4749

4850
func validateIBMPowerVSNetworkReference(res IBMPowerVSResourceReference) (bool, *field.Error) {
51+
// Ensure only one of ID, Name, or RegEx is specified
4952
if (res.ID != nil && res.Name != nil) || (res.ID != nil && res.RegEx != nil) || (res.Name != nil && res.RegEx != nil) {
5053
return false, field.Invalid(field.NewPath("spec", "Network"), res, "Only one of Network - ID, Name or RegEx can be specified")
5154
}
5255
return true, nil
5356
}
5457

58+
// regexMatches validates if a given regex matches the target string
59+
func regexMatches(pattern, target string) bool {
60+
matched, err := regexp.MatchString(pattern, target)
61+
return err == nil && matched
62+
}
63+
5564
func validateIBMPowerVSMemoryValues(resValue int32) bool {
5665
if val := float64(resValue); val < 2 {
5766
return false

api/v1beta2/ibmpowervscluster_webhook.go

+36-2
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,44 @@ func (r *IBMPowerVSCluster) validateIBMPowerVSCluster() (admission.Warnings, err
9595
r.Name, allErrs)
9696
}
9797

98+
func (r *IBMPowerVSCluster) validateNetworkRegex() (bool, *field.Error) {
99+
if r.Spec.Network.RegEx != nil {
100+
var targetName string
101+
var validationMessage string
102+
103+
if *r.Spec.DHCPServer.Name != "" {
104+
targetName = *r.Spec.DHCPServer.Name
105+
validationMessage = "The RegEx should match the DHCP server name when the DHCP server is set"
106+
} else {
107+
if r.GetObjectMeta().GetName() == "" {
108+
return false, field.Required(
109+
field.NewPath("metadata", "name"),
110+
"Cluster name must be set when Network.RegEx is provided and DHCP server name is not set",
111+
)
112+
}
113+
targetName = r.GetObjectMeta().GetName()
114+
validationMessage = "The RegEx should match the cluster name when the DHCP server is not set"
115+
}
116+
117+
if !regexMatches(*r.Spec.Network.RegEx, targetName) {
118+
return false, field.Invalid(
119+
field.NewPath("spec", "Network", "RegEx"),
120+
r.Spec.Network.RegEx,
121+
validationMessage,
122+
)
123+
}
124+
}
125+
126+
return true, nil
127+
}
128+
98129
func (r *IBMPowerVSCluster) validateIBMPowerVSClusterNetwork() *field.Error {
99130
if res, err := validateIBMPowerVSNetworkReference(r.Spec.Network); !res {
100131
return err
101132
}
133+
if res, err := r.validateNetworkRegex(); !res {
134+
return err
135+
}
102136
return nil
103137
}
104138

@@ -198,11 +232,11 @@ func (r *IBMPowerVSCluster) validateIBMPowerVSClusterCreateInfraPrereq() (allErr
198232
allErrs = append(allErrs, field.Invalid(field.NewPath("spec.vpc"), r.Spec.VPC, "value of VPC is empty"))
199233
}
200234

201-
if r.Spec.VPC.Region == nil {
235+
if r.Spec.VPC != nil && r.Spec.VPC.Region == nil {
202236
allErrs = append(allErrs, field.Invalid(field.NewPath("spec.vpc.region"), r.Spec.VPC.Region, "value of VPC region is empty"))
203237
}
204238

205-
if r.Spec.VPC.Region != nil && !regionUtil.ValidateVPCRegion(*r.Spec.VPC.Region) {
239+
if r.Spec.VPC != nil && r.Spec.VPC.Region != nil && !regionUtil.ValidateVPCRegion(*r.Spec.VPC.Region) {
206240
allErrs = append(allErrs, field.Invalid(field.NewPath("spec.vpc.region"), r.Spec.VPC.Region, fmt.Sprintf("vpc region '%s' is not supported", *r.Spec.VPC.Region)))
207241
}
208242

0 commit comments

Comments
 (0)