Skip to content
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

fix: exception happen when creating multiple ascend-gpu pods concurrently #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ascend-device-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rules:
verbs: ["get", "list", "update", "watch", "patch"]
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "patch"]
verbs: ["get", "update", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
10 changes: 8 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/Project-HAMi/HAMi/pkg/api"
"github.com/Project-HAMi/HAMi/pkg/device/ascend"
"github.com/Project-HAMi/HAMi/pkg/util"
"github.com/Project-HAMi/HAMi/pkg/util/nodelock"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
v1 "k8s.io/api/core/v1"
Expand All @@ -37,8 +38,9 @@ import (
)

const (
// RegisterAnnos = "hami.io/node-register-ascend"
// PodAllocAnno = "huawei.com/AscendDevices"
// RegisterAnnos = "hami.io/node-register-ascend"
// PodAllocAnno = "huawei.com/AscendDevices"
NodeLockAscend = "hami.io/mutex.lock"
)

var (
Expand Down Expand Up @@ -316,14 +318,17 @@ func (ps *PluginServer) Allocate(ctx context.Context, reqs *v1beta1.AllocateRequ
pod, err := util.GetPendingPod(ctx, ps.nodeName)
if err != nil {
klog.Errorf("get pending pod error: %v", err)
nodelock.ReleaseNodeLock(ps.nodeName, NodeLockAscend)
return nil, fmt.Errorf("get pending pod error: %v", err)
}
resp := v1beta1.ContainerAllocateResponse{}
IDs, temps, err := ps.parsePodAnnotation(pod)
if err != nil {
nodelock.ReleaseNodeLock(ps.nodeName, NodeLockAscend)
return nil, fmt.Errorf("parse pod annotation error: %v", err)
}
if len(IDs) == 0 {
nodelock.ReleaseNodeLock(ps.nodeName, NodeLockAscend)
return nil, fmt.Errorf("empty id from pod annotation")
}
ascendVisibleDevices := fmt.Sprintf("%d", IDs[0])
Expand All @@ -343,6 +348,7 @@ func (ps *PluginServer) Allocate(ctx context.Context, reqs *v1beta1.AllocateRequ
resp.Envs["ASCEND_VNPU_SPECS"] = ascendVNPUSpec
}
klog.V(5).Infof("allocate response: %v", resp)
nodelock.ReleaseNodeLock(ps.nodeName, NodeLockAscend)
return &v1beta1.AllocateResponse{ContainerResponses: []*v1beta1.ContainerAllocateResponse{&resp}}, nil
}

Expand Down