Skip to content

Commit

Permalink
Remove VirtualMachineClass Status fields in v1a2
Browse files Browse the repository at this point in the history
The Capabilities, Conditions, and Ready fields will be apart of
a later API version.
  • Loading branch information
bryanv committed Dec 11, 2023
1 parent 59cbe30 commit e1d2e46
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 230 deletions.
3 changes: 0 additions & 3 deletions api/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 0 additions & 73 deletions api/v1alpha2/virtualmachineclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
vmClassLabel = "class." + GroupName + "/"

// VirtualMachineClassCapabilityLabel is the prefix for a label that
// advertises a VM class capability.
//
// For more information please see VirtualMachineClassStatus.Capabilities.
VirtualMachineClassCapabilityLabel = "capability." + vmClassLabel

// VirtualMachineClassReadyLabel is applied to VM class resources that can
// be realized in the current cluster.
//
// For more information please see VirtualMachineClassStatus.Ready.
VirtualMachineClassReadyLabel = vmClassLabel + "ready"
)

const (
// VirtualMachineClassConditionReady is a condition on the VM class that
// indicates whether or not the VM class's hardware can be realized on at
// least one host in the cluster.
//
// For example, on Supervisor the VM Class / host compatibility is
// performed by checking with the CheckVmConfig_Task API
// (https://bit.ly/3CvoCc8).
//
// It is possible for this condition's Status to flip between True and False
// over the lifetime of a VM class. For example, if a VM class requires a
// specific vGPU and there is no host that provides that vGPU then the
// Status for this condition is False. However, if a host is added with that
// vGPU then the condition's status changes to True. And vice-versa -- if
// the same host is removed then the condition's status flips back to False.
//
// Please note that a host in maintenance mode that would otherwise provide
// compatibility will not be considered for this check. Only hosts where VMs
// can be scheduled are part of the check.
//
VirtualMachineClassConditionReady = "VirtualMachineClassReady"
)

// VirtualMachineConfigSpec contains additional virtual machine
// configuration settings including hardware specifications for the
// VirtualMachine.
Expand Down Expand Up @@ -207,40 +168,6 @@ type VirtualMachineClassSpec struct {

// VirtualMachineClassStatus defines the observed state of VirtualMachineClass.
type VirtualMachineClassStatus struct {
// Capabilities describes the class's observed capabilities.
//
// The capabilities are discerned when VM Operator reconciles a class
// and inspects its specification. Well-known capabilities include:
//
// * instance-storage
// * nvidia-gpu
// * sriov-net
//
// In addition to "nvidia-gpu", a capability is added for every nVidia
// profile name associated with the class.
//
// Every capability is also added to the resource's labels as
// VirtualMachineClassCapabilityLabel + Value. For example, if the
// capability is "nvidia-gpu" then the following label will be added to the
// resource: capability.class.vmoperator.vmware.com/nvidia-gpu.
//
// +optional
// +listType=set
Capabilities []string `json:"capabilities,omitempty"`

// Conditions describes the observed conditions of the VirtualMachineClass.
//
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`

// Ready describes whether the class's hardware can be realized in the
// cluster.
//
// This field is only set to true if all of the class resource's conditions
// have Status=True.
//
// +optional
Ready bool `json:"ready,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
14 changes: 1 addition & 13 deletions api/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 0 additions & 89 deletions config/crd/bases/vmoperator.vmware.com_virtualmachineclasses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -406,95 +406,6 @@ spec:
type: object
status:
description: VirtualMachineClassStatus defines the observed state of VirtualMachineClass.
properties:
capabilities:
description: "Capabilities describes the class's observed capabilities.
\n The capabilities are discerned when VM Operator reconciles a
class and inspects its specification. Well-known capabilities include:
\n * instance-storage * nvidia-gpu * sriov-net \n In addition to
\"nvidia-gpu\", a capability is added for every nVidia profile name
associated with the class. \n Every capability is also added to
the resource's labels as VirtualMachineClassCapabilityLabel + Value.
For example, if the capability is \"nvidia-gpu\" then the following
label will be added to the resource: capability.class.vmoperator.vmware.com/nvidia-gpu."
items:
type: string
type: array
x-kubernetes-list-type: set
conditions:
description: Conditions describes the observed conditions of the VirtualMachineClass.
items:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
\n type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are: \"Available\",
\"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge
// +listType=map // +listMapKey=type Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
transitioned from one status to another. This should be when
the underlying condition changed. If that is not known, then
using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: message is a human readable message indicating
details about the transition. This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: observedGeneration represents the .metadata.generation
that the condition was set based upon. For instance, if .metadata.generation
is currently 12, but the .status.conditions[x].observedGeneration
is 9, the condition is out of date with respect to the current
state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: reason contains a programmatic identifier indicating
the reason for the condition's last transition. Producers
of specific condition types may define expected values and
meanings for this field, and whether the values are considered
a guaranteed API. The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase.
--- Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be useful
(see .node.status.conditions), the ability to deconflict is
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
ready:
description: "Ready describes whether the class's hardware can be
realized in the cluster. \n This field is only set to true if all
of the class resource's conditions have Status=True."
type: boolean
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,5 @@ func (r *Reconciler) Reconcile(ctx goctx.Context, req ctrl.Request) (_ ctrl.Resu
}

func (r *Reconciler) ReconcileNormal(vmClassCtx *context.VirtualMachineClassContextA2) error {
// Implicitly always ready until we actually check. Don't worry about the conditions for now.
vmClassCtx.VMClass.Status.Ready = true
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
"github.com/vmware-tanzu/vm-operator/test/builder"
Expand Down Expand Up @@ -64,12 +63,7 @@ func intgTests() {
Expect(err == nil || k8serrors.IsNotFound(err)).To(BeTrue())
})

It("Is Ready", func() {
Eventually(func(g Gomega) {
class := &vmopv1.VirtualMachineClass{}
g.Expect(ctx.Client.Get(ctx, client.ObjectKeyFromObject(vmClass), class)).To(Succeed())
g.Expect(class.Status.Ready).To(BeTrue())
}).Should(Succeed())
It("noop", func() {
})
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func unitTestsReconcile() {
It("returns success", func() {
err := reconciler.ReconcileNormal(vmClassCtx)
Expect(err).ToNot(HaveOccurred())
Expect(vmClassCtx.VMClass.Status.Ready).To(BeTrue())
})
})
}
1 change: 0 additions & 1 deletion pkg/vmprovider/providers/vsphere2/vmprovider_vm2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func vmE2ETests() {

vmClass.Namespace = nsInfo.Namespace
Expect(ctx.Client.Create(ctx, vmClass)).To(Succeed())
vmClass.Status.Ready = true
Expect(ctx.Client.Status().Update(ctx, vmClass)).To(Succeed())

cloudInitSecret := &corev1.Secret{
Expand Down
2 changes: 0 additions & 2 deletions pkg/vmprovider/providers/vsphere2/vmprovider_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ func vmTests() {
JustBeforeEach(func() {
vmClass.Namespace = nsInfo.Namespace
Expect(ctx.Client.Create(ctx, vmClass)).To(Succeed())
vmClass.Status.Ready = true
Expect(ctx.Client.Status().Update(ctx, vmClass)).To(Succeed())

clusterVMImage := &vmopv1.ClusterVirtualMachineImage{}
if testConfig.WithContentLibrary {
Expand Down
6 changes: 0 additions & 6 deletions pkg/vmprovider/providers/vsphere2/vmprovider_vm_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ func GetVirtualMachineClass(
return nil, err
}

if !vmClass.Status.Ready {
conditions.MarkFalse(vmCtx.VM, vmopv1.VirtualMachineConditionClassReady,
"NotReady", "VirtualMachineClass is not marked as Ready")
return nil, fmt.Errorf("VirtualMachineClass is not Ready")
}

conditions.MarkTrue(vmCtx.VM, vmopv1.VirtualMachineConditionClassReady)

return vmClass, nil
Expand Down
39 changes: 6 additions & 33 deletions pkg/vmprovider/providers/vsphere2/vmprovider_vm_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,41 +93,14 @@ func vmUtilTests() {
})

Context("VirtualMachineClass custom resource exists", func() {

When("Is not Ready", func() {

BeforeEach(func() {
vmClass.Status.Ready = false
initObjects = append(initObjects, vmClass)
})

It("returns an error", func() {
_, err := vsphere.GetVirtualMachineClass(vmCtx, k8sClient)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("VirtualMachineClass is not Ready"))

expectedCondition := []metav1.Condition{
*conditions.FalseCondition(
vmopv1.VirtualMachineConditionClassReady,
"NotReady",
"VirtualMachineClass is not marked as Ready"),
}
Expect(vmCtx.VM.Status.Conditions).To(conditions.MatchConditions(expectedCondition))
})
BeforeEach(func() {
initObjects = append(initObjects, vmClass)
})

When("Is Ready", func() {

BeforeEach(func() {
vmClass.Status.Ready = true
initObjects = append(initObjects, vmClass)
})

It("returns success", func() {
class, err := vsphere.GetVirtualMachineClass(vmCtx, k8sClient)
Expect(err).ToNot(HaveOccurred())
Expect(class).ToNot(BeNil())
})
It("returns success", func() {
class, err := vsphere.GetVirtualMachineClass(vmCtx, k8sClient)
Expect(err).ToNot(HaveOccurred())
Expect(class).ToNot(BeNil())
})
})
})
Expand Down

0 comments on commit e1d2e46

Please sign in to comment.