Skip to content

Commit 4befde1

Browse files
authored
Merge pull request #439 from shapeblue/support-routed-networks
Support routed networks
2 parents 8ccef79 + 4aec197 commit 4befde1

Some content is hidden

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

45 files changed

+194
-136
lines changed

.github/workflows/go-coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v4
1515
- uses: actions/setup-go@v5
1616
with:
17-
go-version: 1.22
17+
go-version: 1.23
1818
- name: Run go test with coverage
1919
run: COVER_PROFILE=coverage.txt make test
2020
- name: Codecov upload

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ lint: $(GOLANGCI_LINT) $(STATIC_CHECK) generate-mocks ## Run linting for the pro
129129

130130
.PHONY: modules
131131
modules: ## Runs go mod to ensure proper vendoring.
132-
go mod tidy -compat=1.22
133-
cd $(TOOLS_DIR); go mod tidy -compat=1.22
132+
go mod tidy -compat=1.23
133+
cd $(TOOLS_DIR); go mod tidy -compat=1.23
134134

135135
.PHONY: generate-all
136136
generate-all: generate-mocks generate-deepcopy generate-manifests

api/v1beta1/conversion.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,14 @@ func Convert_v1beta3_Network_To_v1beta1_Network(in *v1beta3.Network, out *Networ
185185
// Skip Gateway, Netmask, and VPC fields as they do not exist in v1beta1.Network
186186
return nil
187187
}
188+
189+
// Convert_v1beta3_CloudStackIsolatedNetworkStatus_To_v1beta1_CloudStackIsolatedNetworkStatus handles manual conversion of CloudStackIsolatedNetworkStatus from v1beta3 to v1beta1
190+
//
191+
//nolint:golint,revive,stylecheck
192+
func Convert_v1beta3_CloudStackIsolatedNetworkStatus_To_v1beta1_CloudStackIsolatedNetworkStatus(in *v1beta3.CloudStackIsolatedNetworkStatus, out *CloudStackIsolatedNetworkStatus, _ conv.Scope) error {
193+
out.PublicIPID = in.PublicIPID
194+
out.LBRuleID = in.LBRuleID
195+
out.Ready = in.Ready
196+
// RoutingMode field doesn't exist in v1beta1, so we ignore it during conversion
197+
return nil
198+
}

api/v1beta1/zz_generated.conversion.go

Lines changed: 9 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/conversion.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,14 @@ func Convert_v1beta3_CloudStackIsolatedNetworkSpec_To_v1beta2_CloudStackIsolated
4343
// Skip Gateway, Netmask, and VPC fields as they do not exist in v1beta2.CloudStackIsolatedNetworkSpec
4444
return nil
4545
}
46+
47+
// Convert_v1beta3_CloudStackIsolatedNetworkStatus_To_v1beta2_CloudStackIsolatedNetworkStatus handles manual conversion of CloudStackIsolatedNetworkStatus from v1beta3 to v1beta2
48+
//
49+
//nolint:golint,revive,stylecheck
50+
func Convert_v1beta3_CloudStackIsolatedNetworkStatus_To_v1beta2_CloudStackIsolatedNetworkStatus(in *v1beta3.CloudStackIsolatedNetworkStatus, out *CloudStackIsolatedNetworkStatus, _ conv.Scope) error {
51+
out.PublicIPID = in.PublicIPID
52+
out.LBRuleID = in.LBRuleID
53+
out.Ready = in.Ready
54+
// RoutingMode field doesn't exist in v1beta2, so we ignore it during conversion
55+
return nil
56+
}

api/v1beta2/zz_generated.conversion.go

Lines changed: 9 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta3/cloudstackfailuredomain_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ type Network struct {
7272
// Cloudstack VPC the network belongs to.
7373
// +optional
7474
VPC *VPC `json:"vpc,omitempty"`
75+
76+
// Cloudstack Network's routing mode.
77+
// Routing mode can be Dynamic, or Static.
78+
// Empty value means the network mode is NATTED, not ROUTED.
79+
// +optional
80+
RoutingMode string `json:"routingMode,omitempty"`
7581
}
7682

7783
type VPC struct {

api/v1beta3/cloudstackisolatednetwork_types.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,25 @@ type CloudStackIsolatedNetworkStatus struct {
6868
// The ID of the lb rule used to assign VMs to the lb.
6969
LBRuleID string `json:"loadBalancerRuleID,omitempty"`
7070

71+
// Routing mode of the network.
72+
// Routing mode can be Dynamic, or Static.
73+
// Empty value means the network mode is NATTED, not ROUTED.
74+
RoutingMode string `json:"routingMode,omitempty"`
75+
7176
// Ready indicates the readiness of this provider resource.
7277
Ready bool `json:"ready"`
7378
}
7479

7580
func (n *CloudStackIsolatedNetwork) Network() *Network {
7681
return &Network{
77-
Name: n.Spec.Name,
78-
Type: "IsolatedNetwork",
79-
ID: n.Spec.ID,
80-
Gateway: n.Spec.Gateway,
81-
Netmask: n.Spec.Netmask,
82-
VPC: n.Spec.VPC,
83-
Offering: n.Spec.Offering,
82+
Name: n.Spec.Name,
83+
Type: "IsolatedNetwork",
84+
ID: n.Spec.ID,
85+
Gateway: n.Spec.Gateway,
86+
Netmask: n.Spec.Netmask,
87+
VPC: n.Spec.VPC,
88+
Offering: n.Spec.Offering,
89+
RoutingMode: n.Status.RoutingMode,
8490
}
8591
}
8692

config/crd/bases/infrastructure.cluster.x-k8s.io_cloudstackclusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,12 @@ spec:
432432
isolated networks and "DefaultIsolatedNetworkOfferingForVpcNetworks"
433433
for VPC networks.
434434
type: string
435+
routingMode:
436+
description: |-
437+
Cloudstack Network's routing mode.
438+
Routing mode can be Dynamic, or Static.
439+
Empty value means the network mode is NATTED, not ROUTED.
440+
type: string
435441
type:
436442
description: Cloudstack Network Type the cluster is
437443
built in.

config/crd/bases/infrastructure.cluster.x-k8s.io_cloudstackfailuredomains.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ spec:
200200
isolated networks and "DefaultIsolatedNetworkOfferingForVpcNetworks"
201201
for VPC networks.
202202
type: string
203+
routingMode:
204+
description: |-
205+
Cloudstack Network's routing mode.
206+
Routing mode can be Dynamic, or Static.
207+
Empty value means the network mode is NATTED, not ROUTED.
208+
type: string
203209
type:
204210
description: Cloudstack Network Type the cluster is built
205211
in.

config/crd/bases/infrastructure.cluster.x-k8s.io_cloudstackisolatednetworks.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ spec:
260260
ready:
261261
description: Ready indicates the readiness of this provider resource.
262262
type: boolean
263+
routingMode:
264+
description: |-
265+
Routing mode of the network.
266+
Routing mode can be Dynamic, or Static.
267+
Empty value means the network mode is NATTED, not ROUTED.
268+
type: string
263269
required:
264270
- ready
265271
type: object

controllers/cks_cluster_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ limitations under the License.
1717
package controllers_test
1818

1919
import (
20-
"github.com/golang/mock/gomock"
2120
ginkgo "github.com/onsi/ginkgo/v2"
2221
gomega "github.com/onsi/gomega"
22+
"go.uber.org/mock/gomock"
2323
"k8s.io/apimachinery/pkg/api/errors"
2424
"k8s.io/utils/ptr"
2525
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"

controllers/cks_machine_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ limitations under the License.
1717
package controllers_test
1818

1919
import (
20-
"github.com/golang/mock/gomock"
2120
ginkgo "github.com/onsi/ginkgo/v2"
2221
gomega "github.com/onsi/gomega"
22+
"go.uber.org/mock/gomock"
2323
"k8s.io/apimachinery/pkg/api/errors"
2424
"k8s.io/utils/ptr"
2525

controllers/cloudstackaffinitygroup_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ limitations under the License.
1717
package controllers_test
1818

1919
import (
20-
"github.com/golang/mock/gomock"
2120
ginkgo "github.com/onsi/ginkgo/v2"
2221
gomega "github.com/onsi/gomega"
22+
gomock "go.uber.org/mock/gomock"
2323
"k8s.io/apimachinery/pkg/api/errors"
2424
"k8s.io/utils/ptr"
2525
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"

controllers/cloudstackcluster_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ limitations under the License.
1717
package controllers_test
1818

1919
import (
20-
"github.com/golang/mock/gomock"
2120
ginkgo "github.com/onsi/ginkgo/v2"
2221
gomega "github.com/onsi/gomega"
22+
gomock "go.uber.org/mock/gomock"
2323
"k8s.io/utils/ptr"
2424
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
2525
"sigs.k8s.io/cluster-api-provider-cloudstack/controllers"

controllers/cloudstackfailuredomain_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ limitations under the License.
1717
package controllers_test
1818

1919
import (
20-
"github.com/golang/mock/gomock"
2120
ginkgo "github.com/onsi/ginkgo/v2"
2221
gomega "github.com/onsi/gomega"
22+
gomock "go.uber.org/mock/gomock"
2323
"k8s.io/apimachinery/pkg/api/errors"
2424
"k8s.io/utils/ptr"
2525
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"

controllers/cloudstackisolatednetwork_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ limitations under the License.
1717
package controllers_test
1818

1919
import (
20-
g "github.com/golang/mock/gomock"
2120
ginkgo "github.com/onsi/ginkgo/v2"
2221
gomega "github.com/onsi/gomega"
22+
g "go.uber.org/mock/gomock"
2323
"k8s.io/apimachinery/pkg/types"
2424
"k8s.io/utils/ptr"
2525
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"

controllers/cloudstackmachine_controller.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,17 @@ func (r *CloudStackMachineReconciliationRunner) RequeueIfInstanceNotRunning() (r
295295
// AddToLBIfNeeded adds instance to load balancer if it is a control plane in an isolated network.
296296
func (r *CloudStackMachineReconciliationRunner) AddToLBIfNeeded() (retRes ctrl.Result, reterr error) {
297297
if util.IsControlPlaneMachine(r.CAPIMachine) && r.FailureDomain.Spec.Zone.Network.Type == cloud.NetworkTypeIsolated {
298-
r.Log.Info("Assigning VM to load balancer rule.")
299298
if r.IsoNet.Spec.Name == "" {
300299
return r.RequeueWithMessage("Could not get required Isolated Network for VM, requeueing.")
301300
}
302-
err := r.CSUser.AssignVMToLoadBalancerRule(r.IsoNet, *r.ReconciliationSubject.Spec.InstanceID)
303-
if err != nil {
304-
return ctrl.Result{}, err
301+
302+
if r.IsoNet.Status.RoutingMode == "" {
303+
// For non-routed networks, use load balancer
304+
r.Log.Info("Assigning VM to load balancer rule.")
305+
err := r.CSUser.AssignVMToLoadBalancerRule(r.IsoNet, *r.ReconciliationSubject.Spec.InstanceID)
306+
if err != nil {
307+
return ctrl.Result{}, err
308+
}
305309
}
306310
}
307311
return ctrl.Result{}, nil

controllers/cloudstackmachine_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"fmt"
2121
"strings"
2222

23-
"github.com/golang/mock/gomock"
2423
ginkgo "github.com/onsi/ginkgo/v2"
2524
gomega "github.com/onsi/gomega"
25+
gomock "go.uber.org/mock/gomock"
2626
"k8s.io/apimachinery/pkg/api/errors"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/types"

controllers/controllers_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ import (
3737

3838
"github.com/apache/cloudstack-go/v2/cloudstack"
3939
"github.com/go-logr/logr"
40-
"github.com/golang/mock/gomock"
4140
ginkgo "github.com/onsi/ginkgo/v2"
4241
gomega "github.com/onsi/gomega"
4342
"github.com/pkg/errors"
43+
gomock "go.uber.org/mock/gomock"
4444
"k8s.io/client-go/kubernetes/scheme"
4545
"k8s.io/client-go/rest"
4646
ctrl "sigs.k8s.io/controller-runtime"

controllers/utils/base_reconciler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"context"
2121

2222
"github.com/go-logr/logr"
23-
"github.com/golang/mock/gomock"
2423
"github.com/onsi/ginkgo/v2"
2524
"github.com/onsi/gomega"
25+
gomock "go.uber.org/mock/gomock"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/runtime"
2828
"k8s.io/client-go/tools/record"

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
module sigs.k8s.io/cluster-api-provider-cloudstack
22

3-
go 1.22.0
3+
go 1.23
44

5-
toolchain go1.22.12
5+
toolchain go1.23.2
66

77
require (
8-
github.com/apache/cloudstack-go/v2 v2.16.1
8+
github.com/apache/cloudstack-go/v2 v2.17.0
99
github.com/go-logr/logr v1.4.2
10-
github.com/golang/mock v1.6.0
1110
github.com/hashicorp/go-multierror v1.1.1
1211
github.com/jellydator/ttlcache/v3 v3.2.0
1312
github.com/onsi/ginkgo/v2 v2.22.2
@@ -16,6 +15,7 @@ require (
1615
github.com/prometheus/client_golang v1.19.1
1716
github.com/smallfish/simpleyaml v0.1.0
1817
github.com/spf13/pflag v1.0.5
18+
go.uber.org/mock v0.5.1
1919
golang.org/x/text v0.21.0
2020
gopkg.in/yaml.v3 v3.0.1
2121
k8s.io/api v0.31.3

0 commit comments

Comments
 (0)