Merge pull request #4225 from zhu733756/master

feat: integrate API GPU kinds
This commit is contained in:
KubeSphere CI Bot
2021-09-14 18:47:51 +08:00
committed by GitHub
4 changed files with 51 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/devops/jenkins"
"kubesphere.io/kubesphere/pkg/simple/client/events"
"kubesphere.io/kubesphere/pkg/simple/client/gateway"
"kubesphere.io/kubesphere/pkg/simple/client/gpu"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
"kubesphere.io/kubesphere/pkg/simple/client/kubeedge"
"kubesphere.io/kubesphere/pkg/simple/client/ldap"
@@ -106,6 +107,7 @@ type Config struct {
KubeEdgeOptions *kubeedge.Options `json:"kubeedge,omitempty" yaml:"kubeedge,omitempty" mapstructure:"kubeedge"`
MeteringOptions *metering.Options `json:"metering,omitempty" yaml:"metering,omitempty" mapstructure:"metering"`
GatewayOptions *gateway.Options `json:"gateway,omitempty" yaml:"gateway,omitempty" mapstructure:"gateway"`
GPUOptions *gpu.Options `json:"gpu,omitempty" yaml:"gpu,omitempty" mapstructure:"gpu"`
}
// newConfig creates a default non-empty Config
@@ -132,6 +134,7 @@ func New() *Config {
KubeEdgeOptions: kubeedge.NewKubeEdgeOptions(),
MeteringOptions: metering.NewMeteringOptions(),
GatewayOptions: gateway.NewGatewayOptions(),
GPUOptions: gpu.NewGPUOptions(),
}
}
@@ -299,4 +302,8 @@ func (conf *Config) stripEmptyOptions() {
if conf.KubeEdgeOptions != nil && conf.KubeEdgeOptions.Endpoint == "" {
conf.KubeEdgeOptions = nil
}
if conf.GPUOptions != nil && len(conf.GPUOptions.Kinds) == 0 {
conf.GPUOptions = nil
}
}

View File

@@ -37,6 +37,7 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/devops/jenkins"
"kubesphere.io/kubesphere/pkg/simple/client/events"
"kubesphere.io/kubesphere/pkg/simple/client/gateway"
"kubesphere.io/kubesphere/pkg/simple/client/gpu"
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
"kubesphere.io/kubesphere/pkg/simple/client/kubeedge"
"kubesphere.io/kubesphere/pkg/simple/client/ldap"
@@ -184,6 +185,9 @@ func newTestConfig() (*Config, error) {
WatchesPath: "/etc/kubesphere/watches.yaml",
Namespace: "kubesphere-controls-system",
},
GPUOptions: &gpu.Options{
Kinds: []gpu.GPUKind{},
},
}
return conf, nil
}

View File

@@ -45,6 +45,12 @@ func AddToContainer(c *restful.Container, config *kubesphereconfig.Config) error
response.WriteAsJson(config.ToMap())
}))
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)
}))
c.Add(webservice)
return nil
}

View File

@@ -0,0 +1,34 @@
package gpu
import "github.com/spf13/pflag"
type GPUKind struct {
ResourceName string `json:"resourceName,omitempty" yaml:"resourceName"`
ResourceType string `json:"resourceType,omitempty" yaml:"resourceType"`
Default bool `json:"default,omitempty" yaml:"default"`
}
type Options struct {
Kinds []GPUKind `json:"kinds,omitempty" yaml:"kinds"`
}
func NewGPUOptions() *Options {
return &Options{
Kinds: []GPUKind{},
}
}
func (s *Options) Validate() []error {
var errs []error
return errs
}
func (s *Options) ApplyTo(options *Options) {
if len(s.Kinds) > 0 {
options.Kinds = s.Kinds
}
}
func (s *Options) AddFlags(fs *pflag.FlagSet, c *Options) {
}