From 32d64dd552047ec4abd9b43d5a0e0e327db9049f Mon Sep 17 00:00:00 2001 From: Evan Johnson Date: Thu, 25 Jul 2024 17:13:02 -0400 Subject: [PATCH] add v1alpha2 of linodeMachineTemplate --- .golangci.yml | 4 + PROJECT | 11 + .../linodeclustertemplate_conversion.go | 2 +- .../linodemachinetemplate_conversion.go | 83 ++++++ .../linodemachinetemplate_conversion_test.go | 269 ++++++++++++++++++ api/v1alpha1/zz_generated.conversion.go | 136 +++++++++ .../linodemachinetemplate_conversion.go | 23 ++ api/v1alpha2/linodemachinetemplate_types.go | 56 ++++ api/v1alpha2/linodemachinetemplate_webhook.go | 28 ++ .../linodemachinetemplate_webhook_test.go | 33 +++ api/v1alpha2/zz_generated.deepcopy.go | 90 ++++++ cmd/main.go | 4 + ...uster.x-k8s.io_linodemachinetemplates.yaml | 245 ++++++++++++++++ config/crd/kustomization.yaml | 1 + config/rbac/kustomization.yaml | 2 + ...ucture_v1alpha2_linodemachinetemplate.yaml | 9 + config/samples/kustomization.yaml | 1 + .../validating/chainsaw-test.yaml | 1 + .../validating/invalid-linodevpc.yaml | 2 +- .../minimal-linodevpc/assert-vpc.yaml | 2 +- .../minimal-linodevpc/chainsaw-test.yaml | 4 +- .../minimal-linodevpc/check-vpc-deletion.yaml | 2 +- .../minimal-linodevpc/create-vpc.yaml | 2 +- .../clusterclass-kubeadm/clusterClass.yaml | 20 +- .../deleteTransformer.yaml | 14 - .../clusterclass-kubeadm/kustomization.yaml | 4 +- .../linodeClusterTemplate.yaml | 2 +- .../flavors/k3s/default/k3sControlPlane.yaml | 2 +- .../cilium-bgp-lb/linodeMachineTemplate.yaml | 2 +- .../kubeadm/default/kubeadmControlPlane.yaml | 2 +- .../kubeadm/etcd-disk/kustomization.yaml | 2 +- .../kubeadm/full-vpcless/kustomization.yaml | 2 +- .../flavors/kubeadm/full/kustomization.yaml | 2 +- .../rke2/default/rke2ControlPlane.yaml | 2 +- .../flavors/rke2/etcd-disk/kustomization.yaml | 2 +- .../rke2/full-vpcless/kustomization.yaml | 2 +- .../flavors/rke2/full/kustomization.yaml | 2 +- templates/infra/linodeMachineTemplate.yaml | 4 +- templates/infra/machineDeployment.yaml | 2 +- 39 files changed, 1029 insertions(+), 47 deletions(-) create mode 100644 api/v1alpha1/linodemachinetemplate_conversion.go create mode 100644 api/v1alpha1/linodemachinetemplate_conversion_test.go create mode 100644 api/v1alpha2/linodemachinetemplate_conversion.go create mode 100644 api/v1alpha2/linodemachinetemplate_types.go create mode 100644 api/v1alpha2/linodemachinetemplate_webhook.go create mode 100644 api/v1alpha2/linodemachinetemplate_webhook_test.go create mode 100644 config/samples/infrastructure_v1alpha2_linodemachinetemplate.yaml diff --git a/.golangci.yml b/.golangci.yml index 6813e600..5ff23ccf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -207,6 +207,10 @@ issues: - gosec - exportloopref - unparam + # conversion files rely on largely generated code so are very similar + - path: _conversion\.go + linters: + - dupl # Ease some gocritic warnings on test files. - path: _test\.go diff --git a/PROJECT b/PROJECT index 1c96a162..06dcb928 100644 --- a/PROJECT +++ b/PROJECT @@ -130,4 +130,15 @@ resources: webhooks: conversion: true webhookVersion: v1 +- api: + crdVersion: v1 + namespaced: true + domain: cluster.x-k8s.io + group: infrastructure + kind: LinodeMachineTemplate + path: github.com/linode/cluster-api-provider-linode/api/v1alpha2 + version: v1alpha2 + webhooks: + conversion: true + webhookVersion: v1 version: "3" diff --git a/api/v1alpha1/linodeclustertemplate_conversion.go b/api/v1alpha1/linodeclustertemplate_conversion.go index 442e9a93..b7158256 100644 --- a/api/v1alpha1/linodeclustertemplate_conversion.go +++ b/api/v1alpha1/linodeclustertemplate_conversion.go @@ -64,7 +64,7 @@ func (dst *LinodeClusterTemplate) ConvertFrom(srcRaw conversion.Hub) error { return nil } -// ConvertTo converts this DOClusterList to the Hub version (v1alpha2). +// ConvertTo converts this LinodeClusterTemplateList to the Hub version (v1alpha2). func (src *LinodeClusterTemplateList) ConvertTo(dstRaw conversion.Hub) error { dst, ok := dstRaw.(*infrastructurev1alpha2.LinodeClusterTemplateList) if !ok { diff --git a/api/v1alpha1/linodemachinetemplate_conversion.go b/api/v1alpha1/linodemachinetemplate_conversion.go new file mode 100644 index 00000000..2e135548 --- /dev/null +++ b/api/v1alpha1/linodemachinetemplate_conversion.go @@ -0,0 +1,83 @@ +/* +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" + + utilconversion "sigs.k8s.io/cluster-api/util/conversion" + "sigs.k8s.io/controller-runtime/pkg/conversion" + + infrastructurev1alpha2 "github.com/linode/cluster-api-provider-linode/api/v1alpha2" +) + +// ConvertTo converts this LinodeMachineTemplate to the Hub version (v1alpha2). +func (src *LinodeMachineTemplate) ConvertTo(dstRaw conversion.Hub) error { + dst, ok := dstRaw.(*infrastructurev1alpha2.LinodeMachineTemplate) + if !ok { + return errors.New("failed to convert LinodeMachineTemplate version from v1alpha1 to v1alpha2") + } + + if err := Convert_v1alpha1_LinodeMachineTemplate_To_v1alpha2_LinodeMachineTemplate(src, dst, nil); err != nil { + return err + } + + // Manually restore data from annotations + restored := &LinodeMachineTemplate{} + if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { + return err + } + + return nil +} + +// ConvertFrom converts from the Hub version (v1alpha2) to this version. +func (dst *LinodeMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error { + src, ok := srcRaw.(*infrastructurev1alpha2.LinodeMachineTemplate) + if !ok { + return errors.New("failed to convert LinodeMachineTemplate version from v1alpha2 to v1alpha1") + } + + if err := Convert_v1alpha2_LinodeMachineTemplate_To_v1alpha1_LinodeMachineTemplate(src, dst, nil); err != nil { + return err + } + + // Preserve Hub data on down-conversion. + if err := utilconversion.MarshalData(src, dst); err != nil { + return err + } + + return nil +} + +// ConvertTo converts this LinodeMachineTemplateList to the Hub version (v1alpha2). +func (src *LinodeMachineTemplateList) ConvertTo(dstRaw conversion.Hub) error { + dst, ok := dstRaw.(*infrastructurev1alpha2.LinodeMachineTemplateList) + if !ok { + return errors.New("failed to convert LinodeMachineTemplate version from v1alpha1 to v1alpha2") + } + return Convert_v1alpha1_LinodeMachineTemplateList_To_v1alpha2_LinodeMachineTemplateList(src, dst, nil) +} + +// ConvertFrom converts from the Hub version (v1alpha2) to this version. +func (dst *LinodeMachineTemplateList) ConvertFrom(srcRaw conversion.Hub) error { + src, ok := srcRaw.(*infrastructurev1alpha2.LinodeMachineTemplateList) + if !ok { + return errors.New("failed to convert LinodeMachineTemplate version from v1alpha2 to v1alpha1") + } + return Convert_v1alpha2_LinodeMachineTemplateList_To_v1alpha1_LinodeMachineTemplateList(src, dst, nil) +} diff --git a/api/v1alpha1/linodemachinetemplate_conversion_test.go b/api/v1alpha1/linodemachinetemplate_conversion_test.go new file mode 100644 index 00000000..8b1ad273 --- /dev/null +++ b/api/v1alpha1/linodemachinetemplate_conversion_test.go @@ -0,0 +1,269 @@ +/* +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" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/ptr" + utilconversion "sigs.k8s.io/cluster-api/util/conversion" + + infrav1alpha2 "github.com/linode/cluster-api-provider-linode/api/v1alpha2" + "github.com/linode/cluster-api-provider-linode/mock" + + . "github.com/linode/cluster-api-provider-linode/mock/mocktest" +) + +func TestLinodeMachineTemplateConvertTo(t *testing.T) { + t.Parallel() + + src := &LinodeMachineTemplate{ + ObjectMeta: metav1.ObjectMeta{Name: "test-machine"}, + Spec: LinodeMachineTemplateSpec{ + Template: LinodeMachineTemplateResource{ + Spec: LinodeMachineSpec{ + ProviderID: ptr.To("linode://1234"), + InstanceID: ptr.To(1234), + Region: "us-mia", + Type: "g6-standard-2", + Group: "", + RootPass: "abc123", + AuthorizedKeys: []string{"authorizedKey1"}, + AuthorizedUsers: []string{"authorizedUser1"}, + BackupID: 1234, + Image: "linode/ubuntu24.04", + Interfaces: []InstanceConfigInterfaceCreateOptions{{Primary: true}}, + BackupsEnabled: false, + PrivateIP: ptr.To(true), + Tags: []string{"test instance"}, + FirewallID: 123, + OSDisk: ptr.To(InstanceDisk{ + DiskID: 0, + Size: *resource.NewQuantity(12, resource.DecimalSI), + Label: "main disk", + Filesystem: "", + }), + DataDisks: map[string]*InstanceDisk{"sdb": { + DiskID: 0, + Size: *resource.NewQuantity(145, resource.DecimalSI), + Label: "etcd disk", + Filesystem: "", + }, + "sdc": { + DiskID: 0, + Size: *resource.NewQuantity(543, resource.DecimalSI), + Label: "another disk", + Filesystem: "", + }}, + CredentialsRef: &corev1.SecretReference{ + Namespace: "default", + Name: "cred-secret", + }, + }, + }, + }, + } + expectedDst := &infrav1alpha2.LinodeMachineTemplate{ + ObjectMeta: metav1.ObjectMeta{Name: "test-machine"}, + Spec: infrav1alpha2.LinodeMachineTemplateSpec{ + Template: infrav1alpha2.LinodeMachineTemplateResource{ + Spec: infrav1alpha2.LinodeMachineSpec{ + ProviderID: ptr.To("linode://1234"), + InstanceID: ptr.To(1234), + Region: "us-mia", + Type: "g6-standard-2", + Group: "", + RootPass: "abc123", + AuthorizedKeys: []string{"authorizedKey1"}, + AuthorizedUsers: []string{"authorizedUser1"}, + BackupID: 1234, + Image: "linode/ubuntu24.04", + Interfaces: []infrav1alpha2.InstanceConfigInterfaceCreateOptions{{Primary: true}}, + BackupsEnabled: false, + PrivateIP: ptr.To(true), + Tags: []string{"test instance"}, + FirewallID: 123, + OSDisk: ptr.To(infrav1alpha2.InstanceDisk{ + DiskID: 0, + Size: *resource.NewQuantity(12, resource.DecimalSI), + Label: "main disk", + Filesystem: "", + }), + DataDisks: map[string]*infrav1alpha2.InstanceDisk{"sdb": { + DiskID: 0, + Size: *resource.NewQuantity(145, resource.DecimalSI), + Label: "etcd disk", + Filesystem: "", + }, + "sdc": { + DiskID: 0, + Size: *resource.NewQuantity(543, resource.DecimalSI), + Label: "another disk", + Filesystem: "", + }}, + CredentialsRef: &corev1.SecretReference{ + Namespace: "default", + Name: "cred-secret", + }, + }, + }, + }, + } + dst := &infrav1alpha2.LinodeMachineTemplate{} + + 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 TestLinodeMachineTemplateConvertFrom(t *testing.T) { + t.Parallel() + + src := &infrav1alpha2.LinodeMachineTemplate{ + ObjectMeta: metav1.ObjectMeta{Name: "test-machine"}, + Spec: infrav1alpha2.LinodeMachineTemplateSpec{ + Template: infrav1alpha2.LinodeMachineTemplateResource{ + Spec: infrav1alpha2.LinodeMachineSpec{ + ProviderID: ptr.To("linode://1234"), + InstanceID: ptr.To(1234), + Region: "us-mia", + Type: "g6-standard-2", + Group: "", + RootPass: "abc123", + AuthorizedKeys: []string{"authorizedKey1"}, + AuthorizedUsers: []string{"authorizedUser1"}, + BackupID: 1234, + Image: "linode/ubuntu24.04", + Interfaces: []infrav1alpha2.InstanceConfigInterfaceCreateOptions{{Primary: true}}, + BackupsEnabled: false, + PrivateIP: ptr.To(true), + Tags: []string{"test instance"}, + FirewallID: 123, + OSDisk: ptr.To(infrav1alpha2.InstanceDisk{ + DiskID: 0, + Size: *resource.NewQuantity(12, resource.DecimalSI), + Label: "main disk", + Filesystem: "", + }), + DataDisks: map[string]*infrav1alpha2.InstanceDisk{"sdb": { + DiskID: 0, + Size: *resource.NewQuantity(145, resource.DecimalSI), + Label: "etcd disk", + Filesystem: "", + }, + "sdc": { + DiskID: 0, + Size: *resource.NewQuantity(543, resource.DecimalSI), + Label: "another disk", + Filesystem: "", + }}, + CredentialsRef: &corev1.SecretReference{ + Namespace: "default", + Name: "cred-secret", + }, + }, + }, + }, + } + expectedDst := &LinodeMachineTemplate{ + ObjectMeta: metav1.ObjectMeta{Name: "test-machine"}, + Spec: LinodeMachineTemplateSpec{ + Template: LinodeMachineTemplateResource{ + Spec: LinodeMachineSpec{ + ProviderID: ptr.To("linode://1234"), + InstanceID: ptr.To(1234), + Region: "us-mia", + Type: "g6-standard-2", + Group: "", + RootPass: "abc123", + AuthorizedKeys: []string{"authorizedKey1"}, + AuthorizedUsers: []string{"authorizedUser1"}, + BackupID: 1234, + Image: "linode/ubuntu24.04", + Interfaces: []InstanceConfigInterfaceCreateOptions{{Primary: true}}, + BackupsEnabled: false, + PrivateIP: ptr.To(true), + Tags: []string{"test instance"}, + FirewallID: 123, + OSDisk: ptr.To(InstanceDisk{ + DiskID: 0, + Size: *resource.NewQuantity(12, resource.DecimalSI), + Label: "main disk", + Filesystem: "", + }), + DataDisks: map[string]*InstanceDisk{"sdb": { + DiskID: 0, + Size: *resource.NewQuantity(145, resource.DecimalSI), + Label: "etcd disk", + Filesystem: "", + }, + "sdc": { + DiskID: 0, + Size: *resource.NewQuantity(543, resource.DecimalSI), + Label: "another disk", + Filesystem: "", + }}, + CredentialsRef: &corev1.SecretReference{ + Namespace: "default", + Name: "cred-secret", + }, + }, + }, + }, + } + if err := utilconversion.MarshalData(src, expectedDst); err != nil { + t.Fatalf("ConvertFrom failed: %v", err) + } + dst := &LinodeMachineTemplate{} + + 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) + } + }), + ), + ), + ) +} diff --git a/api/v1alpha1/zz_generated.conversion.go b/api/v1alpha1/zz_generated.conversion.go index 6d1185ec..b89d186a 100644 --- a/api/v1alpha1/zz_generated.conversion.go +++ b/api/v1alpha1/zz_generated.conversion.go @@ -189,6 +189,46 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddGeneratedConversionFunc((*LinodeMachineTemplate)(nil), (*v1alpha2.LinodeMachineTemplate)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_LinodeMachineTemplate_To_v1alpha2_LinodeMachineTemplate(a.(*LinodeMachineTemplate), b.(*v1alpha2.LinodeMachineTemplate), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1alpha2.LinodeMachineTemplate)(nil), (*LinodeMachineTemplate)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_LinodeMachineTemplate_To_v1alpha1_LinodeMachineTemplate(a.(*v1alpha2.LinodeMachineTemplate), b.(*LinodeMachineTemplate), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*LinodeMachineTemplateList)(nil), (*v1alpha2.LinodeMachineTemplateList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_LinodeMachineTemplateList_To_v1alpha2_LinodeMachineTemplateList(a.(*LinodeMachineTemplateList), b.(*v1alpha2.LinodeMachineTemplateList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1alpha2.LinodeMachineTemplateList)(nil), (*LinodeMachineTemplateList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_LinodeMachineTemplateList_To_v1alpha1_LinodeMachineTemplateList(a.(*v1alpha2.LinodeMachineTemplateList), b.(*LinodeMachineTemplateList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*LinodeMachineTemplateResource)(nil), (*v1alpha2.LinodeMachineTemplateResource)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_LinodeMachineTemplateResource_To_v1alpha2_LinodeMachineTemplateResource(a.(*LinodeMachineTemplateResource), b.(*v1alpha2.LinodeMachineTemplateResource), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1alpha2.LinodeMachineTemplateResource)(nil), (*LinodeMachineTemplateResource)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_LinodeMachineTemplateResource_To_v1alpha1_LinodeMachineTemplateResource(a.(*v1alpha2.LinodeMachineTemplateResource), b.(*LinodeMachineTemplateResource), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*LinodeMachineTemplateSpec)(nil), (*v1alpha2.LinodeMachineTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_LinodeMachineTemplateSpec_To_v1alpha2_LinodeMachineTemplateSpec(a.(*LinodeMachineTemplateSpec), b.(*v1alpha2.LinodeMachineTemplateSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1alpha2.LinodeMachineTemplateSpec)(nil), (*LinodeMachineTemplateSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_LinodeMachineTemplateSpec_To_v1alpha1_LinodeMachineTemplateSpec(a.(*v1alpha2.LinodeMachineTemplateSpec), b.(*LinodeMachineTemplateSpec), scope) + }); err != nil { + return err + } if err := s.AddGeneratedConversionFunc((*LinodeVPC)(nil), (*v1alpha2.LinodeVPC)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha1_LinodeVPC_To_v1alpha2_LinodeVPC(a.(*LinodeVPC), b.(*v1alpha2.LinodeVPC), scope) }); err != nil { @@ -726,6 +766,102 @@ func Convert_v1alpha2_LinodeMachineStatus_To_v1alpha1_LinodeMachineStatus(in *v1 return autoConvert_v1alpha2_LinodeMachineStatus_To_v1alpha1_LinodeMachineStatus(in, out, s) } +func autoConvert_v1alpha1_LinodeMachineTemplate_To_v1alpha2_LinodeMachineTemplate(in *LinodeMachineTemplate, out *v1alpha2.LinodeMachineTemplate, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v1alpha1_LinodeMachineTemplateSpec_To_v1alpha2_LinodeMachineTemplateSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha1_LinodeMachineTemplate_To_v1alpha2_LinodeMachineTemplate is an autogenerated conversion function. +func Convert_v1alpha1_LinodeMachineTemplate_To_v1alpha2_LinodeMachineTemplate(in *LinodeMachineTemplate, out *v1alpha2.LinodeMachineTemplate, s conversion.Scope) error { + return autoConvert_v1alpha1_LinodeMachineTemplate_To_v1alpha2_LinodeMachineTemplate(in, out, s) +} + +func autoConvert_v1alpha2_LinodeMachineTemplate_To_v1alpha1_LinodeMachineTemplate(in *v1alpha2.LinodeMachineTemplate, out *LinodeMachineTemplate, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v1alpha2_LinodeMachineTemplateSpec_To_v1alpha1_LinodeMachineTemplateSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha2_LinodeMachineTemplate_To_v1alpha1_LinodeMachineTemplate is an autogenerated conversion function. +func Convert_v1alpha2_LinodeMachineTemplate_To_v1alpha1_LinodeMachineTemplate(in *v1alpha2.LinodeMachineTemplate, out *LinodeMachineTemplate, s conversion.Scope) error { + return autoConvert_v1alpha2_LinodeMachineTemplate_To_v1alpha1_LinodeMachineTemplate(in, out, s) +} + +func autoConvert_v1alpha1_LinodeMachineTemplateList_To_v1alpha2_LinodeMachineTemplateList(in *LinodeMachineTemplateList, out *v1alpha2.LinodeMachineTemplateList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + out.Items = *(*[]v1alpha2.LinodeMachineTemplate)(unsafe.Pointer(&in.Items)) + return nil +} + +// Convert_v1alpha1_LinodeMachineTemplateList_To_v1alpha2_LinodeMachineTemplateList is an autogenerated conversion function. +func Convert_v1alpha1_LinodeMachineTemplateList_To_v1alpha2_LinodeMachineTemplateList(in *LinodeMachineTemplateList, out *v1alpha2.LinodeMachineTemplateList, s conversion.Scope) error { + return autoConvert_v1alpha1_LinodeMachineTemplateList_To_v1alpha2_LinodeMachineTemplateList(in, out, s) +} + +func autoConvert_v1alpha2_LinodeMachineTemplateList_To_v1alpha1_LinodeMachineTemplateList(in *v1alpha2.LinodeMachineTemplateList, out *LinodeMachineTemplateList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + out.Items = *(*[]LinodeMachineTemplate)(unsafe.Pointer(&in.Items)) + return nil +} + +// Convert_v1alpha2_LinodeMachineTemplateList_To_v1alpha1_LinodeMachineTemplateList is an autogenerated conversion function. +func Convert_v1alpha2_LinodeMachineTemplateList_To_v1alpha1_LinodeMachineTemplateList(in *v1alpha2.LinodeMachineTemplateList, out *LinodeMachineTemplateList, s conversion.Scope) error { + return autoConvert_v1alpha2_LinodeMachineTemplateList_To_v1alpha1_LinodeMachineTemplateList(in, out, s) +} + +func autoConvert_v1alpha1_LinodeMachineTemplateResource_To_v1alpha2_LinodeMachineTemplateResource(in *LinodeMachineTemplateResource, out *v1alpha2.LinodeMachineTemplateResource, s conversion.Scope) error { + if err := Convert_v1alpha1_LinodeMachineSpec_To_v1alpha2_LinodeMachineSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha1_LinodeMachineTemplateResource_To_v1alpha2_LinodeMachineTemplateResource is an autogenerated conversion function. +func Convert_v1alpha1_LinodeMachineTemplateResource_To_v1alpha2_LinodeMachineTemplateResource(in *LinodeMachineTemplateResource, out *v1alpha2.LinodeMachineTemplateResource, s conversion.Scope) error { + return autoConvert_v1alpha1_LinodeMachineTemplateResource_To_v1alpha2_LinodeMachineTemplateResource(in, out, s) +} + +func autoConvert_v1alpha2_LinodeMachineTemplateResource_To_v1alpha1_LinodeMachineTemplateResource(in *v1alpha2.LinodeMachineTemplateResource, out *LinodeMachineTemplateResource, s conversion.Scope) error { + if err := Convert_v1alpha2_LinodeMachineSpec_To_v1alpha1_LinodeMachineSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha2_LinodeMachineTemplateResource_To_v1alpha1_LinodeMachineTemplateResource is an autogenerated conversion function. +func Convert_v1alpha2_LinodeMachineTemplateResource_To_v1alpha1_LinodeMachineTemplateResource(in *v1alpha2.LinodeMachineTemplateResource, out *LinodeMachineTemplateResource, s conversion.Scope) error { + return autoConvert_v1alpha2_LinodeMachineTemplateResource_To_v1alpha1_LinodeMachineTemplateResource(in, out, s) +} + +func autoConvert_v1alpha1_LinodeMachineTemplateSpec_To_v1alpha2_LinodeMachineTemplateSpec(in *LinodeMachineTemplateSpec, out *v1alpha2.LinodeMachineTemplateSpec, s conversion.Scope) error { + if err := Convert_v1alpha1_LinodeMachineTemplateResource_To_v1alpha2_LinodeMachineTemplateResource(&in.Template, &out.Template, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha1_LinodeMachineTemplateSpec_To_v1alpha2_LinodeMachineTemplateSpec is an autogenerated conversion function. +func Convert_v1alpha1_LinodeMachineTemplateSpec_To_v1alpha2_LinodeMachineTemplateSpec(in *LinodeMachineTemplateSpec, out *v1alpha2.LinodeMachineTemplateSpec, s conversion.Scope) error { + return autoConvert_v1alpha1_LinodeMachineTemplateSpec_To_v1alpha2_LinodeMachineTemplateSpec(in, out, s) +} + +func autoConvert_v1alpha2_LinodeMachineTemplateSpec_To_v1alpha1_LinodeMachineTemplateSpec(in *v1alpha2.LinodeMachineTemplateSpec, out *LinodeMachineTemplateSpec, s conversion.Scope) error { + if err := Convert_v1alpha2_LinodeMachineTemplateResource_To_v1alpha1_LinodeMachineTemplateResource(&in.Template, &out.Template, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha2_LinodeMachineTemplateSpec_To_v1alpha1_LinodeMachineTemplateSpec is an autogenerated conversion function. +func Convert_v1alpha2_LinodeMachineTemplateSpec_To_v1alpha1_LinodeMachineTemplateSpec(in *v1alpha2.LinodeMachineTemplateSpec, out *LinodeMachineTemplateSpec, s conversion.Scope) error { + return autoConvert_v1alpha2_LinodeMachineTemplateSpec_To_v1alpha1_LinodeMachineTemplateSpec(in, out, s) +} + func autoConvert_v1alpha1_LinodeVPC_To_v1alpha2_LinodeVPC(in *LinodeVPC, out *v1alpha2.LinodeVPC, s conversion.Scope) error { out.ObjectMeta = in.ObjectMeta if err := Convert_v1alpha1_LinodeVPCSpec_To_v1alpha2_LinodeVPCSpec(&in.Spec, &out.Spec, s); err != nil { diff --git a/api/v1alpha2/linodemachinetemplate_conversion.go b/api/v1alpha2/linodemachinetemplate_conversion.go new file mode 100644 index 00000000..df622c38 --- /dev/null +++ b/api/v1alpha2/linodemachinetemplate_conversion.go @@ -0,0 +1,23 @@ +/* +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 + +// Hub marks LinodeMachineTemplate as a conversion hub. +func (*LinodeMachineTemplate) Hub() {} + +// Hub marks LinodeMachineTemplateList as a conversion hub. +func (*LinodeMachineTemplateList) Hub() {} diff --git a/api/v1alpha2/linodemachinetemplate_types.go b/api/v1alpha2/linodemachinetemplate_types.go new file mode 100644 index 00000000..a183c0d3 --- /dev/null +++ b/api/v1alpha2/linodemachinetemplate_types.go @@ -0,0 +1,56 @@ +/* +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 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// LinodeMachineTemplateSpec defines the desired state of LinodeMachineTemplate +type LinodeMachineTemplateSpec struct { + Template LinodeMachineTemplateResource `json:"template"` +} + +// LinodeMachineTemplateResource describes the data needed to create a LinodeMachine from a template. +type LinodeMachineTemplateResource struct { + Spec LinodeMachineSpec `json:"spec"` +} + +// +kubebuilder:object:root=true +// +kubebuilder:storageversion +// +kubebuilder:resource:path=linodemachinetemplates,scope=Namespaced,categories=cluster-api,shortName=lmt + +// LinodeMachineTemplate is the Schema for the linodemachinetemplates API +type LinodeMachineTemplate struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec LinodeMachineTemplateSpec `json:"spec,omitempty"` +} + +// +kubebuilder:object:root=true + +// LinodeMachineTemplateList contains a list of LinodeMachineTemplate +type LinodeMachineTemplateList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []LinodeMachineTemplate `json:"items"` +} + +func init() { + SchemeBuilder.Register(&LinodeMachineTemplate{}, &LinodeMachineTemplateList{}) +} diff --git a/api/v1alpha2/linodemachinetemplate_webhook.go b/api/v1alpha2/linodemachinetemplate_webhook.go new file mode 100644 index 00000000..56bd21f8 --- /dev/null +++ b/api/v1alpha2/linodemachinetemplate_webhook.go @@ -0,0 +1,28 @@ +/* +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 + +import ( + ctrl "sigs.k8s.io/controller-runtime" +) + +// SetupWebhookWithManager will setup the manager to manage the webhooks +func (r *LinodeMachineTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error { + return ctrl.NewWebhookManagedBy(mgr). + For(r). + Complete() +} diff --git a/api/v1alpha2/linodemachinetemplate_webhook_test.go b/api/v1alpha2/linodemachinetemplate_webhook_test.go new file mode 100644 index 00000000..ba1504da --- /dev/null +++ b/api/v1alpha2/linodemachinetemplate_webhook_test.go @@ -0,0 +1,33 @@ +/* +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 + +import ( + . "github.com/onsi/ginkgo/v2" +) + +var _ = Describe("LinodeMachineTemplate Webhook", func() { + + Context("When creating LinodeMachineTemplate under Conversion Webhook", func() { + It("Should get the converted version of LinodeMachineTemplate", func() { + + // TODO(user): Add your logic here + + }) + }) + +}) diff --git a/api/v1alpha2/zz_generated.deepcopy.go b/api/v1alpha2/zz_generated.deepcopy.go index 12bf16a4..61fc97c6 100644 --- a/api/v1alpha2/zz_generated.deepcopy.go +++ b/api/v1alpha2/zz_generated.deepcopy.go @@ -476,6 +476,96 @@ func (in *LinodeMachineStatus) DeepCopy() *LinodeMachineStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LinodeMachineTemplate) DeepCopyInto(out *LinodeMachineTemplate) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LinodeMachineTemplate. +func (in *LinodeMachineTemplate) DeepCopy() *LinodeMachineTemplate { + if in == nil { + return nil + } + out := new(LinodeMachineTemplate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *LinodeMachineTemplate) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LinodeMachineTemplateList) DeepCopyInto(out *LinodeMachineTemplateList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]LinodeMachineTemplate, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LinodeMachineTemplateList. +func (in *LinodeMachineTemplateList) DeepCopy() *LinodeMachineTemplateList { + if in == nil { + return nil + } + out := new(LinodeMachineTemplateList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *LinodeMachineTemplateList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LinodeMachineTemplateResource) DeepCopyInto(out *LinodeMachineTemplateResource) { + *out = *in + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LinodeMachineTemplateResource. +func (in *LinodeMachineTemplateResource) DeepCopy() *LinodeMachineTemplateResource { + if in == nil { + return nil + } + out := new(LinodeMachineTemplateResource) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *LinodeMachineTemplateSpec) DeepCopyInto(out *LinodeMachineTemplateSpec) { + *out = *in + in.Template.DeepCopyInto(&out.Template) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LinodeMachineTemplateSpec. +func (in *LinodeMachineTemplateSpec) DeepCopy() *LinodeMachineTemplateSpec { + if in == nil { + return nil + } + out := new(LinodeMachineTemplateSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LinodeNBPortConfig) DeepCopyInto(out *LinodeNBPortConfig) { *out = *in diff --git a/cmd/main.go b/cmd/main.go index a9ee2aea..e6af1b55 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -279,6 +279,10 @@ func setupWebhooks(mgr manager.Manager) { setupLog.Error(err, "unable to create webhook", "webhook", "LinodeMachine") os.Exit(1) } + if err = (&infrastructurev1alpha2.LinodeMachineTemplate{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "LinodeCluster") + os.Exit(1) + } if err = (&infrastructurev1alpha1.LinodeVPC{}).SetupWebhookWithManager(mgr); err != nil { setupLog.Error(err, "unable to create webhook", "webhook", "LinodeVPC") os.Exit(1) diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachinetemplates.yaml index 6e23c453..17ebc48f 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_linodemachinetemplates.yaml @@ -262,4 +262,249 @@ spec: type: object type: object served: true + storage: false + - name: v1alpha2 + schema: + openAPIV3Schema: + description: LinodeMachineTemplate is the Schema for the linodemachinetemplates + API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: LinodeMachineTemplateSpec defines the desired state of LinodeMachineTemplate + properties: + template: + description: LinodeMachineTemplateResource describes the data needed + to create a LinodeMachine from a template. + properties: + spec: + description: LinodeMachineSpec defines the desired state of LinodeMachine + properties: + authorizedKeys: + items: + type: string + type: array + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf + authorizedUsers: + items: + type: string + type: array + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf + backupID: + type: integer + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf + backupsEnabled: + type: boolean + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf + credentialsRef: + description: |- + CredentialsRef is a reference to a Secret that contains the credentials + to use for provisioning this machine. If not supplied then these + credentials will be used in-order: + 1. LinodeMachine + 2. Owner LinodeCluster + 3. Controller + properties: + name: + description: name is unique within a namespace to reference + a secret resource. + type: string + namespace: + description: namespace defines the space within which + the secret name must be unique. + type: string + type: object + x-kubernetes-map-type: atomic + dataDisks: + additionalProperties: + description: InstanceDisk defines a list of disks to use + for an instance + properties: + diskID: + description: DiskID is the linode assigned ID of the + disk + type: integer + filesystem: + description: Filesystem of disk to provision, the default + disk filesystem is "ext4" + enum: + - raw + - swap + - ext3 + - ext4 + - initrd + type: string + label: + description: Label for the instance disk, if nothing + is provided it will match the device name + type: string + size: + anyOf: + - type: integer + - type: string + description: Size of the disk in resource.Quantity notation + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + required: + - size + type: object + description: |- + DataDisks is a map of any additional disks to add to an instance, + The sum of these disks + the OSDisk must not be more than allowed on a linodes plan + type: object + firewallID: + type: integer + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf + group: + type: string + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf + image: + type: string + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf + instanceID: + description: InstanceID is the Linode instance ID for this + machine. + type: integer + interfaces: + items: + description: InstanceConfigInterfaceCreateOptions defines + network interface config + properties: + ipRanges: + items: + type: string + type: array + ipamAddress: + type: string + ipv4: + description: VPCIPv4 defines VPC IPV4 settings + properties: + nat1to1: + type: string + vpc: + type: string + type: object + label: + maxLength: 63 + minLength: 3 + type: string + primary: + type: boolean + purpose: + description: ConfigInterfacePurpose options start with + InterfacePurpose and include all known interface purpose + types + type: string + subnetId: + type: integer + type: object + type: array + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf + osDisk: + description: |- + OSDisk is configuration for the root disk that includes the OS, + if not specified this defaults to whatever space is not taken up by the DataDisks + properties: + diskID: + description: DiskID is the linode assigned ID of the disk + type: integer + filesystem: + description: Filesystem of disk to provision, the default + disk filesystem is "ext4" + enum: + - raw + - swap + - ext3 + - ext4 + - initrd + type: string + label: + description: Label for the instance disk, if nothing is + provided it will match the device name + type: string + size: + anyOf: + - type: integer + - type: string + description: Size of the disk in resource.Quantity notation + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + required: + - size + type: object + privateIP: + type: boolean + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf + providerID: + description: ProviderID is the unique identifier as specified + by the cloud provider. + type: string + region: + type: string + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf + rootPass: + type: string + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf + tags: + items: + type: string + type: array + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf + type: + type: string + x-kubernetes-validations: + - message: Value is immutable + rule: self == oldSelf + required: + - region + - type + type: object + required: + - spec + type: object + required: + - template + type: object + type: object + served: true storage: true diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index e867863e..660d564d 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -33,6 +33,7 @@ patches: - path: patches/webhook_in_linodevpcs.yaml - path: patches/webhook_in_linodevpcs.yaml - path: patches/webhook_in_linodeclustertemplates.yaml +- path: patches/webhook_in_linodemachinetemplates.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch - path: patches/capicontract_in_linodeclusters.yaml diff --git a/config/rbac/kustomization.yaml b/config/rbac/kustomization.yaml index c72c7aad..a65a526e 100644 --- a/config/rbac/kustomization.yaml +++ b/config/rbac/kustomization.yaml @@ -20,6 +20,8 @@ resources: # default, aiding admins in cluster management. Those roles are # not used by the Project itself. You can comment the following lines # if you do not want those helpers be installed with your Project. +- linodemachinetemplate_editor_role.yaml +- linodemachinetemplate_viewer_role.yaml - linodeclustertemplate_editor_role.yaml - linodeclustertemplate_viewer_role.yaml - linodevpc_editor_role.yaml diff --git a/config/samples/infrastructure_v1alpha2_linodemachinetemplate.yaml b/config/samples/infrastructure_v1alpha2_linodemachinetemplate.yaml new file mode 100644 index 00000000..d8fd2c5a --- /dev/null +++ b/config/samples/infrastructure_v1alpha2_linodemachinetemplate.yaml @@ -0,0 +1,9 @@ +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 +kind: LinodeMachineTemplate +metadata: + labels: + app.kubernetes.io/name: cluster-api-provider-linode + app.kubernetes.io/managed-by: kustomize + name: linodemachinetemplate-sample +spec: + # TODO(user): Add fields here diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yaml index 66b59dad..c1575ff4 100644 --- a/config/samples/kustomization.yaml +++ b/config/samples/kustomization.yaml @@ -10,4 +10,5 @@ resources: - infrastructure_v1alpha2_linodemachine.yaml - infrastructure_v1alpha2_linodevpc.yaml - infrastructure_v1alpha2_linodeclustertemplate.yaml +- infrastructure_v1alpha2_linodemachinetemplate.yaml #+kubebuilder:scaffold:manifestskustomizesamples diff --git a/e2e/admission-webhooks/validating/chainsaw-test.yaml b/e2e/admission-webhooks/validating/chainsaw-test.yaml index 581fd307..027ea92d 100644 --- a/e2e/admission-webhooks/validating/chainsaw-test.yaml +++ b/e2e/admission-webhooks/validating/chainsaw-test.yaml @@ -8,6 +8,7 @@ metadata: labels: all: webhook: + quick: spec: bindings: # A short identifier for the E2E test run diff --git a/e2e/admission-webhooks/validating/invalid-linodevpc.yaml b/e2e/admission-webhooks/validating/invalid-linodevpc.yaml index e3a18f21..23727b65 100644 --- a/e2e/admission-webhooks/validating/invalid-linodevpc.yaml +++ b/e2e/admission-webhooks/validating/invalid-linodevpc.yaml @@ -1,5 +1,5 @@ --- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeVPC metadata: name: ($name) diff --git a/e2e/linodevpc-controller/minimal-linodevpc/assert-vpc.yaml b/e2e/linodevpc-controller/minimal-linodevpc/assert-vpc.yaml index 116e1ad0..7d5158e9 100644 --- a/e2e/linodevpc-controller/minimal-linodevpc/assert-vpc.yaml +++ b/e2e/linodevpc-controller/minimal-linodevpc/assert-vpc.yaml @@ -1,4 +1,4 @@ -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeVPC metadata: name: ($vpc) diff --git a/e2e/linodevpc-controller/minimal-linodevpc/chainsaw-test.yaml b/e2e/linodevpc-controller/minimal-linodevpc/chainsaw-test.yaml index 951f23eb..af590162 100644 --- a/e2e/linodevpc-controller/minimal-linodevpc/chainsaw-test.yaml +++ b/e2e/linodevpc-controller/minimal-linodevpc/chainsaw-test.yaml @@ -30,7 +30,7 @@ spec: file: assert-vpc.yaml catch: - describe: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeVPC - name: Check if the VPC was created try: @@ -53,7 +53,7 @@ spec: try: - delete: ref: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeVPC name: ($vpc) - error: diff --git a/e2e/linodevpc-controller/minimal-linodevpc/check-vpc-deletion.yaml b/e2e/linodevpc-controller/minimal-linodevpc/check-vpc-deletion.yaml index 1f39afc8..fbc936ec 100644 --- a/e2e/linodevpc-controller/minimal-linodevpc/check-vpc-deletion.yaml +++ b/e2e/linodevpc-controller/minimal-linodevpc/check-vpc-deletion.yaml @@ -1,4 +1,4 @@ -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeVPC metadata: name: ($vpc) diff --git a/e2e/linodevpc-controller/minimal-linodevpc/create-vpc.yaml b/e2e/linodevpc-controller/minimal-linodevpc/create-vpc.yaml index 1f39afc8..fbc936ec 100644 --- a/e2e/linodevpc-controller/minimal-linodevpc/create-vpc.yaml +++ b/e2e/linodevpc-controller/minimal-linodevpc/create-vpc.yaml @@ -1,4 +1,4 @@ -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeVPC metadata: name: ($vpc) diff --git a/templates/flavors/clusterclass-kubeadm/clusterClass.yaml b/templates/flavors/clusterclass-kubeadm/clusterClass.yaml index c9ac5b8b..4421be34 100644 --- a/templates/flavors/clusterclass-kubeadm/clusterClass.yaml +++ b/templates/flavors/clusterclass-kubeadm/clusterClass.yaml @@ -10,12 +10,12 @@ spec: name: kubeadm-control-plane machineInfrastructure: ref: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate name: kubeadm-control-plane infrastructure: ref: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeClusterTemplate name: kubeadm workers: @@ -29,7 +29,7 @@ spec: name: kubeadm-worker infrastructure: ref: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate name: kubeadm-worker variables: @@ -61,7 +61,7 @@ spec: - name: region definitions: - selector: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeClusterTemplate matchResources: infrastructureCluster: true @@ -71,7 +71,7 @@ spec: valueFrom: variable: region - selector: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate matchResources: controlPlane: true @@ -81,7 +81,7 @@ spec: valueFrom: variable: region - selector: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate matchResources: machineDeploymentClass: @@ -95,7 +95,7 @@ spec: - name: controlPlaneMachineType definitions: - selector: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate matchResources: controlPlane: true @@ -107,7 +107,7 @@ spec: - name: workerMachineType definitions: - selector: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate matchResources: machineDeploymentClass: @@ -121,7 +121,7 @@ spec: - name: osImage definitions: - selector: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate matchResources: machineDeploymentClass: @@ -133,7 +133,7 @@ spec: valueFrom: variable: osImage - selector: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate matchResources: controlPlane: true diff --git a/templates/flavors/clusterclass-kubeadm/deleteTransformer.yaml b/templates/flavors/clusterclass-kubeadm/deleteTransformer.yaml index 492b3239..43d4f36d 100644 --- a/templates/flavors/clusterclass-kubeadm/deleteTransformer.yaml +++ b/templates/flavors/clusterclass-kubeadm/deleteTransformer.yaml @@ -64,17 +64,3 @@ patch: |- - op: remove path: /spec/template/spec/version value: -# patch: |- -# $patch: delete -# apiVersion: controlplane.cluster.x-k8s.io/v1beta1 -# kind: KubeadmControlPlaneTemplate -# metadata: -# name: kubeadm-control-plane -# spec: -# machineTemplate: -# infrastructureRef: -# apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -# kind: LinodeMachineTemplate -# name: ${CLUSTER_NAME}-control-plane -# replicas: ${CONTROL_PLANE_MACHINE_COUNT} -# version: ${KUBERNETES_VERSION} diff --git a/templates/flavors/clusterclass-kubeadm/kustomization.yaml b/templates/flavors/clusterclass-kubeadm/kustomization.yaml index fc13c216..80bb2f85 100644 --- a/templates/flavors/clusterclass-kubeadm/kustomization.yaml +++ b/templates/flavors/clusterclass-kubeadm/kustomization.yaml @@ -20,7 +20,7 @@ patches: options: allowNameChange: true patch: |- - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate metadata: name: kubeadm-worker @@ -33,7 +33,7 @@ patches: options: allowNameChange: true patch: |- - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate metadata: name: kubeadm-control-plane diff --git a/templates/flavors/clusterclass-kubeadm/linodeClusterTemplate.yaml b/templates/flavors/clusterclass-kubeadm/linodeClusterTemplate.yaml index 1e3f6d74..2bc66d9a 100644 --- a/templates/flavors/clusterclass-kubeadm/linodeClusterTemplate.yaml +++ b/templates/flavors/clusterclass-kubeadm/linodeClusterTemplate.yaml @@ -1,4 +1,4 @@ -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeClusterTemplate metadata: name: kubeadm diff --git a/templates/flavors/k3s/default/k3sControlPlane.yaml b/templates/flavors/k3s/default/k3sControlPlane.yaml index c4aa4207..7a9c4585 100644 --- a/templates/flavors/k3s/default/k3sControlPlane.yaml +++ b/templates/flavors/k3s/default/k3sControlPlane.yaml @@ -5,7 +5,7 @@ metadata: name: ${CLUSTER_NAME}-control-plane spec: infrastructureTemplate: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate name: ${CLUSTER_NAME}-control-plane kthreesConfigSpec: diff --git a/templates/flavors/kubeadm/cilium-bgp-lb/linodeMachineTemplate.yaml b/templates/flavors/kubeadm/cilium-bgp-lb/linodeMachineTemplate.yaml index 943988db..15047c98 100644 --- a/templates/flavors/kubeadm/cilium-bgp-lb/linodeMachineTemplate.yaml +++ b/templates/flavors/kubeadm/cilium-bgp-lb/linodeMachineTemplate.yaml @@ -1,4 +1,4 @@ -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate metadata: name: ${CLUSTER_NAME}-md-bgp diff --git a/templates/flavors/kubeadm/default/kubeadmControlPlane.yaml b/templates/flavors/kubeadm/default/kubeadmControlPlane.yaml index 666cbfa3..9de72b19 100644 --- a/templates/flavors/kubeadm/default/kubeadmControlPlane.yaml +++ b/templates/flavors/kubeadm/default/kubeadmControlPlane.yaml @@ -8,7 +8,7 @@ spec: machineTemplate: infrastructureRef: kind: LinodeMachineTemplate - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 name: ${CLUSTER_NAME}-control-plane kubeadmConfigSpec: preKubeadmCommands: diff --git a/templates/flavors/kubeadm/etcd-disk/kustomization.yaml b/templates/flavors/kubeadm/etcd-disk/kustomization.yaml index bcb0dbca..55327e90 100644 --- a/templates/flavors/kubeadm/etcd-disk/kustomization.yaml +++ b/templates/flavors/kubeadm/etcd-disk/kustomization.yaml @@ -11,7 +11,7 @@ patches: kind: LinodeMachineTemplate name: .*-control-plane patch: |- - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate metadata: name: ${CLUSTER_NAME}-control-plane diff --git a/templates/flavors/kubeadm/full-vpcless/kustomization.yaml b/templates/flavors/kubeadm/full-vpcless/kustomization.yaml index aa46bfca..d528bd03 100644 --- a/templates/flavors/kubeadm/full-vpcless/kustomization.yaml +++ b/templates/flavors/kubeadm/full-vpcless/kustomization.yaml @@ -117,7 +117,7 @@ patches: kind: LinodeMachineTemplate name: .*-control-plane patch: |- - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate metadata: name: ${CLUSTER_NAME}-control-plane diff --git a/templates/flavors/kubeadm/full/kustomization.yaml b/templates/flavors/kubeadm/full/kustomization.yaml index fa7955f3..9a05e63b 100644 --- a/templates/flavors/kubeadm/full/kustomization.yaml +++ b/templates/flavors/kubeadm/full/kustomization.yaml @@ -14,7 +14,7 @@ patches: kind: LinodeMachineTemplate name: .*-control-plane patch: |- - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate metadata: name: ${CLUSTER_NAME}-control-plane diff --git a/templates/flavors/rke2/default/rke2ControlPlane.yaml b/templates/flavors/rke2/default/rke2ControlPlane.yaml index 9f9ded4f..e578e016 100644 --- a/templates/flavors/rke2/default/rke2ControlPlane.yaml +++ b/templates/flavors/rke2/default/rke2ControlPlane.yaml @@ -5,7 +5,7 @@ metadata: name: ${CLUSTER_NAME}-control-plane spec: infrastructureRef: - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate name: ${CLUSTER_NAME}-control-plane registrationMethod: internal-only-ips diff --git a/templates/flavors/rke2/etcd-disk/kustomization.yaml b/templates/flavors/rke2/etcd-disk/kustomization.yaml index bc04d68e..f78ffb7c 100644 --- a/templates/flavors/rke2/etcd-disk/kustomization.yaml +++ b/templates/flavors/rke2/etcd-disk/kustomization.yaml @@ -11,7 +11,7 @@ patches: kind: LinodeMachineTemplate name: .*-control-plane patch: |- - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate metadata: name: ${CLUSTER_NAME}-control-plane diff --git a/templates/flavors/rke2/full-vpcless/kustomization.yaml b/templates/flavors/rke2/full-vpcless/kustomization.yaml index 6cad8ee5..bd6699c9 100644 --- a/templates/flavors/rke2/full-vpcless/kustomization.yaml +++ b/templates/flavors/rke2/full-vpcless/kustomization.yaml @@ -38,7 +38,7 @@ patches: kind: LinodeMachineTemplate name: .*-control-plane patch: |- - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate metadata: name: ${CLUSTER_NAME}-control-plane diff --git a/templates/flavors/rke2/full/kustomization.yaml b/templates/flavors/rke2/full/kustomization.yaml index 0276a2ab..388f4578 100644 --- a/templates/flavors/rke2/full/kustomization.yaml +++ b/templates/flavors/rke2/full/kustomization.yaml @@ -38,7 +38,7 @@ patches: kind: LinodeMachineTemplate name: .*-control-plane patch: |- - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate metadata: name: ${CLUSTER_NAME}-control-plane diff --git a/templates/infra/linodeMachineTemplate.yaml b/templates/infra/linodeMachineTemplate.yaml index 347cbab5..16b213cf 100644 --- a/templates/infra/linodeMachineTemplate.yaml +++ b/templates/infra/linodeMachineTemplate.yaml @@ -1,6 +1,6 @@ --- kind: LinodeMachineTemplate -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 metadata: name: ${CLUSTER_NAME}-control-plane spec: @@ -15,7 +15,7 @@ spec: # uncomment to include your ssh key in linode provisioning # - ${LINODE_SSH_PUBKEY} --- -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate metadata: name: ${CLUSTER_NAME}-md-0 diff --git a/templates/infra/machineDeployment.yaml b/templates/infra/machineDeployment.yaml index ea513bf8..355c9430 100644 --- a/templates/infra/machineDeployment.yaml +++ b/templates/infra/machineDeployment.yaml @@ -19,5 +19,5 @@ spec: kind: REPLACEME infrastructureRef: name: ${CLUSTER_NAME}-md-0 - apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2 kind: LinodeMachineTemplate