Skip to content

Commit

Permalink
Add tests for failure domains on controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
rikatz committed Jul 3, 2023
1 parent 93d304e commit 6ede105
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ spec:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
x-kubernetes-map-type: atomic
server:
description: Server is the address of the vSphere endpoint.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ spec:
description: Name is the name of resource being referenced
type: string
required:
- apiGroup
- kind
- name
type: object
x-kubernetes-map-type: atomic
type: array
dhcp4:
description: DHCP4 is a flag that indicates whether or not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,10 +943,10 @@ spec:
description: Name is the name of resource being referenced
type: string
required:
- apiGroup
- kind
- name
type: object
x-kubernetes-map-type: atomic
type: array
deviceName:
description: DeviceName may be used to explicitly assign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,10 +832,10 @@ spec:
being referenced
type: string
required:
- apiGroup
- kind
- name
type: object
x-kubernetes-map-type: atomic
type: array
deviceName:
description: DeviceName may be used to explicitly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ spec:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
x-kubernetes-map-type: atomic
cloneMode:
description: CloneMode specifies the type of clone operation. The
LinkedClone mode is only support for templates that have at least
Expand Down Expand Up @@ -909,6 +908,7 @@ spec:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
x-kubernetes-map-type: atomic
cloneMode:
description: CloneMode specifies the type of clone operation. The
LinkedClone mode is only support for templates that have at least
Expand Down Expand Up @@ -990,10 +990,10 @@ spec:
description: Name is the name of resource being referenced
type: string
required:
- apiGroup
- kind
- name
type: object
x-kubernetes-map-type: atomic
type: array
deviceName:
description: DeviceName may be used to explicitly assign
Expand Down
139 changes: 139 additions & 0 deletions controllers/vspheredeploymentzone_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,145 @@ func TestVSphereDeploymentZone_Reconcile(t *testing.T) {
g.Expect(ownerRefs[0].Kind).To(Equal("VSphereDeploymentZone"))
})

t.Run("should fail to reconcile a deployment zone with wrong networkconfig", func(t *testing.T) {
g := NewWithT(t)

vsphereFailureDomain := &infrav1.VSphereFailureDomain{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "blah-fd-",
},
Spec: infrav1.VSphereFailureDomainSpec{
Region: infrav1.FailureDomain{
Name: "k8s-region-west",
Type: infrav1.DatacenterFailureDomain,
TagCategory: "k8s-region",
AutoConfigure: pointer.Bool(false),
},
Zone: infrav1.FailureDomain{
Name: "k8s-zone-west-1",
Type: infrav1.ComputeClusterFailureDomain,
TagCategory: "k8s-zone",
AutoConfigure: pointer.Bool(false),
},
Topology: infrav1.Topology{
Datacenter: "DC0",
ComputeCluster: pointer.String("DC0_C0"),
Datastore: "LocalDS_0",
NetworkConfigurations: []infrav1.NetworkConfiguration{
{
NetworkName: "VM Networkxpto",
DHCP4: pointer.Bool(true),
},
},
},
},
}
g.Expect(testEnv.Create(ctx, vsphereFailureDomain)).To(Succeed())

vsphereDeploymentZone := &infrav1.VSphereDeploymentZone{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "blah-",
},
Spec: infrav1.VSphereDeploymentZoneSpec{
Server: simr.ServerURL().Host,
FailureDomain: vsphereFailureDomain.Name,
ControlPlane: pointer.Bool(true),
PlacementConstraint: infrav1.PlacementConstraint{
ResourcePool: "DC0_C0_RP1",
Folder: "/",
},
}}
g.Expect(testEnv.Create(ctx, vsphereDeploymentZone)).To(Succeed())

deploymentZoneKey := client.ObjectKey{Name: vsphereDeploymentZone.Name}
g.Eventually(func() bool {
if err := testEnv.Get(ctx, deploymentZoneKey, vsphereDeploymentZone); err != nil {
return false
}
return conditions.IsFalse(vsphereDeploymentZone, infrav1.VSphereFailureDomainValidatedCondition) &&
conditions.GetReason(vsphereDeploymentZone, infrav1.VSphereFailureDomainValidatedCondition) == infrav1.NetworkNotFoundReason
}, timeout).Should(BeTrue())

})

t.Run("should create a deployment zone & failure domain with networkconfig", func(t *testing.T) {
g := NewWithT(t)

vsphereFailureDomain := &infrav1.VSphereFailureDomain{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "blah-fd-",
},
Spec: infrav1.VSphereFailureDomainSpec{
Region: infrav1.FailureDomain{
Name: "k8s-region-west",
Type: infrav1.DatacenterFailureDomain,
TagCategory: "k8s-region",
AutoConfigure: pointer.Bool(false),
},
Zone: infrav1.FailureDomain{
Name: "k8s-zone-west-1",
Type: infrav1.ComputeClusterFailureDomain,
TagCategory: "k8s-zone",
AutoConfigure: pointer.Bool(false),
},
Topology: infrav1.Topology{
Datacenter: "DC0",
ComputeCluster: pointer.String("DC0_C0"),
Datastore: "LocalDS_0",
NetworkConfigurations: []infrav1.NetworkConfiguration{
{
NetworkName: "VM Network",
DHCP4: pointer.Bool(true),
},
},
},
},
}
g.Expect(testEnv.Create(ctx, vsphereFailureDomain)).To(Succeed())

vsphereDeploymentZone := &infrav1.VSphereDeploymentZone{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "blah-",
},
Spec: infrav1.VSphereDeploymentZoneSpec{
Server: simr.ServerURL().Host,
FailureDomain: vsphereFailureDomain.Name,
ControlPlane: pointer.Bool(true),
PlacementConstraint: infrav1.PlacementConstraint{
ResourcePool: "DC0_C0_RP1",
Folder: "/",
},
}}
g.Expect(testEnv.Create(ctx, vsphereDeploymentZone)).To(Succeed())

defer func(do ...client.Object) {
g.Expect(testEnv.Cleanup(ctx, do...)).To(Succeed())
}(vsphereDeploymentZone, vsphereFailureDomain)

g.Eventually(func() bool {
if err := testEnv.Get(ctx, client.ObjectKeyFromObject(vsphereDeploymentZone), vsphereDeploymentZone); err != nil {
return false
}
return len(vsphereDeploymentZone.Finalizers) > 0
}, timeout).Should(BeTrue())

g.Eventually(func() bool {
if err := testEnv.Get(ctx, client.ObjectKeyFromObject(vsphereDeploymentZone), vsphereDeploymentZone); err != nil {
return false
}
return conditions.IsTrue(vsphereDeploymentZone, infrav1.VCenterAvailableCondition) &&
conditions.IsTrue(vsphereDeploymentZone, infrav1.PlacementConstraintMetCondition) &&
conditions.IsTrue(vsphereDeploymentZone, infrav1.VSphereFailureDomainValidatedCondition)
}, timeout).Should(BeTrue())

By("sets the owner ref on the vsphereFailureDomain object")
g.Expect(testEnv.Get(ctx, client.ObjectKeyFromObject(vsphereFailureDomain), vsphereFailureDomain)).To(Succeed())
ownerRefs := vsphereFailureDomain.GetOwnerReferences()
g.Expect(ownerRefs).To(HaveLen(1))
g.Expect(ownerRefs[0].Name).To(Equal(vsphereDeploymentZone.Name))
g.Expect(ownerRefs[0].Kind).To(Equal("VSphereDeploymentZone"))
})

By("deleting deployment zone")
t.Run("it should delete associated failure domain", func(t *testing.T) {
g := NewWithT(t)
Expand Down

0 comments on commit 6ede105

Please sign in to comment.