From 75803113f64cc83f71f31f78308b02fdb0d2926c Mon Sep 17 00:00:00 2001 From: chengdehao Date: Tue, 10 May 2022 22:52:14 +0800 Subject: [PATCH] fix nil pointer Signed-off-by: chengdehao --- pkg/kapis/config/v1alpha2/register.go | 8 +++++++- pkg/simple/client/gpu/options.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/kapis/config/v1alpha2/register.go b/pkg/kapis/config/v1alpha2/register.go index c9f7671e1..9352f4337 100644 --- a/pkg/kapis/config/v1alpha2/register.go +++ b/pkg/kapis/config/v1alpha2/register.go @@ -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) diff --git a/pkg/simple/client/gpu/options.go b/pkg/simple/client/gpu/options.go index f850046da..dee35bd8a 100644 --- a/pkg/simple/client/gpu/options.go +++ b/pkg/simple/client/gpu/options.go @@ -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 } }