diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index 922cf55b4..60aa85ea2 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -58,6 +58,7 @@ import ( devopsv1alpha3 "kubesphere.io/kubesphere/pkg/kapis/devops/v1alpha3" iamapi "kubesphere.io/kubesphere/pkg/kapis/iam/v1alpha2" monitoringv1alpha3 "kubesphere.io/kubesphere/pkg/kapis/monitoring/v1alpha3" + networkv1alpha2 "kubesphere.io/kubesphere/pkg/kapis/network/v1alpha2" notificationv1 "kubesphere.io/kubesphere/pkg/kapis/notification/v1" "kubesphere.io/kubesphere/pkg/kapis/oauth" openpitrixv1 "kubesphere.io/kubesphere/pkg/kapis/openpitrix/v1" @@ -202,6 +203,7 @@ func (s *APIServer) installKubeSphereAPIs() { im.NewLoginRecorder(s.KubernetesClient.KubeSphere()), s.Config.AuthenticationOptions)) urlruntime.Must(servicemeshv1alpha2.AddToContainer(s.container)) + urlruntime.Must(networkv1alpha2.AddToContainer(s.container, s.Config.NetworkOptions.WeaveScopeHost)) urlruntime.Must(devopsv1alpha2.AddToContainer(s.container, s.InformerFactory.KubeSphereSharedInformerFactory(), s.DevopsClient, diff --git a/pkg/apiserver/config/config_test.go b/pkg/apiserver/config/config_test.go index b6232e27d..42445b544 100644 --- a/pkg/apiserver/config/config_test.go +++ b/pkg/apiserver/config/config_test.go @@ -105,6 +105,7 @@ func newTestConfig() (*Config, error) { NSNPOptions: network.NSNPOptions{ AllowedIngressNamespaces: []string{}, }, + WeaveScopeHost: "weave-scope-app.weave", }, MonitoringOptions: &prometheus.Options{ Endpoint: "http://prometheus.kubesphere-monitoring-system.svc", diff --git a/pkg/kapis/network/v1alpha2/handler.go b/pkg/kapis/network/v1alpha2/handler.go index ebad85002..d8c404499 100644 --- a/pkg/kapis/network/v1alpha2/handler.go +++ b/pkg/kapis/network/v1alpha2/handler.go @@ -31,6 +31,7 @@ import ( const ScopeQueryUrl = "http://%s/api/topology/services" type handler struct { + // if weave scope installed in the cluster, it is maybe `weave-scope-app.weave` weaveScopeHost string } diff --git a/pkg/simple/client/network/options.go b/pkg/simple/client/network/options.go index a75741bc2..834613d7a 100644 --- a/pkg/simple/client/network/options.go +++ b/pkg/simple/client/network/options.go @@ -18,6 +18,7 @@ package network import ( "github.com/spf13/pflag" + "kubesphere.io/kubesphere/pkg/simple/client/network/ippool" ) @@ -30,6 +31,7 @@ type Options struct { NSNPOptions NSNPOptions `json:"nsnpOptions,omitempty" yaml:"nsnpOptions,omitempty"` EnableIPPool bool `json:"enableIPPool,omitempty" yaml:"enableIPPool"` IPPoolOptions ippool.Options `json:"ippoolOptions,omitempty" yaml:"ippoolOptions,omitempty"` + WeaveScopeHost string `json:"weaveScopeHost,omitempty" yaml:"weaveScopeHost,omitempty"` } // NewNetworkOptions returns a `zero` instance @@ -43,6 +45,7 @@ func NewNetworkOptions() *Options { IPPoolOptions: ippool.Options{ Calico: nil, }, + WeaveScopeHost: "", } } @@ -56,6 +59,7 @@ func (s *Options) ApplyTo(options *Options) { options.EnableIPPool = s.EnableIPPool options.NSNPOptions = s.NSNPOptions options.IPPoolOptions = s.IPPoolOptions + options.WeaveScopeHost = s.WeaveScopeHost } func (s *Options) AddFlags(fs *pflag.FlagSet, c *Options) { @@ -63,4 +67,6 @@ func (s *Options) AddFlags(fs *pflag.FlagSet, c *Options) { "This field instructs KubeSphere to enable network policy or not.") fs.BoolVar(&s.EnableIPPool, "enable-ippool", c.EnableIPPool, "This field instructs KubeSphere to enable ippool or not.") + fs.StringVar(&s.WeaveScopeHost, "weave-scope-host", c.WeaveScopeHost, + "Weave Scope service endpoint which build a topology API of the applications and the containers running on the hosts") }