-
Notifications
You must be signed in to change notification settings - Fork 1.4k
🌱 MinReadySeconds for machinepools #9837
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/tools/record" | ||
"k8s.io/utils/ptr" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
|
||
|
@@ -44,6 +45,14 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
Spec: corev1.NodeSpec{ | ||
ProviderID: "aws://us-east-1/id-node-1", | ||
}, | ||
Status: corev1.NodeStatus{ | ||
Conditions: []corev1.NodeCondition{ | ||
{ | ||
Type: corev1.NodeReady, | ||
Status: corev1.ConditionTrue, | ||
}, | ||
}, | ||
}, | ||
}, | ||
&corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
|
@@ -52,6 +61,22 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
Spec: corev1.NodeSpec{ | ||
ProviderID: "aws://us-west-2/id-node-2", | ||
}, | ||
Status: corev1.NodeStatus{ | ||
Conditions: []corev1.NodeCondition{ | ||
{ | ||
Type: corev1.NodeReady, | ||
Status: corev1.ConditionTrue, | ||
}, | ||
}, | ||
}, | ||
}, | ||
&corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "node-3", | ||
}, | ||
Spec: corev1.NodeSpec{ | ||
ProviderID: "aws://us-west-2/id-node-3", | ||
}, | ||
}, | ||
&corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
|
@@ -60,6 +85,14 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
Spec: corev1.NodeSpec{ | ||
ProviderID: "gce://us-central1/gce-id-node-2", | ||
}, | ||
Status: corev1.NodeStatus{ | ||
Conditions: []corev1.NodeCondition{ | ||
{ | ||
Type: corev1.NodeReady, | ||
Status: corev1.ConditionTrue, | ||
}, | ||
}, | ||
}, | ||
}, | ||
&corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
|
@@ -68,6 +101,14 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
Spec: corev1.NodeSpec{ | ||
ProviderID: "azure://westus2/id-node-4", | ||
}, | ||
Status: corev1.NodeStatus{ | ||
Conditions: []corev1.NodeCondition{ | ||
{ | ||
Type: corev1.NodeReady, | ||
Status: corev1.ConditionTrue, | ||
}, | ||
}, | ||
}, | ||
}, | ||
&corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
|
@@ -76,6 +117,14 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
Spec: corev1.NodeSpec{ | ||
ProviderID: "azure://westus2/id-nodepool1/0", | ||
}, | ||
Status: corev1.NodeStatus{ | ||
Conditions: []corev1.NodeCondition{ | ||
{ | ||
Type: corev1.NodeReady, | ||
Status: corev1.ConditionTrue, | ||
}, | ||
}, | ||
}, | ||
}, | ||
&corev1.Node{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
|
@@ -84,16 +133,25 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
Spec: corev1.NodeSpec{ | ||
ProviderID: "azure://westus2/id-nodepool2/0", | ||
}, | ||
Status: corev1.NodeStatus{ | ||
Conditions: []corev1.NodeCondition{ | ||
{ | ||
Type: corev1.NodeReady, | ||
Status: corev1.ConditionTrue, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
client := fake.NewClientBuilder().WithObjects(nodeList...).Build() | ||
|
||
testCases := []struct { | ||
name string | ||
providerIDList []string | ||
expected *getNodeReferencesResult | ||
err error | ||
name string | ||
providerIDList []string | ||
expected *getNodeReferencesResult | ||
err error | ||
minReadySeconds int32 | ||
}{ | ||
{ | ||
name: "valid provider id, valid aws node", | ||
|
@@ -102,6 +160,8 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
references: []corev1.ObjectReference{ | ||
{Name: "node-1"}, | ||
}, | ||
available: 1, | ||
ready: 1, | ||
}, | ||
}, | ||
{ | ||
|
@@ -111,6 +171,19 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
references: []corev1.ObjectReference{ | ||
{Name: "node-2"}, | ||
}, | ||
available: 1, | ||
ready: 1, | ||
}, | ||
}, | ||
{ | ||
name: "valid provider id, valid aws node, nodeReady condition set to false", | ||
providerIDList: []string{"aws://us-west-2/id-node-3"}, | ||
expected: &getNodeReferencesResult{ | ||
references: []corev1.ObjectReference{ | ||
{Name: "node-3"}, | ||
}, | ||
available: 0, | ||
ready: 0, | ||
}, | ||
}, | ||
{ | ||
|
@@ -120,6 +193,8 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
references: []corev1.ObjectReference{ | ||
{Name: "gce-node-2"}, | ||
}, | ||
available: 1, | ||
ready: 1, | ||
}, | ||
}, | ||
{ | ||
|
@@ -129,6 +204,8 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
references: []corev1.ObjectReference{ | ||
{Name: "azure-node-4"}, | ||
}, | ||
available: 1, | ||
ready: 1, | ||
}, | ||
}, | ||
{ | ||
|
@@ -139,6 +216,8 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
{Name: "node-1"}, | ||
{Name: "azure-node-4"}, | ||
}, | ||
available: 2, | ||
ready: 2, | ||
}, | ||
}, | ||
{ | ||
|
@@ -163,6 +242,8 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
references: []corev1.ObjectReference{ | ||
{Name: "azure-nodepool1-0"}, | ||
}, | ||
available: 1, | ||
ready: 1, | ||
}, | ||
}, | ||
{ | ||
|
@@ -173,15 +254,37 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
{Name: "azure-nodepool1-0"}, | ||
{Name: "azure-nodepool2-0"}, | ||
}, | ||
available: 2, | ||
ready: 2, | ||
}, | ||
}, | ||
{ | ||
name: "valid provider id, valid aws node, with minReadySeconds", | ||
providerIDList: []string{"aws://us-east-1/id-node-1"}, | ||
expected: &getNodeReferencesResult{ | ||
references: []corev1.ObjectReference{{Name: "node-1"}}, | ||
available: 0, | ||
sbueringer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ready: 1, | ||
}, | ||
minReadySeconds: 20, | ||
}, | ||
{ | ||
name: "valid provider id, valid aws node, with minReadySeconds equals 0", | ||
providerIDList: []string{"aws://us-east-1/id-node-1"}, | ||
expected: &getNodeReferencesResult{ | ||
references: []corev1.ObjectReference{{Name: "node-1"}}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in a previous comment. Let's start validating expected.available/ready against result (somewhere ~ in l.219) Today this test never validates the available and ready fields. In fact. At the moment they are always 0 because we never set conditions correctly to get ready or available Nodes. Let's change that as well. (otherwise we don't have any test coverage for ready/available) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't able to follow the force-pushes but I see that the test is now validating available and ready fields based on a different minReadySeconds. That looks good!! I think the only thing missing is a test case when the NodeReady condition is false, both ready and available should be 0. |
||
available: 1, | ||
ready: 1, | ||
}, | ||
minReadySeconds: 0, | ||
}, | ||
} | ||
|
||
for _, test := range testCases { | ||
t.Run(test.name, func(t *testing.T) { | ||
g := NewWithT(t) | ||
|
||
result, err := r.getNodeReferences(ctx, client, test.providerIDList) | ||
result, err := r.getNodeReferences(ctx, client, test.providerIDList, ptr.To(test.minReadySeconds)) | ||
if test.err == nil { | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
} else { | ||
|
@@ -195,6 +298,9 @@ func TestMachinePoolGetNodeReference(t *testing.T) { | |
|
||
g.Expect(result.references).To(HaveLen(len(test.expected.references)), "Expected NodeRef count to be %v, got %v", len(result.references), len(test.expected.references)) | ||
|
||
g.Expect(result.available).To(Equal(test.expected.available), "Expected available node count to be %v, got %v", test.expected.available, result.available) | ||
g.Expect(result.ready).To(Equal(test.expected.ready), "Expected ready node count to be %v, got %v", test.expected.ready, result.ready) | ||
|
||
for n := range test.expected.references { | ||
g.Expect(result.references[n].Name).To(Equal(test.expected.references[n].Name), "Expected NodeRef's name to be %v, got %v", result.references[n].Name, test.expected.references[n].Name) | ||
g.Expect(result.references[n].Namespace).To(Equal(test.expected.references[n].Namespace), "Expected NodeRef's namespace to be %v, got %v", result.references[n].Namespace, test.expected.references[n].Namespace) | ||
|
Uh oh!
There was an error while loading. Please reload this page.