Skip to content

Commit

Permalink
Merge pull request #34 from Leaseweb/develop
Browse files Browse the repository at this point in the history
feat: CAPI 1.8 + project support
  • Loading branch information
hrak authored Oct 14, 2024
2 parents 431ff12 + 37f2f0f commit 257f9e1
Show file tree
Hide file tree
Showing 88 changed files with 1,801 additions and 1,859 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ jobs:
name: Lint
runs-on: ubuntu-22.04
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Install Go 1.x
uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Check out code
uses: actions/checkout@v4

- name: Run unit tests
run: make lint

build:
name: Test & Build
runs-on: ubuntu-22.04
steps:
- name: Install Go 1.x
uses: actions/setup-go@v5
with:
go-version: '1.21'

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

- name: Install Go 1.x
uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Cache
uses: actions/cache@v4
with:
Expand Down
128 changes: 104 additions & 24 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ linters-settings:
- standard
- default
- prefix(sigs.k8s.io/cluster-api-provider-cloudstack)
ginkgolinter:
forbid-focus-container: true
godot:
# declarations - for top level declaration comments (default);
# toplevel - for top level comments;
# all - for all comments.
scope: toplevel
exclude:
- '^ \+.*'
- '^ ANCHOR.*'
gocritic:
enabled-tags:
- diagnostic
Expand Down Expand Up @@ -55,42 +65,106 @@ linters-settings:
nestif:
# minimal complexity of if statements to report, 5 by default
min-complexity: 8
nolintlint:
allow-unused: false
allow-leading-space: false
require-specific: true
revive:
rules:
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
arguments:
# dot import should be ONLY allowed for ginkgo testing packages
allowedPackages:
- "github.com/onsi/ginkgo/v2"
- "github.com/onsi/gomega"
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
#
# Rules in addition to the recommended configuration above.
#
- name: bool-literal-in-expr
- name: constant-logical-expr
goconst:
ignore-tests: true

linters:
disable:
- containedctx
- depguard
- err113
- execinquery
- exhaustruct
- forcetypeassert
- funlen
- gochecknoglobals
- gochecknoinits
- godox
- gomnd
- interfacebloat
- ireturn
- lll
- mnd
- nonamedreturns
- paralleltest
- tagliatelle
- varnamelen
- wrapcheck
- wsl
enable-all: true
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- copyloopvar
- dogsled
- dupword
- durationcheck
- errcheck
- errchkjson
- gci
- ginkgolinter
- goconst
- gocritic
- godot
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- importas
- ineffassign
- intrange
- loggercheck
- misspell
- nakedret
- nilerr
- noctx
- nolintlint
- nosprintfhostport
- prealloc
- predeclared
- revive
- rowserrcheck
- staticcheck
- stylecheck
- tenv
- thelper
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- whitespace

run:
issues-exit-code: 1
timeout: 10m
go: "1.22"
build-tags:
- tools
- e2e
allow-parallel-runners: true

issues:
max-same-issues: 0
Expand All @@ -116,6 +190,12 @@ issues:
- stylecheck
path: (test)/.*.go
text: should not use dot imports
- linters:
- revive
# This rule warns when initialism, variable or package naming conventions are not followed.
text: "var-naming: don't use underscores in Go names;"
# Ignoring stylistic checks for generated code
path: api\/.*\/.*conversion.*\.go$
- linters:
- stylecheck
text: "ST1003: should not use underscores in Go names;"
Expand Down
32 changes: 16 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include $(REPO_ROOT)/common.mk
#
# Kubebuilder.
#
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.27.1
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.31.0
export KUBEBUILDER_CONTROLPLANE_START_TIMEOUT ?= 60s
export KUBEBUILDER_CONTROLPLANE_STOP_TIMEOUT ?=

Expand All @@ -39,10 +39,10 @@ get_go_version = $(shell go list -m $1 | awk '{print $$2}')
LDFLAGS := $(shell source ./hack/version.sh; version::ldflags)

# Binaries
KUSTOMIZE_VER := v4.5.7
KUSTOMIZE_VER := v5.3.0
KUSTOMIZE_BIN := kustomize
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER))
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v4
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v5

# This is a commit from CR main (22.05.2024).
# Intentionally using a commit from main to use a setup-envtest version
Expand All @@ -53,17 +53,17 @@ 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.14.0
CONTROLLER_GEN_VER := v0.15.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

GOTESTSUM_VER := v1.6.4
GOTESTSUM_VER := v1.11.0
GOTESTSUM_BIN := gotestsum
GOTESTSUM := $(abspath $(TOOLS_BIN_DIR)/$(GOTESTSUM_BIN)-$(GOTESTSUM_VER))
GOTESTSUM_PKG := gotest.tools/gotestsum

CONVERSION_GEN_VER := v0.27.1
CONVERSION_GEN_VER := v0.30.0
CONVERSION_GEN_BIN := conversion-gen
# We are intentionally using the binary without version suffix, to avoid the version
# in generated files.
Expand All @@ -75,7 +75,7 @@ ENVSUBST_VER := $(call get_go_version,github.com/drone/envsubst/v2)
ENVSUBST := $(abspath $(TOOLS_BIN_DIR)/$(ENVSUBST_BIN)-$(ENVSUBST_VER))
ENVSUBST_PKG := github.com/drone/envsubst/v2/cmd/envsubst

GO_APIDIFF_VER := v0.6.0
GO_APIDIFF_VER := v0.8.2
GO_APIDIFF_BIN := go-apidiff
GO_APIDIFF := $(abspath $(TOOLS_BIN_DIR)/$(GO_APIDIFF_BIN)-$(GO_APIDIFF_VER))
GO_APIDIFF_PKG := github.com/joelanford/go-apidiff
Expand All @@ -86,7 +86,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 := v1.58.1
GOLANGCI_LINT_VER := v1.60.3
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint

Expand Down Expand Up @@ -203,19 +203,19 @@ $(shell grep -qs "$(IMG)" config/default/manager_image_patch_edited.yaml || rm -
generate-manifests: config/.flag.mk ## Generates crd, webhook, rbac, and other configuration manifests from kubebuilder instructions in go comments.
config/.flag.mk: $(CONTROLLER_GEN) $(MANIFEST_GEN_INPUTS)
sed -e 's@image: .*@image: '"$(IMG)"'@' config/default/manager_image_patch.yaml > config/default/manager_image_patch_edited.yaml
$(CONTROLLER_GEN) crd:crdVersions=v1 rbac:roleName=manager-role webhook paths="{./api/...,./controllers/...}" output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) crd:crdVersions=v1 rbac:roleName=manager-role webhook paths="{./,./api/...,./controllers/...}" output:crd:artifacts:config=config/crd/bases
@touch config/.flag.mk

.PHONY: generate-conversion
generate-conversion: $(CONVERSION_GEN) ## Generate code to convert api/v1beta1 and api/v1beta2 to api/v1beta3
$(CONVERSION_GEN) \
--input-dirs=./api/v1beta1 \
--output-file=zz_generated.conversion.go \
--go-header-file=./hack/boilerplate.go.txt \
--output-base=. --output-file-base=zz_generated.conversion
./api/v1beta1
$(CONVERSION_GEN) \
--input-dirs=./api/v1beta2 \
--output-file=zz_generated.conversion.go \
--go-header-file=./hack/boilerplate.go.txt \
--output-base=. --output-file-base=zz_generated.conversion
./api/v1beta2

##@ Build
## --------------------------------------
Expand All @@ -224,7 +224,7 @@ generate-conversion: $(CONVERSION_GEN) ## Generate code to convert api/v1beta1 a

MANAGER_BIN_INPUTS=$(shell find ./controllers ./api ./pkg -name "*mock*" -prune -o -name "*test*" -prune -o -type f -print) main.go go.mod go.sum
.PHONY: build
build: binaries generate-deepcopy lint generate-manifests release-manifests ## Build manager binary.
build: binaries generate-deepcopy generate-manifests release-manifests ## Build manager binary.
$(BIN_DIR)/manager: $(MANAGER_BIN_INPUTS)
go build -ldflags "${LDFLAGS}" -o $(BIN_DIR)/manager main.go

Expand Down Expand Up @@ -292,7 +292,7 @@ delete-kind-cluster:
kind delete cluster --name $(KIND_CLUSTER_NAME)

cluster-api: ## Clone cluster-api repository for tilt use.
git clone --branch v1.5.8 --depth 1 https://github.com/kubernetes-sigs/cluster-api.git
git clone --branch v1.8.4 --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 @@ -390,7 +390,7 @@ $(RELEASE_DIR)/%: $(RELEASE_MANIFEST_INPUTS)

.PHONY: release-manifests-metrics-port
release-manifests-metrics-port:
make release-manifests RELEASE_MANIFEST_SOURCE_BASE=config/default-with-metrics-port
make release-manifests RELEASE_MANIFEST_SOURCE_BASE=config/default

.PHONY: release-staging
release-staging: ## Builds and push container images and manifests to the staging bucket.
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/cloudstackisolatednetwork_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Convert_v1beta3_CloudStackIsolatedNetworkSpec_To_v1beta1_CloudStackIsolated
return autoConvert_v1beta3_CloudStackIsolatedNetworkSpec_To_v1beta1_CloudStackIsolatedNetworkSpec(in, out, s)
}

func Convert_v1beta1_CloudStackIsolatedNetworkStatus_To_v1beta3_CloudStackIsolatedNetworkStatus(in *CloudStackIsolatedNetworkStatus, out *infrav1.CloudStackIsolatedNetworkStatus, s machineryconversion.Scope) error {
func Convert_v1beta1_CloudStackIsolatedNetworkStatus_To_v1beta3_CloudStackIsolatedNetworkStatus(in *CloudStackIsolatedNetworkStatus, out *infrav1.CloudStackIsolatedNetworkStatus, _ machineryconversion.Scope) error {
out.PublicIPID = in.PublicIPID
out.LBRuleID = in.LBRuleID
out.APIServerLoadBalancer = &infrav1.LoadBalancer{}
Expand All @@ -66,7 +66,7 @@ func Convert_v1beta1_CloudStackIsolatedNetworkStatus_To_v1beta3_CloudStackIsolat
return nil
}

func Convert_v1beta3_CloudStackIsolatedNetworkStatus_To_v1beta1_CloudStackIsolatedNetworkStatus(in *infrav1.CloudStackIsolatedNetworkStatus, out *CloudStackIsolatedNetworkStatus, s machineryconversion.Scope) error {
func Convert_v1beta3_CloudStackIsolatedNetworkStatus_To_v1beta1_CloudStackIsolatedNetworkStatus(in *infrav1.CloudStackIsolatedNetworkStatus, out *CloudStackIsolatedNetworkStatus, _ machineryconversion.Scope) error {
out.PublicIPID = in.PublicIPID
out.LBRuleID = in.LBRuleID
out.Ready = in.Ready
Expand Down
6 changes: 1 addition & 5 deletions api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ func Convert_v1beta3_CloudStackCluster_To_v1beta1_CloudStackCluster(in *infrav1.
}

func Convert_v1beta3_Network_To_v1beta1_Network(in *infrav1.Network, out *Network, s machineryconversion.Scope) error {
if err := autoConvert_v1beta3_Network_To_v1beta1_Network(in, out, s); err != nil {
return err
}

return nil
return autoConvert_v1beta3_Network_To_v1beta1_Network(in, out, s)
}

// getZones maps failure domains to zones.
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

v1beta1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
Expand Down Expand Up @@ -106,7 +106,7 @@ var _ = Describe("Conversion", func() {
Port: 443,
},
APIServerLoadBalancer: &v1beta3.APIServerLoadBalancer{
Enabled: pointer.Bool(true),
Enabled: ptr.To(true),
AdditionalPorts: []int{},
AllowedCIDRs: []string{},
},
Expand Down
Loading

0 comments on commit 257f9e1

Please sign in to comment.