Skip to content

Commit 1f920d9

Browse files
authored
Merge pull request #1554 from chrischdi/pr-use-v1beta2
Use and reconcile based on CAPI v1beta2
2 parents 5c2bfd5 + 27c3e2c commit 1f920d9

39 files changed

+299
-485
lines changed

.golangci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ linters:
7777
alias: kerrors
7878
- pkg: sigs.k8s.io/controller-runtime
7979
alias: ctrl
80+
- pkg: "sigs.k8s.io/cluster-api/api/core/v1beta2"
81+
alias: clusterv1
82+
- pkg: "sigs.k8s.io/cluster-api/api/core/v1beta1"
83+
alias: clusterv1beta1
84+
- pkg: "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch"
85+
alias: v1beta1patch
86+
- pkg: "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions"
87+
alias: v1beta1conditions
8088
no-unaliased: true
8189
exclusions:
8290
generated: lax

api/v1beta1/gcpcluster_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package v1beta1
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
21+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
2222
)
2323

2424
const (
@@ -37,7 +37,7 @@ type GCPClusterSpec struct {
3737

3838
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
3939
// +optional
40-
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
40+
ControlPlaneEndpoint clusterv1beta1.APIEndpoint `json:"controlPlaneEndpoint"`
4141

4242
// NetworkSpec encapsulates all things related to GCP network.
4343
// +optional
@@ -77,8 +77,8 @@ type GCPClusterSpec struct {
7777

7878
// GCPClusterStatus defines the observed state of GCPCluster.
7979
type GCPClusterStatus struct {
80-
FailureDomains clusterv1.FailureDomains `json:"failureDomains,omitempty"`
81-
Network Network `json:"network,omitempty"`
80+
FailureDomains clusterv1beta1.FailureDomains `json:"failureDomains,omitempty"`
81+
Network Network `json:"network,omitempty"`
8282

8383
// Bastion Instance `json:"bastion,omitempty"`
8484
Ready bool `json:"ready"`

api/v1beta1/gcpclustertemplate_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package v1beta1
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
21+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
2222
)
2323

2424
// GCPClusterTemplateSpec defines the desired state of GCPClusterTemplate.
@@ -31,7 +31,7 @@ type GCPClusterTemplateResource struct {
3131
// Standard object's metadata.
3232
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
3333
// +optional
34-
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty"`
34+
ObjectMeta clusterv1beta1.ObjectMeta `json:"metadata,omitempty"`
3535

3636
Spec GCPClusterSpec `json:"spec"`
3737
}

api/v1beta1/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ package v1beta1
1919
import (
2020
"fmt"
2121

22-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
22+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
2323
)
2424

2525
// GCPMachineTemplateResource describes the data needed to create am GCPMachine from a template.
2626
type GCPMachineTemplateResource struct {
2727
// Standard object's metadata.
2828
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
2929
// +optional
30-
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty"`
30+
ObjectMeta clusterv1beta1.ObjectMeta `json:"metadata,omitempty"`
3131

3232
// Spec is the specification of the desired behavior of the machine.
3333
Spec GCPMachineSpec `json:"spec"`

cloud/interfaces.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ package cloud
1919
import (
2020
"context"
2121

22+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2223
ctrl "sigs.k8s.io/controller-runtime"
2324

2425
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"
2526
corev1 "k8s.io/api/core/v1"
2627
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
27-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
2828
)
2929

3030
// Cloud alias for cloud.Cloud interface.
@@ -61,7 +61,7 @@ type ClusterGetter interface {
6161
SkipFirewallRuleCreation() bool
6262
Network() *infrav1.Network
6363
AdditionalLabels() infrav1.Labels
64-
FailureDomains() clusterv1.FailureDomains
64+
FailureDomains() []string
6565
ControlPlaneEndpoint() clusterv1.APIEndpoint
6666
ResourceManagerTags() infrav1.ResourceManagerTags
6767
LoadBalancer() infrav1.LoadBalancerSpec

cloud/scope/cluster.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import (
2727
"k8s.io/utils/ptr"
2828
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
2929
"sigs.k8s.io/cluster-api-provider-gcp/cloud"
30-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
30+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
31+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3132
"sigs.k8s.io/cluster-api/util/patch"
3233
"sigs.k8s.io/controller-runtime/pkg/client"
3334
)
@@ -185,17 +186,24 @@ func (s *ClusterScope) ResourceManagerTags() infrav1.ResourceManagerTags {
185186

186187
// ControlPlaneEndpoint returns the cluster control-plane endpoint.
187188
func (s *ClusterScope) ControlPlaneEndpoint() clusterv1.APIEndpoint {
188-
endpoint := s.GCPCluster.Spec.ControlPlaneEndpoint
189-
endpoint.Port = 443
190-
if c := s.Cluster.Spec.ClusterNetwork; c != nil {
191-
endpoint.Port = ptr.Deref(c.APIServerPort, 443)
189+
endpoint := clusterv1.APIEndpoint{
190+
Host: s.GCPCluster.Spec.ControlPlaneEndpoint.Host,
191+
Port: 443,
192+
}
193+
194+
if s.Cluster.Spec.ClusterNetwork.APIServerPort != 0 {
195+
endpoint.Port = s.Cluster.Spec.ClusterNetwork.APIServerPort
192196
}
193197
return endpoint
194198
}
195199

196200
// FailureDomains returns the cluster failure domains.
197-
func (s *ClusterScope) FailureDomains() clusterv1.FailureDomains {
198-
return s.GCPCluster.Status.FailureDomains
201+
func (s *ClusterScope) FailureDomains() []string {
202+
failureDomains := []string{}
203+
for failureDomainName := range s.GCPCluster.Status.FailureDomains {
204+
failureDomains = append(failureDomains, failureDomainName)
205+
}
206+
return failureDomains
199207
}
200208

201209
// ANCHOR_END: ClusterGetter
@@ -208,13 +216,16 @@ func (s *ClusterScope) SetReady() {
208216
}
209217

210218
// SetFailureDomains sets cluster failure domains.
211-
func (s *ClusterScope) SetFailureDomains(fd clusterv1.FailureDomains) {
219+
func (s *ClusterScope) SetFailureDomains(fd clusterv1beta1.FailureDomains) {
212220
s.GCPCluster.Status.FailureDomains = fd
213221
}
214222

215223
// SetControlPlaneEndpoint sets cluster control-plane endpoint.
216224
func (s *ClusterScope) SetControlPlaneEndpoint(endpoint clusterv1.APIEndpoint) {
217-
s.GCPCluster.Spec.ControlPlaneEndpoint = endpoint
225+
s.GCPCluster.Spec.ControlPlaneEndpoint = clusterv1beta1.APIEndpoint{
226+
Host: endpoint.Host,
227+
Port: endpoint.Port,
228+
}
218229
}
219230

220231
// ANCHOR_END: ClusterSetter
@@ -354,8 +365,8 @@ func (s *ClusterScope) BackendServiceSpec(lbname string) *compute.BackendService
354365
// ForwardingRuleSpec returns google compute forwarding-rule spec.
355366
func (s *ClusterScope) ForwardingRuleSpec(lbname string) *compute.ForwardingRule {
356367
port := int32(443)
357-
if c := s.Cluster.Spec.ClusterNetwork; c != nil {
358-
port = ptr.Deref(c.APIServerPort, 443)
368+
if s.Cluster.Spec.ClusterNetwork.APIServerPort != 0 {
369+
port = s.Cluster.Spec.ClusterNetwork.APIServerPort
359370
}
360371
portRange := fmt.Sprintf("%d-%d", port, port)
361372
return &compute.ForwardingRule{

cloud/scope/machine.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"sigs.k8s.io/cluster-api-provider-gcp/cloud"
3737
"sigs.k8s.io/cluster-api-provider-gcp/cloud/providerid"
3838
"sigs.k8s.io/cluster-api-provider-gcp/cloud/services/shared"
39-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
39+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
4040
"sigs.k8s.io/cluster-api/util/patch"
4141
"sigs.k8s.io/controller-runtime/pkg/client"
4242
)
@@ -99,19 +99,15 @@ func (m *MachineScope) NetworkCloud() cloud.Cloud {
9999

100100
// Zone returns the FailureDomain for the GCPMachine.
101101
func (m *MachineScope) Zone() string {
102-
if m.Machine.Spec.FailureDomain == nil {
102+
if m.Machine.Spec.FailureDomain == "" {
103103
fd := m.ClusterGetter.FailureDomains()
104104
if len(fd) == 0 {
105105
return ""
106106
}
107-
zones := make([]string, 0, len(fd))
108-
for zone := range fd {
109-
zones = append(zones, zone)
110-
}
111-
sort.Strings(zones)
112-
return zones[0]
107+
sort.Strings(fd)
108+
return fd[0]
113109
}
114-
return *m.Machine.Spec.FailureDomain
110+
return m.Machine.Spec.FailureDomain
115111
}
116112

117113
// Project return the project for the GCPMachine's cluster.
@@ -228,10 +224,7 @@ func (m *MachineScope) SetAddresses(addressList []corev1.NodeAddress) {
228224

229225
// InstanceImageSpec returns compute instance image attched-disk spec.
230226
func (m *MachineScope) InstanceImageSpec() *compute.AttachedDisk {
231-
version := ""
232-
if m.Machine.Spec.Version != nil {
233-
version = *m.Machine.Spec.Version
234-
}
227+
version := m.Machine.Spec.Version
235228
image := "capi-ubuntu-1804-k8s-" + strings.ReplaceAll(semver.MajorMinor(version), ".", "-")
236229
sourceImage := path.Join("projects", m.ClusterGetter.Project(), "global", "images", "family", image)
237230
if m.GCPMachine.Spec.Image != nil {

cloud/scope/machine_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/stretchr/testify/assert"
88
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
9-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
9+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
1010
"sigs.k8s.io/controller-runtime/pkg/client/fake"
1111
)
1212

@@ -30,7 +30,7 @@ func TestMachineLocalSSDDiskType(t *testing.T) {
3030
failureDomain := "example.com"
3131
testMachine := clusterv1.Machine{
3232
Spec: clusterv1.MachineSpec{
33-
FailureDomain: &failureDomain,
33+
FailureDomain: failureDomain,
3434
},
3535
}
3636

@@ -89,7 +89,7 @@ func TestInstanceNetworkInterfaceAliasIPRangesSpec(t *testing.T) {
8989
failureDomain := "us-central1-a"
9090
testMachine := clusterv1.Machine{
9191
Spec: clusterv1.MachineSpec{
92-
FailureDomain: &failureDomain,
92+
FailureDomain: failureDomain,
9393
},
9494
}
9595

cloud/scope/managedcluster.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import (
2727
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
2828
"sigs.k8s.io/cluster-api-provider-gcp/cloud"
2929
infrav1exp "sigs.k8s.io/cluster-api-provider-gcp/exp/api/v1beta1"
30-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
30+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
31+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3132
"sigs.k8s.io/cluster-api/util/patch"
3233
"sigs.k8s.io/controller-runtime/pkg/client"
3334
)
@@ -173,14 +174,23 @@ func (s *ManagedClusterScope) ResourceManagerTags() infrav1.ResourceManagerTags
173174

174175
// ControlPlaneEndpoint returns the cluster control-plane endpoint.
175176
func (s *ManagedClusterScope) ControlPlaneEndpoint() clusterv1.APIEndpoint {
176-
endpoint := s.GCPManagedCluster.Spec.ControlPlaneEndpoint
177-
endpoint.Port = ptr.Deref(s.Cluster.Spec.ClusterNetwork.APIServerPort, 443)
177+
endpoint := clusterv1.APIEndpoint{
178+
Host: s.GCPManagedCluster.Spec.ControlPlaneEndpoint.Host,
179+
Port: 443,
180+
}
181+
if s.Cluster.Spec.ClusterNetwork.APIServerPort != 0 {
182+
endpoint.Port = s.Cluster.Spec.ClusterNetwork.APIServerPort
183+
}
178184
return endpoint
179185
}
180186

181187
// FailureDomains returns the cluster failure domains.
182-
func (s *ManagedClusterScope) FailureDomains() clusterv1.FailureDomains {
183-
return s.GCPManagedCluster.Status.FailureDomains
188+
func (s *ManagedClusterScope) FailureDomains() []string {
189+
failureDomains := []string{}
190+
for failureDomainName := range s.GCPManagedCluster.Status.FailureDomains {
191+
failureDomains = append(failureDomains, failureDomainName)
192+
}
193+
return failureDomains
184194
}
185195

186196
// ANCHOR_END: ClusterGetter
@@ -193,13 +203,16 @@ func (s *ManagedClusterScope) SetReady() {
193203
}
194204

195205
// SetFailureDomains sets cluster failure domains.
196-
func (s *ManagedClusterScope) SetFailureDomains(fd clusterv1.FailureDomains) {
206+
func (s *ManagedClusterScope) SetFailureDomains(fd clusterv1beta1.FailureDomains) {
197207
s.GCPManagedCluster.Status.FailureDomains = fd
198208
}
199209

200210
// SetControlPlaneEndpoint sets cluster control-plane endpoint.
201211
func (s *ManagedClusterScope) SetControlPlaneEndpoint(endpoint clusterv1.APIEndpoint) {
202-
s.GCPManagedCluster.Spec.ControlPlaneEndpoint = endpoint
212+
s.GCPManagedCluster.Spec.ControlPlaneEndpoint = clusterv1beta1.APIEndpoint{
213+
Host: endpoint.Host,
214+
Port: endpoint.Port,
215+
}
203216
}
204217

205218
// ANCHOR_END: ClusterSetter

cloud/scope/managedcontrolplane.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ import (
2222

2323
"sigs.k8s.io/cluster-api-provider-gcp/util/location"
2424

25-
"sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions"
25+
v1beta1conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions"
2626

2727
container "cloud.google.com/go/container/apiv1"
2828
credentials "cloud.google.com/go/iam/credentials/apiv1"
2929
resourcemanager "cloud.google.com/go/resourcemanager/apiv3"
3030
"github.com/pkg/errors"
3131
infrav1exp "sigs.k8s.io/cluster-api-provider-gcp/exp/api/v1beta1"
32-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
33-
patch "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch"
32+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
33+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
34+
v1beta1patch "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch"
3435
"sigs.k8s.io/controller-runtime/pkg/client"
3536
)
3637

@@ -91,7 +92,7 @@ func NewManagedControlPlaneScope(ctx context.Context, params ManagedControlPlane
9192
params.CredentialsClient = credentialsClient
9293
}
9394

94-
helper, err := patch.NewHelper(params.GCPManagedControlPlane, params.Client)
95+
helper, err := v1beta1patch.NewHelper(params.GCPManagedControlPlane, params.Client)
9596
if err != nil {
9697
return nil, errors.Wrap(err, "failed to init patch helper")
9798
}
@@ -112,7 +113,7 @@ func NewManagedControlPlaneScope(ctx context.Context, params ManagedControlPlane
112113
// ManagedControlPlaneScope defines the basic context for an actuator to operate upon.
113114
type ManagedControlPlaneScope struct {
114115
client client.Client
115-
patchHelper *patch.Helper
116+
patchHelper *v1beta1patch.Helper
116117

117118
Cluster *clusterv1.Cluster
118119
GCPManagedCluster *infrav1exp.GCPManagedCluster
@@ -131,7 +132,7 @@ func (s *ManagedControlPlaneScope) PatchObject() error {
131132
return s.patchHelper.Patch(
132133
context.TODO(),
133134
s.GCPManagedControlPlane,
134-
patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{
135+
v1beta1patch.WithOwnedConditions{Conditions: []clusterv1beta1.ConditionType{
135136
infrav1exp.GKEControlPlaneReadyCondition,
136137
infrav1exp.GKEControlPlaneCreatingCondition,
137138
infrav1exp.GKEControlPlaneUpdatingCondition,
@@ -148,7 +149,7 @@ func (s *ManagedControlPlaneScope) Close() error {
148149
}
149150

150151
// ConditionSetter return a condition setter (which is GCPManagedControlPlane itself).
151-
func (s *ManagedControlPlaneScope) ConditionSetter() conditions.Setter {
152+
func (s *ManagedControlPlaneScope) ConditionSetter() v1beta1conditions.Setter {
152153
return s.GCPManagedControlPlane
153154
}
154155

@@ -226,7 +227,7 @@ func (s *ManagedControlPlaneScope) ClusterName() string {
226227

227228
// SetEndpoint sets the Endpoint of GCPManagedControlPlane.
228229
func (s *ManagedControlPlaneScope) SetEndpoint(host string) {
229-
s.GCPManagedControlPlane.Spec.Endpoint = clusterv1.APIEndpoint{
230+
s.GCPManagedControlPlane.Spec.Endpoint = clusterv1beta1.APIEndpoint{
230231
Host: host,
231232
Port: APIServerPort,
232233
}

0 commit comments

Comments
 (0)