Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ linters:
alias: kerrors
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
- pkg: "sigs.k8s.io/cluster-api/api/core/v1beta2"
alias: clusterv1
- pkg: "sigs.k8s.io/cluster-api/api/core/v1beta1"
alias: clusterv1beta1
- pkg: "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch"
alias: v1beta1patch
- pkg: "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions"
alias: v1beta1conditions
no-unaliased: true
exclusions:
generated: lax
Expand Down
8 changes: 4 additions & 4 deletions api/v1beta1/gcpcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package v1beta1

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

const (
Expand All @@ -37,7 +37,7 @@ type GCPClusterSpec struct {

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

// NetworkSpec encapsulates all things related to GCP network.
// +optional
Expand Down Expand Up @@ -77,8 +77,8 @@ type GCPClusterSpec struct {

// GCPClusterStatus defines the observed state of GCPCluster.
type GCPClusterStatus struct {
FailureDomains clusterv1.FailureDomains `json:"failureDomains,omitempty"`
Network Network `json:"network,omitempty"`
FailureDomains clusterv1beta1.FailureDomains `json:"failureDomains,omitempty"`
Network Network `json:"network,omitempty"`

// Bastion Instance `json:"bastion,omitempty"`
Ready bool `json:"ready"`
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/gcpclustertemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package v1beta1

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

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

Spec GCPClusterSpec `json:"spec"`
}
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ package v1beta1
import (
"fmt"

clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
)

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

// Spec is the specification of the desired behavior of the machine.
Spec GCPMachineSpec `json:"spec"`
Expand Down
4 changes: 2 additions & 2 deletions cloud/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package cloud
import (
"context"

clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"
corev1 "k8s.io/api/core/v1"
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
)

// Cloud alias for cloud.Cloud interface.
Expand Down Expand Up @@ -61,7 +61,7 @@ type ClusterGetter interface {
SkipFirewallRuleCreation() bool
Network() *infrav1.Network
AdditionalLabels() infrav1.Labels
FailureDomains() clusterv1.FailureDomains
FailureDomains() []string
ControlPlaneEndpoint() clusterv1.APIEndpoint
ResourceManagerTags() infrav1.ResourceManagerTags
LoadBalancer() infrav1.LoadBalancerSpec
Expand Down
33 changes: 22 additions & 11 deletions cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
"k8s.io/utils/ptr"
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-gcp/cloud"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -185,17 +186,24 @@ func (s *ClusterScope) ResourceManagerTags() infrav1.ResourceManagerTags {

// ControlPlaneEndpoint returns the cluster control-plane endpoint.
func (s *ClusterScope) ControlPlaneEndpoint() clusterv1.APIEndpoint {
endpoint := s.GCPCluster.Spec.ControlPlaneEndpoint
endpoint.Port = 443
if c := s.Cluster.Spec.ClusterNetwork; c != nil {
endpoint.Port = ptr.Deref(c.APIServerPort, 443)
endpoint := clusterv1.APIEndpoint{
Host: s.GCPCluster.Spec.ControlPlaneEndpoint.Host,
Port: 443,
}

if s.Cluster.Spec.ClusterNetwork.APIServerPort != 0 {
endpoint.Port = s.Cluster.Spec.ClusterNetwork.APIServerPort
}
return endpoint
}

// FailureDomains returns the cluster failure domains.
func (s *ClusterScope) FailureDomains() clusterv1.FailureDomains {
return s.GCPCluster.Status.FailureDomains
func (s *ClusterScope) FailureDomains() []string {
failureDomains := []string{}
for failureDomainName := range s.GCPCluster.Status.FailureDomains {
failureDomains = append(failureDomains, failureDomainName)
}
return failureDomains
}

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

// SetFailureDomains sets cluster failure domains.
func (s *ClusterScope) SetFailureDomains(fd clusterv1.FailureDomains) {
func (s *ClusterScope) SetFailureDomains(fd clusterv1beta1.FailureDomains) {
s.GCPCluster.Status.FailureDomains = fd
}

// SetControlPlaneEndpoint sets cluster control-plane endpoint.
func (s *ClusterScope) SetControlPlaneEndpoint(endpoint clusterv1.APIEndpoint) {
s.GCPCluster.Spec.ControlPlaneEndpoint = endpoint
s.GCPCluster.Spec.ControlPlaneEndpoint = clusterv1beta1.APIEndpoint{
Host: endpoint.Host,
Port: endpoint.Port,
}
}

// ANCHOR_END: ClusterSetter
Expand Down Expand Up @@ -354,8 +365,8 @@ func (s *ClusterScope) BackendServiceSpec(lbname string) *compute.BackendService
// ForwardingRuleSpec returns google compute forwarding-rule spec.
func (s *ClusterScope) ForwardingRuleSpec(lbname string) *compute.ForwardingRule {
port := int32(443)
if c := s.Cluster.Spec.ClusterNetwork; c != nil {
port = ptr.Deref(c.APIServerPort, 443)
if s.Cluster.Spec.ClusterNetwork.APIServerPort != 0 {
port = s.Cluster.Spec.ClusterNetwork.APIServerPort
}
portRange := fmt.Sprintf("%d-%d", port, port)
return &compute.ForwardingRule{
Expand Down
19 changes: 6 additions & 13 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"sigs.k8s.io/cluster-api-provider-gcp/cloud"
"sigs.k8s.io/cluster-api-provider-gcp/cloud/providerid"
"sigs.k8s.io/cluster-api-provider-gcp/cloud/services/shared"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -99,19 +99,15 @@ func (m *MachineScope) NetworkCloud() cloud.Cloud {

// Zone returns the FailureDomain for the GCPMachine.
func (m *MachineScope) Zone() string {
if m.Machine.Spec.FailureDomain == nil {
if m.Machine.Spec.FailureDomain == "" {
fd := m.ClusterGetter.FailureDomains()
if len(fd) == 0 {
return ""
}
zones := make([]string, 0, len(fd))
for zone := range fd {
zones = append(zones, zone)
}
sort.Strings(zones)
return zones[0]
sort.Strings(fd)
return fd[0]
}
return *m.Machine.Spec.FailureDomain
return m.Machine.Spec.FailureDomain
}

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

// InstanceImageSpec returns compute instance image attched-disk spec.
func (m *MachineScope) InstanceImageSpec() *compute.AttachedDisk {
version := ""
if m.Machine.Spec.Version != nil {
version = *m.Machine.Spec.Version
}
version := m.Machine.Spec.Version
image := "capi-ubuntu-1804-k8s-" + strings.ReplaceAll(semver.MajorMinor(version), ".", "-")
sourceImage := path.Join("projects", m.ClusterGetter.Project(), "global", "images", "family", image)
if m.GCPMachine.Spec.Image != nil {
Expand Down
6 changes: 3 additions & 3 deletions cloud/scope/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/assert"
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

Expand All @@ -30,7 +30,7 @@ func TestMachineLocalSSDDiskType(t *testing.T) {
failureDomain := "example.com"
testMachine := clusterv1.Machine{
Spec: clusterv1.MachineSpec{
FailureDomain: &failureDomain,
FailureDomain: failureDomain,
},
}

Expand Down Expand Up @@ -89,7 +89,7 @@ func TestInstanceNetworkInterfaceAliasIPRangesSpec(t *testing.T) {
failureDomain := "us-central1-a"
testMachine := clusterv1.Machine{
Spec: clusterv1.MachineSpec{
FailureDomain: &failureDomain,
FailureDomain: failureDomain,
},
}

Expand Down
27 changes: 20 additions & 7 deletions cloud/scope/managedcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-gcp/cloud"
infrav1exp "sigs.k8s.io/cluster-api-provider-gcp/exp/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -173,14 +174,23 @@ func (s *ManagedClusterScope) ResourceManagerTags() infrav1.ResourceManagerTags

// ControlPlaneEndpoint returns the cluster control-plane endpoint.
func (s *ManagedClusterScope) ControlPlaneEndpoint() clusterv1.APIEndpoint {
endpoint := s.GCPManagedCluster.Spec.ControlPlaneEndpoint
endpoint.Port = ptr.Deref(s.Cluster.Spec.ClusterNetwork.APIServerPort, 443)
endpoint := clusterv1.APIEndpoint{
Host: s.GCPManagedCluster.Spec.ControlPlaneEndpoint.Host,
Port: 443,
}
if s.Cluster.Spec.ClusterNetwork.APIServerPort != 0 {
endpoint.Port = s.Cluster.Spec.ClusterNetwork.APIServerPort
}
return endpoint
}

// FailureDomains returns the cluster failure domains.
func (s *ManagedClusterScope) FailureDomains() clusterv1.FailureDomains {
return s.GCPManagedCluster.Status.FailureDomains
func (s *ManagedClusterScope) FailureDomains() []string {
failureDomains := []string{}
for failureDomainName := range s.GCPManagedCluster.Status.FailureDomains {
failureDomains = append(failureDomains, failureDomainName)
}
return failureDomains
}

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

// SetFailureDomains sets cluster failure domains.
func (s *ManagedClusterScope) SetFailureDomains(fd clusterv1.FailureDomains) {
func (s *ManagedClusterScope) SetFailureDomains(fd clusterv1beta1.FailureDomains) {
s.GCPManagedCluster.Status.FailureDomains = fd
}

// SetControlPlaneEndpoint sets cluster control-plane endpoint.
func (s *ManagedClusterScope) SetControlPlaneEndpoint(endpoint clusterv1.APIEndpoint) {
s.GCPManagedCluster.Spec.ControlPlaneEndpoint = endpoint
s.GCPManagedCluster.Spec.ControlPlaneEndpoint = clusterv1beta1.APIEndpoint{
Host: endpoint.Host,
Port: endpoint.Port,
}
}

// ANCHOR_END: ClusterSetter
Expand Down
17 changes: 9 additions & 8 deletions cloud/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ import (

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

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

container "cloud.google.com/go/container/apiv1"
credentials "cloud.google.com/go/iam/credentials/apiv1"
resourcemanager "cloud.google.com/go/resourcemanager/apiv3"
"github.com/pkg/errors"
infrav1exp "sigs.k8s.io/cluster-api-provider-gcp/exp/api/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
patch "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch"
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
v1beta1patch "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -91,7 +92,7 @@ func NewManagedControlPlaneScope(ctx context.Context, params ManagedControlPlane
params.CredentialsClient = credentialsClient
}

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

Cluster *clusterv1.Cluster
GCPManagedCluster *infrav1exp.GCPManagedCluster
Expand All @@ -131,7 +132,7 @@ func (s *ManagedControlPlaneScope) PatchObject() error {
return s.patchHelper.Patch(
context.TODO(),
s.GCPManagedControlPlane,
patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{
v1beta1patch.WithOwnedConditions{Conditions: []clusterv1beta1.ConditionType{
infrav1exp.GKEControlPlaneReadyCondition,
infrav1exp.GKEControlPlaneCreatingCondition,
infrav1exp.GKEControlPlaneUpdatingCondition,
Expand All @@ -148,7 +149,7 @@ func (s *ManagedControlPlaneScope) Close() error {
}

// ConditionSetter return a condition setter (which is GCPManagedControlPlane itself).
func (s *ManagedControlPlaneScope) ConditionSetter() conditions.Setter {
func (s *ManagedControlPlaneScope) ConditionSetter() v1beta1conditions.Setter {
return s.GCPManagedControlPlane
}

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

// SetEndpoint sets the Endpoint of GCPManagedControlPlane.
func (s *ManagedControlPlaneScope) SetEndpoint(host string) {
s.GCPManagedControlPlane.Spec.Endpoint = clusterv1.APIEndpoint{
s.GCPManagedControlPlane.Spec.Endpoint = clusterv1beta1.APIEndpoint{
Host: host,
Port: APIServerPort,
}
Expand Down
Loading