Skip to content

Commit

Permalink
changes for machine status to track a reference for its claimed Volum…
Browse files Browse the repository at this point in the history
…e resource
  • Loading branch information
ushabelgur authored and Rohit-0505 committed Oct 3, 2024
1 parent 07f85be commit 8fce8ad
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 7 deletions.
2 changes: 2 additions & 0 deletions api/compute/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ type VolumeStatus struct {
State VolumeState `json:"state,omitempty"`
// LastStateTransitionTime is the last time the State transitioned.
LastStateTransitionTime *metav1.Time `json:"lastStateTransitionTime,omitempty"`
// VolumeRef reference to the claimed Volume
VolumeRef corev1.LocalObjectReference `json:"volumeRef,omitempty"`
}

// VolumeState is the infrastructure attachment state a Volume can be in.
Expand Down
1 change: 1 addition & 0 deletions api/compute/v1alpha1/zz_generated.deepcopy.go

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

18 changes: 14 additions & 4 deletions client-go/applyconfigurations/compute/v1alpha1/volumestatus.go

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

4 changes: 4 additions & 0 deletions client-go/applyconfigurations/internal/internal.go

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

9 changes: 8 additions & 1 deletion client-go/openapi/zz_generated.openapi.go

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

2 changes: 2 additions & 0 deletions internal/apis/compute/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ type VolumeStatus struct {
State VolumeState
// LastStateTransitionTime is the last time the State transitioned.
LastStateTransitionTime *metav1.Time
//VolumeRef reference to the claimed Volume
VolumeRef corev1.LocalObjectReference
}

// VolumeState is the infrastructure attachment state a Volume can be in.
Expand Down
2 changes: 2 additions & 0 deletions internal/apis/compute/v1alpha1/zz_generated.conversion.go

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

1 change: 1 addition & 0 deletions internal/apis/compute/zz_generated.deepcopy.go

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

100 changes: 100 additions & 0 deletions poollet/machinepoollet/controllers/machine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
. "github.com/onsi/gomega/gstruct"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
)
Expand Down Expand Up @@ -325,6 +326,13 @@ var _ = Describe("MachineController", func() {
Eventually(srv.Machines[iriMachine.Metadata.Id]).Should(SatisfyAll(
HaveField("Spec.NetworkInterfaces", BeEmpty()),
))

By("Verifying ironcore machine volume status with correct volume reference")
Eventually(Object(machine)).Should(HaveField("Status.Volumes", ConsistOf(MatchFields(IgnoreExtras, Fields{
"Name": Equal("primary"),
"State": Equal(computev1alpha1.VolumeStatePending),
"VolumeRef": Equal(corev1.LocalObjectReference{Name: volume.Name}),
}))))
})

It("should correctly manage the power state of a machine", func(ctx SpecContext) {
Expand Down Expand Up @@ -392,6 +400,98 @@ var _ = Describe("MachineController", func() {
srv.SetMachines([]*testingmachine.FakeMachine{iriMachine})
Eventually(Object(machine)).Should(HaveField("Status.State", Equal(computev1alpha1.MachineStateTerminating)))
})

It("should create a machine and verify claimed volume reference with ephemeral volume", func(ctx SpecContext) {
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{
Ephemeral: &computev1alpha1.EphemeralVolumeSource{
VolumeTemplate: &storagev1alpha1.VolumeTemplateSpec{
Spec: storagev1alpha1.VolumeSpec{},
},
},
},
},
},
},
}
Expect(k8sClient.Create(ctx, machine)).To(Succeed())
By("By getting ephimeral volume")
volumeKey := types.NamespacedName{
Namespace: ns.Name,
Name: computev1alpha1.MachineEphemeralVolumeName(machine.Name, "primary"),
}
ephimeralVolume := &storagev1alpha1.Volume{}
Eventually(func(g Gomega) {
err := k8sClient.Get(ctx, volumeKey, ephimeralVolume)
Expect(client.IgnoreNotFound(err)).NotTo(HaveOccurred())
g.Expect(err).NotTo(HaveOccurred())
}).Should(Succeed())

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

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

By("inspecting the iri machine")
Expect(iriMachine.Metadata.Labels).To(HaveKeyWithValue(machinepoolletv1alpha1.DownwardAPILabel(fooDownwardAPILabel), fooAnnotationValue))
Expect(iriMachine.Spec.Class).To(Equal(mc.Name))
Expect(iriMachine.Spec.Power).To(Equal(iri.Power_POWER_ON))
Expect(iriMachine.Spec.Volumes).To(ConsistOf(&iri.Volume{
Name: "primary",
Device: "oda",
Connection: &iri.VolumeConnection{
Driver: "test",
Handle: "testhandle",
},
}))

By("waiting for the ironcore machine status to be up-to-date")
expectedMachineID := machinepoolletmachine.MakeID(testingmachine.FakeRuntimeName, iriMachine.Metadata.Id)
Eventually(Object(machine)).Should(SatisfyAll(
HaveField("Status.MachineID", expectedMachineID.String()),
HaveField("Status.ObservedGeneration", machine.Generation),
))

By("setting the network interface id in the machine status")
iriMachine = &testingmachine.FakeMachine{Machine: *proto.Clone(&iriMachine.Machine).(*iri.Machine)}
iriMachine.Metadata.Generation = 1
iriMachine.Status.ObservedGeneration = 1

srv.SetMachines([]*testingmachine.FakeMachine{iriMachine})

By("Verifying ironcore machine volume status with correct volume reference")
Eventually(Object(machine)).Should(HaveField("Status.Volumes", ConsistOf(MatchFields(IgnoreExtras, Fields{
"Name": Equal("primary"),
"State": Equal(computev1alpha1.VolumeStatePending),
"VolumeRef": Equal(corev1.LocalObjectReference{Name: ephimeralVolume.Name}),
}))))
})

})

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 @@ -353,10 +353,12 @@ func (r *MachineReconciler) getVolumeStatusesForMachine(
if err != nil {
return nil, fmt.Errorf("[volume %s] %w", machineVolume.Name, err)
}
volumeStatusValues.VolumeRef = corev1.LocalObjectReference{Name: computev1alpha1.MachineVolumeName(machine.Name, machineVolume)}
} else {
volumeStatusValues = computev1alpha1.VolumeStatus{
Name: machineVolume.Name,
State: computev1alpha1.VolumeStatePending,
Name: machineVolume.Name,
State: computev1alpha1.VolumeStatePending,
VolumeRef: corev1.LocalObjectReference{Name: computev1alpha1.MachineVolumeName(machine.Name, machineVolume)},
}
}

Expand Down Expand Up @@ -402,4 +404,5 @@ func (r *MachineReconciler) addVolumeStatusValues(now metav1.Time, existing, new
existing.Name = newValues.Name
existing.State = newValues.State
existing.Handle = newValues.Handle
existing.VolumeRef = newValues.VolumeRef
}

0 comments on commit 8fce8ad

Please sign in to comment.