Skip to content

Commit

Permalink
First pass at v1a2 enabled "provider" and releated API changes
Browse files Browse the repository at this point in the history
Still lots of misc things to sort out but works well enough to get TKGs
created.
  • Loading branch information
bryanv committed Sep 8, 2023
1 parent bfeb472 commit bb8c2c0
Show file tree
Hide file tree
Showing 113 changed files with 19,577 additions and 162 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha1/condition_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ func Convert_v1alpha1_Condition_To_v1_Condition(in *Condition, out *metav1.Condi
out.Reason = in.Reason
out.Message = in.Message

// The metav1.Condition requires the reason to be non-empty, when it was not in our prior v1a1 Condition.
// We don't have any great options as to what we can fill this in as.
if out.Reason == "" {
out.Reason = string(out.Status)
}

// TODO: out.ObservedGeneration =

return nil
Expand Down
28 changes: 23 additions & 5 deletions api/v1alpha1/virtualmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func convert_v1alpha1_VmMetadata_To_v1alpha2_BootstrapSpec(
out.CloudInit = &v1alpha2.VirtualMachineBootstrapCloudInitSpec{
RawCloudConfig: corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: objectName},
Key: "guestinfo.userdata",
Key: "guestinfo.userdata", // TODO: Is this good enough? v1a1 would include everything with the "guestinfo" prefix
},
}
case VirtualMachineMetadataOvfEnvTransport:
Expand Down Expand Up @@ -449,6 +449,12 @@ func convert_v1alpha2_NetworkStatus_To_v1alpha1_Network(
func Convert_v1alpha1_VirtualMachineSpec_To_v1alpha2_VirtualMachineSpec(
in *VirtualMachineSpec, out *v1alpha2.VirtualMachineSpec, s apiconversion.Scope) error {

// The generated auto convert will convert the power modes as-is strings which breaks things, so keep
// this first.
if err := autoConvert_v1alpha1_VirtualMachineSpec_To_v1alpha2_VirtualMachineSpec(in, out, s); err != nil {
return err
}

out.PowerState = convert_v1alpha1_VirtualMachinePowerState_To_v1alpha2_VirtualMachinePowerState(in.PowerState)
out.PowerOffMode = convert_v1alpha1_VirtualMachinePowerOpMode_To_v1alpha2_VirtualMachinePowerOpMode(in.PowerOffMode)
out.SuspendMode = convert_v1alpha1_VirtualMachinePowerOpMode_To_v1alpha2_VirtualMachinePowerOpMode(in.SuspendMode)
Expand All @@ -469,12 +475,16 @@ func Convert_v1alpha1_VirtualMachineSpec_To_v1alpha2_VirtualMachineSpec(
// Deprecated:
// in.Ports

return autoConvert_v1alpha1_VirtualMachineSpec_To_v1alpha2_VirtualMachineSpec(in, out, s)
return nil
}

func Convert_v1alpha2_VirtualMachineSpec_To_v1alpha1_VirtualMachineSpec(
in *v1alpha2.VirtualMachineSpec, out *VirtualMachineSpec, s apiconversion.Scope) error {

if err := autoConvert_v1alpha2_VirtualMachineSpec_To_v1alpha1_VirtualMachineSpec(in, out, s); err != nil {
return err
}

out.PowerState = convert_v1alpha2_VirtualMachinePowerState_To_v1alpha1_VirtualMachinePowerState(in.PowerState)
out.PowerOffMode = convert_v1alpha2_VirtualMachinePowerOpMode_To_v1alpha1_VirtualMachinePowerOpMode(in.PowerOffMode)
out.SuspendMode = convert_v1alpha2_VirtualMachinePowerOpMode_To_v1alpha1_VirtualMachinePowerOpMode(in.SuspendMode)
Expand All @@ -496,7 +506,7 @@ func Convert_v1alpha2_VirtualMachineSpec_To_v1alpha1_VirtualMachineSpec(
// Deprecated:
// out.Ports

return autoConvert_v1alpha2_VirtualMachineSpec_To_v1alpha1_VirtualMachineSpec(in, out, s)
return nil
}

func Convert_v1alpha1_VirtualMachineVolumeStatus_To_v1alpha2_VirtualMachineVolumeStatus(
Expand All @@ -518,18 +528,26 @@ func Convert_v1alpha2_VirtualMachineVolumeStatus_To_v1alpha1_VirtualMachineVolum
func Convert_v1alpha1_VirtualMachineStatus_To_v1alpha2_VirtualMachineStatus(
in *VirtualMachineStatus, out *v1alpha2.VirtualMachineStatus, s apiconversion.Scope) error {

if err := autoConvert_v1alpha1_VirtualMachineStatus_To_v1alpha2_VirtualMachineStatus(in, out, s); err != nil {
return err
}

out.PowerState = convert_v1alpha1_VirtualMachinePowerState_To_v1alpha2_VirtualMachinePowerState(in.PowerState)
out.Network = convert_v1alpha1_Network_To_v1alpha2_NetworkStatus(in.VmIp, in.NetworkInterfaces)
out.LastRestartTime = in.LastRestartTime

// WARNING: in.Phase requires manual conversion: does not exist in peer-type

return autoConvert_v1alpha1_VirtualMachineStatus_To_v1alpha2_VirtualMachineStatus(in, out, s)
return nil
}

func Convert_v1alpha2_VirtualMachineStatus_To_v1alpha1_VirtualMachineStatus(
in *v1alpha2.VirtualMachineStatus, out *VirtualMachineStatus, s apiconversion.Scope) error {

if err := autoConvert_v1alpha2_VirtualMachineStatus_To_v1alpha1_VirtualMachineStatus(in, out, s); err != nil {
return err
}

out.PowerState = convert_v1alpha2_VirtualMachinePowerState_To_v1alpha1_VirtualMachinePowerState(in.PowerState)
out.Phase = convert_v1alpha2_Conditions_To_v1alpha1_Phase(in.Conditions)
out.VmIp, out.NetworkInterfaces = convert_v1alpha2_NetworkStatus_To_v1alpha1_Network(in.Network)
Expand All @@ -538,7 +556,7 @@ func Convert_v1alpha2_VirtualMachineStatus_To_v1alpha1_VirtualMachineStatus(
// WARNING: in.Image requires manual conversion: does not exist in peer-type
// WARNING: in.Class requires manual conversion: does not exist in peer-type

return autoConvert_v1alpha2_VirtualMachineStatus_To_v1alpha1_VirtualMachineStatus(in, out, s)
return nil
}

// ConvertTo converts this VirtualMachine to the Hub version.
Expand Down
21 changes: 16 additions & 5 deletions pkg/conditions2/setter.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,20 @@ func Set(to Setter, condition *metav1.Condition) {
func TrueCondition(t string) *metav1.Condition {
return &metav1.Condition{
Type: t,
Reason: t, // BMV: This is required field in metav1.Conditions. Fixup API later.
Status: metav1.ConditionTrue,
// This is a non-empty field in metav1.Conditions, when it was not in our v1a1 Conditions. This
// really doesn't work with how we've defined our conditions so do something to make things
// work for now.
Reason: string(metav1.ConditionTrue),
}
}

// FalseCondition returns a condition with Status=False and the given type.
func FalseCondition(t string, reason string, messageFormat string, messageArgs ...interface{}) *metav1.Condition {
if reason == "" {
reason = string(metav1.ConditionFalse)
}

return &metav1.Condition{
Type: t,
Status: metav1.ConditionFalse,
Expand All @@ -95,6 +102,10 @@ func FalseCondition(t string, reason string, messageFormat string, messageArgs .

// UnknownCondition returns a condition with Status=Unknown and the given type.
func UnknownCondition(t string, reason string, messageFormat string, messageArgs ...interface{}) *metav1.Condition {
if reason == "" {
reason = string(metav1.ConditionUnknown)
}

return &metav1.Condition{
Type: t,
Status: metav1.ConditionUnknown,
Expand Down Expand Up @@ -124,14 +135,14 @@ func SetSummary(to Setter, options ...MergeOption) {
Set(to, summary(to, options...))
}

// SetMirror creates a new condition by mirroring the the Ready condition from a dependent object;
// if the Ready condition does not exists in the source object, no target conditions is generated.
// SetMirror creates a new condition by mirroring the Ready condition from a dependent object;
// if the Ready condition does not exist in the source object, no target conditions is generated.
func SetMirror(to Setter, targetCondition string, from Getter, options ...MirrorOptions) {
Set(to, mirror(from, targetCondition, options...))
}

// SetAggregate creates a new condition with the aggregation of all the the Ready condition
// from a list of dependent objects; if the Ready condition does not exists in one of the source object,
// SetAggregate creates a new condition with the aggregation of all the Ready condition
// from a list of dependent objects; if the Ready condition does not exist in one of the source object,
// the object is excluded from the aggregation; if none of the source object have ready condition,
// no target conditions is generated.
func SetAggregate(to Setter, targetCondition string, from []Getter, options ...MergeOption) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/conditions2/setter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func TestMarkMethods(t *testing.T) {
g.Expect(Get(vm, "conditionFoo")).To(haveSameStateOf(&metav1.Condition{
Type: "conditionFoo",
Status: metav1.ConditionTrue,
Reason: "conditionFoo",
Reason: "True",
}))

// test MarkFalse
Expand Down
8 changes: 7 additions & 1 deletion pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/vmware-tanzu/vm-operator/pkg/lib"
"github.com/vmware-tanzu/vm-operator/pkg/record"
"github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere"
vsphere2 "github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere2"
)

// Manager is a VM Operator controller manager.
Expand Down Expand Up @@ -116,7 +117,12 @@ func New(opts Options) (Manager, error) {
func InitializeProviders(ctx *context.ControllerManagerContext, mgr ctrlmgr.Manager) error {
vmProviderName := fmt.Sprintf("%s/%s/vmProvider", ctx.Namespace, ctx.Name)
recorder := record.New(mgr.GetEventRecorderFor(vmProviderName))
ctx.VMProvider = vsphere.NewVSphereVMProviderFromClient(mgr.GetClient(), recorder)

if lib.IsVMServiceV1Alpha2FSSEnabled() {
ctx.VMProviderA2 = vsphere2.NewVSphereVMProviderFromClient(mgr.GetClient(), recorder)
} else {
ctx.VMProvider = vsphere.NewVSphereVMProviderFromClient(mgr.GetClient(), recorder)
}
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/vmprovider/providers/vsphere/vmprovider_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func vmTests() {
)

BeforeEach(func() {
testConfig.WithNetworkEnv = builder.NetworkEnvNamed
testConfig.WithVMClassAsConfigDaynDate = true

ethCard = types.VirtualEthernetCard{
Expand Down Expand Up @@ -1512,6 +1513,8 @@ func vmTests() {

Context("Multiple NICs are specified", func() {
BeforeEach(func() {
testConfig.WithNetworkEnv = builder.NetworkEnvNamed

vm.Spec.NetworkInterfaces = []vmopv1.VirtualMachineNetworkInterface{
{
NetworkName: "VM Network",
Expand Down
Loading

0 comments on commit bb8c2c0

Please sign in to comment.