diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index 4620051eb..2ec4de7fc 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -73,6 +73,7 @@ import ( configv1alpha2 "kubesphere.io/kubesphere/pkg/kapis/config/v1alpha2" devopsv1alpha2 "kubesphere.io/kubesphere/pkg/kapis/devops/v1alpha2" devopsv1alpha3 "kubesphere.io/kubesphere/pkg/kapis/devops/v1alpha3" + edgeruntimev1alpha1 "kubesphere.io/kubesphere/pkg/kapis/edgeruntime/v1alpha1" gatewayv1alpha1 "kubesphere.io/kubesphere/pkg/kapis/gateway/v1alpha1" iamapi "kubesphere.io/kubesphere/pkg/kapis/iam/v1alpha2" kubeedgev1alpha1 "kubesphere.io/kubesphere/pkg/kapis/kubeedge/v1alpha1" @@ -254,6 +255,7 @@ func (s *APIServer) installKubeSphereAPIs() { s.KubernetesClient.Prometheus(), s.AlertingClient, s.Config.AlertingOptions)) urlruntime.Must(version.AddToContainer(s.container, s.KubernetesClient.Discovery())) urlruntime.Must(kubeedgev1alpha1.AddToContainer(s.container, s.Config.KubeEdgeOptions.Endpoint)) + urlruntime.Must(edgeruntimev1alpha1.AddToContainer(s.container, s.Config.EdgeRuntimeOptions.Endpoint)) urlruntime.Must(notificationkapisv2beta1.AddToContainer(s.container, s.InformerFactory, s.KubernetesClient.Kubernetes(), s.KubernetesClient.KubeSphere())) urlruntime.Must(notificationkapisv2beta2.AddToContainer(s.container, s.Config.NotificationOptions)) diff --git a/pkg/apiserver/config/config.go b/pkg/apiserver/config/config.go index 6f1c46c5b..785f8f43c 100644 --- a/pkg/apiserver/config/config.go +++ b/pkg/apiserver/config/config.go @@ -33,6 +33,7 @@ import ( "kubesphere.io/kubesphere/pkg/simple/client/auditing" "kubesphere.io/kubesphere/pkg/simple/client/cache" "kubesphere.io/kubesphere/pkg/simple/client/devops/jenkins" + "kubesphere.io/kubesphere/pkg/simple/client/edgeruntime" "kubesphere.io/kubesphere/pkg/simple/client/events" "kubesphere.io/kubesphere/pkg/simple/client/gateway" "kubesphere.io/kubesphere/pkg/simple/client/gpu" @@ -107,6 +108,7 @@ type Config struct { AlertingOptions *alerting.Options `json:"alerting,omitempty" yaml:"alerting,omitempty" mapstructure:"alerting"` NotificationOptions *notification.Options `json:"notification,omitempty" yaml:"notification,omitempty" mapstructure:"notification"` KubeEdgeOptions *kubeedge.Options `json:"kubeedge,omitempty" yaml:"kubeedge,omitempty" mapstructure:"kubeedge"` + EdgeRuntimeOptions *edgeruntime.Options `json:"edgeruntime,omitempty" yaml:"edgeruntime,omitempty" mapstructure:"edgeruntime"` 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"` @@ -135,6 +137,7 @@ func New() *Config { EventsOptions: events.NewEventsOptions(), AuditingOptions: auditing.NewAuditingOptions(), KubeEdgeOptions: kubeedge.NewKubeEdgeOptions(), + EdgeRuntimeOptions: edgeruntime.NewEdgeRuntimeOptions(), MeteringOptions: metering.NewMeteringOptions(), GatewayOptions: gateway.NewGatewayOptions(), GPUOptions: gpu.NewGPUOptions(), @@ -307,6 +310,10 @@ func (conf *Config) stripEmptyOptions() { conf.KubeEdgeOptions = nil } + if conf.EdgeRuntimeOptions != nil && conf.EdgeRuntimeOptions.Endpoint == "" { + conf.EdgeRuntimeOptions = nil + } + if conf.GPUOptions != nil && len(conf.GPUOptions.Kinds) == 0 { conf.GPUOptions = nil } diff --git a/pkg/apiserver/config/config_test.go b/pkg/apiserver/config/config_test.go index 3b35a301c..24d61039c 100644 --- a/pkg/apiserver/config/config_test.go +++ b/pkg/apiserver/config/config_test.go @@ -38,6 +38,7 @@ import ( "kubesphere.io/kubesphere/pkg/simple/client/auditing" "kubesphere.io/kubesphere/pkg/simple/client/cache" "kubesphere.io/kubesphere/pkg/simple/client/devops/jenkins" + edgeruntime "kubesphere.io/kubesphere/pkg/simple/client/edgeruntime" "kubesphere.io/kubesphere/pkg/simple/client/events" "kubesphere.io/kubesphere/pkg/simple/client/gateway" "kubesphere.io/kubesphere/pkg/simple/client/gpu" @@ -182,6 +183,9 @@ func newTestConfig() (*Config, error) { KubeEdgeOptions: &kubeedge.Options{ Endpoint: "http://edge-watcher.kubeedge.svc/api/", }, + EdgeRuntimeOptions: &edgeruntime.Options{ + Endpoint: "http://edgeservice.kubeedge.svc/api/", + }, MeteringOptions: &metering.Options{ RetentionDay: "7d", }, @@ -277,6 +281,7 @@ func TestStripEmptyOptions(t *testing.T) { config.EventsOptions = &events.Options{Host: ""} config.AuditingOptions = &auditing.Options{Host: ""} config.KubeEdgeOptions = &kubeedge.Options{Endpoint: ""} + config.EdgeRuntimeOptions = &edgeruntime.Options{Endpoint: ""} config.stripEmptyOptions() @@ -294,7 +299,8 @@ func TestStripEmptyOptions(t *testing.T) { config.MultiClusterOptions != nil || config.EventsOptions != nil || config.AuditingOptions != nil || - config.KubeEdgeOptions != nil { + config.KubeEdgeOptions != nil || + config.EdgeRuntimeOptions != nil { t.Fatal("config stripEmptyOptions failed") } } diff --git a/pkg/kapis/edgeruntime/v1alpha1/register.go b/pkg/kapis/edgeruntime/v1alpha1/register.go new file mode 100644 index 000000000..7568852f1 --- /dev/null +++ b/pkg/kapis/edgeruntime/v1alpha1/register.go @@ -0,0 +1,36 @@ +/* +Copyright 2020 KubeSphere Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1 + +import ( + "github.com/emicklei/go-restful" + "k8s.io/apimachinery/pkg/runtime/schema" + + "kubesphere.io/kubesphere/pkg/kapis/generic" +) + +// there are no versions specified cause we want to proxy all versions of requests to backend service +var GroupVersion = schema.GroupVersion{Group: "edgeruntime.kubesphere.io", Version: ""} + +func AddToContainer(container *restful.Container, endpoint string) error { + proxy, err := generic.NewGenericProxy(endpoint, GroupVersion.Group, GroupVersion.Version) + if err != nil { + return nil + } + + return proxy.AddToContainer(container) +} diff --git a/pkg/kapis/kubeedge/v1alpha1/register.go b/pkg/kapis/kubeedge/v1alpha1/register.go index 781afc7c3..58f536fab 100644 --- a/pkg/kapis/kubeedge/v1alpha1/register.go +++ b/pkg/kapis/kubeedge/v1alpha1/register.go @@ -24,6 +24,7 @@ import ( ) // there are no versions specified cause we want to proxy all versions of requests to backend service +// Deprecated: this api group would be removed in v4.0 var GroupVersion = schema.GroupVersion{Group: "kubeedge.kubesphere.io", Version: ""} func AddToContainer(container *restful.Container, endpoint string) error { diff --git a/pkg/simple/client/edgeruntime/options.go b/pkg/simple/client/edgeruntime/options.go new file mode 100644 index 000000000..e132345fb --- /dev/null +++ b/pkg/simple/client/edgeruntime/options.go @@ -0,0 +1,48 @@ +/* +Copyright 2021 KubeSphere Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package edgeruntime + +import ( + "github.com/spf13/pflag" + + "kubesphere.io/kubesphere/pkg/utils/reflectutils" +) + +type Options struct { + Endpoint string `json:"endpoint" yaml:"endpoint"` +} + +func NewEdgeRuntimeOptions() *Options { + return &Options{ + Endpoint: "", + } +} + +func (o *Options) ApplyTo(options *Options) { + reflectutils.Override(options, o) +} + +func (o *Options) Validate() []error { + errs := []error{} + + return errs +} + +func (o *Options) AddFlags(fs *pflag.FlagSet, c *Options) { + fs.StringVar(&o.Endpoint, "edgeservice-endpoint", c.Endpoint, + "edgeservice endpoint for edgeruntime v1alpha1.") +}