未验证 提交 8ad17a46 编写于 作者: Z Zhengyi Lai

Add network configuration to apiserver/config

上级 828f7726
......@@ -17,6 +17,7 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/ldap"
esclient "kubesphere.io/kubesphere/pkg/simple/client/logging/elasticsearch"
"kubesphere.io/kubesphere/pkg/simple/client/monitoring/prometheus"
"kubesphere.io/kubesphere/pkg/simple/client/network"
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
"kubesphere.io/kubesphere/pkg/simple/client/s3"
fakes3 "kubesphere.io/kubesphere/pkg/simple/client/s3/fake"
......@@ -43,6 +44,7 @@ func NewServerRunOptions() *ServerRunOptions {
DevopsOptions: jenkins.NewDevopsOptions(),
SonarQubeOptions: sonarqube.NewSonarQubeOptions(),
ServiceMeshOptions: servicemesh.NewServiceMeshOptions(),
NetworkOptions: network.NewNetworkOptions(),
MonitoringOptions: prometheus.NewPrometheusOptions(),
S3Options: s3.NewS3Options(),
OpenPitrixOptions: openpitrix.NewOptions(),
......@@ -68,6 +70,7 @@ func (s *ServerRunOptions) Flags() (fss cliflag.NamedFlagSets) {
s.RedisOptions.AddFlags(fss.FlagSet("redis"), s.RedisOptions)
s.S3Options.AddFlags(fss.FlagSet("s3"), s.S3Options)
s.OpenPitrixOptions.AddFlags(fss.FlagSet("openpitrix"), s.OpenPitrixOptions)
s.NetworkOptions.AddFlags(fss.FlagSet("network"), s.NetworkOptions)
s.ServiceMeshOptions.AddFlags(fss.FlagSet("servicemesh"), s.ServiceMeshOptions)
s.MonitoringOptions.AddFlags(fss.FlagSet("monitoring"), s.MonitoringOptions)
s.LoggingOptions.AddFlags(fss.FlagSet("logging"), s.LoggingOptions)
......
......@@ -13,6 +13,7 @@ func (s *ServerRunOptions) Validate() []error {
errors = append(errors, s.SonarQubeOptions.Validate()...)
errors = append(errors, s.S3Options.Validate()...)
errors = append(errors, s.OpenPitrixOptions.Validate()...)
errors = append(errors, s.NetworkOptions.Validate()...)
errors = append(errors, s.LoggingOptions.Validate()...)
return errors
......
......@@ -140,7 +140,7 @@ func (s *APIServer) installKubeSphereAPIs() {
urlruntime.Must(loggingv1alpha2.AddToContainer(s.container, s.KubernetesClient, s.LoggingClient))
urlruntime.Must(monitoringv1alpha3.AddToContainer(s.container, s.KubernetesClient.Kubernetes(), s.MonitoringClient))
urlruntime.Must(openpitrixv1.AddToContainer(s.container, s.InformerFactory, s.OpenpitrixClient))
urlruntime.Must(networkv1alpha2.AddToContainer(s.container))
urlruntime.Must(networkv1alpha2.AddToContainer(s.container, s.Config.NetworkOptions.WeaveScopeHost))
urlruntime.Must(operationsv1alpha2.AddToContainer(s.container, s.KubernetesClient.Kubernetes()))
urlruntime.Must(resourcesv1alpha2.AddToContainer(s.container, s.KubernetesClient.Kubernetes(), s.InformerFactory))
urlruntime.Must(tenantv1alpha2.AddToContainer(s.container, s.KubernetesClient, s.InformerFactory))
......
......@@ -11,6 +11,7 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/ldap"
"kubesphere.io/kubesphere/pkg/simple/client/logging/elasticsearch"
"kubesphere.io/kubesphere/pkg/simple/client/monitoring/prometheus"
"kubesphere.io/kubesphere/pkg/simple/client/network"
"kubesphere.io/kubesphere/pkg/simple/client/notification"
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
"kubesphere.io/kubesphere/pkg/simple/client/s3"
......@@ -61,6 +62,7 @@ type Config struct {
SonarQubeOptions *sonarqube.Options `json:"sonarqube,omitempty" yaml:"sonarQube,omitempty" mapstructure:"sonarqube"`
KubernetesOptions *k8s.KubernetesOptions `json:"kubernetes,omitempty" yaml:"kubernetes,omitempty" mapstructure:"kubernetes"`
ServiceMeshOptions *servicemesh.Options `json:"servicemesh,omitempty" yaml:"servicemesh,omitempty" mapstructure:"servicemesh"`
NetworkOptions *network.Options `json:"network,omitempty" yaml:"network,omitempty" mapstructure:"network"`
LdapOptions *ldap.Options `json:"ldap,omitempty" yaml:"ldap,omitempty" mapstructure:"ldap"`
RedisOptions *cache.Options `json:"redis,omitempty" yaml:"redis,omitempty" mapstructure:"redis"`
S3Options *s3.Options `json:"s3,omitempty" yaml:"s3,omitempty" mapstructure:"s3"`
......@@ -81,6 +83,7 @@ func New() *Config {
SonarQubeOptions: sonarqube.NewSonarQubeOptions(),
KubernetesOptions: k8s.NewKubernetesOptions(),
ServiceMeshOptions: servicemesh.NewServiceMeshOptions(),
NetworkOptions: network.NewNetworkOptions(),
LdapOptions: ldap.NewOptions(),
RedisOptions: cache.NewRedisOptions(),
S3Options: s3.NewS3Options(),
......@@ -175,6 +178,10 @@ func (conf *Config) stripEmptyOptions() {
conf.OpenPitrixOptions = nil
}
if conf.NetworkOptions != nil && conf.NetworkOptions.WeaveScopeHost == "" {
conf.NetworkOptions = nil
}
if conf.ServiceMeshOptions != nil && conf.ServiceMeshOptions.IstioPilotHost == "" &&
conf.ServiceMeshOptions.ServicemeshPrometheusHost == "" &&
conf.ServiceMeshOptions.JaegerQueryHost == "" {
......
......@@ -14,6 +14,7 @@ import (
"kubesphere.io/kubesphere/pkg/simple/client/ldap"
"kubesphere.io/kubesphere/pkg/simple/client/logging/elasticsearch"
"kubesphere.io/kubesphere/pkg/simple/client/monitoring/prometheus"
"kubesphere.io/kubesphere/pkg/simple/client/network"
"kubesphere.io/kubesphere/pkg/simple/client/notification"
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
"kubesphere.io/kubesphere/pkg/simple/client/s3"
......@@ -79,6 +80,9 @@ func newTestConfig() (*Config, error) {
CategoryManagerEndpoint: "openpitrix-hyperpitrix.openpitrix-system.svc:9113",
AttachmentManagerEndpoint: "openpitrix-hyperpitrix.openpitrix-system.svc:9122",
},
NetworkOptions: &network.Options{
WeaveScopeHost: "weave-scope-app.weave.svc",
},
MonitoringOptions: &prometheus.Options{
Endpoint: "http://prometheus.kubesphere-monitoring-system.svc",
SecondaryEndpoint: "http://prometheus.kubesphere-monitoring-system.svc",
......
......@@ -3,35 +3,45 @@ package v1alpha2
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
restful "github.com/emicklei/go-restful"
"github.com/emicklei/go-restful"
"k8s.io/klog"
"kubesphere.io/kubesphere/pkg/api"
)
const ScopeQueryUrl = "http://weave-scope-app.weave.svc/api/topology/services"
const ScopeQueryUrl = "http://%s/api/topology/services"
type handler struct {
weaveScopeHost string
}
func (h *handler) getScopeUrl() string {
return fmt.Sprintf(ScopeQueryUrl, h.weaveScopeHost)
}
func getNamespaceTopology(request *restful.Request, response *restful.Response) {
func (h *handler) getNamespaceTopology(request *restful.Request, response *restful.Response) {
var query = url.Values{
"namespace": []string{request.PathParameter("namespace")},
"timestamp": request.QueryParameters("timestamp"),
}
var u = fmt.Sprintf("%s?%s", ScopeQueryUrl, query.Encode())
var u = fmt.Sprintf("%s?%s", h.getScopeUrl(), query.Encode())
resp, err := http.Get(u)
if err != nil {
log.Printf("query scope faile with err %v", err)
_ = response.WriteError(http.StatusInternalServerError, err)
klog.Errorf("query scope faile with err %v", err)
api.HandleInternalError(response, nil, err)
return
}
body, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
log.Printf("read response error : %v", err)
_ = response.WriteError(http.StatusInternalServerError, err)
klog.Errorf("read response error : %v", err)
api.HandleInternalError(response, nil, err)
return
}
......@@ -40,30 +50,30 @@ func getNamespaceTopology(request *restful.Request, response *restful.Response)
_, err = response.Write(body)
if err != nil {
log.Printf("write response failed %v", err)
klog.Errorf("write response failed %v", err)
}
}
func getNamespaceNodeTopology(request *restful.Request, response *restful.Response) {
func (h *handler) getNamespaceNodeTopology(request *restful.Request, response *restful.Response) {
var query = url.Values{
"namespace": []string{request.PathParameter("namespace")},
"timestamp": request.QueryParameters("timestamp"),
}
var u = fmt.Sprintf("%s/%s?%s", ScopeQueryUrl, request.PathParameter("node_id"), query.Encode())
var u = fmt.Sprintf("%s/%s?%s", h.getScopeUrl(), request.PathParameter("node_id"), query.Encode())
resp, err := http.Get(u)
if err != nil {
log.Printf("query scope faile with err %v", err)
_ = response.WriteError(http.StatusInternalServerError, err)
klog.Errorf("query scope faile with err %v", err)
api.HandleInternalError(response, nil, err)
return
}
body, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
log.Printf("read response error : %v", err)
_ = response.WriteError(http.StatusInternalServerError, err)
klog.Errorf("read response error : %v", err)
api.HandleInternalError(response, nil, err)
return
}
......@@ -72,6 +82,6 @@ func getNamespaceNodeTopology(request *restful.Request, response *restful.Respon
_, err = response.Write(body)
if err != nil {
log.Printf("write response failed %v", err)
klog.Errorf("write response failed %v", err)
}
}
......@@ -30,25 +30,28 @@ const GroupName = "network.kubesphere.io"
var GroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"}
func AddToContainer(c *restful.Container) error {
func AddToContainer(c *restful.Container, weaveScopeHost string) error {
webservice := runtime.NewWebService(GroupVersion)
h := handler{weaveScopeHost: weaveScopeHost}
webservice.Route(webservice.GET("/namespaces/{namespace}/topology").
To(getNamespaceTopology).
To(h.getNamespaceTopology).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NetworkTopologyTag}).
Doc("Get the topology with specifying a namespace").
Param(webservice.PathParameter("namespace", "name of the namespace").Required(true)).
Returns(http.StatusOK, "ok", TopologyResponse{}).
Writes(TopologyResponse{})).Produces(restful.MIME_JSON)
Writes(TopologyResponse{})).
Produces(restful.MIME_JSON)
webservice.Route(webservice.GET("/namespaces/{namespace}/topology/{node_id}").
To(getNamespaceNodeTopology).
To(h.getNamespaceNodeTopology).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NetworkTopologyTag}).
Doc("Get the topology with specifying a node id in the whole topology and specifying a namespace").
Param(webservice.PathParameter("namespace", "name of the namespace").Required(true)).
Param(webservice.PathParameter("node_id", "id of the node in the whole topology").Required(true)).
Returns(http.StatusOK, "ok", NodeResponse{}).
Writes(NodeResponse{})).Produces(restful.MIME_JSON)
Writes(NodeResponse{})).
Produces(restful.MIME_JSON)
c.Add(webservice)
......
package network
import "github.com/spf13/pflag"
type Options struct {
// weave scope service host
WeaveScopeHost string `json:"weaveScopeHost,omitempty" yaml:"weaveScopeHost"`
}
// NewNetworkOptions returns a `zero` instance
func NewNetworkOptions() *Options {
return &Options{
WeaveScopeHost: "weave-scope-app.weave.svc",
}
}
func (s *Options) Validate() []error {
var errors []error
return errors
}
func (s *Options) ApplyTo(options *Options) {
if s.WeaveScopeHost != "" {
options.WeaveScopeHost = s.WeaveScopeHost
}
}
func (s *Options) AddFlags(fs *pflag.FlagSet, c *Options) {
fs.StringVar(&s.WeaveScopeHost, "weave-scope-host", c.WeaveScopeHost, ""+
"weave scope service host")
}
......@@ -123,7 +123,7 @@ func generateSwaggerJson() []byte {
urlruntime.Must(tenantv1alpha2.AddToContainer(container, clientsets, informerFactory))
urlruntime.Must(terminalv1alpha2.AddToContainer(container, clientsets.Kubernetes(), nil))
urlruntime.Must(metricsv1alpha2.AddToContainer(container))
urlruntime.Must(networkv1alpha2.AddToContainer(container))
urlruntime.Must(networkv1alpha2.AddToContainer(container, ""))
config := restfulspec.Config{
WebServices: container.RegisteredWebServices(),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册