Skip to content

Commit

Permalink
fix IRI volume list update
Browse files Browse the repository at this point in the history
  • Loading branch information
ushabelgur committed Feb 7, 2025
1 parent 8297a47 commit 6cfe69a
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 1 deletion.
149 changes: 149 additions & 0 deletions poollet/machinepoollet/controllers/machine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,155 @@ var _ = Describe("MachineController", func() {
}))))
})

It("should validate IRI volume update for machine", func(ctx SpecContext) {
By("creating a network")
network := &networkingv1alpha1.Network{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns.Name,
GenerateName: "network-",
},
Spec: networkingv1alpha1.NetworkSpec{
ProviderID: "foo",
},
}
Expect(k8sClient.Create(ctx, network)).To(Succeed())

By("patching the network to be available")
Eventually(UpdateStatus(network, func() {
network.Status.State = networkingv1alpha1.NetworkStateAvailable
})).Should(Succeed())

By("creating a network interface")
nic := &networkingv1alpha1.NetworkInterface{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns.Name,
GenerateName: "nic-",
},
Spec: networkingv1alpha1.NetworkInterfaceSpec{
NetworkRef: corev1.LocalObjectReference{Name: network.Name},
IPs: []networkingv1alpha1.IPSource{
{Value: commonv1alpha1.MustParseNewIP("10.0.0.1")},
},
},
}
Expect(k8sClient.Create(ctx, nic)).To(Succeed())

By("creating a volume")
volume := &storagev1alpha1.Volume{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns.Name,
GenerateName: "volume-",
},
Spec: storagev1alpha1.VolumeSpec{},
}
Expect(k8sClient.Create(ctx, volume)).To(Succeed())

By("patching the volume to be available")
Eventually(UpdateStatus(volume, func() {
volume.Status.State = storagev1alpha1.VolumeStateAvailable
volume.Status.Access = &storagev1alpha1.VolumeAccess{
Driver: "test",
Handle: "testhandle",
}
})).Should(Succeed())

secondaryVolume := &storagev1alpha1.Volume{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns.Name,
GenerateName: "volume-",
},
Spec: storagev1alpha1.VolumeSpec{},
}
Expect(k8sClient.Create(ctx, secondaryVolume)).To(Succeed())

By("patching the secondary volume to be available")
Eventually(UpdateStatus(secondaryVolume, func() {
secondaryVolume.Status.State = storagev1alpha1.VolumeStateAvailable
secondaryVolume.Status.Access = &storagev1alpha1.VolumeAccess{
Driver: "test",
Handle: "testhandle",
}
})).Should(Succeed())

By("creating a machine")
const fooAnnotationValue = "bar"
machine := &computev1alpha1.Machine{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns.Name,
GenerateName: "machine-",
Annotations: map[string]string{
fooAnnotation: fooAnnotationValue,
},
},
Spec: computev1alpha1.MachineSpec{
MachineClassRef: corev1.LocalObjectReference{Name: mc.Name},
MachinePoolRef: &corev1.LocalObjectReference{Name: mp.Name},
Volumes: []computev1alpha1.Volume{
{
Name: "primary",
VolumeSource: computev1alpha1.VolumeSource{
VolumeRef: &corev1.LocalObjectReference{Name: volume.Name},
},
},
{
Name: "secondary",
VolumeSource: computev1alpha1.VolumeSource{
VolumeRef: &corev1.LocalObjectReference{Name: secondaryVolume.Name},
},
},
},
NetworkInterfaces: []computev1alpha1.NetworkInterface{
{
Name: "primary",
NetworkInterfaceSource: computev1alpha1.NetworkInterfaceSource{
NetworkInterfaceRef: &corev1.LocalObjectReference{Name: nic.Name},
},
},
},
},
}
Expect(k8sClient.Create(ctx, machine)).To(Succeed())

By("waiting for the runtime to report the machine, volume and network interface")
Eventually(srv).Should(SatisfyAll(
HaveField("Machines", HaveLen(1)),
))
_, iriMachine := GetSingleMapEntry(srv.Machines)

By("inspecting the iri machine volumes")
Expect(iriMachine.Spec.Volumes).To(ConsistOf(&iri.Volume{
Name: "primary",
Device: "oda",
Connection: &iri.VolumeConnection{
Driver: "test",
Handle: "testhandle",
},
}, &iri.Volume{
Name: "secondary",
Device: "odb",
Connection: &iri.VolumeConnection{
Driver: "test",
Handle: "testhandle",
},
}))

By("patching the secondary volume to be in error state")
Eventually(UpdateStatus(secondaryVolume, func() {
secondaryVolume.Status.State = storagev1alpha1.VolumeStateError
})).Should(Succeed())

By("verifying only erroneous volume is detached")
Eventually(func() []*iri.Volume {
return srv.Machines[iriMachine.Metadata.Id].Spec.Volumes
}).Should(SatisfyAll((ConsistOf(&iri.Volume{
Name: "primary",
Device: "oda",
Connection: &iri.VolumeConnection{
Driver: "test",
Handle: "testhandle",
},
}))))
})
})

func GetSingleMapEntry[K comparable, V any](m map[K]V) (K, V) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (r *MachineReconciler) prepareIRIVolumes(
actualVolumeNames := utilslices.ToSetFunc(iriVolumes, (*iri.Volume).GetName)
missingVolumeNames := sets.List(expectedVolumeNames.Difference(actualVolumeNames))
r.Eventf(machine, corev1.EventTypeNormal, events.VolumeNotReady, "Machine volumes are not ready: %v", missingVolumeNames)
return nil, false, nil
return iriVolumes, false, nil
}
return iriVolumes, true, nil
}
Expand Down

0 comments on commit 6cfe69a

Please sign in to comment.