Commit 9546ba9b authored by Irfan Ur Rehman's avatar Irfan Ur Rehman

[Federation] Register autoscaling apis to federation api server

parent 8d5227bb
......@@ -10,6 +10,7 @@ load(
go_library(
name = "go_default_library",
srcs = [
"autoscaling.go",
"batch.go",
"core.go",
"extensions.go",
......@@ -28,6 +29,8 @@ go_library(
"//federation/registry/cluster/etcd:go_default_library",
"//pkg/api:go_default_library",
"//pkg/api/install:go_default_library",
"//pkg/apis/autoscaling:go_default_library",
"//pkg/apis/autoscaling/install:go_default_library",
"//pkg/apis/batch:go_default_library",
"//pkg/apis/batch/install:go_default_library",
"//pkg/apis/extensions:go_default_library",
......@@ -43,6 +46,7 @@ go_library(
"//pkg/genericapiserver/server/filters:go_default_library",
"//pkg/kubeapiserver:go_default_library",
"//pkg/kubeapiserver/admission:go_default_library",
"//pkg/registry/autoscaling/horizontalpodautoscaler/storage:go_default_library",
"//pkg/registry/batch/job/storage:go_default_library",
"//pkg/registry/cachesize:go_default_library",
"//pkg/registry/core/configmap/storage:go_default_library",
......
/*
Copyright 2016 The Kubernetes 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 app
import (
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/autoscaling"
_ "k8s.io/kubernetes/pkg/apis/autoscaling/install"
"k8s.io/kubernetes/pkg/genericapiserver/registry/generic"
"k8s.io/kubernetes/pkg/genericapiserver/registry/rest"
genericapiserver "k8s.io/kubernetes/pkg/genericapiserver/server"
hpastorage "k8s.io/kubernetes/pkg/registry/autoscaling/horizontalpodautoscaler/storage"
)
func installAutoscalingAPIs(g *genericapiserver.GenericAPIServer, optsGetter generic.RESTOptionsGetter) {
hpaStorage, hpaStatusStorage := hpastorage.NewREST(optsGetter)
autoscalingResources := map[string]rest.Storage{
"horizontalpodautoscalers": hpaStorage,
"horizontalpodautoscalers/status": hpaStatusStorage,
}
autoscalingGroupMeta := api.Registry.GroupOrDie(autoscaling.GroupName)
apiGroupInfo := genericapiserver.APIGroupInfo{
GroupMeta: *autoscalingGroupMeta,
VersionedResourcesStorageMap: map[string]map[string]rest.Storage{
"v1": autoscalingResources,
},
OptionsExternalVersion: &api.Registry.GroupOrDie(api.GroupName).GroupVersion,
Scheme: api.Scheme,
ParameterCodec: api.ParameterCodec,
NegotiatedSerializer: api.Codecs,
}
if err := g.InstallAPIGroup(&apiGroupInfo); err != nil {
glog.Fatalf("Error in registering group versions: %v", err)
}
}
......@@ -213,6 +213,7 @@ func Run(s *options.ServerRunOptions) error {
installCoreAPIs(s, m, restOptionsFactory)
installExtensionsAPIs(m, restOptionsFactory)
installBatchAPIs(m, restOptionsFactory)
installAutoscalingAPIs(m, restOptionsFactory)
sharedInformers.Start(wait.NeverStop)
m.PrepareRun().Run(wait.NeverStop)
......
......@@ -16,6 +16,7 @@ go_test(
"//federation/cmd/federation-apiserver/app:go_default_library",
"//federation/cmd/federation-apiserver/app/options:go_default_library",
"//pkg/api/v1:go_default_library",
"//pkg/apis/autoscaling/v1:go_default_library",
"//pkg/apis/batch/v1:go_default_library",
"//pkg/apis/extensions/v1beta1:go_default_library",
"//vendor:github.com/stretchr/testify/assert",
......
......@@ -33,6 +33,7 @@ import (
"k8s.io/kubernetes/federation/cmd/federation-apiserver/app"
"k8s.io/kubernetes/federation/cmd/federation-apiserver/app/options"
"k8s.io/kubernetes/pkg/api/v1"
autoscaling_v1 "k8s.io/kubernetes/pkg/apis/autoscaling/v1"
batch_v1 "k8s.io/kubernetes/pkg/apis/batch/v1"
ext_v1b1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
)
......@@ -44,6 +45,7 @@ var groupVersions = []schema.GroupVersion{
fed_v1b1.SchemeGroupVersion,
ext_v1b1.SchemeGroupVersion,
batch_v1.SchemeGroupVersion,
autoscaling_v1.SchemeGroupVersion,
}
func TestRun(t *testing.T) {
......@@ -214,6 +216,7 @@ func testAPIResourceList(t *testing.T) {
testCoreResourceList(t)
testExtensionsResourceList(t)
testBatchResourceList(t)
testAutoscalingResourceList(t)
}
func testFederationResourceList(t *testing.T) {
......@@ -373,3 +376,29 @@ func testBatchResourceList(t *testing.T) {
assert.NotNil(t, found)
assert.True(t, found.Namespaced)
}
func testAutoscalingResourceList(t *testing.T) {
serverURL := serverIP + "/apis/" + autoscaling_v1.SchemeGroupVersion.String()
contents, err := readResponse(serverURL)
if err != nil {
t.Fatalf("%v", err)
}
var apiResourceList metav1.APIResourceList
err = json.Unmarshal(contents, &apiResourceList)
if err != nil {
t.Fatalf("Error in unmarshalling response from server %s: %v", serverURL, err)
}
// empty APIVersion for extensions group
assert.Equal(t, "v1", apiResourceList.APIVersion)
assert.Equal(t, autoscaling_v1.SchemeGroupVersion.String(), apiResourceList.GroupVersion)
// Assert that there are exactly this number of resources.
assert.Equal(t, 2, len(apiResourceList.APIResources))
// Verify hpa
found := findResource(apiResourceList.APIResources, "horizontalpodautoscalers")
assert.NotNil(t, found)
assert.True(t, found.Namespaced)
found = findResource(apiResourceList.APIResources, "horizontalpodautoscalers/status")
assert.NotNil(t, found)
assert.True(t, found.Namespaced)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment