Skip to content

Commit

Permalink
yarn-operator: add uts (#63)
Browse files Browse the repository at this point in the history
Signed-off-by: 佑祎 <zzw261520@alibaba-inc.com>
  • Loading branch information
zwzhang0107 committed Dec 7, 2023
1 parent c8a0705 commit 94bfc5a
Show file tree
Hide file tree
Showing 4 changed files with 419 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
k8s.io/api v0.26.0
k8s.io/apimachinery v0.26.0
k8s.io/client-go v0.26.0
k8s.io/cri-api v0.25.3
k8s.io/cri-api v0.25.3 // indirect
k8s.io/klog/v2 v2.80.1
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
sigs.k8s.io/controller-runtime v0.12.3
Expand Down
16 changes: 8 additions & 8 deletions pkg/controller/noderesource/resource_sync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"strings"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/cri-api/pkg/errors"
"k8s.io/klog/v2"
"k8s.io/utils/pointer"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -96,10 +96,7 @@ func (r *YARNResourceSyncReconciler) Reconcile(ctx context.Context, req reconcil
klog.V(4).Infof("update batch resource to yarn node %+v finish, cpu-core %v, memory-mb %v, k8s node name: %s",
yarnNode, vcores, memoryMB, node.Name)

core, mb, err := r.getYARNNodeAllocatedResource(yarnNode)
if err != nil {
return reconcile.Result{Requeue: true}, err
}
core, mb := r.getYARNNodeAllocatedResource(yarnNode)
if err := r.updateYARNAllocatedResource(node, core, mb); err != nil {
klog.Warningf("failed to update yarn allocated resource for node %v, error %v", node.Name, err)
return reconcile.Result{Requeue: true}, err
Expand Down Expand Up @@ -144,6 +141,9 @@ func (r *YARNResourceSyncReconciler) updateYARNAllocatedResource(node *corev1.No
return nil
}
newNode := node.DeepCopy()
if newNode.Annotations == nil {
newNode.Annotations = map[string]string{}
}
if err := SetYARNAllocatedResource(newNode.Annotations, vcores, memoryMB); err != nil {
return err
}
Expand Down Expand Up @@ -316,13 +316,13 @@ func (r *YARNResourceSyncReconciler) getYARNClient(yarnNode *cache.YarnNode) (ya
return clusterClient, nil
}

func (r *YARNResourceSyncReconciler) getYARNNodeAllocatedResource(yarnNode *cache.YarnNode) (vcores int32, memoryMB int64, err error) {
func (r *YARNResourceSyncReconciler) getYARNNodeAllocatedResource(yarnNode *cache.YarnNode) (vcores int32, memoryMB int64) {
if yarnNode == nil {
return 0, 0, nil
return 0, 0
}
nodeResource, exist := r.yarnNodeCache.GetNodeResource(yarnNode)
if !exist {
return 0, 0, nil
return 0, 0
}
if nodeResource.Used.VirtualCores != nil {
vcores = *nodeResource.Used.VirtualCores
Expand Down
Loading

0 comments on commit 94bfc5a

Please sign in to comment.