Skip to content

Commit

Permalink
Merge pull request #1 from DirectXMan12/refactor/custom-api-installer
Browse files Browse the repository at this point in the history
Custom API Installer
  • Loading branch information
DirectXMan12 authored Apr 13, 2017
2 parents 4616b24 + a3b76e0 commit 04f8dc2
Show file tree
Hide file tree
Showing 9 changed files with 1,642 additions and 73 deletions.
413 changes: 413 additions & 0 deletions glide.lock

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package: k8s.io/custom-metrics-boilerplate
import:
- package: github.com/emicklei/go-restful
- package: github.com/spf13/cobra
- package: k8s.io/apimachinery
subpackages:
- pkg/api/errors
- pkg/api/meta
- pkg/api/resource
- pkg/apimachinery
- pkg/apimachinery/announced
- pkg/apimachinery/registered
- pkg/apis/meta/internalversion
- pkg/apis/meta/v1
- pkg/conversion
- pkg/labels
- pkg/runtime
- pkg/runtime/schema
- pkg/runtime/serializer
- pkg/util/errors
- pkg/util/wait
- pkg/version
- package: k8s.io/apiserver
subpackages:
- pkg/endpoints
- pkg/endpoints/handlers
- pkg/endpoints/handlers/negotiation
- pkg/endpoints/metrics
- pkg/endpoints/request
- pkg/registry/rest
- pkg/server
- pkg/server/options
- pkg/util/logs
- package: k8s.io/client-go
subpackages:
- kubernetes/scheme
- kubernetes/typed/core/v1
- pkg/api
- pkg/api/install
- rest
- tools/clientcmd
- package: k8s.io/metrics
subpackages:
- pkg/apis/custom_metrics
- pkg/apis/custom_metrics/install
78 changes: 36 additions & 42 deletions pkg/apiserver/cmapis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ limitations under the License.
package apiserver

import (
"k8s.io/apimachinery/pkg/apimachinery"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/apimachinery"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apiserver/pkg/registry/rest"
genericapiserver "k8s.io/apiserver/pkg/server"
genericapi "k8s.io/apiserver/pkg/endpoints"
genericapiserver "k8s.io/apiserver/pkg/server"

"k8s.io/metrics/pkg/apis/custom_metrics"
metricstorage "k8s.io/custom-metrics-boilerplate/pkg/registry/custom_metrics"
specificapi "k8s.io/custom-metrics-boilerplate/pkg/apiserver/installer"
"k8s.io/custom-metrics-boilerplate/pkg/provider"
metricstorage "k8s.io/custom-metrics-boilerplate/pkg/registry/custom_metrics"
"k8s.io/metrics/pkg/apis/custom_metrics"
)

func (s *CustomMetricsAdapterServer) InstallCustomMetricsAPI() error {
Expand All @@ -38,14 +38,14 @@ func (s *CustomMetricsAdapterServer) InstallCustomMetricsAPI() error {
GroupVersion: groupMeta.GroupVersion.String(),
Version: groupMeta.GroupVersion.Version,
}
groupVersion := metav1.GroupVersionForDiscovery{
GroupVersion: groupMeta.GroupVersion.String(),
Version: groupMeta.GroupVersion.Version,
}
groupVersion := metav1.GroupVersionForDiscovery{
GroupVersion: groupMeta.GroupVersion.String(),
Version: groupMeta.GroupVersion.Version,
}
apiGroup := metav1.APIGroup{
Name: groupMeta.GroupVersion.String(),
Versions: []metav1.GroupVersionForDiscovery{groupVersion},
PreferredVersion: preferredVersionForDiscovery,
Name: groupMeta.GroupVersion.String(),
Versions: []metav1.GroupVersionForDiscovery{groupVersion},
PreferredVersion: preferredVersionForDiscovery,
}

cmAPI := s.cmAPI(groupMeta, &groupMeta.GroupVersion)
Expand All @@ -54,41 +54,35 @@ func (s *CustomMetricsAdapterServer) InstallCustomMetricsAPI() error {
return err
}

path := genericapiserver.APIGroupPrefix+"/"+groupMeta.GroupVersion.Group
path := genericapiserver.APIGroupPrefix + "/" + groupMeta.GroupVersion.Group
s.GenericAPIServer.HandlerContainer.Add(genericapi.NewGroupWebService(s.GenericAPIServer.Serializer, path, apiGroup))

return nil
}
func (s *CustomMetricsAdapterServer) cmAPI(groupMeta *apimachinery.GroupMeta, groupVersion *schema.GroupVersion) *genericapi.APIGroupVersion {
func (s *CustomMetricsAdapterServer) cmAPI(groupMeta *apimachinery.GroupMeta, groupVersion *schema.GroupVersion) *specificapi.MetricsAPIGroupVersion {
resourceStorage := metricstorage.NewREST(s.Provider)

storage := map[string]rest.Storage{
// TODO: make this non-returning storage
"*": resourceStorage,
"*/*": resourceStorage,
}

return &genericapi.APIGroupVersion{
Root: genericapiserver.APIGroupPrefix,
GroupVersion: *groupVersion,

ParameterCodec: metav1.ParameterCodec,
Serializer: Codecs,
Creater: Scheme,
Convertor: Scheme,
UnsafeConvertor: runtime.UnsafeObjectConvertor(Scheme),
Copier: Scheme,
Typer: Scheme,
SubresourceGroupVersionKind: nil, // TODO: do we need this?
Linker: groupMeta.SelfLinker,
Mapper: groupMeta.RESTMapper,
Storage: storage,

// TODO: Admit?
Context: s.GenericAPIServer.RequestContextMapper(),
MinRequestTimeout: s.GenericAPIServer.MinRequestTimeout(),
OptionsExternalVersion: &schema.GroupVersion{Version: "v1"},

ResourceLister: provider.NewResourceLister(s.Provider),
return &specificapi.MetricsAPIGroupVersion{
DynamicStorage: resourceStorage,
APIGroupVersion: &genericapi.APIGroupVersion{
Root: genericapiserver.APIGroupPrefix,
GroupVersion: *groupVersion,

ParameterCodec: metav1.ParameterCodec,
Serializer: Codecs,
Creater: Scheme,
Convertor: Scheme,
UnsafeConvertor: runtime.UnsafeObjectConvertor(Scheme),
Copier: Scheme,
Typer: Scheme,
Linker: groupMeta.SelfLinker,
Mapper: groupMeta.RESTMapper,

Context: s.GenericAPIServer.RequestContextMapper(),
MinRequestTimeout: s.GenericAPIServer.MinRequestTimeout(),
OptionsExternalVersion: &schema.GroupVersion{Version: "v1"},

ResourceLister: provider.NewResourceLister(s.Provider),
},
}
}
Loading

0 comments on commit 04f8dc2

Please sign in to comment.