Skip to content

Commit

Permalink
apis: unify the param of get funcs of node resource amplification
Browse files Browse the repository at this point in the history
Signed-off-by: Zach Zhu <[email protected]>
  • Loading branch information
zqzten committed Sep 24, 2023
1 parent fc26933 commit b9bf498
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions apis/extension/node_resource_amplification.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (f Ratio) MarshalJSON() ([]byte, error) {
return []byte(strconv.FormatFloat(float64(f), 'f', 2, 64)), nil
}

// GetNodeResourceAmplificationRatios gets the resource amplification ratios of the node.
// GetNodeResourceAmplificationRatios gets the resource amplification ratios of node from annotations.
func GetNodeResourceAmplificationRatios(annotations map[string]string) (map[corev1.ResourceName]Ratio, error) {
s, ok := annotations[AnnotationNodeResourceAmplificationRatio]
if !ok {
Expand All @@ -59,10 +59,10 @@ func GetNodeResourceAmplificationRatios(annotations map[string]string) (map[core
return ratios, nil
}

// GetNodeResourceAmplificationRatio gets the amplification ratio of a specific resource of the node.
// GetNodeResourceAmplificationRatio gets the amplification ratio of a specific resource of node from annotations.
// It returns -1 without an error when the amplification ratio is not set for this resource.
func GetNodeResourceAmplificationRatio(node *corev1.Node, resource corev1.ResourceName) (Ratio, error) {
ratios, err := GetNodeResourceAmplificationRatios(node.Annotations)
func GetNodeResourceAmplificationRatio(annotations map[string]string, resource corev1.ResourceName) (Ratio, error) {
ratios, err := GetNodeResourceAmplificationRatios(annotations)
if err != nil {
return -1, err
}
Expand Down Expand Up @@ -106,9 +106,9 @@ func SetNodeResourceAmplificationRatio(node *corev1.Node, resource corev1.Resour
return true, nil
}

// GetNodeRawCapacity gets the raw capacity of the node.
func GetNodeRawCapacity(node *corev1.Node) (corev1.ResourceList, error) {
s, ok := node.Annotations[AnnotationNodeRawCapacity]
// GetNodeRawCapacity gets the raw capacity of node from annotations.
func GetNodeRawCapacity(annotations map[string]string) (corev1.ResourceList, error) {
s, ok := annotations[AnnotationNodeRawCapacity]
if !ok {
return nil, nil
}
Expand All @@ -130,9 +130,9 @@ func SetNodeRawCapacity(node *corev1.Node, capacity corev1.ResourceList) {
node.Annotations[AnnotationNodeRawCapacity] = string(s)
}

// GetNodeRawAllocatable gets the raw allocatable of the node.
func GetNodeRawAllocatable(node *corev1.Node) (corev1.ResourceList, error) {
s, ok := node.Annotations[AnnotationNodeRawAllocatable]
// GetNodeRawAllocatable gets the raw allocatable of node from annotations.
func GetNodeRawAllocatable(annotations map[string]string) (corev1.ResourceList, error) {
s, ok := annotations[AnnotationNodeRawAllocatable]
if !ok {
return nil, nil
}
Expand Down
6 changes: 3 additions & 3 deletions apis/extension/node_resource_amplification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestGetNodeResourceAmplificationRatio(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, gotErr := GetNodeResourceAmplificationRatio(tt.args.node, tt.args.resource)
got, gotErr := GetNodeResourceAmplificationRatio(tt.args.node.Annotations, tt.args.resource)
assert.Equal(t, tt.want, got)
assert.Equal(t, tt.wantErr, gotErr != nil)
})
Expand Down Expand Up @@ -425,7 +425,7 @@ func TestGetNodeRawCapacity(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, gotErr := GetNodeRawCapacity(tt.arg)
got, gotErr := GetNodeRawCapacity(tt.arg.Annotations)
assert.Equal(t, tt.want, got)
assert.Equal(t, tt.wantErr, gotErr != nil)
})
Expand Down Expand Up @@ -545,7 +545,7 @@ func TestGetNodeRawAllocatable(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, gotErr := GetNodeRawAllocatable(tt.arg)
got, gotErr := GetNodeRawAllocatable(tt.arg.Annotations)
assert.Equal(t, tt.want, got)
assert.Equal(t, tt.wantErr, gotErr != nil)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func estimatedUsedByResource(requests, limits corev1.ResourceList, resourceName
}

func (e *DefaultEstimator) EstimateNode(node *corev1.Node) (corev1.ResourceList, error) {
rawAllocatable, err := extension.GetNodeRawAllocatable(node)
rawAllocatable, err := extension.GetNodeRawAllocatable(node.Annotations)
if err != nil {
return node.Status.Allocatable, nil
}
Expand Down

0 comments on commit b9bf498

Please sign in to comment.