Skip to content

Commit

Permalink
bump version for linodecluster to v1alpha2
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulait committed Jun 4, 2024
1 parent a4c218c commit 74ef43a
Show file tree
Hide file tree
Showing 84 changed files with 1,490 additions and 255 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN go mod download

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY api/infrastructure api/infrastructure
COPY clients/ clients/
COPY controller/ controller/
COPY cloud/ cloud/
Expand Down
24 changes: 18 additions & 6 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
domain: cluster.x-k8s.io
layout:
- go.kubebuilder.io/v4
multigroup: true
projectName: cluster-api-provider-linode
repo: github.com/linode/cluster-api-provider-linode
resources:
Expand All @@ -15,7 +16,7 @@ resources:
domain: cluster.x-k8s.io
group: infrastructure
kind: LinodeCluster
path: github.com/linode/cluster-api-provider-linode/api/v1alpha1
path: github.com/linode/cluster-api-provider-linode/api/infrastructure/v1alpha1
version: v1alpha1
webhooks:
validation: true
Expand All @@ -27,7 +28,7 @@ resources:
domain: cluster.x-k8s.io
group: infrastructure
kind: LinodeMachine
path: github.com/linode/cluster-api-provider-linode/api/v1alpha1
path: github.com/linode/cluster-api-provider-linode/api/infrastructure/v1alpha1
version: v1alpha1
webhooks:
validation: true
Expand All @@ -38,15 +39,15 @@ resources:
domain: cluster.x-k8s.io
group: infrastructure
kind: LinodeClusterTemplate
path: github.com/linode/cluster-api-provider-linode/api/v1alpha1
path: github.com/linode/cluster-api-provider-linode/api/infrastructure/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: cluster.x-k8s.io
group: infrastructure
kind: LinodeMachineTemplate
path: github.com/linode/cluster-api-provider-linode/api/v1alpha1
path: github.com/linode/cluster-api-provider-linode/api/infrastructure/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
Expand All @@ -55,7 +56,7 @@ resources:
domain: cluster.x-k8s.io
group: infrastructure
kind: LinodeVPC
path: github.com/linode/cluster-api-provider-linode/api/v1alpha1
path: github.com/linode/cluster-api-provider-linode/api/infrastructure/v1alpha1
version: v1alpha1
webhooks:
validation: true
Expand All @@ -67,9 +68,20 @@ resources:
domain: cluster.x-k8s.io
group: infrastructure
kind: LinodeObjectStorageBucket
path: github.com/linode/cluster-api-provider-linode/api/v1alpha1
path: github.com/linode/cluster-api-provider-linode/api/infrastructure/v1alpha1
version: v1alpha1
webhooks:
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
domain: cluster.x-k8s.io
group: infrastructure
kind: LinodeCluster
path: github.com/linode/cluster-api-provider-linode/api/infrastructure/v1alpha2
version: v1alpha2
webhooks:
conversion: true
webhookVersion: v1
version: "3"
File renamed without changes.
85 changes: 85 additions & 0 deletions api/infrastructure/v1alpha1/linodecluster_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright 2023 Akamai Technologies, Inc.
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 v1alpha1

import (
"errors"

"sigs.k8s.io/controller-runtime/pkg/conversion"

infrastructurev1alpha2 "github.com/linode/cluster-api-provider-linode/api/infrastructure/v1alpha2"
)

// ConvertTo converts this LinodeCluster to the Hub version (v1alpha2).
func (src *LinodeCluster) ConvertTo(dstRaw conversion.Hub) error {
dst, ok := dstRaw.(*infrastructurev1alpha2.LinodeCluster)
if !ok {
return errors.New("failed to convert LinodeCluster version from v1alpha1 to v1alpha2")
}

// ObjectMeta
dst.ObjectMeta = src.ObjectMeta

// Spec
dst.Spec.Network = infrastructurev1alpha2.NetworkSpec{
LoadBalancerType: src.Spec.Network.LoadBalancerType,
ApiserverLoadBalancerPort: src.Spec.Network.LoadBalancerPort,
NodeBalancerID: src.Spec.Network.NodeBalancerID,
ApiserverNodeBalancerConfigID: src.Spec.Network.NodeBalancerConfigID,
}
dst.Spec.ControlPlaneEndpoint = src.Spec.ControlPlaneEndpoint
dst.Spec.Region = src.Spec.Region
dst.Spec.VPCRef = src.Spec.VPCRef
dst.Spec.CredentialsRef = src.Spec.CredentialsRef

// Status
dst.Status.Ready = src.Status.Ready
dst.Status.Conditions = src.Status.Conditions
dst.Status.FailureMessage = src.Status.FailureMessage
dst.Status.FailureReason = src.Status.FailureReason

return nil
}

// ConvertFrom converts from the Hub version (v1alpha2) to this version.
func (dst *LinodeCluster) ConvertFrom(srcRaw conversion.Hub) error {
src, ok := srcRaw.(*infrastructurev1alpha2.LinodeCluster)
if !ok {
return errors.New("failed to convert LinodeCluster version from v1alpha2 to v1alpha1")
}

// ObjectMeta
dst.ObjectMeta = src.ObjectMeta

// Spec
dst.Spec.Network.LoadBalancerPort = src.Spec.Network.ApiserverLoadBalancerPort
dst.Spec.Network.LoadBalancerType = src.Spec.Network.LoadBalancerType
dst.Spec.Network.NodeBalancerID = src.Spec.Network.NodeBalancerID
dst.Spec.Network.NodeBalancerConfigID = src.Spec.Network.ApiserverNodeBalancerConfigID
dst.Spec.ControlPlaneEndpoint = src.Spec.ControlPlaneEndpoint
dst.Spec.Region = src.Spec.Region
dst.Spec.VPCRef = src.Spec.VPCRef
dst.Spec.CredentialsRef = src.Spec.CredentialsRef

// Status
dst.Status.Ready = src.Status.Ready
dst.Status.Conditions = src.Status.Conditions
dst.Status.FailureMessage = src.Status.FailureMessage
dst.Status.FailureReason = src.Status.FailureReason

return nil
}
140 changes: 140 additions & 0 deletions api/infrastructure/v1alpha1/linodecluster_conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
Copyright 2023 Akamai Technologies, Inc.
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 v1alpha1

import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"

infrav1alpha2 "github.com/linode/cluster-api-provider-linode/api/infrastructure/v1alpha2"
"github.com/linode/cluster-api-provider-linode/mock"

. "github.com/linode/cluster-api-provider-linode/mock/mocktest"
)

func TestConvertTo(t *testing.T) {
t.Parallel()

src := &LinodeCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
},
Spec: LinodeClusterSpec{
Network: NetworkSpec{
LoadBalancerType: "test-type",
LoadBalancerPort: 12345,
NodeBalancerID: ptr.To(1234),
NodeBalancerConfigID: ptr.To(2345),
},
ControlPlaneEndpoint: clusterv1.APIEndpoint{Host: "1.2.3.4"},
Region: "test-region",
},
}
expectedDst := &infrav1alpha2.LinodeCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
},
Spec: infrav1alpha2.LinodeClusterSpec{
Network: infrav1alpha2.NetworkSpec{
LoadBalancerType: "test-type",
NodeBalancerID: ptr.To(1234),
ApiserverLoadBalancerPort: 12345,
ApiserverNodeBalancerConfigID: ptr.To(2345),
},
ControlPlaneEndpoint: clusterv1.APIEndpoint{Host: "1.2.3.4"},
Region: "test-region",
},
}
dst := &infrav1alpha2.LinodeCluster{}

NewSuite(t, mock.MockLinodeClient{}).Run(
OneOf(
Path(
Call("convert v1alpha1 to v1alpha2", func(ctx context.Context, mck Mock) {
err := src.ConvertTo(dst)
if err != nil {
t.Fatalf("ConvertTo failed: %v", err)
}
}),
Result("conversion succeeded", func(ctx context.Context, mck Mock) {
if diff := cmp.Diff(expectedDst, dst); diff != "" {
t.Errorf("ConvertTo() mismatch (-expected +got):\n%s", diff)
}
}),
),
),
)
}

func TestConvertFrom(t *testing.T) {
t.Parallel()

src := &infrav1alpha2.LinodeCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
},
Spec: infrav1alpha2.LinodeClusterSpec{
Network: infrav1alpha2.NetworkSpec{
LoadBalancerType: "test-type",
NodeBalancerID: ptr.To(1234),
ApiserverLoadBalancerPort: 12345,
ApiserverNodeBalancerConfigID: ptr.To(2345),
},
ControlPlaneEndpoint: clusterv1.APIEndpoint{Host: "1.2.3.4"},
Region: "test-region",
},
}
expectedDst := &LinodeCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
},
Spec: LinodeClusterSpec{
Network: NetworkSpec{
LoadBalancerType: "test-type",
LoadBalancerPort: 12345,
NodeBalancerID: ptr.To(1234),
NodeBalancerConfigID: ptr.To(2345),
},
ControlPlaneEndpoint: clusterv1.APIEndpoint{Host: "1.2.3.4"},
Region: "test-region",
},
}
dst := &LinodeCluster{}

NewSuite(t, mock.MockLinodeClient{}).Run(
OneOf(
Path(
Call("convert v1alpha2 to v1alpha1", func(ctx context.Context, mck Mock) {
err := dst.ConvertFrom(src)
if err != nil {
t.Fatalf("ConvertFrom failed: %v", err)
}
}),
Result("conversion succeeded", func(ctx context.Context, mck Mock) {
if diff := cmp.Diff(expectedDst, dst); diff != "" {
t.Errorf("ConvertFrom() mismatch (-expected +got):\n%s", diff)
}
}),
),
),
)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions api/infrastructure/v1alpha2/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2023 Akamai Technologies, Inc.
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 v1alpha2 contains API Schema definitions for the infrastructure v1alpha2 API group
// +kubebuilder:object:generate=true
// +groupName=infrastructure.cluster.x-k8s.io
package v1alpha2

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "infrastructure.cluster.x-k8s.io", Version: "v1alpha2"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
3 changes: 3 additions & 0 deletions api/infrastructure/v1alpha2/linodecluster_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package v1alpha2

func (*LinodeCluster) Hub() {}
Loading

0 comments on commit 74ef43a

Please sign in to comment.