提交 59839439 编写于 作者: P pengcong06

feat:multi cluster application

上级 d4b7d88b
...@@ -8,32 +8,27 @@ go 1.12 ...@@ -8,32 +8,27 @@ go 1.12
require ( require (
code.cloudfoundry.org/bytefmt v0.0.0-20190710193110-1eb035ffe2b6 code.cloudfoundry.org/bytefmt v0.0.0-20190710193110-1eb035ffe2b6
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Microsoft/go-winio v0.4.12 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/PuerkitoBio/goquery v1.5.0 github.com/PuerkitoBio/goquery v1.5.0
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
github.com/aws/aws-sdk-go v1.22.2 github.com/aws/aws-sdk-go v1.25.21
github.com/beevik/etree v1.1.0 github.com/beevik/etree v1.1.0
github.com/container-storage-interface/spec v1.2.0 github.com/container-storage-interface/spec v1.2.0
github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/docker/distribution v2.7.1+incompatible github.com/docker/distribution v2.7.1+incompatible
github.com/docker/docker v1.4.2-0.20190822205725-ed20165a37b4 github.com/docker/docker v1.4.2-0.20190822205725-ed20165a37b4
github.com/docker/go-connections v0.3.0 // indirect
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
github.com/elastic/go-elasticsearch/v5 v5.6.1 github.com/elastic/go-elasticsearch/v5 v5.6.1
github.com/elastic/go-elasticsearch/v6 v6.8.2 github.com/elastic/go-elasticsearch/v6 v6.8.2
github.com/elastic/go-elasticsearch/v7 v7.3.0 github.com/elastic/go-elasticsearch/v7 v7.3.0
github.com/elazarl/goproxy v0.0.0-20190711103511-473e67f1d7d2 // indirect
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 // indirect github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible github.com/emicklei/go-restful v2.11.1+incompatible
github.com/emicklei/go-restful-openapi v1.0.0 github.com/emicklei/go-restful-openapi v1.0.0
github.com/emirpasic/gods v1.12.0 // indirect github.com/emirpasic/gods v1.12.0 // indirect
github.com/fatih/structs v1.1.0 github.com/fatih/structs v1.1.0
github.com/go-ldap/ldap v3.0.3+incompatible github.com/go-ldap/ldap v3.0.3+incompatible
github.com/go-logr/zapr v0.1.1 // indirect github.com/go-logr/zapr v0.1.1 // indirect
github.com/go-openapi/loads v0.19.2 github.com/go-openapi/loads v0.19.2
github.com/go-openapi/spec v0.19.3 github.com/go-openapi/spec v0.19.4
github.com/go-openapi/strfmt v0.19.3 github.com/go-openapi/strfmt v0.19.3
github.com/go-openapi/validate v0.19.5 github.com/go-openapi/validate v0.19.5
github.com/go-redis/redis v6.15.2+incompatible github.com/go-redis/redis v6.15.2+incompatible
...@@ -46,7 +41,7 @@ require ( ...@@ -46,7 +41,7 @@ require (
github.com/google/go-querystring v1.0.0 // indirect github.com/google/go-querystring v1.0.0 // indirect
github.com/google/uuid v1.1.1 github.com/google/uuid v1.1.1
github.com/gorilla/mux v1.7.1 // indirect github.com/gorilla/mux v1.7.1 // indirect
github.com/gorilla/websocket v1.4.0 github.com/gorilla/websocket v1.4.1
github.com/hashicorp/go-version v1.2.0 // indirect github.com/hashicorp/go-version v1.2.0 // indirect
github.com/json-iterator/go v1.1.9 github.com/json-iterator/go v1.1.9
github.com/kelseyhightower/envconfig v1.4.0 // indirect github.com/kelseyhightower/envconfig v1.4.0 // indirect
...@@ -56,22 +51,20 @@ require ( ...@@ -56,22 +51,20 @@ require (
github.com/kubesphere/sonargo v0.0.2 github.com/kubesphere/sonargo v0.0.2
github.com/lib/pq v1.2.0 // indirect github.com/lib/pq v1.2.0 // indirect
github.com/mattn/go-sqlite3 v1.11.0 // indirect github.com/mattn/go-sqlite3 v1.11.0 // indirect
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c // indirect
github.com/onsi/ginkgo v1.12.0 github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.9.0 github.com/onsi/gomega v1.9.0
github.com/open-policy-agent/opa v0.18.0 github.com/open-policy-agent/opa v0.18.0
github.com/opencontainers/go-digest v1.0.0-rc1 github.com/opencontainers/go-digest v1.0.0-rc1
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/openshift/api v0.0.0-20180801171038-322a19404e37 // indirect github.com/openshift/api v0.0.0-20180801171038-322a19404e37 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/projectcalico/kube-controllers v3.8.8+incompatible github.com/projectcalico/kube-controllers v3.8.8+incompatible
github.com/projectcalico/libcalico-go v1.7.2-0.20191104213956-8f81e1e344ce github.com/projectcalico/libcalico-go v1.7.2-0.20191104213956-8f81e1e344ce
github.com/prometheus/client_golang v1.0.0 github.com/prometheus/client_golang v1.2.1
github.com/prometheus/common v0.4.1 github.com/prometheus/common v0.4.1
github.com/prometheus/prometheus v1.8.2 github.com/prometheus/prometheus v1.8.2
github.com/sony/sonyflake v0.0.0-20181109022403-6d5bd6181009 github.com/sony/sonyflake v1.0.0
github.com/speps/go-hashids v2.0.0+incompatible github.com/speps/go-hashids v2.0.0+incompatible
github.com/spf13/cobra v0.0.5 github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
...@@ -79,7 +72,7 @@ require ( ...@@ -79,7 +72,7 @@ require (
github.com/stretchr/testify v1.4.0 github.com/stretchr/testify v1.4.0
github.com/syndtr/goleveldb v1.0.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/xanzy/ssh-agent v0.2.1 // indirect github.com/xanzy/ssh-agent v0.2.1 // indirect
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
google.golang.org/grpc v1.26.0 google.golang.org/grpc v1.26.0
...@@ -102,8 +95,6 @@ require ( ...@@ -102,8 +95,6 @@ require (
k8s.io/klog v1.0.0 k8s.io/klog v1.0.0
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a
k8s.io/kubectl v0.17.3 k8s.io/kubectl v0.17.3
kubesphere.io/im v0.1.0 // indirect
openpitrix.io/iam v0.1.0 // indirect
openpitrix.io/openpitrix v0.4.1-0.20190920134345-4d2be6e4965c openpitrix.io/openpitrix v0.4.1-0.20190920134345-4d2be6e4965c
sigs.k8s.io/controller-runtime v0.5.0 sigs.k8s.io/controller-runtime v0.5.0
sigs.k8s.io/controller-tools v0.2.4 sigs.k8s.io/controller-tools v0.2.4
...@@ -240,7 +231,7 @@ replace ( ...@@ -240,7 +231,7 @@ replace (
github.com/gregjones/httpcache => github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7 github.com/gregjones/httpcache => github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7
github.com/grpc-ecosystem/go-grpc-middleware => github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 github.com/grpc-ecosystem/go-grpc-middleware => github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
github.com/grpc-ecosystem/go-grpc-prometheus => github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 github.com/grpc-ecosystem/go-grpc-prometheus => github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway => github.com/grpc-ecosystem/grpc-gateway v1.9.6 github.com/grpc-ecosystem/grpc-gateway => github.com/grpc-ecosystem/grpc-gateway v1.11.3
github.com/hashicorp/go-version => github.com/hashicorp/go-version v1.2.0 github.com/hashicorp/go-version => github.com/hashicorp/go-version v1.2.0
github.com/hashicorp/golang-lru => github.com/hashicorp/golang-lru v0.5.3 github.com/hashicorp/golang-lru => github.com/hashicorp/golang-lru v0.5.3
github.com/hashicorp/hcl => github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/hcl => github.com/hashicorp/hcl v1.0.0
...@@ -435,7 +426,7 @@ replace ( ...@@ -435,7 +426,7 @@ replace (
modernc.org/xc => modernc.org/xc v1.0.0 modernc.org/xc => modernc.org/xc v1.0.0
openpitrix.io/iam => openpitrix.io/iam v0.1.0 openpitrix.io/iam => openpitrix.io/iam v0.1.0
openpitrix.io/logger => openpitrix.io/logger v0.1.0 openpitrix.io/logger => openpitrix.io/logger v0.1.0
openpitrix.io/openpitrix => openpitrix.io/openpitrix v0.4.1-0.20190920134345-4d2be6e4965c openpitrix.io/openpitrix => github.com/pengcong06/openpitrix v0.4.1-0.20200527062040-411ab8612348
rsc.io/goversion => rsc.io/goversion v1.0.0 rsc.io/goversion => rsc.io/goversion v1.0.0
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.4.0 sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.4.0
sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.2.4 sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.2.4
......
此差异已折叠。
/*
Copyright 2020 The 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 package v1
import ( import (
...@@ -10,7 +23,6 @@ import ( ...@@ -10,7 +23,6 @@ import (
"kubesphere.io/kubesphere/pkg/api" "kubesphere.io/kubesphere/pkg/api"
"kubesphere.io/kubesphere/pkg/constants" "kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/informers" "kubesphere.io/kubesphere/pkg/informers"
"kubesphere.io/kubesphere/pkg/models"
"kubesphere.io/kubesphere/pkg/models/openpitrix" "kubesphere.io/kubesphere/pkg/models/openpitrix"
"kubesphere.io/kubesphere/pkg/server/errors" "kubesphere.io/kubesphere/pkg/server/errors"
"kubesphere.io/kubesphere/pkg/server/params" "kubesphere.io/kubesphere/pkg/server/params"
...@@ -34,6 +46,7 @@ func newOpenpitrixHandler(factory informers.InformerFactory, opClient op.Client) ...@@ -34,6 +46,7 @@ func newOpenpitrixHandler(factory informers.InformerFactory, opClient op.Client)
func (h *openpitrixHandler) ListApplications(request *restful.Request, response *restful.Response) { func (h *openpitrixHandler) ListApplications(request *restful.Request, response *restful.Response) {
limit, offset := params.ParsePaging(request) limit, offset := params.ParsePaging(request)
runtimeId := request.PathParameter("cluster")
namespace := request.PathParameter("namespace") namespace := request.PathParameter("namespace")
orderBy := params.GetStringValueWithDefault(request, params.OrderByParam, openpitrix.CreateTime) orderBy := params.GetStringValueWithDefault(request, params.OrderByParam, openpitrix.CreateTime)
reverse := params.GetBoolValueWithDefault(request, params.ReverseParam, false) reverse := params.GetBoolValueWithDefault(request, params.ReverseParam, false)
...@@ -44,28 +57,8 @@ func (h *openpitrixHandler) ListApplications(request *restful.Request, response ...@@ -44,28 +57,8 @@ func (h *openpitrixHandler) ListApplications(request *restful.Request, response
api.HandleBadRequest(response, nil, err) api.HandleBadRequest(response, nil, err)
return return
} }
conditions.Match[openpitrix.Zone] = namespace
// filter namespaced applications by runtime_id conditions.Match[openpitrix.RuntimeId] = runtimeId
if namespace != "" {
ns, err := h.informers.Core().V1().Namespaces().Lister().Get(namespace)
if err != nil {
klog.Errorln(err)
api.HandleInternalError(response, nil, err)
return
}
runtimeId := ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey]
if runtimeId == "" {
// runtime id not exist,return empty response
response.WriteAsJson(models.PageableResponse{Items: []interface{}{}, TotalCount: 0})
return
} else {
// filter by runtime id
conditions.Match[openpitrix.RuntimeId] = runtimeId
}
}
result, err := h.openpitrix.ListApplications(conditions, limit, offset, orderBy, reverse) result, err := h.openpitrix.ListApplications(conditions, limit, offset, orderBy, reverse)
...@@ -81,8 +74,9 @@ func (h *openpitrixHandler) ListApplications(request *restful.Request, response ...@@ -81,8 +74,9 @@ func (h *openpitrixHandler) ListApplications(request *restful.Request, response
func (h *openpitrixHandler) DescribeApplication(req *restful.Request, resp *restful.Response) { func (h *openpitrixHandler) DescribeApplication(req *restful.Request, resp *restful.Response) {
clusterId := req.PathParameter("application") clusterId := req.PathParameter("application")
namespace := req.PathParameter("namespace") namespace := req.PathParameter("namespace")
runtimeId := req.PathParameter("cluster")
app, err := h.openpitrix.DescribeApplication(namespace, clusterId) app, err := h.openpitrix.DescribeApplication(namespace, clusterId, runtimeId)
if err != nil { if err != nil {
klog.Errorln(err) klog.Errorln(err)
...@@ -90,28 +84,29 @@ func (h *openpitrixHandler) DescribeApplication(req *restful.Request, resp *rest ...@@ -90,28 +84,29 @@ func (h *openpitrixHandler) DescribeApplication(req *restful.Request, resp *rest
return return
} }
ns, err := h.informers.Core().V1().Namespaces().Lister().Get(namespace) //ns, err := h.informers.Core().V1().Namespaces().Lister().Get(namespace)
//
if err != nil { //if err != nil {
klog.Errorln(err) // klog.Errorln(err)
api.HandleInternalError(resp, nil, err) // api.HandleInternalError(resp, nil, err)
return // return
} //}
//
runtimeId := ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey] //runtimeId := ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey]
//
if runtimeId != app.Cluster.RuntimeId { //if runtimeId != app.Cluster.RuntimeId {
err = fmt.Errorf("rumtime not match %s,%s", app.Cluster.RuntimeId, runtimeId) // err = fmt.Errorf("rumtime not match %s,%s", app.Cluster.RuntimeId, runtimeId)
klog.V(4).Infoln(err) // klog.V(4).Infoln(err)
api.HandleForbidden(resp, nil, err) // api.HandleForbidden(resp, nil, err)
return // return
} //}
resp.WriteEntity(app) resp.WriteEntity(app)
return return
} }
func (h *openpitrixHandler) CreateApplication(req *restful.Request, resp *restful.Response) { func (h *openpitrixHandler) CreateApplication(req *restful.Request, resp *restful.Response) {
runtimeId := req.PathParameter("cluster")
namespace := req.PathParameter("namespace") namespace := req.PathParameter("namespace")
var createClusterRequest openpitrix.CreateClusterRequest var createClusterRequest openpitrix.CreateClusterRequest
err := req.ReadEntity(&createClusterRequest) err := req.ReadEntity(&createClusterRequest)
...@@ -123,7 +118,7 @@ func (h *openpitrixHandler) CreateApplication(req *restful.Request, resp *restfu ...@@ -123,7 +118,7 @@ func (h *openpitrixHandler) CreateApplication(req *restful.Request, resp *restfu
createClusterRequest.Username = req.HeaderParameter(constants.UserNameHeader) createClusterRequest.Username = req.HeaderParameter(constants.UserNameHeader)
err = h.openpitrix.CreateApplication(namespace, createClusterRequest) err = h.openpitrix.CreateApplication(runtimeId, namespace, createClusterRequest)
if err != nil { if err != nil {
klog.Errorln(err) klog.Errorln(err)
...@@ -136,6 +131,7 @@ func (h *openpitrixHandler) CreateApplication(req *restful.Request, resp *restfu ...@@ -136,6 +131,7 @@ func (h *openpitrixHandler) CreateApplication(req *restful.Request, resp *restfu
func (h *openpitrixHandler) ModifyApplication(req *restful.Request, resp *restful.Response) { func (h *openpitrixHandler) ModifyApplication(req *restful.Request, resp *restful.Response) {
var modifyClusterAttributesRequest openpitrix.ModifyClusterAttributesRequest var modifyClusterAttributesRequest openpitrix.ModifyClusterAttributesRequest
runtimeId := req.PathParameter("cluster")
clusterId := req.PathParameter("application") clusterId := req.PathParameter("application")
namespace := req.PathParameter("namespace") namespace := req.PathParameter("namespace")
err := req.ReadEntity(&modifyClusterAttributesRequest) err := req.ReadEntity(&modifyClusterAttributesRequest)
...@@ -145,7 +141,7 @@ func (h *openpitrixHandler) ModifyApplication(req *restful.Request, resp *restfu ...@@ -145,7 +141,7 @@ func (h *openpitrixHandler) ModifyApplication(req *restful.Request, resp *restfu
return return
} }
app, err := h.openpitrix.DescribeApplication(namespace, clusterId) app, err := h.openpitrix.DescribeApplication(namespace, clusterId, runtimeId)
if err != nil { if err != nil {
klog.Errorln(err) klog.Errorln(err)
...@@ -153,16 +149,6 @@ func (h *openpitrixHandler) ModifyApplication(req *restful.Request, resp *restfu ...@@ -153,16 +149,6 @@ func (h *openpitrixHandler) ModifyApplication(req *restful.Request, resp *restfu
return return
} }
ns, err := h.informers.Core().V1().Namespaces().Lister().Get(namespace)
if err != nil {
klog.Errorln(err)
api.HandleInternalError(resp, nil, err)
return
}
runtimeId := ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey]
if runtimeId != app.Cluster.RuntimeId { if runtimeId != app.Cluster.RuntimeId {
err = fmt.Errorf("rumtime not match %s,%s", app.Cluster.RuntimeId, runtimeId) err = fmt.Errorf("rumtime not match %s,%s", app.Cluster.RuntimeId, runtimeId)
klog.V(4).Infoln(err) klog.V(4).Infoln(err)
...@@ -182,9 +168,10 @@ func (h *openpitrixHandler) ModifyApplication(req *restful.Request, resp *restfu ...@@ -182,9 +168,10 @@ func (h *openpitrixHandler) ModifyApplication(req *restful.Request, resp *restfu
} }
func (h *openpitrixHandler) DeleteApplication(req *restful.Request, resp *restful.Response) { func (h *openpitrixHandler) DeleteApplication(req *restful.Request, resp *restful.Response) {
runtimeId := req.PathParameter("cluster")
clusterId := req.PathParameter("application") clusterId := req.PathParameter("application")
namespace := req.PathParameter("namespace") namespace := req.PathParameter("namespace")
app, err := h.openpitrix.DescribeApplication(namespace, clusterId) app, err := h.openpitrix.DescribeApplication(namespace, clusterId, runtimeId)
if err != nil { if err != nil {
klog.Errorln(err) klog.Errorln(err)
...@@ -192,15 +179,45 @@ func (h *openpitrixHandler) DeleteApplication(req *restful.Request, resp *restfu ...@@ -192,15 +179,45 @@ func (h *openpitrixHandler) DeleteApplication(req *restful.Request, resp *restfu
return return
} }
ns, err := h.informers.Core().V1().Namespaces().Lister().Get(namespace) if runtimeId != app.Cluster.RuntimeId {
err = fmt.Errorf("rumtime not match %s,%s", app.Cluster.RuntimeId, runtimeId)
klog.V(4).Infoln(err)
api.HandleForbidden(resp, nil, err)
return
}
err = h.openpitrix.DeleteApplication(clusterId)
if err != nil { if err != nil {
klog.Errorln(err) klog.Errorln(err)
api.HandleInternalError(resp, nil, err) handleOpenpitrixError(resp, err)
return return
} }
runtimeId := ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey] resp.WriteEntity(errors.None)
}
func (h *openpitrixHandler) UpgradeApplication(req *restful.Request, resp *restful.Response) {
runtimeId := req.PathParameter("cluster")
namespace := req.PathParameter("namespace")
clusterId := req.PathParameter("application")
var upgradeClusterRequest openpitrix.UpgradeClusterRequest
err := req.ReadEntity(&upgradeClusterRequest)
if err != nil {
klog.V(4).Infoln(err)
api.HandleBadRequest(resp, nil, err)
return
}
upgradeClusterRequest.Username = req.HeaderParameter(constants.UserNameHeader)
app, err := h.openpitrix.DescribeApplication(namespace, clusterId, runtimeId)
if err != nil {
klog.Errorln(err)
handleOpenpitrixError(resp, err)
return
}
if runtimeId != app.Cluster.RuntimeId { if runtimeId != app.Cluster.RuntimeId {
err = fmt.Errorf("rumtime not match %s,%s", app.Cluster.RuntimeId, runtimeId) err = fmt.Errorf("rumtime not match %s,%s", app.Cluster.RuntimeId, runtimeId)
...@@ -209,11 +226,11 @@ func (h *openpitrixHandler) DeleteApplication(req *restful.Request, resp *restfu ...@@ -209,11 +226,11 @@ func (h *openpitrixHandler) DeleteApplication(req *restful.Request, resp *restfu
return return
} }
err = h.openpitrix.DeleteApplication(clusterId) err = h.openpitrix.UpgradeApplication(upgradeClusterRequest)
if err != nil { if err != nil {
klog.Errorln(err) klog.Errorln(err)
handleOpenpitrixError(resp, err) api.HandleInternalError(resp, nil, err)
return return
} }
......
/* /*
Copyright 2019 The KubeSphere Authors. Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package v1 package v1
import ( import (
...@@ -45,22 +43,22 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op ...@@ -45,22 +43,22 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
webservice := runtime.NewWebService(GroupVersion) webservice := runtime.NewWebService(GroupVersion)
handler := newOpenpitrixHandler(factory, op) handler := newOpenpitrixHandler(factory, op)
webservice.Route(webservice.GET("/applications"). webservice.Route(webservice.GET("/clusters/{cluster}/applications").
To(handler.ListApplications). To(handler.ListApplications).
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}). Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}). Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
Doc("List all applications"). Doc("List all applications in special cluster").
Param(webservice.QueryParameter(params.ConditionsParam, "query conditions, connect multiple conditions with commas, equal symbol for exact query, wave symbol for fuzzy query e.g. name~a"). Param(webservice.QueryParameter(params.ConditionsParam, "query conditions, connect multiple conditions with commas, equal symbol for exact query, wave symbol for fuzzy query e.g. name~a").
Required(false). Required(false).
DataFormat("key=value,key~value"). DataFormat("key=value,key~value").
DefaultValue("")). DefaultValue("")).
Param(webservice.PathParameter("namespace", "the name of the project")). Param(webservice.PathParameter("cluster", "the id of cluster(runtime)")).
Param(webservice.QueryParameter(params.PagingParam, "paging query, e.g. limit=100,page=1"). Param(webservice.QueryParameter(params.PagingParam, "paging query, e.g. limit=100,page=1").
Required(false). Required(false).
DataFormat("limit=%d,page=%d"). DataFormat("limit=%d,page=%d").
DefaultValue("limit=10,page=1"))) DefaultValue("limit=10,page=1")))
webservice.Route(webservice.GET("/namespaces/{namespace}/applications"). webservice.Route(webservice.GET("/clusters/{cluster}/namespaces/{namespace}/applications").
To(handler.ListApplications). To(handler.ListApplications).
Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}). Returns(http.StatusOK, api.StatusOK, models.PageableResponse{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}). Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
...@@ -69,43 +67,59 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op ...@@ -69,43 +67,59 @@ func AddToContainer(c *restful.Container, factory informers.InformerFactory, op
Required(false). Required(false).
DataFormat("key=value,key~value"). DataFormat("key=value,key~value").
DefaultValue("")). DefaultValue("")).
Param(webservice.PathParameter("cluster", "the id of cluster(runtime)")).
Param(webservice.PathParameter("namespace", "the name of the project")). Param(webservice.PathParameter("namespace", "the name of the project")).
Param(webservice.QueryParameter(params.PagingParam, "paging query, e.g. limit=100,page=1"). Param(webservice.QueryParameter(params.PagingParam, "paging query, e.g. limit=100,page=1").
Required(false). Required(false).
DataFormat("limit=%d,page=%d"). DataFormat("limit=%d,page=%d").
DefaultValue("limit=10,page=1"))) DefaultValue("limit=10,page=1")))
webservice.Route(webservice.GET("/namespaces/{namespace}/applications/{application}"). webservice.Route(webservice.GET("/clusters/{cluster}/namespaces/{namespace}/applications/{application}").
To(handler.DescribeApplication). To(handler.DescribeApplication).
Returns(http.StatusOK, api.StatusOK, openpitrix2.Application{}). Returns(http.StatusOK, api.StatusOK, openpitrix2.Application{}).
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}). Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
Doc("Describe the specified application of the namespace"). Doc("Describe the specified application of the namespace").
Param(webservice.PathParameter("cluster", "the id of cluster(runtime)")).
Param(webservice.PathParameter("namespace", "the name of the project")). Param(webservice.PathParameter("namespace", "the name of the project")).
Param(webservice.PathParameter("application", "application ID"))) Param(webservice.PathParameter("application", "application ID")))
webservice.Route(webservice.POST("/namespaces/{namespace}/applications"). webservice.Route(webservice.POST("/clusters/{cluster}/namespaces/{namespace}/applications").
To(handler.CreateApplication). To(handler.CreateApplication).
Doc("Deploy a new application"). Doc("Deploy a new application").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}). Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
Reads(openpitrix2.CreateClusterRequest{}). Reads(openpitrix2.CreateClusterRequest{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}). Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("cluster", "the id of cluster(runtime)")).
Param(webservice.PathParameter("namespace", "the name of the project"))) Param(webservice.PathParameter("namespace", "the name of the project")))
webservice.Route(webservice.PATCH("/namespaces/{namespace}/applications/{application}"). webservice.Route(webservice.PATCH("/clusters/{cluster}/namespaces/{namespace}/applications/{application}").
Consumes(mimePatch...). Consumes(mimePatch...).
To(handler.ModifyApplication). To(handler.ModifyApplication).
Doc("Modify application"). Doc("Modify application").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}). Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
Reads(openpitrix2.ModifyClusterAttributesRequest{}). Reads(openpitrix2.ModifyClusterAttributesRequest{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}). Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("cluster", "the id of cluster(runtime)")).
Param(webservice.PathParameter("namespace", "the name of the project")). Param(webservice.PathParameter("namespace", "the name of the project")).
Param(webservice.PathParameter("application", "the id of the application cluster"))) Param(webservice.PathParameter("application", "the id of the application cluster")))
webservice.Route(webservice.DELETE("/namespaces/{namespace}/applications/{application}"). webservice.Route(webservice.DELETE("/clusters/cluster/namespaces/{namespace}/applications/{application}").
To(handler.DeleteApplication). To(handler.DeleteApplication).
Doc("Delete the specified application"). Doc("Delete the specified application").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}). Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}). Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("cluster", "the id of cluster(runtime")).
Param(webservice.PathParameter("namespace", "the name of the project")).
Param(webservice.PathParameter("application", "the id of the application cluster")))
webservice.Route(webservice.POST("/clusters/{cluster}/namespaces/{namespace}/applications/{application}").
Consumes(mimePatch...).
To(handler.UpgradeApplication).
Doc("Upgrade application").
Metadata(restfulspec.KeyOpenAPITags, []string{constants.NamespaceResourcesTag}).
Reads(openpitrix2.UpgradeClusterRequest{}).
Returns(http.StatusOK, api.StatusOK, errors.Error{}).
Param(webservice.PathParameter("cluster", "the id of cluster(runtime)")).
Param(webservice.PathParameter("namespace", "the name of the project")). Param(webservice.PathParameter("namespace", "the name of the project")).
Param(webservice.PathParameter("application", "the id of the application cluster"))) Param(webservice.PathParameter("application", "the id of the application cluster")))
......
/* /*
Copyright 2020 The KubeSphere Authors. Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package openpitrix package openpitrix
import ( import (
"fmt" "encoding/json"
"github.com/golang/protobuf/ptypes/wrappers" "github.com/golang/protobuf/ptypes/wrappers"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
...@@ -27,20 +25,21 @@ import ( ...@@ -27,20 +25,21 @@ import (
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/informers" "k8s.io/client-go/informers"
"k8s.io/klog" "k8s.io/klog"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/models" "kubesphere.io/kubesphere/pkg/models"
"kubesphere.io/kubesphere/pkg/server/params" "kubesphere.io/kubesphere/pkg/server/params"
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix" "kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
"openpitrix.io/openpitrix/pkg/pb" "openpitrix.io/openpitrix/pkg/pb"
"openpitrix.io/openpitrix/pkg/util/pbutil"
"strings" "strings"
) )
type ApplicationInterface interface { type ApplicationInterface interface {
ListApplications(conditions *params.Conditions, limit, offset int, orderBy string, reverse bool) (*models.PageableResponse, error) ListApplications(conditions *params.Conditions, limit, offset int, orderBy string, reverse bool) (*models.PageableResponse, error)
DescribeApplication(namespace, clusterId string) (*Application, error) DescribeApplication(namespace, clusterId, runtimeId string) (*Application, error)
CreateApplication(namespace string, request CreateClusterRequest) error CreateApplication(runtimeId, namespace string, request CreateClusterRequest) error
ModifyApplication(request ModifyClusterAttributesRequest) error ModifyApplication(request ModifyClusterAttributesRequest) error
DeleteApplication(id string) error DeleteApplication(id string) error
UpgradeApplication(request UpgradeClusterRequest) error
} }
type applicationOperator struct { type applicationOperator struct {
...@@ -68,6 +67,14 @@ type workLoads struct { ...@@ -68,6 +67,14 @@ type workLoads struct {
Daemonsets []appsv1.DaemonSet `json:"daemonsets,omitempty" description:"daemonset list"` Daemonsets []appsv1.DaemonSet `json:"daemonsets,omitempty" description:"daemonset list"`
} }
type resourceInfo struct {
Deployments []appsv1.Deployment `json:"deployments,omitempty" description:"deployment list"`
Statefulsets []appsv1.StatefulSet `json:"statefulsets,omitempty" description:"statefulset list"`
Daemonsets []appsv1.DaemonSet `json:"daemonsets,omitempty" description:"daemonset list"`
Services []v1.Service `json:"services,omitempty" description:"application services"`
Ingresses []v1beta1.Ingress `json:"ingresses,omitempty" description:"application ingresses"`
}
func (c *applicationOperator) ListApplications(conditions *params.Conditions, limit, offset int, orderBy string, reverse bool) (*models.PageableResponse, error) { func (c *applicationOperator) ListApplications(conditions *params.Conditions, limit, offset int, orderBy string, reverse bool) (*models.PageableResponse, error) {
describeClustersRequest := &pb.DescribeClustersRequest{ describeClustersRequest := &pb.DescribeClustersRequest{
Limit: uint32(limit), Limit: uint32(limit),
...@@ -133,9 +140,15 @@ func (c *applicationOperator) describeApplication(cluster *pb.Cluster) (*Applica ...@@ -133,9 +140,15 @@ func (c *applicationOperator) describeApplication(cluster *pb.Cluster) (*Applica
return &app, nil return &app, nil
} }
func (c *applicationOperator) DescribeApplication(namespace string, clusterId string) (*Application, error) { func (c *applicationOperator) DescribeApplication(namespace string, clusterId string, runtimeId string) (*Application, error) {
describeClusterRequest := &pb.DescribeClustersRequest{
clusters, err := c.opClient.DescribeClusters(openpitrix.SystemContext(), &pb.DescribeClustersRequest{ClusterId: []string{clusterId}, Limit: 1}) ClusterId: []string{clusterId},
RuntimeId: []string{runtimeId},
Zone: []string{namespace},
WithDetail: pbutil.ToProtoBool(true),
Limit: 1,
}
clusters, err := c.opClient.DescribeClusters(openpitrix.SystemContext(), describeClusterRequest)
if err != nil { if err != nil {
klog.Errorln(err) klog.Errorln(err)
...@@ -156,16 +169,26 @@ func (c *applicationOperator) DescribeApplication(namespace string, clusterId st ...@@ -156,16 +169,26 @@ func (c *applicationOperator) DescribeApplication(namespace string, clusterId st
return nil, err return nil, err
} }
workloads, err := c.getWorkLoads(namespace, cluster.ClusterRoleSet) resource := new(resourceInfo)
workloads := cluster.AdditionalInfo.GetValue()
if workloads == "" {
err := status.New(codes.NotFound, "cannot get workload").Err()
klog.Errorln(err)
return nil, err
}
err = json.Unmarshal([]byte(workloads), resource)
if err != nil { if err != nil {
klog.Errorln(err) klog.Errorln(err)
return nil, err return nil, err
} }
app.WorkLoads = workloads
workloadLabels := c.getLabels(namespace, app.WorkLoads) app.WorkLoads = &workLoads{
app.Services = c.getSvcs(namespace, workloadLabels) Deployments: resource.Deployments,
app.Ingresses = c.getIng(namespace, app.Services) Statefulsets: resource.Statefulsets,
Daemonsets: resource.Daemonsets,
}
app.Services = resource.Services
app.Ingresses = resource.Ingresses
return app, nil return app, nil
} }
...@@ -332,23 +355,12 @@ func (c *applicationOperator) getIng(namespace string, services []v1.Service) [] ...@@ -332,23 +355,12 @@ func (c *applicationOperator) getIng(namespace string, services []v1.Service) []
return ings return ings
} }
func (c *applicationOperator) CreateApplication(namespace string, request CreateClusterRequest) error { func (c *applicationOperator) CreateApplication(runtimeId, namespace string, request CreateClusterRequest) error {
ns, err := c.informers.Core().V1().Namespaces().Lister().Get(namespace) _, err := c.opClient.CreateCluster(openpitrix.ContextWithUsername(request.Username), &pb.CreateClusterRequest{
if err != nil {
klog.Error(err)
return err
}
if runtimeId := ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey]; runtimeId != "" {
request.RuntimeId = runtimeId
} else {
return fmt.Errorf("runtime not init: namespace %s", namespace)
}
_, err = c.opClient.CreateCluster(openpitrix.ContextWithUsername(request.Username), &pb.CreateClusterRequest{
AppId: &wrappers.StringValue{Value: request.AppId}, AppId: &wrappers.StringValue{Value: request.AppId},
VersionId: &wrappers.StringValue{Value: request.VersionId}, VersionId: &wrappers.StringValue{Value: request.VersionId},
RuntimeId: &wrappers.StringValue{Value: request.RuntimeId}, RuntimeId: &wrappers.StringValue{Value: request.RuntimeId},
Namespace: &wrappers.StringValue{Value: namespace},
Conf: &wrappers.StringValue{Value: request.Conf}, Conf: &wrappers.StringValue{Value: request.Conf},
}) })
...@@ -390,3 +402,18 @@ func (c *applicationOperator) DeleteApplication(clusterId string) error { ...@@ -390,3 +402,18 @@ func (c *applicationOperator) DeleteApplication(clusterId string) error {
return nil return nil
} }
func (c *applicationOperator) UpgradeApplication(request UpgradeClusterRequest) error {
_, err := c.opClient.UpgradeCluster(openpitrix.ContextWithUsername(request.Username), &pb.UpgradeClusterRequest{
ClusterId: &wrappers.StringValue{Value: request.ClusterId},
VersionId: &wrappers.StringValue{Value: request.VersionId},
Conf: &wrappers.StringValue{Value: request.Conf},
})
if err != nil {
klog.Errorln(err)
return err
}
return nil
}
/* /*
Copyright 2020 The KubeSphere Authors. Copyright 2020 The KubeSphere Authors.
<<<<<<< HEAD
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
...@@ -7,6 +8,12 @@ You may obtain a copy of the License at ...@@ -7,6 +8,12 @@ You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
=======
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
>>>>>>> support UpgradeCluster
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...@@ -101,7 +108,7 @@ func TestApplicationOperator_CreateApplication(t *testing.T) { ...@@ -101,7 +108,7 @@ func TestApplicationOperator_CreateApplication(t *testing.T) {
t.Run(test.description, func(t *testing.T) { t.Run(test.description, func(t *testing.T) {
err := applicationOperator.CreateApplication(test.targetNamespace, test.createClusterRequest) err := applicationOperator.CreateApplication(test.createClusterRequest.RuntimeId, test.targetNamespace, test.createClusterRequest)
if err != nil && err.Error() != test.expected.Error() { if err != nil && err.Error() != test.expected.Error() {
t.Error(err) t.Error(err)
......
/* /*
Copyright 2020 The KubeSphere Authors. Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
>>>>>>> support UpgradeCluster
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......
/* /*
Copyright 2019 The KubeSphere Authors. Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......
/* /*
Copyright 2020 The KubeSphere Authors. Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......
/* /*
Copyright 2020 The KubeSphere Authors. Copyright 2020 The KubeSphere Authors.
<<<<<<< HEAD
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
...@@ -7,6 +8,12 @@ You may obtain a copy of the License at ...@@ -7,6 +8,12 @@ You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
=======
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
>>>>>>> support UpgradeCluster
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......
/* /*
Copyright 2020 The KubeSphere Authors. Copyright 2020 The KubeSphere Authors.
<<<<<<< HEAD
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
...@@ -7,6 +8,12 @@ You may obtain a copy of the License at ...@@ -7,6 +8,12 @@ You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
=======
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
>>>>>>> support UpgradeCluster
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......
/*
Copyright 2020 The 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 openpitrix package openpitrix
import ( import (
...@@ -737,6 +750,25 @@ type CreateClusterRequest struct { ...@@ -737,6 +750,25 @@ type CreateClusterRequest struct {
Username string `json:"-"` Username string `json:"-"`
} }
type UpgradeClusterRequest struct {
// cluster id
ClusterId string `json:"cluster_id"`
// advanced param
AdvancedParam []string `json:"advanced_param"`
// required, conf a json string, include cpu, memory info of cluster
Conf string `json:"conf,omitempty"`
// required, id of runtime
RuntimeId string `json:"runtime_id,omitempty"`
// required, id of app version
VersionId string `json:"version_id,omitempty"`
Username string `json:"-"`
}
type Cluster struct { type Cluster struct {
// additional info // additional info
...@@ -840,6 +872,7 @@ const ( ...@@ -840,6 +872,7 @@ const (
CreateTime = "create_time" CreateTime = "create_time"
StatusTime = "status_time" StatusTime = "status_time"
RuntimeId = "runtime_id" RuntimeId = "runtime_id"
Zone = "zone"
VersionId = "version_id" VersionId = "version_id"
RepoId = "repo_id" RepoId = "repo_id"
CategoryId = "category_id" CategoryId = "category_id"
......
/* /*
Copyright 2019 The KubeSphere Authors. Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......
// Go support for Protocol Buffers - Google's data interchange format // Go support for Protocol Buffers - Google's data interchange format
// //
// Copyright 2017 The Go Authors. All rights reserved. // Copyright 2016 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf // https://github.com/golang/protobuf
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
...@@ -29,89 +29,65 @@ ...@@ -29,89 +29,65 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* // Package descriptor provides functions for obtaining protocol buffer
Package remap handles tracking the locations of Go tokens in a source text // descriptors for generated Go types.
across a rewrite by the Go formatter. //
*/ // These functions cannot go in package proto because they depend on the
package remap // generated protobuf descriptor messages, which themselves depend on proto.
package descriptor
import ( import (
"bytes"
"compress/gzip"
"fmt" "fmt"
"go/scanner" "io/ioutil"
"go/token"
)
// A Location represents a span of byte offsets in the source text. "github.com/golang/protobuf/proto"
type Location struct { protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor"
Pos, End int // End is exclusive )
}
// A Map represents a mapping between token locations in an input source text // extractFile extracts a FileDescriptorProto from a gzip'd buffer.
// and locations in the correspnding output text. func extractFile(gz []byte) (*protobuf.FileDescriptorProto, error) {
type Map map[Location]Location r, err := gzip.NewReader(bytes.NewReader(gz))
if err != nil {
return nil, fmt.Errorf("failed to open gzip reader: %v", err)
}
defer r.Close()
// Find reports whether the specified span is recorded by m, and if so returns b, err := ioutil.ReadAll(r)
// the new location it was mapped to. If the input span was not found, the if err != nil {
// returned location is the same as the input. return nil, fmt.Errorf("failed to uncompress descriptor: %v", err)
func (m Map) Find(pos, end int) (Location, bool) {
key := Location{
Pos: pos,
End: end,
} }
if loc, ok := m[key]; ok {
return loc, true fd := new(protobuf.FileDescriptorProto)
if err := proto.Unmarshal(b, fd); err != nil {
return nil, fmt.Errorf("malformed FileDescriptorProto: %v", err)
} }
return key, false
}
func (m Map) add(opos, oend, npos, nend int) { return fd, nil
m[Location{Pos: opos, End: oend}] = Location{Pos: npos, End: nend}
} }
// Compute constructs a location mapping from input to output. An error is // Message is a proto.Message with a method to return its descriptor.
// reported if any of the tokens of output cannot be mapped. //
func Compute(input, output []byte) (Map, error) { // Message types generated by the protocol compiler always satisfy
itok := tokenize(input) // the Message interface.
otok := tokenize(output) type Message interface {
if len(itok) != len(otok) { proto.Message
return nil, fmt.Errorf("wrong number of tokens, %d ≠ %d", len(itok), len(otok)) Descriptor() ([]byte, []int)
}
m := make(Map)
for i, ti := range itok {
to := otok[i]
if ti.Token != to.Token {
return nil, fmt.Errorf("token %d type mismatch: %s ≠ %s", i+1, ti, to)
}
m.add(ti.pos, ti.end, to.pos, to.end)
}
return m, nil
} }
// tokinfo records the span and type of a source token. // ForMessage returns a FileDescriptorProto and a DescriptorProto from within it
type tokinfo struct { // describing the given message.
pos, end int func ForMessage(msg Message) (fd *protobuf.FileDescriptorProto, md *protobuf.DescriptorProto) {
token.Token gz, path := msg.Descriptor()
} fd, err := extractFile(gz)
if err != nil {
panic(fmt.Sprintf("invalid FileDescriptorProto for %T: %v", msg, err))
}
func tokenize(src []byte) []tokinfo { md = fd.MessageType[path[0]]
fs := token.NewFileSet() for _, i := range path[1:] {
var s scanner.Scanner md = md.NestedType[i]
s.Init(fs.AddFile("src", fs.Base(), len(src)), src, nil, scanner.ScanComments)
var info []tokinfo
for {
pos, next, lit := s.Scan()
switch next {
case token.SEMICOLON:
continue
}
info = append(info, tokinfo{
pos: int(pos - 1),
end: int(pos + token.Pos(len(lit)) - 1),
Token: next,
})
if next == token.EOF {
break
}
} }
return info return fd, md
} }
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: google/protobuf/compiler/plugin.proto
/*
Package plugin_go is a generated protocol buffer package.
It is generated from these files:
google/protobuf/compiler/plugin.proto
It has these top-level messages:
Version
CodeGeneratorRequest
CodeGeneratorResponse
*/
package plugin_go
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import google_protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
// The version number of protocol compiler.
type Version struct {
Major *int32 `protobuf:"varint,1,opt,name=major" json:"major,omitempty"`
Minor *int32 `protobuf:"varint,2,opt,name=minor" json:"minor,omitempty"`
Patch *int32 `protobuf:"varint,3,opt,name=patch" json:"patch,omitempty"`
// A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should
// be empty for mainline stable releases.
Suffix *string `protobuf:"bytes,4,opt,name=suffix" json:"suffix,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Version) Reset() { *m = Version{} }
func (m *Version) String() string { return proto.CompactTextString(m) }
func (*Version) ProtoMessage() {}
func (*Version) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *Version) Unmarshal(b []byte) error {
return xxx_messageInfo_Version.Unmarshal(m, b)
}
func (m *Version) Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Version.Marshal(b, m, deterministic)
}
func (dst *Version) XXX_Merge(src proto.Message) {
xxx_messageInfo_Version.Merge(dst, src)
}
func (m *Version) XXX_Size() int {
return xxx_messageInfo_Version.Size(m)
}
func (m *Version) XXX_DiscardUnknown() {
xxx_messageInfo_Version.DiscardUnknown(m)
}
var xxx_messageInfo_Version proto.InternalMessageInfo
func (m *Version) GetMajor() int32 {
if m != nil && m.Major != nil {
return *m.Major
}
return 0
}
func (m *Version) GetMinor() int32 {
if m != nil && m.Minor != nil {
return *m.Minor
}
return 0
}
func (m *Version) GetPatch() int32 {
if m != nil && m.Patch != nil {
return *m.Patch
}
return 0
}
func (m *Version) GetSuffix() string {
if m != nil && m.Suffix != nil {
return *m.Suffix
}
return ""
}
// An encoded CodeGeneratorRequest is written to the plugin's stdin.
type CodeGeneratorRequest struct {
// The .proto files that were explicitly listed on the command-line. The
// code generator should generate code only for these files. Each file's
// descriptor will be included in proto_file, below.
FileToGenerate []string `protobuf:"bytes,1,rep,name=file_to_generate,json=fileToGenerate" json:"file_to_generate,omitempty"`
// The generator parameter passed on the command-line.
Parameter *string `protobuf:"bytes,2,opt,name=parameter" json:"parameter,omitempty"`
// FileDescriptorProtos for all files in files_to_generate and everything
// they import. The files will appear in topological order, so each file
// appears before any file that imports it.
//
// protoc guarantees that all proto_files will be written after
// the fields above, even though this is not technically guaranteed by the
// protobuf wire format. This theoretically could allow a plugin to stream
// in the FileDescriptorProtos and handle them one by one rather than read
// the entire set into memory at once. However, as of this writing, this
// is not similarly optimized on protoc's end -- it will store all fields in
// memory at once before sending them to the plugin.
//
// Type names of fields and extensions in the FileDescriptorProto are always
// fully qualified.
ProtoFile []*google_protobuf.FileDescriptorProto `protobuf:"bytes,15,rep,name=proto_file,json=protoFile" json:"proto_file,omitempty"`
// The version number of protocol compiler.
CompilerVersion *Version `protobuf:"bytes,3,opt,name=compiler_version,json=compilerVersion" json:"compiler_version,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *CodeGeneratorRequest) Reset() { *m = CodeGeneratorRequest{} }
func (m *CodeGeneratorRequest) String() string { return proto.CompactTextString(m) }
func (*CodeGeneratorRequest) ProtoMessage() {}
func (*CodeGeneratorRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *CodeGeneratorRequest) Unmarshal(b []byte) error {
return xxx_messageInfo_CodeGeneratorRequest.Unmarshal(m, b)
}
func (m *CodeGeneratorRequest) Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_CodeGeneratorRequest.Marshal(b, m, deterministic)
}
func (dst *CodeGeneratorRequest) XXX_Merge(src proto.Message) {
xxx_messageInfo_CodeGeneratorRequest.Merge(dst, src)
}
func (m *CodeGeneratorRequest) XXX_Size() int {
return xxx_messageInfo_CodeGeneratorRequest.Size(m)
}
func (m *CodeGeneratorRequest) XXX_DiscardUnknown() {
xxx_messageInfo_CodeGeneratorRequest.DiscardUnknown(m)
}
var xxx_messageInfo_CodeGeneratorRequest proto.InternalMessageInfo
func (m *CodeGeneratorRequest) GetFileToGenerate() []string {
if m != nil {
return m.FileToGenerate
}
return nil
}
func (m *CodeGeneratorRequest) GetParameter() string {
if m != nil && m.Parameter != nil {
return *m.Parameter
}
return ""
}
func (m *CodeGeneratorRequest) GetProtoFile() []*google_protobuf.FileDescriptorProto {
if m != nil {
return m.ProtoFile
}
return nil
}
func (m *CodeGeneratorRequest) GetCompilerVersion() *Version {
if m != nil {
return m.CompilerVersion
}
return nil
}
// The plugin writes an encoded CodeGeneratorResponse to stdout.
type CodeGeneratorResponse struct {
// Error message. If non-empty, code generation failed. The plugin process
// should exit with status code zero even if it reports an error in this way.
//
// This should be used to indicate errors in .proto files which prevent the
// code generator from generating correct code. Errors which indicate a
// problem in protoc itself -- such as the input CodeGeneratorRequest being
// unparseable -- should be reported by writing a message to stderr and
// exiting with a non-zero status code.
Error *string `protobuf:"bytes,1,opt,name=error" json:"error,omitempty"`
File []*CodeGeneratorResponse_File `protobuf:"bytes,15,rep,name=file" json:"file,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *CodeGeneratorResponse) Reset() { *m = CodeGeneratorResponse{} }
func (m *CodeGeneratorResponse) String() string { return proto.CompactTextString(m) }
func (*CodeGeneratorResponse) ProtoMessage() {}
func (*CodeGeneratorResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
func (m *CodeGeneratorResponse) Unmarshal(b []byte) error {
return xxx_messageInfo_CodeGeneratorResponse.Unmarshal(m, b)
}
func (m *CodeGeneratorResponse) Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_CodeGeneratorResponse.Marshal(b, m, deterministic)
}
func (dst *CodeGeneratorResponse) XXX_Merge(src proto.Message) {
xxx_messageInfo_CodeGeneratorResponse.Merge(dst, src)
}
func (m *CodeGeneratorResponse) XXX_Size() int {
return xxx_messageInfo_CodeGeneratorResponse.Size(m)
}
func (m *CodeGeneratorResponse) XXX_DiscardUnknown() {
xxx_messageInfo_CodeGeneratorResponse.DiscardUnknown(m)
}
var xxx_messageInfo_CodeGeneratorResponse proto.InternalMessageInfo
func (m *CodeGeneratorResponse) GetError() string {
if m != nil && m.Error != nil {
return *m.Error
}
return ""
}
func (m *CodeGeneratorResponse) GetFile() []*CodeGeneratorResponse_File {
if m != nil {
return m.File
}
return nil
}
// Represents a single generated file.
type CodeGeneratorResponse_File struct {
// The file name, relative to the output directory. The name must not
// contain "." or ".." components and must be relative, not be absolute (so,
// the file cannot lie outside the output directory). "/" must be used as
// the path separator, not "\".
//
// If the name is omitted, the content will be appended to the previous
// file. This allows the generator to break large files into small chunks,
// and allows the generated text to be streamed back to protoc so that large
// files need not reside completely in memory at one time. Note that as of
// this writing protoc does not optimize for this -- it will read the entire
// CodeGeneratorResponse before writing files to disk.
Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
// If non-empty, indicates that the named file should already exist, and the
// content here is to be inserted into that file at a defined insertion
// point. This feature allows a code generator to extend the output
// produced by another code generator. The original generator may provide
// insertion points by placing special annotations in the file that look
// like:
// @@protoc_insertion_point(NAME)
// The annotation can have arbitrary text before and after it on the line,
// which allows it to be placed in a comment. NAME should be replaced with
// an identifier naming the point -- this is what other generators will use
// as the insertion_point. Code inserted at this point will be placed
// immediately above the line containing the insertion point (thus multiple
// insertions to the same point will come out in the order they were added).
// The double-@ is intended to make it unlikely that the generated code
// could contain things that look like insertion points by accident.
//
// For example, the C++ code generator places the following line in the
// .pb.h files that it generates:
// // @@protoc_insertion_point(namespace_scope)
// This line appears within the scope of the file's package namespace, but
// outside of any particular class. Another plugin can then specify the
// insertion_point "namespace_scope" to generate additional classes or
// other declarations that should be placed in this scope.
//
// Note that if the line containing the insertion point begins with
// whitespace, the same whitespace will be added to every line of the
// inserted text. This is useful for languages like Python, where
// indentation matters. In these languages, the insertion point comment
// should be indented the same amount as any inserted code will need to be
// in order to work correctly in that context.
//
// The code generator that generates the initial file and the one which
// inserts into it must both run as part of a single invocation of protoc.
// Code generators are executed in the order in which they appear on the
// command line.
//
// If |insertion_point| is present, |name| must also be present.
InsertionPoint *string `protobuf:"bytes,2,opt,name=insertion_point,json=insertionPoint" json:"insertion_point,omitempty"`
// The file contents.
Content *string `protobuf:"bytes,15,opt,name=content" json:"content,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *CodeGeneratorResponse_File) Reset() { *m = CodeGeneratorResponse_File{} }
func (m *CodeGeneratorResponse_File) String() string { return proto.CompactTextString(m) }
func (*CodeGeneratorResponse_File) ProtoMessage() {}
func (*CodeGeneratorResponse_File) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2, 0} }
func (m *CodeGeneratorResponse_File) Unmarshal(b []byte) error {
return xxx_messageInfo_CodeGeneratorResponse_File.Unmarshal(m, b)
}
func (m *CodeGeneratorResponse_File) Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_CodeGeneratorResponse_File.Marshal(b, m, deterministic)
}
func (dst *CodeGeneratorResponse_File) XXX_Merge(src proto.Message) {
xxx_messageInfo_CodeGeneratorResponse_File.Merge(dst, src)
}
func (m *CodeGeneratorResponse_File) XXX_Size() int {
return xxx_messageInfo_CodeGeneratorResponse_File.Size(m)
}
func (m *CodeGeneratorResponse_File) XXX_DiscardUnknown() {
xxx_messageInfo_CodeGeneratorResponse_File.DiscardUnknown(m)
}
var xxx_messageInfo_CodeGeneratorResponse_File proto.InternalMessageInfo
func (m *CodeGeneratorResponse_File) GetName() string {
if m != nil && m.Name != nil {
return *m.Name
}
return ""
}
func (m *CodeGeneratorResponse_File) GetInsertionPoint() string {
if m != nil && m.InsertionPoint != nil {
return *m.InsertionPoint
}
return ""
}
func (m *CodeGeneratorResponse_File) GetContent() string {
if m != nil && m.Content != nil {
return *m.Content
}
return ""
}
func init() {
proto.RegisterType((*Version)(nil), "google.protobuf.compiler.Version")
proto.RegisterType((*CodeGeneratorRequest)(nil), "google.protobuf.compiler.CodeGeneratorRequest")
proto.RegisterType((*CodeGeneratorResponse)(nil), "google.protobuf.compiler.CodeGeneratorResponse")
proto.RegisterType((*CodeGeneratorResponse_File)(nil), "google.protobuf.compiler.CodeGeneratorResponse.File")
}
func init() { proto.RegisterFile("google/protobuf/compiler/plugin.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 417 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xcf, 0x6a, 0x14, 0x41,
0x10, 0xc6, 0x19, 0x77, 0x63, 0x98, 0x8a, 0x64, 0x43, 0x13, 0xa5, 0x09, 0x39, 0x8c, 0x8b, 0xe2,
0x5c, 0x32, 0x0b, 0xc1, 0x8b, 0x78, 0x4b, 0x44, 0x3d, 0x78, 0x58, 0x1a, 0xf1, 0x20, 0xc8, 0x30,
0x99, 0xd4, 0x74, 0x5a, 0x66, 0xba, 0xc6, 0xee, 0x1e, 0xf1, 0x49, 0x7d, 0x0f, 0xdf, 0x40, 0xfa,
0xcf, 0x24, 0xb2, 0xb8, 0xa7, 0xee, 0xef, 0x57, 0xd5, 0xd5, 0x55, 0x1f, 0x05, 0x2f, 0x25, 0x91,
0xec, 0x71, 0x33, 0x1a, 0x72, 0x74, 0x33, 0x75, 0x9b, 0x96, 0x86, 0x51, 0xf5, 0x68, 0x36, 0x63,
0x3f, 0x49, 0xa5, 0xab, 0x10, 0x60, 0x3c, 0xa6, 0x55, 0x73, 0x5a, 0x35, 0xa7, 0x9d, 0x15, 0xbb,
0x05, 0x6e, 0xd1, 0xb6, 0x46, 0x8d, 0x8e, 0x4c, 0xcc, 0x5e, 0xb7, 0x70, 0xf8, 0x05, 0x8d, 0x55,
0xa4, 0xd9, 0x29, 0x1c, 0x0c, 0xcd, 0x77, 0x32, 0x3c, 0x2b, 0xb2, 0xf2, 0x40, 0x44, 0x11, 0xa8,
0xd2, 0x64, 0xf8, 0xa3, 0x44, 0xbd, 0xf0, 0x74, 0x6c, 0x5c, 0x7b, 0xc7, 0x17, 0x91, 0x06, 0xc1,
0x9e, 0xc1, 0x63, 0x3b, 0x75, 0x9d, 0xfa, 0xc5, 0x97, 0x45, 0x56, 0xe6, 0x22, 0xa9, 0xf5, 0x9f,
0x0c, 0x4e, 0xaf, 0xe9, 0x16, 0x3f, 0xa0, 0x46, 0xd3, 0x38, 0x32, 0x02, 0x7f, 0x4c, 0x68, 0x1d,
0x2b, 0xe1, 0xa4, 0x53, 0x3d, 0xd6, 0x8e, 0x6a, 0x19, 0x63, 0xc8, 0xb3, 0x62, 0x51, 0xe6, 0xe2,
0xd8, 0xf3, 0xcf, 0x94, 0x5e, 0x20, 0x3b, 0x87, 0x7c, 0x6c, 0x4c, 0x33, 0xa0, 0xc3, 0xd8, 0x4a,
0x2e, 0x1e, 0x00, 0xbb, 0x06, 0x08, 0xe3, 0xd4, 0xfe, 0x15, 0x5f, 0x15, 0x8b, 0xf2, 0xe8, 0xf2,
0x45, 0xb5, 0x6b, 0xcb, 0x7b, 0xd5, 0xe3, 0xbb, 0x7b, 0x03, 0xb6, 0x1e, 0x8b, 0x3c, 0x44, 0x7d,
0x84, 0x7d, 0x82, 0x93, 0xd9, 0xb8, 0xfa, 0x67, 0xf4, 0x24, 0x8c, 0x77, 0x74, 0xf9, 0xbc, 0xda,
0xe7, 0x70, 0x95, 0xcc, 0x13, 0xab, 0x99, 0x24, 0xb0, 0xfe, 0x9d, 0xc1, 0xd3, 0x9d, 0x99, 0xed,
0x48, 0xda, 0xa2, 0xf7, 0x0e, 0x8d, 0x49, 0x3e, 0xe7, 0x22, 0x0a, 0xf6, 0x11, 0x96, 0xff, 0x34,
0xff, 0x7a, 0xff, 0x8f, 0xff, 0x2d, 0x1a, 0x66, 0x13, 0xa1, 0xc2, 0xd9, 0x37, 0x58, 0x86, 0x79,
0x18, 0x2c, 0x75, 0x33, 0x60, 0xfa, 0x26, 0xdc, 0xd9, 0x2b, 0x58, 0x29, 0x6d, 0xd1, 0x38, 0x45,
0xba, 0x1e, 0x49, 0x69, 0x97, 0xcc, 0x3c, 0xbe, 0xc7, 0x5b, 0x4f, 0x19, 0x87, 0xc3, 0x96, 0xb4,
0x43, 0xed, 0xf8, 0x2a, 0x24, 0xcc, 0xf2, 0x4a, 0xc2, 0x79, 0x4b, 0xc3, 0xde, 0xfe, 0xae, 0x9e,
0x6c, 0xc3, 0x6e, 0x06, 0x7b, 0xed, 0xd7, 0x37, 0x52, 0xb9, 0xbb, 0xe9, 0xc6, 0x87, 0x37, 0x92,
0xfa, 0x46, 0xcb, 0x87, 0x65, 0x0c, 0x97, 0xf6, 0x42, 0xa2, 0xbe, 0x90, 0x94, 0x56, 0xfa, 0x6d,
0x3c, 0x6a, 0x49, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xf7, 0x15, 0x40, 0xc5, 0xfe, 0x02, 0x00,
0x00,
}
// Code generated by protoc-gen-go.
// source: google/protobuf/compiler/plugin.proto
// DO NOT EDIT!
package google_protobuf_compiler
import proto "github.com/golang/protobuf/proto"
import "math"
import google_protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor"
// Reference proto and math imports to suppress error if they are not otherwise used.
var _ = proto.GetString
var _ = math.Inf
type CodeGeneratorRequest struct {
FileToGenerate []string `protobuf:"bytes,1,rep,name=file_to_generate" json:"file_to_generate,omitempty"`
Parameter *string `protobuf:"bytes,2,opt,name=parameter" json:"parameter,omitempty"`
ProtoFile []*google_protobuf.FileDescriptorProto `protobuf:"bytes,15,rep,name=proto_file" json:"proto_file,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (this *CodeGeneratorRequest) Reset() { *this = CodeGeneratorRequest{} }
func (this *CodeGeneratorRequest) String() string { return proto.CompactTextString(this) }
func (*CodeGeneratorRequest) ProtoMessage() {}
func (this *CodeGeneratorRequest) GetParameter() string {
if this != nil && this.Parameter != nil {
return *this.Parameter
}
return ""
}
type CodeGeneratorResponse struct {
Error *string `protobuf:"bytes,1,opt,name=error" json:"error,omitempty"`
File []*CodeGeneratorResponse_File `protobuf:"bytes,15,rep,name=file" json:"file,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (this *CodeGeneratorResponse) Reset() { *this = CodeGeneratorResponse{} }
func (this *CodeGeneratorResponse) String() string { return proto.CompactTextString(this) }
func (*CodeGeneratorResponse) ProtoMessage() {}
func (this *CodeGeneratorResponse) GetError() string {
if this != nil && this.Error != nil {
return *this.Error
}
return ""
}
type CodeGeneratorResponse_File struct {
Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
InsertionPoint *string `protobuf:"bytes,2,opt,name=insertion_point" json:"insertion_point,omitempty"`
Content *string `protobuf:"bytes,15,opt,name=content" json:"content,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (this *CodeGeneratorResponse_File) Reset() { *this = CodeGeneratorResponse_File{} }
func (this *CodeGeneratorResponse_File) String() string { return proto.CompactTextString(this) }
func (*CodeGeneratorResponse_File) ProtoMessage() {}
func (this *CodeGeneratorResponse_File) GetName() string {
if this != nil && this.Name != nil {
return *this.Name
}
return ""
}
func (this *CodeGeneratorResponse_File) GetInsertionPoint() string {
if this != nil && this.InsertionPoint != nil {
return *this.InsertionPoint
}
return ""
}
func (this *CodeGeneratorResponse_File) GetContent() string {
if this != nil && this.Content != nil {
return *this.Content
}
return ""
}
func init() {
}
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Author: kenton@google.com (Kenton Varda)
//
// WARNING: The plugin interface is currently EXPERIMENTAL and is subject to
// change.
//
// protoc (aka the Protocol Compiler) can be extended via plugins. A plugin is
// just a program that reads a CodeGeneratorRequest from stdin and writes a
// CodeGeneratorResponse to stdout.
//
// Plugins written using C++ can use google/protobuf/compiler/plugin.h instead
// of dealing with the raw protocol defined here.
//
// A plugin executable needs only to be placed somewhere in the path. The
// plugin should be named "protoc-gen-$NAME", and will then be used when the
// flag "--${NAME}_out" is passed to protoc.
syntax = "proto2";
package google.protobuf.compiler;
option java_package = "com.google.protobuf.compiler";
option java_outer_classname = "PluginProtos";
option go_package = "github.com/golang/protobuf/protoc-gen-go/plugin;plugin_go";
import "google/protobuf/descriptor.proto";
// The version number of protocol compiler.
message Version {
optional int32 major = 1;
optional int32 minor = 2;
optional int32 patch = 3;
// A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should
// be empty for mainline stable releases.
optional string suffix = 4;
}
// An encoded CodeGeneratorRequest is written to the plugin's stdin.
message CodeGeneratorRequest {
// The .proto files that were explicitly listed on the command-line. The
// code generator should generate code only for these files. Each file's
// descriptor will be included in proto_file, below.
repeated string file_to_generate = 1;
// The generator parameter passed on the command-line.
optional string parameter = 2;
// FileDescriptorProtos for all files in files_to_generate and everything
// they import. The files will appear in topological order, so each file
// appears before any file that imports it.
//
// protoc guarantees that all proto_files will be written after
// the fields above, even though this is not technically guaranteed by the
// protobuf wire format. This theoretically could allow a plugin to stream
// in the FileDescriptorProtos and handle them one by one rather than read
// the entire set into memory at once. However, as of this writing, this
// is not similarly optimized on protoc's end -- it will store all fields in
// memory at once before sending them to the plugin.
//
// Type names of fields and extensions in the FileDescriptorProto are always
// fully qualified.
repeated FileDescriptorProto proto_file = 15;
// The version number of protocol compiler.
optional Version compiler_version = 3;
}
// The plugin writes an encoded CodeGeneratorResponse to stdout.
message CodeGeneratorResponse {
// Error message. If non-empty, code generation failed. The plugin process
// should exit with status code zero even if it reports an error in this way.
//
// This should be used to indicate errors in .proto files which prevent the
// code generator from generating correct code. Errors which indicate a
// problem in protoc itself -- such as the input CodeGeneratorRequest being
// unparseable -- should be reported by writing a message to stderr and
// exiting with a non-zero status code.
optional string error = 1;
// Represents a single generated file.
message File {
// The file name, relative to the output directory. The name must not
// contain "." or ".." components and must be relative, not be absolute (so,
// the file cannot lie outside the output directory). "/" must be used as
// the path separator, not "\".
//
// If the name is omitted, the content will be appended to the previous
// file. This allows the generator to break large files into small chunks,
// and allows the generated text to be streamed back to protoc so that large
// files need not reside completely in memory at one time. Note that as of
// this writing protoc does not optimize for this -- it will read the entire
// CodeGeneratorResponse before writing files to disk.
optional string name = 1;
// If non-empty, indicates that the named file should already exist, and the
// content here is to be inserted into that file at a defined insertion
// point. This feature allows a code generator to extend the output
// produced by another code generator. The original generator may provide
// insertion points by placing special annotations in the file that look
// like:
// @@protoc_insertion_point(NAME)
// The annotation can have arbitrary text before and after it on the line,
// which allows it to be placed in a comment. NAME should be replaced with
// an identifier naming the point -- this is what other generators will use
// as the insertion_point. Code inserted at this point will be placed
// immediately above the line containing the insertion point (thus multiple
// insertions to the same point will come out in the order they were added).
// The double-@ is intended to make it unlikely that the generated code
// could contain things that look like insertion points by accident.
//
// For example, the C++ code generator places the following line in the
// .pb.h files that it generates:
// // @@protoc_insertion_point(namespace_scope)
// This line appears within the scope of the file's package namespace, but
// outside of any particular class. Another plugin can then specify the
// insertion_point "namespace_scope" to generate additional classes or
// other declarations that should be placed in this scope.
//
// Note that if the line containing the insertion point begins with
// whitespace, the same whitespace will be added to every line of the
// inserted text. This is useful for languages like Python, where
// indentation matters. In these languages, the insertion point comment
// should be indented the same amount as any inserted code will need to be
// in order to work correctly in that context.
//
// The code generator that generates the initial file and the one which
// inserts into it must both run as part of a single invocation of protoc.
// Code generators are executed in the order in which they appear on the
// command line.
//
// If |insertion_point| is present, |name| must also be present.
optional string insertion_point = 2;
// The file contents.
optional string content = 15;
}
repeated File file = 15;
}
...@@ -26,6 +26,7 @@ proto_library( ...@@ -26,6 +26,7 @@ proto_library(
deps = [ deps = [
"@com_google_protobuf//:any_proto", "@com_google_protobuf//:any_proto",
"@com_google_protobuf//:descriptor_proto", "@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:struct_proto",
], ],
) )
......
...@@ -5,6 +5,7 @@ package grpc.gateway.protoc_gen_swagger.options; ...@@ -5,6 +5,7 @@ package grpc.gateway.protoc_gen_swagger.options;
option go_package = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options"; option go_package = "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options";
import "google/protobuf/any.proto"; import "google/protobuf/any.proto";
import "google/protobuf/struct.proto";
// `Swagger` is a representation of OpenAPI v2 specification's Swagger object. // `Swagger` is a representation of OpenAPI v2 specification's Swagger object.
// //
...@@ -45,6 +46,7 @@ message Swagger { ...@@ -45,6 +46,7 @@ message Swagger {
// service objects into OpenAPI v2 Tag objects. // service objects into OpenAPI v2 Tag objects.
reserved 13; reserved 13;
ExternalDocumentation external_docs = 14; ExternalDocumentation external_docs = 14;
map<string, google.protobuf.Value> extensions = 15;
} }
// `Operation` is a representation of OpenAPI v2 specification's Operation object. // `Operation` is a representation of OpenAPI v2 specification's Operation object.
...@@ -66,6 +68,7 @@ message Operation { ...@@ -66,6 +68,7 @@ message Operation {
repeated string schemes = 10; repeated string schemes = 10;
bool deprecated = 11; bool deprecated = 11;
repeated SecurityRequirement security = 12; repeated SecurityRequirement security = 12;
map<string, google.protobuf.Value> extensions = 13;
} }
// `Response` is a representation of OpenAPI v2 specification's Response object. // `Response` is a representation of OpenAPI v2 specification's Response object.
...@@ -83,6 +86,7 @@ message Response { ...@@ -83,6 +86,7 @@ message Response {
reserved 3; reserved 3;
// field 3 is reserved for 'example'. // field 3 is reserved for 'example'.
reserved 4; reserved 4;
map<string, google.protobuf.Value> extensions = 5;
} }
// `Info` is a representation of OpenAPI v2 specification's Info object. // `Info` is a representation of OpenAPI v2 specification's Info object.
...@@ -97,6 +101,7 @@ message Info { ...@@ -97,6 +101,7 @@ message Info {
Contact contact = 4; Contact contact = 4;
License license = 5; License license = 5;
string version = 6; string version = 6;
map<string, google.protobuf.Value> extensions = 7;
} }
// `Contact` is a representation of OpenAPI v2 specification's Contact object. // `Contact` is a representation of OpenAPI v2 specification's Contact object.
...@@ -334,6 +339,7 @@ message SecurityScheme { ...@@ -334,6 +339,7 @@ message SecurityScheme {
// //
// Valid for oauth2. // Valid for oauth2.
Scopes scopes = 8; Scopes scopes = 8;
map<string, google.protobuf.Value> extensions = 9;
} }
// `SecurityRequirement` is a representation of OpenAPI v2 specification's // `SecurityRequirement` is a representation of OpenAPI v2 specification's
......
...@@ -27,11 +27,12 @@ go_library( ...@@ -27,11 +27,12 @@ go_library(
deps = [ deps = [
"//internal:go_default_library", "//internal:go_default_library",
"//utilities:go_default_library", "//utilities:go_default_library",
"@com_github_golang_protobuf//descriptor:go_default_library_gen",
"@com_github_golang_protobuf//jsonpb:go_default_library_gen", "@com_github_golang_protobuf//jsonpb:go_default_library_gen",
"@com_github_golang_protobuf//proto:go_default_library", "@com_github_golang_protobuf//proto:go_default_library",
"@com_github_golang_protobuf//protoc-gen-go/generator:go_default_library_gen",
"@go_googleapis//google/api:httpbody_go_proto", "@go_googleapis//google/api:httpbody_go_proto",
"@io_bazel_rules_go//proto/wkt:any_go_proto", "@io_bazel_rules_go//proto/wkt:any_go_proto",
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
"@io_bazel_rules_go//proto/wkt:duration_go_proto", "@io_bazel_rules_go//proto/wkt:duration_go_proto",
"@io_bazel_rules_go//proto/wkt:field_mask_go_proto", "@io_bazel_rules_go//proto/wkt:field_mask_go_proto",
"@io_bazel_rules_go//proto/wkt:timestamp_go_proto", "@io_bazel_rules_go//proto/wkt:timestamp_go_proto",
...@@ -48,6 +49,7 @@ go_test( ...@@ -48,6 +49,7 @@ go_test(
size = "small", size = "small",
srcs = [ srcs = [
"context_test.go", "context_test.go",
"convert_test.go",
"errors_test.go", "errors_test.go",
"fieldmask_test.go", "fieldmask_test.go",
"handler_test.go", "handler_test.go",
......
...@@ -57,13 +57,39 @@ except that the forwarded destination is not another HTTP service but rather ...@@ -57,13 +57,39 @@ except that the forwarded destination is not another HTTP service but rather
a gRPC service. a gRPC service.
*/ */
func AnnotateContext(ctx context.Context, mux *ServeMux, req *http.Request) (context.Context, error) { func AnnotateContext(ctx context.Context, mux *ServeMux, req *http.Request) (context.Context, error) {
ctx, md, err := annotateContext(ctx, mux, req)
if err != nil {
return nil, err
}
if md == nil {
return ctx, nil
}
return metadata.NewOutgoingContext(ctx, md), nil
}
// AnnotateIncomingContext adds context information such as metadata from the request.
// Attach metadata as incoming context.
func AnnotateIncomingContext(ctx context.Context, mux *ServeMux, req *http.Request) (context.Context, error) {
ctx, md, err := annotateContext(ctx, mux, req)
if err != nil {
return nil, err
}
if md == nil {
return ctx, nil
}
return metadata.NewIncomingContext(ctx, md), nil
}
func annotateContext(ctx context.Context, mux *ServeMux, req *http.Request) (context.Context, metadata.MD, error) {
var pairs []string var pairs []string
timeout := DefaultContextTimeout timeout := DefaultContextTimeout
if tm := req.Header.Get(metadataGrpcTimeout); tm != "" { if tm := req.Header.Get(metadataGrpcTimeout); tm != "" {
var err error var err error
timeout, err = timeoutDecode(tm) timeout, err = timeoutDecode(tm)
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid grpc-timeout: %s", tm) return nil, nil, status.Errorf(codes.InvalidArgument, "invalid grpc-timeout: %s", tm)
} }
} }
...@@ -80,7 +106,7 @@ func AnnotateContext(ctx context.Context, mux *ServeMux, req *http.Request) (con ...@@ -80,7 +106,7 @@ func AnnotateContext(ctx context.Context, mux *ServeMux, req *http.Request) (con
if strings.HasSuffix(key, metadataHeaderBinarySuffix) { if strings.HasSuffix(key, metadataHeaderBinarySuffix) {
b, err := decodeBinHeader(val) b, err := decodeBinHeader(val)
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid binary header %s: %s", key, err) return nil, nil, status.Errorf(codes.InvalidArgument, "invalid binary header %s: %s", key, err)
} }
val = string(b) val = string(b)
...@@ -111,13 +137,13 @@ func AnnotateContext(ctx context.Context, mux *ServeMux, req *http.Request) (con ...@@ -111,13 +137,13 @@ func AnnotateContext(ctx context.Context, mux *ServeMux, req *http.Request) (con
ctx, _ = context.WithTimeout(ctx, timeout) ctx, _ = context.WithTimeout(ctx, timeout)
} }
if len(pairs) == 0 { if len(pairs) == 0 {
return ctx, nil return ctx, nil, nil
} }
md := metadata.Pairs(pairs...) md := metadata.Pairs(pairs...)
for _, mda := range mux.metadataAnnotators { for _, mda := range mux.metadataAnnotators {
md = metadata.Join(md, mda(ctx, req)) md = metadata.Join(md, mda(ctx, req))
} }
return metadata.NewOutgoingContext(ctx, md), nil return ctx, md, nil
} }
// ServerMetadata consists of metadata sent from gRPC server. // ServerMetadata consists of metadata sent from gRPC server.
......
...@@ -206,16 +206,22 @@ func BytesSlice(val, sep string) ([][]byte, error) { ...@@ -206,16 +206,22 @@ func BytesSlice(val, sep string) ([][]byte, error) {
// Timestamp converts the given RFC3339 formatted string into a timestamp.Timestamp. // Timestamp converts the given RFC3339 formatted string into a timestamp.Timestamp.
func Timestamp(val string) (*timestamp.Timestamp, error) { func Timestamp(val string) (*timestamp.Timestamp, error) {
var r *timestamp.Timestamp var r timestamp.Timestamp
err := jsonpb.UnmarshalString(val, r) err := jsonpb.UnmarshalString(val, &r)
return r, err if err != nil {
return nil, err
}
return &r, nil
} }
// Duration converts the given string into a timestamp.Duration. // Duration converts the given string into a timestamp.Duration.
func Duration(val string) (*duration.Duration, error) { func Duration(val string) (*duration.Duration, error) {
var r *duration.Duration var r duration.Duration
err := jsonpb.UnmarshalString(val, r) err := jsonpb.UnmarshalString(val, &r)
return r, err if err != nil {
return nil, err
}
return &r, nil
} }
// Enum converts the given string into an int32 that should be type casted into the // Enum converts the given string into an int32 that should be type casted into the
......
...@@ -66,12 +66,12 @@ var ( ...@@ -66,12 +66,12 @@ var (
) )
type errorBody struct { type errorBody struct {
Error string `protobuf:"bytes,1,name=error" json:"error"` Error string `protobuf:"bytes,100,name=error" json:"error"`
// This is to make the error more compatible with users that expect errors to be Status objects: // This is to make the error more compatible with users that expect errors to be Status objects:
// https://github.com/grpc/grpc/blob/master/src/proto/grpc/status/status.proto // https://github.com/grpc/grpc/blob/master/src/proto/grpc/status/status.proto
// It should be the exact same message as the Error field. // It should be the exact same message as the Error field.
Message string `protobuf:"bytes,1,name=message" json:"message"` Code int32 `protobuf:"varint,1,name=code" json:"code"`
Code int32 `protobuf:"varint,2,name=code" json:"code"` Message string `protobuf:"bytes,2,name=message" json:"message"`
Details []*any.Any `protobuf:"bytes,3,rep,name=details" json:"details,omitempty"` Details []*any.Any `protobuf:"bytes,3,rep,name=details" json:"details,omitempty"`
} }
......
...@@ -5,12 +5,37 @@ import ( ...@@ -5,12 +5,37 @@ import (
"io" "io"
"strings" "strings"
"github.com/golang/protobuf/protoc-gen-go/generator" descriptor2 "github.com/golang/protobuf/descriptor"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
"google.golang.org/genproto/protobuf/field_mask" "google.golang.org/genproto/protobuf/field_mask"
) )
func translateName(name string, md *descriptor.DescriptorProto) (string, *descriptor.DescriptorProto) {
// TODO - should really gate this with a test that the marshaller has used json names
if md != nil {
for _, f := range md.Field {
if f.JsonName != nil && f.Name != nil && *f.JsonName == name {
var subType *descriptor.DescriptorProto
// If the field has a TypeName then we retrieve the nested type for translating the embedded message names.
if f.TypeName != nil {
typeSplit := strings.Split(*f.TypeName, ".")
typeName := typeSplit[len(typeSplit)-1]
for _, t := range md.NestedType {
if typeName == *t.Name {
subType = t
}
}
}
return *f.Name, subType
}
}
}
return name, nil
}
// FieldMaskFromRequestBody creates a FieldMask printing all complete paths from the JSON body. // FieldMaskFromRequestBody creates a FieldMask printing all complete paths from the JSON body.
func FieldMaskFromRequestBody(r io.Reader) (*field_mask.FieldMask, error) { func FieldMaskFromRequestBody(r io.Reader, md *descriptor.DescriptorProto) (*field_mask.FieldMask, error) {
fm := &field_mask.FieldMask{} fm := &field_mask.FieldMask{}
var root interface{} var root interface{}
if err := json.NewDecoder(r).Decode(&root); err != nil { if err := json.NewDecoder(r).Decode(&root); err != nil {
...@@ -20,7 +45,7 @@ func FieldMaskFromRequestBody(r io.Reader) (*field_mask.FieldMask, error) { ...@@ -20,7 +45,7 @@ func FieldMaskFromRequestBody(r io.Reader) (*field_mask.FieldMask, error) {
return nil, err return nil, err
} }
queue := []fieldMaskPathItem{{node: root}} queue := []fieldMaskPathItem{{node: root, md: md}}
for len(queue) > 0 { for len(queue) > 0 {
// dequeue an item // dequeue an item
item := queue[0] item := queue[0]
...@@ -29,7 +54,11 @@ func FieldMaskFromRequestBody(r io.Reader) (*field_mask.FieldMask, error) { ...@@ -29,7 +54,11 @@ func FieldMaskFromRequestBody(r io.Reader) (*field_mask.FieldMask, error) {
if m, ok := item.node.(map[string]interface{}); ok { if m, ok := item.node.(map[string]interface{}); ok {
// if the item is an object, then enqueue all of its children // if the item is an object, then enqueue all of its children
for k, v := range m { for k, v := range m {
queue = append(queue, fieldMaskPathItem{path: append(item.path, generator.CamelCase(k)), node: v}) protoName, subMd := translateName(k, item.md)
if subMsg, ok := v.(descriptor2.Message); ok {
_, subMd = descriptor2.ForMessage(subMsg)
}
queue = append(queue, fieldMaskPathItem{path: append(item.path, protoName), node: v, md: subMd})
} }
} else if len(item.path) > 0 { } else if len(item.path) > 0 {
// otherwise, it's a leaf node so print its path // otherwise, it's a leaf node so print its path
...@@ -47,24 +76,7 @@ type fieldMaskPathItem struct { ...@@ -47,24 +76,7 @@ type fieldMaskPathItem struct {
// a generic decoded json object the current item to inspect for further path extraction // a generic decoded json object the current item to inspect for further path extraction
node interface{} node interface{}
}
// CamelCaseFieldMask updates the given FieldMask by converting all of its paths to CamelCase, using the same heuristic
// that's used for naming protobuf fields in Go.
func CamelCaseFieldMask(mask *field_mask.FieldMask) {
if mask == nil || mask.Paths == nil {
return
}
var newPaths []string
for _, path := range mask.Paths {
lowerCasedParts := strings.Split(path, ".")
var camelCasedParts []string
for _, part := range lowerCasedParts {
camelCasedParts = append(camelCasedParts, generator.CamelCase(part))
}
newPaths = append(newPaths, strings.Join(camelCasedParts, "."))
}
mask.Paths = newPaths // descriptor for parent message
md *descriptor.DescriptorProto
} }
...@@ -15,15 +15,13 @@ import ( ...@@ -15,15 +15,13 @@ import (
"google.golang.org/grpc/grpclog" "google.golang.org/grpc/grpclog"
) )
var valuesKeyRegexp = regexp.MustCompile("^(.*)\\[(.*)\\]$")
// PopulateQueryParameters populates "values" into "msg". // PopulateQueryParameters populates "values" into "msg".
// A value is ignored if its key starts with one of the elements in "filter". // A value is ignored if its key starts with one of the elements in "filter".
func PopulateQueryParameters(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error { func PopulateQueryParameters(msg proto.Message, values url.Values, filter *utilities.DoubleArray) error {
for key, values := range values { for key, values := range values {
re, err := regexp.Compile("^(.*)\\[(.*)\\]$") match := valuesKeyRegexp.FindStringSubmatch(key)
if err != nil {
return err
}
match := re.FindStringSubmatch(key)
if len(match) == 3 { if len(match) == 3 {
key = match[1] key = match[1]
values = append([]string{match[2]}, values...) values = append([]string{match[2]}, values...)
......
...@@ -26,7 +26,7 @@ github.com/alecthomas/units ...@@ -26,7 +26,7 @@ github.com/alecthomas/units
github.com/andybalholm/cascadia github.com/andybalholm/cascadia
# github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a => github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a # github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a => github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
github.com/asaskevich/govalidator github.com/asaskevich/govalidator
# github.com/aws/aws-sdk-go v1.22.2 => github.com/aws/aws-sdk-go v1.22.2 # github.com/aws/aws-sdk-go v1.25.21 => github.com/aws/aws-sdk-go v1.22.2
github.com/aws/aws-sdk-go/aws github.com/aws/aws-sdk-go/aws
github.com/aws/aws-sdk-go/aws/awserr github.com/aws/aws-sdk-go/aws/awserr
github.com/aws/aws-sdk-go/aws/awsutil github.com/aws/aws-sdk-go/aws/awsutil
...@@ -110,11 +110,11 @@ github.com/docker/docker/client ...@@ -110,11 +110,11 @@ github.com/docker/docker/client
github.com/docker/docker/errdefs github.com/docker/docker/errdefs
github.com/docker/docker/pkg/term github.com/docker/docker/pkg/term
github.com/docker/docker/pkg/term/windows github.com/docker/docker/pkg/term/windows
# github.com/docker/go-connections v0.3.0 => github.com/docker/go-connections v0.3.0 # github.com/docker/go-connections v0.4.0 => github.com/docker/go-connections v0.3.0
github.com/docker/go-connections/nat github.com/docker/go-connections/nat
github.com/docker/go-connections/sockets github.com/docker/go-connections/sockets
github.com/docker/go-connections/tlsconfig github.com/docker/go-connections/tlsconfig
# github.com/docker/go-units v0.3.3 => github.com/docker/go-units v0.3.3 # github.com/docker/go-units v0.4.0 => github.com/docker/go-units v0.3.3
github.com/docker/go-units github.com/docker/go-units
# github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c => github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c # github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c => github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c
github.com/docker/spdystream github.com/docker/spdystream
...@@ -134,11 +134,11 @@ github.com/elastic/go-elasticsearch/v7 ...@@ -134,11 +134,11 @@ github.com/elastic/go-elasticsearch/v7
github.com/elastic/go-elasticsearch/v7/esapi github.com/elastic/go-elasticsearch/v7/esapi
github.com/elastic/go-elasticsearch/v7/estransport github.com/elastic/go-elasticsearch/v7/estransport
github.com/elastic/go-elasticsearch/v7/internal/version github.com/elastic/go-elasticsearch/v7/internal/version
# github.com/emicklei/go-restful v2.9.5+incompatible => github.com/emicklei/go-restful v2.9.5+incompatible # github.com/emicklei/go-restful v2.11.1+incompatible => github.com/emicklei/go-restful v2.9.5+incompatible
github.com/emicklei/go-restful github.com/emicklei/go-restful
github.com/emicklei/go-restful/log
# github.com/emicklei/go-restful-openapi v1.0.0 => github.com/emicklei/go-restful-openapi v1.0.0 # github.com/emicklei/go-restful-openapi v1.0.0 => github.com/emicklei/go-restful-openapi v1.0.0
github.com/emicklei/go-restful-openapi github.com/emicklei/go-restful-openapi
github.com/emicklei/go-restful/log
# github.com/emirpasic/gods v1.12.0 => github.com/emirpasic/gods v1.12.0 # github.com/emirpasic/gods v1.12.0 => github.com/emirpasic/gods v1.12.0
github.com/emirpasic/gods/containers github.com/emirpasic/gods/containers
github.com/emirpasic/gods/lists github.com/emirpasic/gods/lists
...@@ -176,9 +176,9 @@ github.com/go-openapi/jsonpointer ...@@ -176,9 +176,9 @@ github.com/go-openapi/jsonpointer
github.com/go-openapi/jsonreference github.com/go-openapi/jsonreference
# github.com/go-openapi/loads v0.19.2 => github.com/go-openapi/loads v0.19.2 # github.com/go-openapi/loads v0.19.2 => github.com/go-openapi/loads v0.19.2
github.com/go-openapi/loads github.com/go-openapi/loads
# github.com/go-openapi/runtime v0.19.0 => github.com/go-openapi/runtime v0.19.0 # github.com/go-openapi/runtime v0.19.7 => github.com/go-openapi/runtime v0.19.0
github.com/go-openapi/runtime github.com/go-openapi/runtime
# github.com/go-openapi/spec v0.19.3 => github.com/go-openapi/spec v0.19.3 # github.com/go-openapi/spec v0.19.4 => github.com/go-openapi/spec v0.19.3
github.com/go-openapi/spec github.com/go-openapi/spec
# github.com/go-openapi/strfmt v0.19.3 => github.com/go-openapi/strfmt v0.19.0 # github.com/go-openapi/strfmt v0.19.3 => github.com/go-openapi/strfmt v0.19.0
github.com/go-openapi/strfmt github.com/go-openapi/strfmt
...@@ -210,7 +210,7 @@ github.com/gobwas/glob/util/strings ...@@ -210,7 +210,7 @@ github.com/gobwas/glob/util/strings
# github.com/gocraft/dbr v0.0.0-20180507214907-a0fd650918f6 => github.com/gocraft/dbr v0.0.0-20180507214907-a0fd650918f6 # github.com/gocraft/dbr v0.0.0-20180507214907-a0fd650918f6 => github.com/gocraft/dbr v0.0.0-20180507214907-a0fd650918f6
github.com/gocraft/dbr github.com/gocraft/dbr
github.com/gocraft/dbr/dialect github.com/gocraft/dbr/dialect
# github.com/gogo/protobuf v1.3.0 => github.com/gogo/protobuf v1.3.0 # github.com/gogo/protobuf v1.3.1 => github.com/gogo/protobuf v1.3.0
github.com/gogo/protobuf/gogoproto github.com/gogo/protobuf/gogoproto
github.com/gogo/protobuf/jsonpb github.com/gogo/protobuf/jsonpb
github.com/gogo/protobuf/proto github.com/gogo/protobuf/proto
...@@ -221,17 +221,15 @@ github.com/gogo/protobuf/types ...@@ -221,17 +221,15 @@ github.com/gogo/protobuf/types
github.com/golang/example/stringutil github.com/golang/example/stringutil
# github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b => github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b # github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b => github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/glog github.com/golang/glog
# github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 => github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 # github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 => github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6
github.com/golang/groupcache/lru github.com/golang/groupcache/lru
# github.com/golang/mock v1.2.0 => github.com/golang/mock v1.2.0 # github.com/golang/mock v1.2.0 => github.com/golang/mock v1.2.0
github.com/golang/mock/gomock github.com/golang/mock/gomock
# github.com/golang/protobuf v1.3.2 => github.com/golang/protobuf v1.3.2 # github.com/golang/protobuf v1.3.2 => github.com/golang/protobuf v1.3.2
github.com/golang/protobuf/descriptor
github.com/golang/protobuf/jsonpb github.com/golang/protobuf/jsonpb
github.com/golang/protobuf/proto github.com/golang/protobuf/proto
github.com/golang/protobuf/protoc-gen-go/descriptor github.com/golang/protobuf/protoc-gen-go/descriptor
github.com/golang/protobuf/protoc-gen-go/generator
github.com/golang/protobuf/protoc-gen-go/generator/internal/remap
github.com/golang/protobuf/protoc-gen-go/plugin
github.com/golang/protobuf/ptypes github.com/golang/protobuf/ptypes
github.com/golang/protobuf/ptypes/any github.com/golang/protobuf/ptypes/any
github.com/golang/protobuf/ptypes/duration github.com/golang/protobuf/ptypes/duration
...@@ -259,15 +257,15 @@ github.com/googleapis/gnostic/compiler ...@@ -259,15 +257,15 @@ github.com/googleapis/gnostic/compiler
github.com/googleapis/gnostic/extensions github.com/googleapis/gnostic/extensions
# github.com/gorilla/mux v1.7.1 => github.com/gorilla/mux v1.7.1 # github.com/gorilla/mux v1.7.1 => github.com/gorilla/mux v1.7.1
github.com/gorilla/mux github.com/gorilla/mux
# github.com/gorilla/websocket v1.4.0 => github.com/gorilla/websocket v1.4.0 # github.com/gorilla/websocket v1.4.1 => github.com/gorilla/websocket v1.4.0
github.com/gorilla/websocket github.com/gorilla/websocket
# github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4 => github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 # github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 => github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
github.com/grpc-ecosystem/go-grpc-middleware github.com/grpc-ecosystem/go-grpc-middleware
github.com/grpc-ecosystem/go-grpc-middleware/recovery github.com/grpc-ecosystem/go-grpc-middleware/recovery
github.com/grpc-ecosystem/go-grpc-middleware/validator github.com/grpc-ecosystem/go-grpc-middleware/validator
# github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 => github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 # github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 => github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/go-grpc-prometheus github.com/grpc-ecosystem/go-grpc-prometheus
# github.com/grpc-ecosystem/grpc-gateway v1.9.6 => github.com/grpc-ecosystem/grpc-gateway v1.9.6 # github.com/grpc-ecosystem/grpc-gateway v1.11.3 => github.com/grpc-ecosystem/grpc-gateway v1.11.3
github.com/grpc-ecosystem/grpc-gateway/internal github.com/grpc-ecosystem/grpc-gateway/internal
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options
github.com/grpc-ecosystem/grpc-gateway/runtime github.com/grpc-ecosystem/grpc-gateway/runtime
...@@ -294,7 +292,7 @@ github.com/hpcloud/tail/ratelimiter ...@@ -294,7 +292,7 @@ github.com/hpcloud/tail/ratelimiter
github.com/hpcloud/tail/util github.com/hpcloud/tail/util
github.com/hpcloud/tail/watch github.com/hpcloud/tail/watch
github.com/hpcloud/tail/winfile github.com/hpcloud/tail/winfile
# github.com/imdario/mergo v0.3.7 => github.com/imdario/mergo v0.3.7 # github.com/imdario/mergo v0.3.8 => github.com/imdario/mergo v0.3.7
github.com/imdario/mergo github.com/imdario/mergo
# github.com/inconshreveable/mousetrap v1.0.0 => github.com/inconshreveable/mousetrap v1.0.0 # github.com/inconshreveable/mousetrap v1.0.0 => github.com/inconshreveable/mousetrap v1.0.0
github.com/inconshreveable/mousetrap github.com/inconshreveable/mousetrap
...@@ -498,7 +496,7 @@ github.com/projectcalico/libcalico-go/lib/scope ...@@ -498,7 +496,7 @@ github.com/projectcalico/libcalico-go/lib/scope
github.com/projectcalico/libcalico-go/lib/selector github.com/projectcalico/libcalico-go/lib/selector
github.com/projectcalico/libcalico-go/lib/selector/parser github.com/projectcalico/libcalico-go/lib/selector/parser
github.com/projectcalico/libcalico-go/lib/selector/tokenizer github.com/projectcalico/libcalico-go/lib/selector/tokenizer
# github.com/prometheus/client_golang v1.0.0 => github.com/prometheus/client_golang v0.9.4 # github.com/prometheus/client_golang v1.2.1 => github.com/prometheus/client_golang v0.9.4
github.com/prometheus/client_golang/api github.com/prometheus/client_golang/api
github.com/prometheus/client_golang/api/prometheus/v1 github.com/prometheus/client_golang/api/prometheus/v1
github.com/prometheus/client_golang/prometheus github.com/prometheus/client_golang/prometheus
...@@ -532,7 +530,7 @@ github.com/rcrowley/go-metrics ...@@ -532,7 +530,7 @@ github.com/rcrowley/go-metrics
github.com/sergi/go-diff/diffmatchpatch github.com/sergi/go-diff/diffmatchpatch
# github.com/sirupsen/logrus v1.4.2 => github.com/sirupsen/logrus v1.4.2 # github.com/sirupsen/logrus v1.4.2 => github.com/sirupsen/logrus v1.4.2
github.com/sirupsen/logrus github.com/sirupsen/logrus
# github.com/sony/sonyflake v0.0.0-20181109022403-6d5bd6181009 => github.com/sony/sonyflake v0.0.0-20181109022403-6d5bd6181009 # github.com/sony/sonyflake v1.0.0 => github.com/sony/sonyflake v0.0.0-20181109022403-6d5bd6181009
github.com/sony/sonyflake github.com/sony/sonyflake
# github.com/speps/go-hashids v2.0.0+incompatible => github.com/speps/go-hashids v2.0.0+incompatible # github.com/speps/go-hashids v2.0.0+incompatible => github.com/speps/go-hashids v2.0.0+incompatible
github.com/speps/go-hashids github.com/speps/go-hashids
...@@ -576,7 +574,7 @@ github.com/syndtr/goleveldb/leveldb/util ...@@ -576,7 +574,7 @@ github.com/syndtr/goleveldb/leveldb/util
github.com/xanzy/ssh-agent github.com/xanzy/ssh-agent
# github.com/yashtewari/glob-intersection v0.0.0-20180916065949-5c77d914dd0b => github.com/yashtewari/glob-intersection v0.0.0-20180916065949-5c77d914dd0b # github.com/yashtewari/glob-intersection v0.0.0-20180916065949-5c77d914dd0b => github.com/yashtewari/glob-intersection v0.0.0-20180916065949-5c77d914dd0b
github.com/yashtewari/glob-intersection github.com/yashtewari/glob-intersection
# go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738 => go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738 # go.etcd.io/etcd v3.3.17+incompatible => go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738
go.etcd.io/etcd/auth/authpb go.etcd.io/etcd/auth/authpb
go.etcd.io/etcd/clientv3 go.etcd.io/etcd/clientv3
go.etcd.io/etcd/clientv3/balancer go.etcd.io/etcd/clientv3/balancer
...@@ -608,7 +606,7 @@ go.uber.org/zap/internal/bufferpool ...@@ -608,7 +606,7 @@ go.uber.org/zap/internal/bufferpool
go.uber.org/zap/internal/color go.uber.org/zap/internal/color
go.uber.org/zap/internal/exit go.uber.org/zap/internal/exit
go.uber.org/zap/zapcore go.uber.org/zap/zapcore
# golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 => golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 # golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975 => golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
golang.org/x/crypto/bcrypt golang.org/x/crypto/bcrypt
golang.org/x/crypto/blowfish golang.org/x/crypto/blowfish
golang.org/x/crypto/cast5 golang.org/x/crypto/cast5
...@@ -676,9 +674,9 @@ golang.org/x/text/transform ...@@ -676,9 +674,9 @@ golang.org/x/text/transform
golang.org/x/text/unicode/bidi golang.org/x/text/unicode/bidi
golang.org/x/text/unicode/norm golang.org/x/text/unicode/norm
golang.org/x/text/width golang.org/x/text/width
# golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0 => golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 # golang.org/x/time v0.0.0-20191024005414-555d28b269f0 => golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
golang.org/x/time/rate golang.org/x/time/rate
# golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72 => golang.org/x/tools v0.0.0-20190710153321-831012c29e42 # golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c => golang.org/x/tools v0.0.0-20190710153321-831012c29e42
golang.org/x/tools/go/ast/astutil golang.org/x/tools/go/ast/astutil
golang.org/x/tools/go/gcexportdata golang.org/x/tools/go/gcexportdata
golang.org/x/tools/go/internal/gcimporter golang.org/x/tools/go/internal/gcimporter
...@@ -1361,7 +1359,7 @@ k8s.io/utils/net ...@@ -1361,7 +1359,7 @@ k8s.io/utils/net
k8s.io/utils/path k8s.io/utils/path
k8s.io/utils/pointer k8s.io/utils/pointer
k8s.io/utils/trace k8s.io/utils/trace
# openpitrix.io/openpitrix v0.4.1-0.20190920134345-4d2be6e4965c => openpitrix.io/openpitrix v0.4.1-0.20190920134345-4d2be6e4965c # openpitrix.io/openpitrix v0.4.1-0.20190920134345-4d2be6e4965c => github.com/pengcong06/openpitrix v0.4.1-0.20200527062040-411ab8612348
openpitrix.io/openpitrix/pkg/config openpitrix.io/openpitrix/pkg/config
openpitrix.io/openpitrix/pkg/constants openpitrix.io/openpitrix/pkg/constants
openpitrix.io/openpitrix/pkg/db openpitrix.io/openpitrix/pkg/db
......
...@@ -83,7 +83,8 @@ func (r *RuntimeProviderConfig) GetPort() int { ...@@ -83,7 +83,8 @@ func (r *RuntimeProviderConfig) GetPort() int {
if r.Port > 0 { if r.Port > 0 {
return r.Port return r.Port
} else { } else {
return constants.RuntimeProviderManagerPort //todo attention
return constants.KubernetesProviderPort
} }
} }
......
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册