Refactor DevOps API proxy
Signed-off-by: johnniang <johnniang@fastmail.com>
This commit is contained in:
@@ -18,18 +18,21 @@ package devops
|
||||
|
||||
import (
|
||||
"github.com/emicklei/go-restful"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
"kubesphere.io/kubesphere/pkg/kapis/generic"
|
||||
)
|
||||
|
||||
const groupName = "devops.kubesphere.io"
|
||||
|
||||
var versions = []string{"v1alpha1", "v1alpha2", "v1alpha3"}
|
||||
var devopsGroupVersions = []schema.GroupVersion{
|
||||
{Group: "devops.kubesphere.io", Version: "v1alpha2"},
|
||||
{Group: "devops.kubesphere.io", Version: "v1alpha3"},
|
||||
// TODO Add other group versions here, like cd.devops.kubesphere.io
|
||||
}
|
||||
|
||||
// AddToContainer registers DevOps proxies to the container.
|
||||
func AddToContainer(container *restful.Container, endpoint string) error {
|
||||
for _, version := range versions {
|
||||
proxy, err := generic.NewGenericProxy(endpoint, groupName, version)
|
||||
for _, groupVersion := range devopsGroupVersions {
|
||||
proxy, err := generic.NewGenericProxy(endpoint, groupVersion.Group, groupVersion.Version)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
|
||||
func TestAddToContainer(t *testing.T) {
|
||||
fakeResponse := "fake DevOps APIServer response"
|
||||
notFoundResponse := "404 page not found\n"
|
||||
type args struct {
|
||||
target string
|
||||
mockAPIPattern string
|
||||
@@ -44,7 +45,7 @@ func TestAddToContainer(t *testing.T) {
|
||||
mockAPIPattern: "/v1alpha1/resources",
|
||||
mockResponse: fakeResponse,
|
||||
},
|
||||
wantResponse: fakeResponse,
|
||||
wantResponse: notFoundResponse,
|
||||
}, {
|
||||
name: "Should proxy v1alpha2 API properly",
|
||||
args: args{
|
||||
@@ -67,14 +68,14 @@ func TestAddToContainer(t *testing.T) {
|
||||
target: "/kapis/devops.kubesphere.io/v1alpha3/resources",
|
||||
mockAPIPattern: "/v1alpha4/resources",
|
||||
},
|
||||
wantResponse: "404 page not found\n",
|
||||
wantResponse: notFoundResponse,
|
||||
}, {
|
||||
name: "Should not proxy v1alpha123 API properly event if pattern matched",
|
||||
args: args{
|
||||
target: "/kapis/devops.kubesphere.io/v1alpha123/resources",
|
||||
mockAPIPattern: "/v1alpha123/resources",
|
||||
},
|
||||
wantResponse: "404 page not found\n",
|
||||
wantResponse: notFoundResponse,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user