Skip to content

Commit e806138

Browse files
committed
remove label key overwrite to fix re-creation of already existing machine
fix
1 parent f522663 commit e806138

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

poollet/machinepoollet/controllers/controllers_suite_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ import (
2121
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
2222
"github.com/ironcore-dev/ironcore/iri/testing/machine"
2323
"github.com/ironcore-dev/ironcore/poollet/irievent"
24+
"github.com/ironcore-dev/ironcore/poollet/machinepoollet/api/v1alpha1"
2425
machinepoolletclient "github.com/ironcore-dev/ironcore/poollet/machinepoollet/client"
2526
"github.com/ironcore-dev/ironcore/poollet/machinepoollet/controllers"
2627
"github.com/ironcore-dev/ironcore/poollet/machinepoollet/mcm"
2728
utilsenvtest "github.com/ironcore-dev/ironcore/utils/envtest"
2829
"github.com/ironcore-dev/ironcore/utils/envtest/apiserver"
2930
"github.com/ironcore-dev/ironcore/utils/envtest/controllermanager"
3031
"github.com/ironcore-dev/ironcore/utils/envtest/process"
31-
. "github.com/onsi/ginkgo/v2"
32-
. "github.com/onsi/gomega"
32+
3333
corev1 "k8s.io/api/core/v1"
3434
"k8s.io/apimachinery/pkg/api/resource"
3535
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -41,10 +41,13 @@ import (
4141
"sigs.k8s.io/controller-runtime/pkg/client"
4242
ctrlconfig "sigs.k8s.io/controller-runtime/pkg/config"
4343
"sigs.k8s.io/controller-runtime/pkg/envtest"
44-
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
4544
logf "sigs.k8s.io/controller-runtime/pkg/log"
4645
"sigs.k8s.io/controller-runtime/pkg/log/zap"
4746
metricserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
47+
48+
. "github.com/onsi/ginkgo/v2"
49+
. "github.com/onsi/gomega"
50+
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
4851
)
4952

5053
var (
@@ -231,7 +234,8 @@ func SetupTest() (*corev1.Namespace, *computev1alpha1.MachinePool, *computev1alp
231234
MachineClassMapper: machineClassMapper,
232235
MachinePoolName: mp.Name,
233236
DownwardAPILabels: map[string]string{
234-
fooDownwardAPILabel: fmt.Sprintf("metadata.annotations['%s']", fooAnnotation),
237+
fooDownwardAPILabel: fmt.Sprintf("metadata.annotations['%s']", fooAnnotation),
238+
v1alpha1.RootMachineUIDLabelSuffix: "metadata.uid",
235239
},
236240
}).SetupWithManager(k8sManager)).To(Succeed())
237241

poollet/machinepoollet/controllers/machine_controller.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@ func (r *MachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
9797

9898
func (r *MachineReconciler) getIRIMachinesForMachine(ctx context.Context, machine *computev1alpha1.Machine) ([]*iri.Machine, error) {
9999
labelKey := poolletutils.DownwardAPILabel(v1alpha1.MachineDownwardAPIPrefix, v1alpha1.RootMachineUIDLabelSuffix)
100-
machineUID := machine.Labels[poolletutils.DownwardAPILabel(v1alpha1.MachineDownwardAPIPrefix, v1alpha1.RootMachineUIDLabelSuffix)]
100+
machineUID := machine.Labels[labelKey]
101101
if machineUID == "" {
102102
machineUID = string(machine.GetUID())
103-
labelKey = v1alpha1.MachineUIDLabel
104103
}
105104
labels := map[string]string{
106105
labelKey: machineUID,
@@ -217,10 +216,9 @@ func (r *MachineReconciler) delete(ctx context.Context, log logr.Logger, machine
217216

218217
log.V(1).Info("Deleting machines by UID")
219218
labelKey := poolletutils.DownwardAPILabel(v1alpha1.MachineDownwardAPIPrefix, v1alpha1.RootMachineUIDLabelSuffix)
220-
machineUID := machine.Labels[poolletutils.DownwardAPILabel(v1alpha1.MachineDownwardAPIPrefix, v1alpha1.RootMachineUIDLabelSuffix)]
219+
machineUID := machine.Labels[labelKey]
221220
if machineUID == "" {
222221
machineUID = string(machine.GetUID())
223-
labelKey = v1alpha1.MachineUIDLabel
224222
}
225223
labels := map[string]string{
226224
labelKey: machineUID,

poollet/machinepoollet/mem/mem_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
1515
"github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
1616
fakemachine "github.com/ironcore-dev/ironcore/iri/testing/machine"
17+
machinepoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/machinepoollet/api/v1alpha1"
1718
"github.com/ironcore-dev/ironcore/poollet/machinepoollet/controllers"
1819
"github.com/ironcore-dev/ironcore/poollet/machinepoollet/mcm"
1920
"github.com/ironcore-dev/ironcore/poollet/machinepoollet/mem"
@@ -82,6 +83,7 @@ var _ = Describe("MachineEventMapper", func() {
8283
MachinePoolName: mp.Name,
8384
DownwardAPILabels: map[string]string{
8485
fooDownwardAPILabel: fmt.Sprintf("metadata.annotations['%s']", fooAnnotation),
86+
machinepoolletv1alpha1.RootMachineUIDLabelSuffix: "metadata.uid",
8587
},
8688
}).SetupWithManager(k8sManager)).To(Succeed())
8789

0 commit comments

Comments
 (0)