Skip to content

Commit

Permalink
Merge pull request #487 from akutz/fix/issue-485
Browse files Browse the repository at this point in the history
  • Loading branch information
akutz authored May 1, 2024
2 parents d4ba58c + 2cd4422 commit 5259d2d
Show file tree
Hide file tree
Showing 34 changed files with 1,926 additions and 169 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ endif

generate-go-conversions:
$(CONVERSION_GEN) \
--input-dirs='./api/v1alpha1,./api/v1alpha2' \
--input-dirs='./api/v1alpha1,./api/v1alpha2,./api/v1alpha2/sysprep/conversion/v1alpha2,./api/v1alpha2/sysprep/conversion/v1alpha3' \
--output-file-base=zz_generated.conversion \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt

Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/virtualmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ func restore_v1alpha3_VirtualMachineNetworkSpec(
}
dstNetwork := dst.Spec.Network

dstNetwork.DomainName = srcNetwork.DomainName
dstNetwork.HostName = srcNetwork.HostName
dstNetwork.Disabled = srcNetwork.Disabled
dstNetwork.Nameservers = srcNetwork.Nameservers
Expand Down
3 changes: 2 additions & 1 deletion api/v1alpha1/virtualmachine_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestVirtualMachineConversion(t *testing.T) {
},
},
Network: &vmopv1.VirtualMachineNetworkSpec{
DomainName: "my-domain.com",
HostName: "my-test-vm",
Disabled: true,
Nameservers: []string{"10.11.12.13", "9.9.9.9"},
Expand Down Expand Up @@ -352,7 +353,7 @@ func TestVirtualMachineConversion(t *testing.T) {
Bootstrap: &vmopv1.VirtualMachineBootstrapSpec{
Sysprep: &vmopv1.VirtualMachineBootstrapSysprepSpec{
Sysprep: &vmopv1sysprep.Sysprep{
GUIRunOnce: vmopv1sysprep.GUIRunOnce{
GUIRunOnce: &vmopv1sysprep.GUIRunOnce{
Commands: []string{"echo", "hello"},
},
GUIUnattended: &vmopv1sysprep.GUIUnattended{
Expand Down
8 changes: 8 additions & 0 deletions api/v1alpha2/conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package v1alpha2_test

func ptrOf[T any](v T) *T {
return &v
}
33 changes: 33 additions & 0 deletions api/v1alpha2/sysprep/conversion/v1alpha2/sysprep_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2024 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package v1alpha2

import (
"unsafe"

apiconversion "k8s.io/apimachinery/pkg/conversion"

vmopv1a2sysprep "github.com/vmware-tanzu/vm-operator/api/v1alpha2/sysprep"
vmopv1sysprep "github.com/vmware-tanzu/vm-operator/api/v1alpha3/sysprep"
)

// Please see https://github.com/kubernetes/code-generator/issues/172 for why
// this function exists in this directory structure.
func Convert_sysprep_Sysprep_To_sysprep_Sysprep(
in *vmopv1a2sysprep.Sysprep, out *vmopv1sysprep.Sysprep, s apiconversion.Scope) error {

out.GUIRunOnce = (*vmopv1sysprep.GUIRunOnce)(unsafe.Pointer(&in.GUIRunOnce))
out.GUIUnattended = (*vmopv1sysprep.GUIUnattended)(unsafe.Pointer(in.GUIUnattended))
out.LicenseFilePrintData = (*vmopv1sysprep.LicenseFilePrintData)(unsafe.Pointer(in.LicenseFilePrintData))
out.UserData = (*vmopv1sysprep.UserData)(unsafe.Pointer(in.UserData))
if id := in.Identification; id != nil {
out.Identification = &vmopv1sysprep.Identification{
DomainAdmin: id.DomainAdmin,
DomainAdminPassword: (*vmopv1sysprep.DomainPasswordSecretKeySelector)(unsafe.Pointer(id.DomainAdminPassword)),
JoinWorkgroup: id.JoinWorkgroup,
}
}

return nil
}
33 changes: 33 additions & 0 deletions api/v1alpha2/sysprep/conversion/v1alpha3/sysprep_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2024 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package v1alpha3

import (
"unsafe"

apiconversion "k8s.io/apimachinery/pkg/conversion"

vmopv1a2sysprep "github.com/vmware-tanzu/vm-operator/api/v1alpha2/sysprep"
vmopv1sysprep "github.com/vmware-tanzu/vm-operator/api/v1alpha3/sysprep"
)

// Please see https://github.com/kubernetes/code-generator/issues/172 for why
// this function exists in this directory structure.
func Convert_sysprep_Sysprep_To_sysprep_Sysprep(
in *vmopv1sysprep.Sysprep, out *vmopv1a2sysprep.Sysprep, s apiconversion.Scope) error {

out.GUIRunOnce = *(*vmopv1a2sysprep.GUIRunOnce)(unsafe.Pointer(in.GUIRunOnce))
out.GUIUnattended = (*vmopv1a2sysprep.GUIUnattended)(unsafe.Pointer(in.GUIUnattended))
out.LicenseFilePrintData = (*vmopv1a2sysprep.LicenseFilePrintData)(unsafe.Pointer(in.LicenseFilePrintData))
out.UserData = (*vmopv1a2sysprep.UserData)(unsafe.Pointer(in.UserData))
if id := in.Identification; id != nil {
out.Identification = &vmopv1a2sysprep.Identification{
DomainAdmin: id.DomainAdmin,
DomainAdminPassword: (*vmopv1a2sysprep.DomainPasswordSecretKeySelector)(unsafe.Pointer(id.DomainAdminPassword)),
JoinWorkgroup: id.JoinWorkgroup,
}
}

return nil
}
66 changes: 66 additions & 0 deletions api/v1alpha2/virtualmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ func Convert_v1alpha3_VirtualMachineBootstrapCloudInitSpec_To_v1alpha2_VirtualMa
return autoConvert_v1alpha3_VirtualMachineBootstrapCloudInitSpec_To_v1alpha2_VirtualMachineBootstrapCloudInitSpec(in, out, s)
}

func Convert_v1alpha3_VirtualMachineNetworkConfigDNSStatus_To_v1alpha2_VirtualMachineNetworkConfigDNSStatus(
in *vmopv1.VirtualMachineNetworkConfigDNSStatus, out *VirtualMachineNetworkConfigDNSStatus, s apiconversion.Scope) error {

return autoConvert_v1alpha3_VirtualMachineNetworkConfigDNSStatus_To_v1alpha2_VirtualMachineNetworkConfigDNSStatus(in, out, s)
}

func Convert_v1alpha3_VirtualMachineNetworkSpec_To_v1alpha2_VirtualMachineNetworkSpec(
in *vmopv1.VirtualMachineNetworkSpec, out *VirtualMachineNetworkSpec, s apiconversion.Scope) error {

return autoConvert_v1alpha3_VirtualMachineNetworkSpec_To_v1alpha2_VirtualMachineNetworkSpec(in, out, s)
}

func Convert_v1alpha3_VirtualMachineSpec_To_v1alpha2_VirtualMachineSpec(
in *vmopv1.VirtualMachineSpec, out *VirtualMachineSpec, s apiconversion.Scope) error {

Expand Down Expand Up @@ -56,6 +68,21 @@ func Convert_v1alpha3_VirtualMachine_To_v1alpha2_VirtualMachine(
}
}

// Copy in.spec.network.domainName to
// out.spec.bootstrap.sysprep.sysprep.identification.joinDomain on
// down-convert.
if net := in.Spec.Network; net != nil && net.DomainName != "" {
if bs := out.Spec.Bootstrap; bs != nil {
if sp := bs.Sysprep; sp != nil {
if spsp := sp.Sysprep; spsp != nil {
if spid := spsp.Identification; spid != nil {
spid.JoinDomain = net.DomainName
}
}
}
}
}

return nil
}

Expand All @@ -64,6 +91,27 @@ func restore_v1alpha3_VirtualMachineImage(dst, src *vmopv1.VirtualMachine) {
dst.Spec.ImageName = src.Spec.ImageName
}

func restore_v1alpha3_VirtualMachineSpecNetworkDomainName(dst, src *vmopv1.VirtualMachine) {
var (
dstDN string
srcDN string
)

if net := dst.Spec.Network; net != nil {
dstDN = net.DomainName
}
if net := src.Spec.Network; net != nil {
srcDN = net.DomainName
}

if dstDN == "" && srcDN != dstDN {
if dst.Spec.Network == nil {
dst.Spec.Network = &vmopv1.VirtualMachineNetworkSpec{}
}
dst.Spec.Network.DomainName = srcDN
}
}

func Convert_v1alpha2_VirtualMachine_To_v1alpha3_VirtualMachine(in *VirtualMachine, out *vmopv1.VirtualMachine, s apiconversion.Scope) error {
if err := autoConvert_v1alpha2_VirtualMachine_To_v1alpha3_VirtualMachine(in, out, s); err != nil {
return err
Expand Down Expand Up @@ -94,6 +142,23 @@ func Convert_v1alpha2_VirtualMachine_To_v1alpha3_VirtualMachine(in *VirtualMachi
}
}

// Copy in.bootstrap.sysprep.sysprep.identification.joinDomain to
// out.spec.domainName on up-convert.
if bs := in.Spec.Bootstrap; bs != nil {
if sp := bs.Sysprep; sp != nil {
if spsp := sp.Sysprep; spsp != nil {
if spid := spsp.Identification; spid != nil {
if dn := spid.JoinDomain; dn != "" {
if out.Spec.Network == nil {
out.Spec.Network = &vmopv1.VirtualMachineNetworkSpec{}
}
out.Spec.Network.DomainName = dn
}
}
}
}
}

return nil
}

Expand Down Expand Up @@ -142,6 +207,7 @@ func (src *VirtualMachine) ConvertTo(dstRaw ctrlconversion.Hub) error {
restore_v1alpha3_VirtualMachineImage(dst, restored)
restore_v1alpha3_VirtualMachineBiosUUID(dst, restored)
restore_v1alpha3_VirtualMachineBootstrapCloudInitInstanceID(dst, restored)
restore_v1alpha3_VirtualMachineSpecNetworkDomainName(dst, restored)

// END RESTORE

Expand Down
Loading

0 comments on commit 5259d2d

Please sign in to comment.