Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add APIServerLoadBalancer setting to enable/disable API server LB, allow adding ports, configure firewall #26

Merged
merged 45 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bd8117b
refactor: rename OpenFirewallRules to CreateEgressFirewallRules
hrak Jul 23, 2024
90c6782
fix: update default registry and tag
hrak Aug 1, 2024
9238940
refactor: rename getOfferingID to getNetworkOfferingID
hrak Aug 1, 2024
72838bc
feat: add version flag and refactor flag handling
hrak Aug 1, 2024
1b5abba
chore: remove staticcheck
hrak Aug 3, 2024
878a2f9
fix: add generate-conversion to generate-all
hrak Aug 12, 2024
5e96113
chore: remove some unused code and update some comments
hrak Aug 12, 2024
8acd547
feat: Allow firewall rules to be defined for the API server load bala…
hrak Aug 12, 2024
795d4e0
chore: Update to k8s v1.27.16
hrak Aug 12, 2024
a5971d5
chore: Update to Go 1.22
hrak Aug 12, 2024
c10a42d
fix: use klog.FlushAndExit instead of os.Exit
hrak Aug 13, 2024
7e9e6e2
fix: fix LDFLAGS for docker build
hrak Aug 13, 2024
3b67bab
fix(ci): set fetch-depth 0 to get tags as well
hrak Aug 13, 2024
0e9a10a
fix: Add missing leader election flags, remove cloud-config-file flag
hrak Aug 13, 2024
bc2002e
fix: Add condition to AddToLBIfNeeded which checks if API server lb i…
hrak Aug 13, 2024
6dfe5bd
feat: Log end of reconciliation
hrak Aug 14, 2024
6362bc1
fix: Watch for changes in CloudStackCluster in the isonet controller …
hrak Aug 14, 2024
f01f7d5
chore: fix incorrect function name in comment
hrak Aug 15, 2024
df2577f
fix: Make sure lb rules are deleted when a port is removed from addit…
hrak Aug 15, 2024
af09d28
fix: Delete related fw rule when a port is removed from additionalPor…
hrak Aug 15, 2024
0447baf
fix: Add predicate to only reconcile on generation change of cscluster
hrak Aug 15, 2024
0c9fd17
fix: Use async cs client for fw/lb rule deletion
hrak Aug 15, 2024
4aa2d64
fix: Make sure VM's get assigned to lb rules when a change in lb rule…
hrak Aug 16, 2024
a0648f6
fix: Fetch clustername from isonet labels
hrak Aug 16, 2024
c289b43
fix: Add some type checking
hrak Aug 16, 2024
0bfddd7
fix: Updated the mapper funcs so they actually work
hrak Aug 16, 2024
0cdc08d
refactor: Refactor fw/lb reconcile functions for lower cyclomatic com…
hrak Aug 19, 2024
3758502
chore: add 0.5.x and 0.5.x series to the metadata.yaml
hrak Aug 21, 2024
5f6e709
fix: Solved several issues with the firewalling implementation
hrak Aug 23, 2024
04008c3
fix: Some old find/replace mistake
hrak Aug 27, 2024
c9f806c
feat: Consider that isonet outgoing IP might not be the same as LB IP
hrak Aug 27, 2024
cdf9f2a
feat: Allow isolated network CIDR to be configured
hrak Aug 27, 2024
f5ab380
fix(tests): Add webhook tests for validity of fd/network name and net…
hrak Aug 27, 2024
c26adc4
fix: Remove lint from test target
hrak Aug 27, 2024
8bd85c7
fix: Separate load balancer reconciliation from GetOrCreateIsolatedNe…
hrak Aug 27, 2024
e86ef49
fix: Tag the outgoing IP
hrak Aug 27, 2024
b010f50
fix(tests): Update the tests for ReconcileLoadBalancer
hrak Aug 27, 2024
2cca369
chore: Fix copy/pasta in DeleteLoadBalancerRule error msg
hrak Aug 27, 2024
8bda463
fix: The resource type for a lb rule is LoadBalancer, not LoadBalance…
hrak Aug 27, 2024
49040f3
fix: Remove double strings.ToLower
hrak Aug 28, 2024
8a0b6b3
fix: Break out of loop when instance is found
hrak Aug 28, 2024
5835fce
fix: Reduce excessive logging/events
hrak Aug 28, 2024
bf8d10a
fix: Revert to the old behavior of isonet outgoing IP = loadbalancer …
hrak Aug 29, 2024
00692df
fix(tests): Remove injection of ginkgo recover statements
hrak Aug 30, 2024
f472057
fix(tests): remove need for REPO_ROOT env var
hrak Aug 30, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/go-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ on:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'
- name: Run go test with coverage
run: COVER_PROFILE=coverage.txt make test
- name: Codecov upload
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ on:
jobs:
lint:
name: Lint
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Install Go 1.x
uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version: '1.22'

- name: Check out code
uses: actions/checkout@v4
Expand All @@ -21,7 +21,7 @@ jobs:

build:
name: Test & Build
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Install Go 1.x
uses: actions/setup-go@v5
Expand All @@ -30,6 +30,8 @@ jobs:

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

- name: Cache
uses: actions/cache@v4
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ env:
jobs:
push:
name: Push images
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
# 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 @@ -64,7 +66,7 @@ jobs:

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

# Run only if previous job has succeeded
needs: [push]
Expand Down
10 changes: 7 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ linters-settings:

linters:
enable:
- gosec
- goheader
- revive
- gocyclo
- goheader
- gosec
- misspell
- revive
- staticcheck

run:
issues-exit-code: 1
Expand All @@ -51,3 +52,6 @@ issues:
- path: _test\.go
linters:
- gosec
- text: "SA1019: .+LBRuleID is deprecated"
linters:
- staticcheck
46 changes: 14 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ 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}')

# Set build time variables including version details
LDFLAGS := $(shell source ./hack/version.sh; version::ldflags)

# Binaries
KUSTOMIZE_VER := v4.5.7
KUSTOMIZE_BIN := kustomize
Expand Down Expand Up @@ -92,15 +95,10 @@ MOCKGEN_VER := v1.6.0
MOCKGEN := $(abspath $(TOOLS_BIN_DIR)/$(MOCKGEN_BIN)-$(MOCKGEN_VER))
MOCKGEN_PKG := github.com/golang/mock/mockgen

STATIC_CHECK_BIN := staticcheck
STATIC_CHECK_VER := v0.4.7
STATIC_CHECK := $(abspath $(TOOLS_BIN_DIR)/staticcheck)
STATIC_CHECK_PKG := honnef.co/go/tools/cmd/staticcheck

KUBECTL := $(TOOLS_BIN_DIR)/kubectl

# Release
STAGING_REGISTRY := gcr.io/k8s-staging-capi-cloudstack
STAGING_REGISTRY := ghcr.io/leaseweb
STAGING_BUCKET ?= artifacts.k8s-staging-capi-cloudstack.appspot.com
BUCKET ?= $(STAGING_BUCKET)
PROD_REGISTRY ?= registry.k8s.io/capi-cloudstack
Expand All @@ -112,7 +110,7 @@ RELEASE_ALIAS_TAG ?= $(PULL_BASE_REF)
# Image URL to use all building/pushing image targets
REGISTRY ?= $(STAGING_REGISTRY)
IMAGE_NAME ?= capi-cloudstack-controller
TAG ?= dev
TAG ?= develop
CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME)
IMG ?= $(CONTROLLER_IMG):$(TAG)
IMG_LOCAL ?= localhost:5000/$(IMAGE_NAME):$(TAG)
Expand Down Expand Up @@ -143,7 +141,7 @@ all: build
## --------------------------------------

.PHONY: binaries
binaries: $(CONTROLLER_GEN) $(CONVERSION_GEN) $(GOLANGCI_LINT) $(STATIC_CHECK) $(GINKGO) $(MOCKGEN) $(KUSTOMIZE) $(SETUP_ENVTEST) managers # Builds and installs all binaries
binaries: $(CONTROLLER_GEN) $(CONVERSION_GEN) $(GOLANGCI_LINT) $(GINKGO) $(MOCKGEN) $(KUSTOMIZE) $(SETUP_ENVTEST) managers # Builds and installs all binaries

.PHONY: managers
managers:
Expand All @@ -167,17 +165,10 @@ vet: ## Run go vet on the whole project.
go vet ./...

.PHONY: lint
lint: $(GOLANGCI_LINT) $(STATIC_CHECK) generate-mocks ## Run linting for the project.
lint: $(GOLANGCI_LINT) generate-mocks ## Run linting for the project.
$(MAKE) fmt
$(MAKE) vet
$(GOLANGCI_LINT) run -v --timeout 360s ./...
$(STATIC_CHECK) ./...
@ # The below string of commands checks that ginkgo isn't present in the controllers.
@(grep ginkgo ${REPO_ROOT}/controllers/cloudstack*_controller.go | grep -v import && \
echo "Remove ginkgo from controllers. This is probably an artifact of testing." \
"See the hack/testing_ginkgo_recover_statements.sh file") && exit 1 || \
echo "Gingko statements not found in controllers... (passed)"


##@ Generate
## --------------------------------------
Expand All @@ -186,11 +177,11 @@ lint: $(GOLANGCI_LINT) $(STATIC_CHECK) generate-mocks ## Run linting for the pro

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

.PHONY: generate-all
generate-all: generate-mocks generate-deepcopy generate-manifests
generate-all: generate-mocks generate-conversion generate-deepcopy generate-manifests

.PHONY: generate-mocks
generate-mocks: $(MOCKGEN) generate-deepcopy pkg/mocks/mock_client.go $(shell find ./pkg/mocks -type f -name "mock*.go") ## Generate mocks needed for testing. Primarily mocks of the cloud package.
Expand Down Expand Up @@ -235,13 +226,13 @@ MANAGER_BIN_INPUTS=$(shell find ./controllers ./api ./pkg -name "*mock*" -prune
.PHONY: build
build: binaries generate-deepcopy lint generate-manifests release-manifests ## Build manager binary.
$(BIN_DIR)/manager: $(MANAGER_BIN_INPUTS)
go build -o $(BIN_DIR)/manager main.go
go build -ldflags "${LDFLAGS}" -o $(BIN_DIR)/manager main.go

.PHONY: build-for-docker
build-for-docker: $(BIN_DIR)/manager-linux-amd64 ## Build manager binary for docker image building.
$(BIN_DIR)/manager-linux-amd64: $(MANAGER_BIN_INPUTS)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -a -ldflags "${ldflags} -extldflags '-static'" \
go build -a -ldflags "${LDFLAGS} -extldflags '-static'" \
-o $(BIN_DIR)/manager-linux-amd64 main.go

.PHONY: run
Expand Down Expand Up @@ -333,11 +324,8 @@ setup-envtest: $(SETUP_ENVTEST) ## Set up envtest (download kubebuilder assets)

.PHONY: test
test: ## Run tests.
test: generate-deepcopy-test generate-manifest-test generate-mocks lint setup-envtest $(GINKGO)
@./hack/testing_ginkgo_recover_statements.sh --add # Add ginkgo.GinkgoRecover() statements to controllers.
@# The following is a slightly funky way to make sure the ginkgo statements are removed regardless the test results.
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" $(GINKGO) --label-filter="!integ" --cover -coverprofile cover.out --covermode=atomic -v ./api/... ./controllers/... ./pkg/...; EXIT_STATUS=$$?;\
./hack/testing_ginkgo_recover_statements.sh --remove; exit $$EXIT_STATUS
test: generate-deepcopy-test generate-manifest-test generate-mocks setup-envtest $(GINKGO)
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" $(GINKGO) --label-filter="!integ" --cover -coverprofile cover.out --covermode=atomic -v ./api/... ./controllers/... ./pkg/...

.PHONY: test-pkg
test-pkg: $(GINKGO) ## Run pkg tests.
Expand Down Expand Up @@ -452,9 +440,6 @@ $(GOLANGCI_LINT_BIN): $(GOLANGCI_LINT) ## Build a local copy of golangci-lint.
.PHONY: $(MOCKGEN_BIN)
$(MOCKGEN_BIN): $(MOCKGEN) ## Build a local copy of mockgen.

.PHONY: $(STATIC_CHECK_BIN)
$(STATIC_CHECK_BIN): $(STATIC_CHECK) ## Build a local copy of staticcheck.

$(CONTROLLER_GEN): # Build controller-gen from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(CONTROLLER_GEN_PKG) $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER)

Expand All @@ -481,6 +466,3 @@ $(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)

$(STATIC_CHECK): # Build golangci-lint from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(STATIC_CHECK_PKG) $(STATIC_CHECK_BIN) $(STATIC_CHECK_VER)
17 changes: 17 additions & 0 deletions api/v1beta1/cloudstackisolatednetwork_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
machineryconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)
Expand Down Expand Up @@ -53,3 +54,19 @@ func (dst *CloudStackIsolatedNetwork) ConvertFrom(srcRaw conversion.Hub) error {
func Convert_v1beta3_CloudStackIsolatedNetworkSpec_To_v1beta1_CloudStackIsolatedNetworkSpec(in *v1beta3.CloudStackIsolatedNetworkSpec, out *CloudStackIsolatedNetworkSpec, s machineryconversion.Scope) error { // nolint
return autoConvert_v1beta3_CloudStackIsolatedNetworkSpec_To_v1beta1_CloudStackIsolatedNetworkSpec(in, out, s)
}

func Convert_v1beta1_CloudStackIsolatedNetworkStatus_To_v1beta3_CloudStackIsolatedNetworkStatus(in *CloudStackIsolatedNetworkStatus, out *v1beta3.CloudStackIsolatedNetworkStatus, s machineryconversion.Scope) error {
out.PublicIPID = in.PublicIPID
out.LBRuleID = in.LBRuleID
out.APIServerLoadBalancer = &infrav1.LoadBalancer{}
out.LoadBalancerRuleIDs = []string{in.LBRuleID}
out.Ready = in.Ready
return nil
}

func Convert_v1beta3_CloudStackIsolatedNetworkStatus_To_v1beta1_CloudStackIsolatedNetworkStatus(in *v1beta3.CloudStackIsolatedNetworkStatus, out *CloudStackIsolatedNetworkStatus, s machineryconversion.Scope) error {
out.PublicIPID = in.PublicIPID
out.LBRuleID = in.LBRuleID
out.Ready = in.Ready
return nil
}
8 changes: 5 additions & 3 deletions api/v1beta1/cloudstackmachinetemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ limitations under the License.
package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
machineryconversion "k8s.io/apimachinery/pkg/conversion"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

func (src *CloudStackMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { // nolint
Expand All @@ -43,6 +42,9 @@ func (src *CloudStackMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { /
if restored.Spec.Template.Spec.UncompressedUserData != nil {
dst.Spec.Template.Spec.UncompressedUserData = restored.Spec.Template.Spec.UncompressedUserData
}

dst.Spec.Template.ObjectMeta = restored.Spec.Template.ObjectMeta

return nil
}

Expand Down
5 changes: 2 additions & 3 deletions api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package v1beta1

import (
"context"
"fmt"

"errors"
corev1 "k8s.io/api/core/v1"
machineryconversion "k8s.io/apimachinery/pkg/conversion"
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
Expand Down Expand Up @@ -51,7 +50,7 @@ func Convert_v1beta1_CloudStackCluster_To_v1beta3_CloudStackCluster(in *CloudSta
//nolint:golint,revive,stylecheck
func Convert_v1beta3_CloudStackCluster_To_v1beta1_CloudStackCluster(in *infrav1.CloudStackCluster, out *CloudStackCluster, _ machineryconversion.Scope) error {
if len(in.Spec.FailureDomains) < 1 {
return fmt.Errorf("infrav1 to v1beta1 conversion not supported when < 1 failure domain is provided. Input CloudStackCluster spec %s", in.Spec)
return errors.New("v1beta3 to v1beta1 conversion not supported when < 1 failure domain is provided")
}
out.ObjectMeta = in.ObjectMeta
out.Spec = CloudStackClusterSpec{
Expand Down
6 changes: 6 additions & 0 deletions api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +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"
v1beta1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -103,6 +104,11 @@ var _ = Describe("Conversion", func() {
Host: "endpoint1",
Port: 443,
},
APIServerLoadBalancer: &v1beta3.APIServerLoadBalancer{
Enabled: pointer.Bool(true),
AdditionalPorts: []int{},
AllowedCIDRs: []string{},
},
},
Status: v1beta3.CloudStackClusterStatus{},
}
Expand Down
29 changes: 29 additions & 0 deletions api/v1beta1/v1beta1_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestV1beta1(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "V1beta1 Suite")
}
Loading
Loading