Skip to content

Commit 3f56e75

Browse files
Merge branch 'main' into fix-network-nil-pointer-exception
2 parents bf6e61f + 7503b6e commit 3f56e75

25 files changed

+815
-173
lines changed

.github/workflows/cover.yaml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
1616

17-
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
17+
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
1818
with:
1919
go-version: "1.21"
2020
check-latest: true
2121
cache: false
2222

2323
- name: golangci-lint
24-
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
24+
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
2525
with:
2626
version: v1.58

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST) $(KIND) $(KUBECTL)
489489
./hack/install-cert-manager.sh $(CERT_MANAGER_VER)
490490

491491
# Deploy CAPI
492-
curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.7.2/cluster-api-components.yaml | $(ENVSUBST) | $(KUBECTL) apply -f -
492+
curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.7.3/cluster-api-components.yaml | $(ENVSUBST) | $(KUBECTL) apply -f -
493493

494494
# Deploy CAPG
495495
$(KIND) load docker-image $(CONTROLLER_IMG)-$(ARCH):$(TAG) --name=clusterapi

Tiltfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ settings = {
1818
"deploy_cert_manager": True,
1919
"preload_images_for_kind": True,
2020
"kind_cluster_name": "capg",
21-
"capi_version": "v1.7.2",
21+
"capi_version": "v1.7.3",
2222
"cert_manager_version": "v1.14.4",
2323
"kubernetes_version": "v1.29.3",
2424
}

api/v1beta1/gcpcluster_webhook.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ func (c *GCPCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings,
9292
)
9393
}
9494

95+
if c.Spec.Network.Mtu < int64(1300) {
96+
allErrs = append(allErrs,
97+
field.Invalid(field.NewPath("spec", "Network", "Mtu"),
98+
c.Spec.Network.Mtu, "field cannot be lesser than 1300"),
99+
)
100+
}
101+
102+
if c.Spec.Network.Mtu > int64(8896) {
103+
allErrs = append(allErrs,
104+
field.Invalid(field.NewPath("spec", "Network", "Mtu"),
105+
c.Spec.Network.Mtu, "field cannot be greater than 8896"),
106+
)
107+
}
108+
95109
if len(allErrs) == 0 {
96110
return nil, nil
97111
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
"testing"
21+
22+
. "github.com/onsi/gomega"
23+
)
24+
25+
func TestGCPCluster_ValidateUpdate(t *testing.T) {
26+
g := NewWithT(t)
27+
28+
tests := []struct {
29+
name string
30+
newCluster *GCPCluster
31+
oldCluster *GCPCluster
32+
wantErr bool
33+
}{
34+
{
35+
name: "GCPCluster with MTU field is within the limits of more than 1300 and less than 8896",
36+
newCluster: &GCPCluster{
37+
Spec: GCPClusterSpec{
38+
Network: NetworkSpec{
39+
Mtu: int64(1500),
40+
},
41+
},
42+
},
43+
oldCluster: &GCPCluster{
44+
Spec: GCPClusterSpec{
45+
Network: NetworkSpec{
46+
Mtu: int64(1400),
47+
},
48+
},
49+
},
50+
wantErr: false,
51+
},
52+
{
53+
name: "GCPCluster with MTU field more than 8896",
54+
newCluster: &GCPCluster{
55+
Spec: GCPClusterSpec{
56+
Network: NetworkSpec{
57+
Mtu: int64(10000),
58+
},
59+
},
60+
},
61+
oldCluster: &GCPCluster{
62+
Spec: GCPClusterSpec{
63+
Network: NetworkSpec{
64+
Mtu: int64(1500),
65+
},
66+
},
67+
},
68+
wantErr: true,
69+
},
70+
{
71+
name: "GCPCluster with MTU field less than 8896",
72+
newCluster: &GCPCluster{
73+
Spec: GCPClusterSpec{
74+
Network: NetworkSpec{
75+
Mtu: int64(1250),
76+
},
77+
},
78+
},
79+
oldCluster: &GCPCluster{
80+
Spec: GCPClusterSpec{
81+
Network: NetworkSpec{
82+
Mtu: int64(1500),
83+
},
84+
},
85+
},
86+
wantErr: true,
87+
},
88+
}
89+
for _, test := range tests {
90+
test := test
91+
t.Run(test.name, func(t *testing.T) {
92+
t.Parallel()
93+
warn, err := test.newCluster.ValidateUpdate(test.oldCluster)
94+
if test.wantErr {
95+
g.Expect(err).To(HaveOccurred())
96+
} else {
97+
g.Expect(err).NotTo(HaveOccurred())
98+
}
99+
g.Expect(warn).To(BeNil())
100+
})
101+
}
102+
}

api/v1beta1/types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ type NetworkSpec struct {
136136
// HostProject is the name of the project hosting the shared VPC network resources.
137137
// +optional
138138
HostProject *string `json:"hostProject,omitempty"`
139+
140+
// Mtu: Maximum Transmission Unit in bytes. The minimum value for this field is
141+
// 1300 and the maximum value is 8896. The suggested value is 1500, which is
142+
// the default MTU used on the Internet, or 8896 if you want to use Jumbo
143+
// frames. If unspecified, the value defaults to 1460.
144+
// More info: https://pkg.go.dev/google.golang.org/api/compute/v1#Network
145+
// +kubebuilder:validation:Minimum:=1300
146+
// +kubebuilder:validation:Maximum:=8896
147+
// +kubebuilder:default:=1460
148+
// +optional
149+
Mtu int64 `json:"mtu,omitempty"`
139150
}
140151

141152
// LoadBalancerType defines the Load Balancer that should be created.

cloud/scope/cluster.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ func (s *ClusterScope) NetworkName() string {
131131
return ptr.Deref(s.GCPCluster.Spec.Network.Name, "default")
132132
}
133133

134+
// NetworkMtu returns the Network MTU of 1440 which is the default, otherwise returns back what is being set.
135+
// Mtu: Maximum Transmission Unit in bytes. The minimum value for this field is
136+
// 1300 and the maximum value is 8896. The suggested value is 1500, which is
137+
// the default MTU used on the Internet, or 8896 if you want to use Jumbo
138+
// frames. If unspecified, the value defaults to 1460.
139+
// More info
140+
// - https://pkg.go.dev/google.golang.org/api/compute/v1#Network
141+
// - https://cloud.google.com/vpc/docs/mtu
142+
func (s *ClusterScope) NetworkMtu() int64 {
143+
if s.GCPCluster.Spec.Network.Mtu == 0 {
144+
return int64(1460)
145+
}
146+
return s.GCPCluster.Spec.Network.Mtu
147+
}
148+
134149
// NetworkLink returns the partial URL for the network.
135150
func (s *ClusterScope) NetworkLink() string {
136151
return fmt.Sprintf("projects/%s/global/networks/%s", s.NetworkProject(), s.NetworkName())
@@ -206,6 +221,7 @@ func (s *ClusterScope) NetworkSpec() *compute.Network {
206221
Description: infrav1.ClusterTagKey(s.Name()),
207222
AutoCreateSubnetworks: createSubnet,
208223
ForceSendFields: []string{"AutoCreateSubnetworks"},
224+
Mtu: s.NetworkMtu(),
209225
}
210226

211227
return network
@@ -337,6 +353,7 @@ func (s *ClusterScope) ForwardingRuleSpec(lbname string) *compute.ForwardingRule
337353
IPProtocol: "TCP",
338354
LoadBalancingScheme: "EXTERNAL",
339355
PortRange: portRange,
356+
Labels: s.AdditionalLabels(),
340357
}
341358
}
342359

cloud/scope/machine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ func (m *MachineScope) InstanceImageSpec() *compute.AttachedDisk {
249249
DiskType: path.Join("zones", m.Zone(), "diskTypes", string(diskType)),
250250
ResourceManagerTags: shared.ResourceTagConvert(context.TODO(), m.GCPMachine.Spec.ResourceManagerTags),
251251
SourceImage: sourceImage,
252+
Labels: m.ClusterGetter.AdditionalLabels().AddLabels(m.GCPMachine.Spec.AdditionalLabels),
252253
},
253254
}
254255

cloud/services/compute/instances/reconcile_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ func TestService_createOrGetInstance(t *testing.T) {
237237
DiskType: "zones/us-central1-c/diskTypes/pd-standard",
238238
SourceImage: "projects/my-proj/global/images/family/capi-ubuntu-1804-k8s-v1-19",
239239
ResourceManagerTags: map[string]string{},
240+
Labels: map[string]string{
241+
"foo": "bar",
242+
},
240243
},
241244
},
242245
},
@@ -302,6 +305,9 @@ func TestService_createOrGetInstance(t *testing.T) {
302305
DiskType: "zones/us-central1-c/diskTypes/pd-standard",
303306
SourceImage: "projects/my-proj/global/images/family/capi-ubuntu-1804-k8s-v1-19",
304307
ResourceManagerTags: map[string]string{},
308+
Labels: map[string]string{
309+
"foo": "bar",
310+
},
305311
},
306312
},
307313
},
@@ -369,6 +375,9 @@ func TestService_createOrGetInstance(t *testing.T) {
369375
DiskType: "zones/us-central1-c/diskTypes/pd-standard",
370376
SourceImage: "projects/my-proj/global/images/family/capi-ubuntu-1804-k8s-v1-19",
371377
ResourceManagerTags: map[string]string{},
378+
Labels: map[string]string{
379+
"foo": "bar",
380+
},
372381
},
373382
},
374383
},
@@ -436,6 +445,9 @@ func TestService_createOrGetInstance(t *testing.T) {
436445
DiskType: "zones/us-central1-c/diskTypes/pd-standard",
437446
SourceImage: "projects/my-proj/global/images/family/capi-ubuntu-1804-k8s-v1-19",
438447
ResourceManagerTags: map[string]string{},
448+
Labels: map[string]string{
449+
"foo": "bar",
450+
},
439451
},
440452
},
441453
},
@@ -506,6 +518,9 @@ func TestService_createOrGetInstance(t *testing.T) {
506518
DiskType: "zones/us-central1-c/diskTypes/pd-standard",
507519
SourceImage: "projects/my-proj/global/images/family/capi-ubuntu-1804-k8s-v1-19",
508520
ResourceManagerTags: map[string]string{},
521+
Labels: map[string]string{
522+
"foo": "bar",
523+
},
509524
},
510525
},
511526
},
@@ -569,6 +584,9 @@ func TestService_createOrGetInstance(t *testing.T) {
569584
DiskType: "zones/us-central1-a/diskTypes/pd-standard",
570585
SourceImage: "projects/my-proj/global/images/family/capi-ubuntu-1804-k8s-v1-19",
571586
ResourceManagerTags: map[string]string{},
587+
Labels: map[string]string{
588+
"foo": "bar",
589+
},
572590
},
573591
},
574592
},
@@ -639,6 +657,9 @@ func TestService_createOrGetInstance(t *testing.T) {
639657
DiskType: "zones/us-central1-c/diskTypes/pd-standard",
640658
SourceImage: "projects/my-proj/global/images/family/capi-ubuntu-1804-k8s-v1-19",
641659
ResourceManagerTags: map[string]string{},
660+
Labels: map[string]string{
661+
"foo": "bar",
662+
},
642663
},
643664
DiskEncryptionKey: &compute.CustomerEncryptionKey{
644665
KmsKeyName: "projects/my-project/locations/us-central1/keyRings/us-central1/cryptoKeys/some-key",
@@ -712,6 +733,9 @@ func TestService_createOrGetInstance(t *testing.T) {
712733
DiskType: "zones/us-central1-c/diskTypes/pd-standard",
713734
SourceImage: "projects/my-proj/global/images/family/capi-ubuntu-1804-k8s-v1-19",
714735
ResourceManagerTags: map[string]string{},
736+
Labels: map[string]string{
737+
"foo": "bar",
738+
},
715739
},
716740
DiskEncryptionKey: &compute.CustomerEncryptionKey{
717741
RawKey: "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=",
@@ -785,6 +809,9 @@ func TestService_createOrGetInstance(t *testing.T) {
785809
DiskType: "zones/us-central1-c/diskTypes/pd-standard",
786810
SourceImage: "projects/my-proj/global/images/family/capi-ubuntu-1804-k8s-v1-19",
787811
ResourceManagerTags: map[string]string{},
812+
Labels: map[string]string{
813+
"foo": "bar",
814+
},
788815
},
789816
DiskEncryptionKey: &compute.CustomerEncryptionKey{
790817
RsaEncryptedKey: "ieCx/NcW06PcT7Ep1X6LUTc/hLvUDYyzSZPPVCVPTVEohpeHASqC8uw5TzyO9U+Fka9JFHiz0mBibXUInrC/jEk014kCK/NPjYgEMOyssZ4ZINPKxlUh2zn1bV+MCaTICrdmuSBTWlUUiFoDiD6PYznLwh8ZNdaheCeZ8ewEXgFQ8V+sDroLaN3Xs3MDTXQEMMoNUXMCZEIpg9Vtp9x2oe==",

0 commit comments

Comments
 (0)