Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#53 from 44past4/master
Browse files Browse the repository at this point in the history
Expose v1beta2 version of an API
  • Loading branch information
k8s-ci-robot authored Jul 3, 2019
2 parents 8fcee3f + 7cfe378 commit abe4331
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
46 changes: 25 additions & 21 deletions pkg/apiserver/cmapis.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,34 @@ import (

func (s *CustomMetricsAdapterServer) InstallCustomMetricsAPI() error {
groupInfo := genericapiserver.NewDefaultAPIGroupInfo(custom_metrics.GroupName, Scheme, runtime.NewParameterCodec(Scheme), Codecs)
container := s.GenericAPIServer.Handler.GoRestfulContainer

mainGroupVer := groupInfo.PrioritizedVersions[0]
preferredVersionForDiscovery := metav1.GroupVersionForDiscovery{
GroupVersion: mainGroupVer.String(),
Version: mainGroupVer.Version,
}
groupVersion := metav1.GroupVersionForDiscovery{
GroupVersion: mainGroupVer.String(),
Version: mainGroupVer.Version,
}
apiGroup := metav1.APIGroup{
Name: mainGroupVer.Group,
Versions: []metav1.GroupVersionForDiscovery{groupVersion},
PreferredVersion: preferredVersionForDiscovery,
}
// Register custom metrics REST handler for all supported API versions.
for versionIndex, mainGroupVer := range groupInfo.PrioritizedVersions {
preferredVersionForDiscovery := metav1.GroupVersionForDiscovery{
GroupVersion: mainGroupVer.String(),
Version: mainGroupVer.Version,
}
groupVersion := metav1.GroupVersionForDiscovery{
GroupVersion: mainGroupVer.String(),
Version: mainGroupVer.Version,
}
apiGroup := metav1.APIGroup{
Name: mainGroupVer.Group,
Versions: []metav1.GroupVersionForDiscovery{groupVersion},
PreferredVersion: preferredVersionForDiscovery,
}

cmAPI := s.cmAPI(&groupInfo, mainGroupVer)
if err := cmAPI.InstallREST(s.GenericAPIServer.Handler.GoRestfulContainer); err != nil {
return err
}

s.GenericAPIServer.DiscoveryGroupManager.AddGroup(apiGroup)
s.GenericAPIServer.Handler.GoRestfulContainer.Add(discovery.NewAPIGroupHandler(s.GenericAPIServer.Serializer, apiGroup).WebService())
cmAPI := s.cmAPI(&groupInfo, mainGroupVer)
if err := cmAPI.InstallREST(container); err != nil {
return err
}

if versionIndex == 0 {
s.GenericAPIServer.DiscoveryGroupManager.AddGroup(apiGroup)
container.Add(discovery.NewAPIGroupHandler(s.GenericAPIServer.Serializer, apiGroup).WebService())
}
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion test-adapter-deploy/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Sample Deployment Files

These files can be used to deploy the sample adapter container. You can
build that with `make sample-container`. The Dockerfile describes the
build that with `make test-adapter-container`. The Dockerfile describes the
container itself, while the [manifests](manifests) can be used to deploy
that container as a provider of the custom metrics and external metrics
APIs on the cluster.
14 changes: 14 additions & 0 deletions test-adapter-deploy/testing-adapter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ spec:
groupPriorityMinimum: 100
versionPriority: 100
---
apiVersion: apiregistration.k8s.io/v1beta1
kind: APIService
metadata:
name: v1beta2.custom.metrics.k8s.io
spec:
service:
name: custom-metrics-apiserver
namespace: custom-metrics
group: custom.metrics.k8s.io
version: v1beta2
insecureSkipTLSVerify: true
groupPriorityMinimum: 100
versionPriority: 200
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
Expand Down

0 comments on commit abe4331

Please sign in to comment.