-
Notifications
You must be signed in to change notification settings - Fork 13
Monitor MachinePool Health
#1476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
caaf1d3
20479ee
dfbde77
b5cb8db
5e558bc
b680ff0
19013f7
8c93fce
2dd3b0a
4f324d3
9767f6e
25c5ff8
5f530b9
396214d
4d187cb
647d10a
12e5ec7
3da78dd
76df535
5744f71
14e2f89
10a03d4
eedce59
5690f06
d89d8e4
58dcd60
1eb1426
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and IronCore contributors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package v1alpha1 | ||
|
|
||
| import ( | ||
| "slices" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // FindMachinePoolCondition returns a pointer to the condition of the given type, | ||
| // or nil if no condition of that type is present. | ||
| func FindMachinePoolCondition(conditions []MachinePoolCondition, typ MachinePoolConditionType) *MachinePoolCondition { | ||
| idx := slices.IndexFunc(conditions, func(cond MachinePoolCondition) bool { | ||
| return cond.Type == typ | ||
| }) | ||
| if idx < 0 { | ||
| return nil | ||
| } | ||
| return &conditions[idx] | ||
| } | ||
|
|
||
| // SetMachinePoolCondition inserts or updates a condition of the given type in the | ||
| // conditions slice. LastUpdateTime is always set to now. LastTransitionTime is set | ||
| // to now only when the condition is newly inserted or its Status differs from the | ||
| // previous value. | ||
| func SetMachinePoolCondition(conditions []MachinePoolCondition, cond MachinePoolCondition) []MachinePoolCondition { | ||
| idx := slices.IndexFunc(conditions, func(c MachinePoolCondition) bool { | ||
| return c.Type == cond.Type | ||
| }) | ||
|
|
||
| cond.LastUpdateTime = metav1.Now() | ||
|
|
||
| if idx < 0 || conditions[idx].Status != cond.Status { | ||
| cond.LastTransitionTime = metav1.Now() | ||
| } else { | ||
| cond.LastTransitionTime = conditions[idx].LastTransitionTime | ||
| } | ||
|
|
||
| if idx < 0 { | ||
| return append(conditions, cond) | ||
| } | ||
| conditions[idx] = cond | ||
| return conditions | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and IronCore contributors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package v1alpha1_test | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| computev1alpha1 "github.com/ironcore-dev/ironcore/api/compute/v1alpha1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| func TestFindMachinePoolCondition_returnsMatch(t *testing.T) { | ||
| conds := []computev1alpha1.MachinePoolCondition{ | ||
| {Type: "Other", Status: corev1.ConditionTrue}, | ||
| {Type: computev1alpha1.MachinePoolReady, Status: corev1.ConditionFalse, Reason: "X"}, | ||
| } | ||
| got := computev1alpha1.FindMachinePoolCondition(conds, computev1alpha1.MachinePoolReady) | ||
| if got == nil || got.Reason != "X" { | ||
| t.Fatalf("expected Ready condition with reason X, got %+v", got) | ||
| } | ||
| } | ||
|
|
||
| func TestFindMachinePoolCondition_returnsNilWhenMissing(t *testing.T) { | ||
| conds := []computev1alpha1.MachinePoolCondition{{Type: "Other"}} | ||
| if got := computev1alpha1.FindMachinePoolCondition(conds, computev1alpha1.MachinePoolReady); got != nil { | ||
| t.Fatalf("expected nil, got %+v", got) | ||
| } | ||
| } | ||
|
|
||
| func TestSetMachinePoolCondition_appendsWhenAbsent(t *testing.T) { | ||
| out := computev1alpha1.SetMachinePoolCondition(nil, computev1alpha1.MachinePoolCondition{ | ||
| Type: computev1alpha1.MachinePoolReady, | ||
| Status: corev1.ConditionTrue, | ||
| }) | ||
| if len(out) != 1 || out[0].Type != computev1alpha1.MachinePoolReady { | ||
| t.Fatalf("expected Ready appended, got %+v", out) | ||
| } | ||
| if out[0].LastTransitionTime.IsZero() { | ||
| t.Fatal("expected LastTransitionTime to be set on first append") | ||
| } | ||
| if out[0].LastUpdateTime.IsZero() { | ||
| t.Fatal("expected LastUpdateTime to be set on first append") | ||
| } | ||
| } | ||
|
|
||
| func TestSetMachinePoolCondition_updatesInPlaceWithoutTransition(t *testing.T) { | ||
| earlier := metav1.NewTime(time.Now().Add(-time.Hour)) | ||
| in := []computev1alpha1.MachinePoolCondition{{ | ||
| Type: computev1alpha1.MachinePoolReady, | ||
| Status: corev1.ConditionTrue, | ||
| LastTransitionTime: earlier, | ||
| }} | ||
| out := computev1alpha1.SetMachinePoolCondition(in, computev1alpha1.MachinePoolCondition{ | ||
| Type: computev1alpha1.MachinePoolReady, | ||
| Status: corev1.ConditionTrue, // same status | ||
| Message: "still ready", | ||
| }) | ||
| if !out[0].LastTransitionTime.Equal(&earlier) { | ||
| t.Fatalf("expected LastTransitionTime preserved when status unchanged, got %v", out[0].LastTransitionTime) | ||
| } | ||
| if out[0].LastUpdateTime.IsZero() { | ||
| t.Fatal("expected LastUpdateTime advanced") | ||
| } | ||
| } | ||
|
|
||
| func TestSetMachinePoolCondition_advancesTransitionWhenStatusChanges(t *testing.T) { | ||
| earlier := metav1.NewTime(time.Now().Add(-time.Hour)) | ||
| in := []computev1alpha1.MachinePoolCondition{{ | ||
| Type: computev1alpha1.MachinePoolReady, | ||
| Status: corev1.ConditionTrue, | ||
| LastTransitionTime: earlier, | ||
| }} | ||
| out := computev1alpha1.SetMachinePoolCondition(in, computev1alpha1.MachinePoolCondition{ | ||
| Type: computev1alpha1.MachinePoolReady, | ||
| Status: corev1.ConditionFalse, | ||
| }) | ||
| if out[0].LastTransitionTime.Equal(&earlier) { | ||
| t.Fatal("expected LastTransitionTime to advance when status changes") | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.