Skip to content

Commit

Permalink
chore: Only consider node shape for requested resources (aws#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis authored Oct 25, 2023
1 parent f65946b commit 8c11172
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
9 changes: 9 additions & 0 deletions pkg/controllers/nodeclaim/consistency/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ var _ = Describe("MachineController", func() {
v1alpha5.LabelNodeInitialized: "true",
},
},
Spec: v1alpha5.MachineSpec{
Resources: v1alpha5.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("8"),
v1.ResourceMemory: resource.MustParse("64Gi"),
v1.ResourcePods: resource.MustParse("5"),
},
},
},
Status: v1alpha5.MachineStatus{
ProviderID: test.RandomProviderID(),
Capacity: v1.ResourceList{
Expand Down
9 changes: 9 additions & 0 deletions pkg/controllers/nodeclaim/consistency/nodeclaim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ var _ = Describe("NodeClaimController", func() {
v1beta1.NodeInitializedLabelKey: "true",
},
},
Spec: v1beta1.NodeClaimSpec{
Resources: v1beta1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("8"),
v1.ResourceMemory: resource.MustParse("64Gi"),
v1.ResourcePods: resource.MustParse("5"),
},
},
},
Status: v1beta1.NodeClaimStatus{
ProviderID: test.RandomProviderID(),
Capacity: v1.ResourceList{
Expand Down
14 changes: 6 additions & 8 deletions pkg/controllers/nodeclaim/consistency/nodeshape.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,26 @@ func NewNodeShape(provider cloudprovider.CloudProvider) Check {
}

func (n *NodeShape) Check(_ context.Context, node *v1.Node, nodeClaim *v1beta1.NodeClaim) ([]Issue, error) {
// ignore machines that are deleting
// ignore NodeClaims that are deleting
if !nodeClaim.DeletionTimestamp.IsZero() {
return nil, nil
}
// and machines that haven't initialized yet
// and NodeClaims that haven't initialized yet
if !nodeClaim.StatusConditions().GetCondition(v1beta1.Initialized).IsTrue() {
return nil, nil
}
var issues []Issue
for resourceName, expectedQuantity := range nodeClaim.Status.Capacity {
nodeQuantity, ok := node.Status.Capacity[resourceName]
if !ok && !expectedQuantity.IsZero() {
issues = append(issues, Issue(fmt.Sprintf("expected resource %q not found", resourceName)))
for resourceName, requested := range nodeClaim.Spec.Resources.Requests {
nodeQuantity := node.Status.Capacity[resourceName]
expectedQuantity := nodeClaim.Status.Capacity[resourceName]
if requested.IsZero() || expectedQuantity.IsZero() {
continue
}

pct := nodeQuantity.AsApproximateFloat64() / expectedQuantity.AsApproximateFloat64()
if pct < 0.90 {
issues = append(issues, Issue(fmt.Sprintf("expected %s of resource %s, but found %s (%0.1f%% of expected)", expectedQuantity.String(),
resourceName, nodeQuantity.String(), pct*100)))
}

}
return issues, nil
}

0 comments on commit 8c11172

Please sign in to comment.