Skip to content

Commit 1934750

Browse files
authored
Merge pull request #1241 from yastij/add-meta
add metadata to the vspheremachinetemplate
2 parents e537c0a + f71b6b7 commit 1934750

File tree

8 files changed

+257
-27
lines changed

8 files changed

+257
-27
lines changed

api/v1alpha3/conversion_test.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
2626
"k8s.io/apimachinery/pkg/runtime"
2727
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
28+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
2829
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2930

3031
nextver "sigs.k8s.io/cluster-api-provider-vsphere/api/v1alpha4"
@@ -40,17 +41,18 @@ func TestFuzzyConversion(t *testing.T) {
4041
Scheme: scheme,
4142
Hub: &nextver.VSphereCluster{},
4243
Spoke: &VSphereCluster{},
43-
FuzzerFuncs: []fuzzer.FuzzerFuncs{overrideDeprecatedFieldsFuncs},
44+
FuzzerFuncs: []fuzzer.FuzzerFuncs{overrideVSphereClusterDeprecatedFieldsFuncs},
4445
}))
4546
t.Run("for VSphereMachine", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
4647
Scheme: scheme,
4748
Hub: &nextver.VSphereMachine{},
4849
Spoke: &VSphereMachine{},
4950
}))
5051
t.Run("for VSphereMachineTemplate", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
51-
Scheme: scheme,
52-
Hub: &nextver.VSphereMachineTemplate{},
53-
Spoke: &VSphereMachineTemplate{},
52+
Scheme: scheme,
53+
Hub: &nextver.VSphereMachineTemplate{},
54+
Spoke: &VSphereMachineTemplate{},
55+
FuzzerFuncs: []fuzzer.FuzzerFuncs{CustomObjectMetaFuzzFunc},
5456
}))
5557
t.Run("for VSphereVM", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
5658
Scheme: scheme,
@@ -59,10 +61,28 @@ func TestFuzzyConversion(t *testing.T) {
5961
}))
6062
}
6163

62-
func overrideDeprecatedFieldsFuncs(codecs runtimeserializer.CodecFactory) []interface{} {
64+
func overrideVSphereClusterDeprecatedFieldsFuncs(codecs runtimeserializer.CodecFactory) []interface{} {
6365
return []interface{}{
6466
func(vsphereClusterSpec *VSphereClusterSpec, c fuzz.Continue) {
6567
vsphereClusterSpec.CloudProviderConfiguration = CPIConfig{}
6668
},
6769
}
6870
}
71+
72+
func CustomObjectMetaFuzzFunc(_ runtimeserializer.CodecFactory) []interface{} {
73+
return []interface{}{
74+
CustomObjectMetaFuzzer,
75+
}
76+
}
77+
78+
//nolint
79+
func CustomObjectMetaFuzzer(in *clusterv1.ObjectMeta, c fuzz.Continue) {
80+
c.FuzzNoCustom(in)
81+
82+
// These fields have been removed in v1alpha4
83+
// data is going to be lost, so we're forcing zero values here.
84+
in.Name = ""
85+
in.GenerateName = ""
86+
in.Namespace = ""
87+
in.OwnerReferences = nil
88+
}

api/v1alpha3/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package v1alpha3
1818

1919
import (
2020
"fmt"
21+
22+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
2123
)
2224

2325
const (
@@ -142,6 +144,12 @@ type VirtualMachineCloneSpec struct {
142144

143145
// VSphereMachineTemplateResource describes the data needed to create a VSphereMachine from a template
144146
type VSphereMachineTemplateResource struct {
147+
148+
// Standard object's metadata.
149+
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
150+
// +optional
151+
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty"`
152+
145153
// Spec is the specification of the desired behavior of the machine.
146154
Spec VSphereMachineSpec `json:"spec"`
147155
}

api/v1alpha3/vspheremachinetemplate_conversion.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ limitations under the License.
1717
package v1alpha3
1818

1919
import (
20+
apiconversion "k8s.io/apimachinery/pkg/conversion"
2021
infrav1alpha4 "sigs.k8s.io/cluster-api-provider-vsphere/api/v1alpha4"
22+
clusterv1a3 "sigs.k8s.io/cluster-api/api/v1alpha3"
23+
clusterv1a4 "sigs.k8s.io/cluster-api/api/v1alpha4"
2124
"sigs.k8s.io/controller-runtime/pkg/conversion"
2225
)
2326

@@ -41,3 +44,39 @@ func (dst *VSphereMachineTemplateList) ConvertFrom(srcRaw conversion.Hub) error
4144
src := srcRaw.(*infrav1alpha4.VSphereMachineTemplateList)
4245
return Convert_v1alpha4_VSphereMachineTemplateList_To_v1alpha3_VSphereMachineTemplateList(src, dst, nil)
4346
}
47+
48+
//nolint
49+
func Convert_v1alpha3_VSphereMachineTemplateResource_To_v1alpha4_VSphereMachineTemplateResource(in *VSphereMachineTemplateResource, out *infrav1alpha4.VSphereMachineTemplateResource, s apiconversion.Scope) error {
50+
if err := clusterv1a3.Convert_v1alpha3_ObjectMeta_To_v1alpha4_ObjectMeta(&in.ObjectMeta, &out.ObjectMeta, s); err != nil {
51+
return err
52+
}
53+
if err := Convert_v1alpha3_VSphereMachineSpec_To_v1alpha4_VSphereMachineSpec(&in.Spec, &out.Spec, s); err != nil {
54+
return err
55+
}
56+
return nil
57+
}
58+
59+
//nolint
60+
func Convert_v1alpha4_VSphereMachineTemplateResource_To_v1alpha3_VSphereMachineTemplateResource(in *infrav1alpha4.VSphereMachineTemplateResource, out *VSphereMachineTemplateResource, s apiconversion.Scope) error {
61+
if err := clusterv1a3.Convert_v1alpha4_ObjectMeta_To_v1alpha3_ObjectMeta(&in.ObjectMeta, &out.ObjectMeta, s); err != nil {
62+
return err
63+
}
64+
if err := Convert_v1alpha4_VSphereMachineSpec_To_v1alpha3_VSphereMachineSpec(&in.Spec, &out.Spec, s); err != nil {
65+
return err
66+
}
67+
return nil
68+
}
69+
70+
//nolint
71+
func Convert_v1alpha3_ObjectMeta_To_v1alpha4_ObjectMeta(in *clusterv1a3.ObjectMeta, out *clusterv1a4.ObjectMeta, s apiconversion.Scope) error {
72+
// wrapping the conversion func to avoid having compile errors due to compileErrorOnMissingConversion()
73+
// more details at https://github.com/kubernetes/kubernetes/issues/98380
74+
return clusterv1a3.Convert_v1alpha3_ObjectMeta_To_v1alpha4_ObjectMeta(in, out, s)
75+
}
76+
77+
//nolint
78+
func Convert_v1alpha4_ObjectMeta_To_v1alpha3_ObjectMeta(in *clusterv1a4.ObjectMeta, out *clusterv1a3.ObjectMeta, s apiconversion.Scope) error {
79+
// wrapping the conversion func to avoid having compile errors due to compileErrorOnMissingConversion()
80+
// more details at https://github.com/kubernetes/kubernetes/issues/98380
81+
return clusterv1a3.Convert_v1alpha4_ObjectMeta_To_v1alpha3_ObjectMeta(in, out, s)
82+
}

api/v1alpha3/zz_generated.conversion.go

Lines changed: 48 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha3/zz_generated.deepcopy.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha4/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package v1alpha4
1818

1919
import (
2020
"fmt"
21+
22+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
2123
)
2224

2325
const (
@@ -142,6 +144,12 @@ type VirtualMachineCloneSpec struct {
142144

143145
// VSphereMachineTemplateResource describes the data needed to create a VSphereMachine from a template
144146
type VSphereMachineTemplateResource struct {
147+
148+
// Standard object's metadata.
149+
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
150+
// +optional
151+
ObjectMeta clusterv1.ObjectMeta `json:"metadata,omitempty"`
152+
145153
// Spec is the specification of the desired behavior of the machine.
146154
Spec VSphereMachineSpec `json:"spec"`
147155
}

api/v1alpha4/zz_generated.deepcopy.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)