Merge pull request #4866 from wenchajun/gpu

Fix gpu null pointer exception
This commit is contained in:
KubeSphere CI Bot
2022-05-11 10:12:38 +08:00
committed by GitHub
2 changed files with 8 additions and 2 deletions

View File

@@ -20,6 +20,8 @@ import (
"github.com/emicklei/go-restful"
"k8s.io/apimachinery/pkg/runtime/schema"
"kubesphere.io/kubesphere/pkg/simple/client/gpu"
kubesphereconfig "kubesphere.io/kubesphere/pkg/apiserver/config"
"kubesphere.io/kubesphere/pkg/apiserver/runtime"
)
@@ -48,7 +50,11 @@ func AddToContainer(c *restful.Container, config *kubesphereconfig.Config) error
webservice.Route(webservice.GET("/configs/gpu/kinds").
Doc("Get all supported GPU kinds.").
To(func(request *restful.Request, response *restful.Response) {
response.WriteAsJson(config.GPUOptions.Kinds)
var kinds []gpu.GPUKind
if config.GPUOptions != nil {
kinds = config.GPUOptions.Kinds
}
response.WriteAsJson(kinds)
}))
c.Add(webservice)

View File

@@ -24,7 +24,7 @@ func (s *Options) Validate() []error {
}
func (s *Options) ApplyTo(options *Options) {
if len(s.Kinds) > 0 {
if s != nil && len(s.Kinds) > 0 {
options.Kinds = s.Kinds
}
}