Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #13 from nebius/PLATFORMINFRA-198
Browse files Browse the repository at this point in the history
PLATFORMINFRA-198: namespaced byohost selector
  • Loading branch information
bullet1337 authored Apr 2, 2024
2 parents 5f72e50 + 8d3a7db commit a8967b2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion controllers/infrastructure/byomachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func (r *ByoMachineReconciler) attachByoHost(ctx context.Context, machineScope *
byohostLabels, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.DoesNotExist, nil)
selector = selector.Add(*byohostLabels)

err = r.Client.List(ctx, hostsList, &client.ListOptions{LabelSelector: selector})
err = r.Client.List(ctx, hostsList, &client.ListOptions{LabelSelector: selector, Namespace: machineScope.ByoMachine.Namespace})
if err != nil {
logger.Error(err, "failed to list byohosts")
return ctrl.Result{RequeueAfter: RequeueForbyohost}, err
Expand Down
50 changes: 50 additions & 0 deletions controllers/infrastructure/byomachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var _ = Describe("Controllers/ByomachineController", func() {
k8sInstallerConfigTemplate *infrastructurev1beta1.K8sInstallerConfigTemplate
k8sInstallerConfig *infrastructurev1beta1.K8sInstallerConfig
byoHost *infrastructurev1beta1.ByoHost
differentNamespace *corev1.Namespace
testClusterVersion = "v1.22.1_xyz"
)

Expand Down Expand Up @@ -654,6 +655,55 @@ var _ = Describe("Controllers/ByomachineController", func() {
})
})

Context("When no BYO Hosts are available in the same namespace", func() {
BeforeEach(func() {
differentNamespace = builder.Namespace("different-namespace").Build()
Expect(k8sClientUncached.Create(ctx, differentNamespace)).Should(Succeed())
byoHost = builder.ByoHost(differentNamespace.Name, "byohost-in-different-namespace").
WithLabels(map[string]string{"CPUs": "4"}).
Build()
Expect(k8sClientUncached.Create(ctx, byoHost)).Should(Succeed())

byoMachine = builder.ByoMachine(defaultNamespace, "byomachine-with-label-selector").
WithClusterLabel(defaultClusterName).
WithOwnerMachine(machine).
WithLabelSelector(map[string]string{"CPUs": "4"}).
Build()
Expect(k8sClientUncached.Create(ctx, byoMachine)).Should(Succeed())

WaitForObjectsToBePopulatedInCache(byoHost, byoMachine)
byoMachineLookupKey = types.NamespacedName{Name: byoMachine.Name, Namespace: byoMachine.Namespace}
})

AfterEach(func() {
Expect(k8sClientUncached.Delete(ctx, byoHost)).ToNot(HaveOccurred())
Expect(k8sClientUncached.Delete(ctx, differentNamespace)).ToNot(HaveOccurred())
})

It("should mark BYOHostReady as False when BYOHosts is available but namespace is different", func() {
_, err := reconciler.Reconcile(ctx, reconcile.Request{NamespacedName: byoMachineLookupKey})
Expect(err).To(MatchError("no hosts found"))

createdByoMachine := &infrastructurev1beta1.ByoMachine{}
err = k8sClientUncached.Get(ctx, byoMachineLookupKey, createdByoMachine)
Expect(err).ToNot(HaveOccurred())

actualCondition := conditions.Get(createdByoMachine, infrastructurev1beta1.BYOHostReady)
Expect(*actualCondition).To(conditions.MatchCondition(clusterv1.Condition{
Type: infrastructurev1beta1.BYOHostReady,
Status: corev1.ConditionFalse,
Reason: infrastructurev1beta1.BYOHostsUnavailableReason,
Severity: clusterv1.ConditionSeverityInfo,
}))

// assert events
events := eventutils.CollectEvents(recorder.Events)
Expect(events).Should(ConsistOf([]string{
"Warning ByoHostSelectionFailed No available ByoHost",
}))
})
})

Context("When all ByoHost are attached", func() {
BeforeEach(func() {
byoHost = builder.ByoHost(defaultNamespace, "byohost-attached-different-cluster").
Expand Down

0 comments on commit a8967b2

Please sign in to comment.