Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/go-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ on:

jobs:
build:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
- name: Calculate go version
id: vars
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: '1.25'
go-version: ${{ steps.vars.outputs.go_version }}
- name: Run go test with coverage
run: COVER_PROFILE=coverage.txt make test
- name: Codecov upload
Expand Down
22 changes: 15 additions & 7 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,40 @@ on:
jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Check out code
uses: actions/checkout@v7

- name: Install Go 1.x
- name: Calculate go version
id: vars
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT

- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: '1.25'
go-version: ${{ steps.vars.outputs.go_version }}

- name: Run lint checks
run: make lint

build:
name: Test & Build
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Check out code
uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Install Go 1.x
- name: Calculate go version
id: vars
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT

- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: '1.25'
go-version: ${{ steps.vars.outputs.go_version }}

- name: Cache
uses: actions/cache@v6
Expand All @@ -45,4 +53,4 @@ jobs:
run: make test

- name: Build
run: make build
run: make build
23 changes: 21 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@ env:
jobs:
push:
name: Push images
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04

steps:
- name: Check out code
uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Calculate go version
id: vars
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT

- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: ${{ steps.vars.outputs.go_version }}

# This step is run when the branch is main and no tag is set
- name: Sets env vars for main
run: |
Expand Down Expand Up @@ -65,7 +75,7 @@ jobs:

release:
name: Release
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04

# Run only if previous job has succeeded
needs: [push]
Expand All @@ -77,6 +87,15 @@ jobs:
- name: Checkout code
uses: actions/checkout@v7

- name: Calculate go version
id: vars
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT

- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: ${{ steps.vars.outputs.go_version }}

- name: Sets env vars for tag
run: |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,' | sed -e 's/^v//')
Expand Down
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: "2"
run:
go: "1.25"
go: "1.26"
build-tags:
- tools
- e2e
Expand Down Expand Up @@ -184,10 +184,10 @@ linters:
text: 'SA1019: .+LBRuleID is deprecated'
- linters:
- staticcheck
text: 'SA1019: "sigs.k8s.io/cluster-api/(.*)" is deprecated: This package is deprecated and is going to be removed when support for v1beta1 will be dropped.'
text: 'SA1019: "?sigs.k8s.io/cluster-api/(.*)"? is deprecated: This package is deprecated and is going to be removed when support for v1beta1 will be dropped.'
- linters:
- staticcheck
text: 'SA1019: scope.Cluster.Status.Deprecated.V1Beta1.Conditions is deprecated'
text: 'SA1019: .*(ClusterV1Beta1DeprecatedStatus\)|Deprecated\.V1Beta1)\.Conditions is deprecated'
- linters:
- revive
- staticcheck
Expand Down
59 changes: 46 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,47 @@ export REPO_ROOT := $(shell git rev-parse --show-toplevel)

include $(REPO_ROOT)/common.mk

#
# Go.
#
GO_VERSION ?= 1.26.7

# Ensure correct toolchain is used
GOTOOLCHAIN = go$(GO_VERSION)
export GOTOOLCHAIN

# Use GOPROXY environment variable if set.
# Note: make's `export` does not reach $(shell ...) calls evaluated at parse
# time, so GOTOOLCHAIN is set explicitly here. Without it these lookups run
# with GOTOOLCHAIN=auto and download a toolchain matching the go.mod directive,
# which pollutes GOMODCACHE before actions/setup-go restores its cache.
GOPROXY := $(shell GOTOOLCHAIN=local go env GOPROXY)
ifeq ($(GOPROXY),)
GOPROXY := https://proxy.golang.org
endif
export GOPROXY

#
# Kubebuilder.
#
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.35.0
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.36.0
export KUBEBUILDER_CONTROLPLANE_START_TIMEOUT ?= 60s
export KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT ?=

# Directories
TOOLS_DIR := $(REPO_ROOT)/hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
E2E_DIR := $(REPO_ROOT)/test/e2e
BIN_DIR ?= bin
RELEASE_DIR ?= out
GO_INSTALL := ./hack/go_install.sh

GH_REPO ?= kubernetes-sigs/cluster-api-provider-cloudstack

# Helper function to get dependency version from go.mod
get_go_version = $(shell go list -m $1 | awk '{print $$2}')
# Helper function to get dependency version from go.mod.
# GOTOOLCHAIN=local for the same reason as above: this runs at parse time on
# every make invocation, and must not trigger a toolchain download.
get_go_version = $(shell GOTOOLCHAIN=local go list -m $1 | awk '{print $$2}')

# Set build time variables including version details
LDFLAGS := $(shell source ./hack/version.sh; version::ldflags)
Expand All @@ -44,12 +67,12 @@ KUSTOMIZE_BIN := kustomize
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER))
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v5

SETUP_ENVTEST_VER := release-0.22
SETUP_ENVTEST_VER := release-0.23
SETUP_ENVTEST_BIN := setup-envtest
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER))
SETUP_ENVTEST_PKG := sigs.k8s.io/controller-runtime/tools/setup-envtest

CONTROLLER_GEN_VER := v0.19.0
CONTROLLER_GEN_VER := v0.20.0
CONTROLLER_GEN_BIN := controller-gen
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER))
CONTROLLER_GEN_PKG := sigs.k8s.io/controller-tools/cmd/controller-gen
Expand All @@ -59,7 +82,7 @@ GOTESTSUM_BIN := gotestsum
GOTESTSUM := $(abspath $(TOOLS_BIN_DIR)/$(GOTESTSUM_BIN)-$(GOTESTSUM_VER))
GOTESTSUM_PKG := gotest.tools/gotestsum

CONVERSION_GEN_VER := v0.34.0
CONVERSION_GEN_VER := v0.35.0
CONVERSION_GEN_BIN := conversion-gen
# We are intentionally using the binary without version suffix, to avoid the version
# in generated files.
Expand All @@ -82,7 +105,7 @@ GINKGO := $(abspath $(TOOLS_BIN_DIR)/$(GINKGO_BIN)-$(GINGKO_VER))
GINKGO_PKG := github.com/onsi/ginkgo/v2/ginkgo

GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT_VER := v2.7.2
GOLANGCI_LINT_VER := v2.13.1
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/v2/cmd/golangci-lint

Expand Down Expand Up @@ -115,10 +138,10 @@ CONFIG_DIR := config
NAMESPACE := capc-system

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
ifeq (,$(shell GOTOOLCHAIN=local go env GOBIN))
GOBIN=$(shell GOTOOLCHAIN=local go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
GOBIN=$(shell GOTOOLCHAIN=local go env GOBIN)
endif

# Setting SHELL to bash allows bash commands to be executed by recipes.
Expand Down Expand Up @@ -173,8 +196,9 @@ lint: $(GOLANGCI_LINT) generate-mocks ## Run linting for the project.

.PHONY: modules
modules: ## Runs go mod to ensure proper vendoring.
go mod tidy -compat=1.25
cd $(TOOLS_DIR); go mod tidy -compat=1.25
go mod tidy -compat=1.26
cd $(TOOLS_DIR); go mod tidy -compat=1.26
cd $(E2E_DIR); go mod tidy -compat=1.26

.PHONY: generate-all
generate-all: generate-mocks generate-deepcopy generate-manifests
Expand Down Expand Up @@ -288,7 +312,7 @@ delete-kind-cluster:
kind delete cluster --name $(KIND_CLUSTER_NAME)

cluster-api: ## Clone cluster-api repository for tilt use.
git clone --branch v1.12.11 --depth 1 https://github.com/kubernetes-sigs/cluster-api.git
git clone --branch v1.13.5 --depth 1 https://github.com/kubernetes-sigs/cluster-api.git

cluster-api/tilt-settings.json: hack/tilt-settings.json cluster-api
cp ./hack/tilt-settings.json cluster-api
Expand Down Expand Up @@ -448,3 +472,12 @@ $(GOLANGCI_LINT): # Build golangci-lint from tools folder.

$(MOCKGEN): # Build mockgen from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(MOCKGEN_PKG) $(MOCKGEN_BIN) $(MOCKGEN_VER)

## --------------------------------------
## Helpers
## --------------------------------------

##@ helpers:

go-version: ## Print the go version we use to compile our binaries and images
@echo $(GO_VERSION)
28 changes: 5 additions & 23 deletions api/v1beta3/cloudstackcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ package v1beta3

import (
"context"
"fmt"
"net"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
"sigs.k8s.io/cluster-api/util/annotations"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/webhookutil"
Expand All @@ -36,40 +32,26 @@ import (
type CloudStackClusterWebhook struct{}

func (r *CloudStackClusterWebhook) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(&CloudStackCluster{}).
return ctrl.NewWebhookManagedBy(mgr, &CloudStackCluster{}).
WithValidator(r).
Complete()
}

// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta3-cloudstackcluster,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=cloudstackclusters,versions=v1beta3,name=validation.cloudstackcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1

var (
_ webhook.CustomValidator = &CloudStackClusterWebhook{}
_ admission.Validator[*CloudStackCluster] = &CloudStackClusterWebhook{}
)

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackClusterWebhook) ValidateCreate(_ context.Context, objRaw runtime.Object) (admission.Warnings, error) {
obj, ok := objRaw.(*CloudStackCluster)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackCluster but got a %T", objRaw))
}

func (r *CloudStackClusterWebhook) ValidateCreate(_ context.Context, obj *CloudStackCluster) (admission.Warnings, error) {
errorList := validateCloudStackClusterSpec(obj.Spec)

return nil, webhookutil.AggregateObjErrors(obj.GroupVersionKind().GroupKind(), obj.Name, errorList)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackClusterWebhook) ValidateUpdate(_ context.Context, oldRaw runtime.Object, newRaw runtime.Object) (admission.Warnings, error) {
oldObj, ok := oldRaw.(*CloudStackCluster)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackCluster but got a %T", oldRaw))
}
newObj, ok := newRaw.(*CloudStackCluster)
if !ok {
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected a CloudStackCluster but got a %T", newRaw))
}
func (r *CloudStackClusterWebhook) ValidateUpdate(_ context.Context, oldObj, newObj *CloudStackCluster) (admission.Warnings, error) {
spec := newObj.Spec

oldSpec := oldObj.Spec
Expand Down Expand Up @@ -99,7 +81,7 @@ func (r *CloudStackClusterWebhook) ValidateUpdate(_ context.Context, oldRaw runt
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *CloudStackClusterWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
func (r *CloudStackClusterWebhook) ValidateDelete(_ context.Context, _ *CloudStackCluster) (admission.Warnings, error) {
return nil, nil
}

Expand Down
Loading