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

feat: add gpu values for app install #118

Merged
merged 1 commit into from
Dec 20, 2024
Merged
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
1 change: 1 addition & 0 deletions pkg/apiserver/api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import "errors"
var (
// ErrResourceNotFound indicates that a resource is not found.
ErrResourceNotFound = errors.New("resource not found")
ErrGPUNodeNotFound = errors.New("no available gpu node found")
)
14 changes: 11 additions & 3 deletions pkg/apiserver/handler_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"strings"

"bytetrade.io/web3os/app-service/pkg/apiserver/api"
"bytetrade.io/web3os/app-service/pkg/appinstaller"
"bytetrade.io/web3os/app-service/pkg/constants"
"bytetrade.io/web3os/app-service/pkg/provider"
Expand Down Expand Up @@ -281,13 +282,20 @@ func (h *Handler) gpuLimitMutate(ctx context.Context, req *admissionv1.Admission
}

gpuRequired := appcfg.Requirement.GPU
if gpuRequired == nil || gpuRequired.IsZero() {
if gpuRequired == nil {
return resp
}
GPUType, err := h.findNvidiaGpuFromNodes(ctx)
if err != nil {
if err != nil && !errors.Is(err, api.ErrGPUNodeNotFound) {
return h.sidecarWebhook.AdmissionError(req.UID, err)
}
// no gpu found and gpu required is zero, no need to inject env, just return.
if gpuRequired.IsZero() && GPUType == "" {
return resp
}
if !gpuRequired.IsZero() && GPUType == "" {
return h.sidecarWebhook.AdmissionError(req.UID, api.ErrGPUNodeNotFound)
}

patchBytes, err := webhook.CreatePatchForDeployment(tpl, req.Namespace, gpuRequired, GPUType)
if err != nil {
Expand Down Expand Up @@ -325,7 +333,7 @@ func (h *Handler) findNvidiaGpuFromNodes(ctx context.Context) (string, error) {
return gtype, nil
}

return "", errors.New("no available gpu node found")
return "", api.ErrGPUNodeNotFound
}

func (h *Handler) providerRegistryValidate(req *restful.Request, resp *restful.Response) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/appinstaller/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ func (h *HelmOps) setValues() (values map[string]interface{}, err error) {
klog.Errorf("Failed to get gpuType err=%v", err)
return values, err
}
values["GPU"] = map[string]interface{}{
"Type": gpuType,
"Cuda": os.Getenv("CUDA_VERSION"),
}

values["gpu"] = gpuType

if h.app.OIDC.Enabled {
Expand Down
1 change: 1 addition & 0 deletions pkg/utils/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func GetResourceListFromChart(chartPath string) (resources kube.ResourceList, er
"subjects": map[string]interface{}{},
"refs": map[string]interface{}{},
}
values["GPU"] = map[string]interface{}{}

ret, err := instAction.RunWithContext(context.Background(), chartRequested, values)
if err != nil {
Expand Down
Loading