Skip to content

Commit

Permalink
Set up new "metrics" API group.
Browse files Browse the repository at this point in the history
This commit only adds 2 placeholder structs to the API, for the purposes
of separating the API group setup from the API discussion.
  • Loading branch information
tallclair committed Nov 2, 2015
1 parent 17e36b0 commit 5cd5b80
Show file tree
Hide file tree
Showing 21 changed files with 1,384 additions and 23 deletions.
2 changes: 2 additions & 0 deletions cmd/genconversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
_ "k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1"
_ "k8s.io/kubernetes/pkg/apis/extensions"
_ "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
_ "k8s.io/kubernetes/pkg/apis/metrics"
_ "k8s.io/kubernetes/pkg/apis/metrics/v1alpha1"
kruntime "k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/sets"

Expand Down
2 changes: 2 additions & 0 deletions cmd/gendeepcopy/deep_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
_ "k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1"
_ "k8s.io/kubernetes/pkg/apis/extensions"
_ "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
_ "k8s.io/kubernetes/pkg/apis/metrics"
_ "k8s.io/kubernetes/pkg/apis/metrics/v1alpha1"
kruntime "k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/sets"

Expand Down
1 change: 1 addition & 0 deletions cmd/kube-version-change/import_known_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ import (
_ "k8s.io/kubernetes/pkg/api/install"
_ "k8s.io/kubernetes/pkg/apis/componentconfig/install"
_ "k8s.io/kubernetes/pkg/apis/extensions/install"
_ "k8s.io/kubernetes/pkg/apis/metrics/install"
)
2 changes: 1 addition & 1 deletion hack/after-build/update-generated-conversions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ EOF
}

# TODO(lavalamp): get this list by listing the pkg/apis/ directory?
DEFAULT_GROUP_VERSIONS="v1 extensions/v1beta1 componentconfig/v1alpha1"
DEFAULT_GROUP_VERSIONS="v1 extensions/v1beta1 componentconfig/v1alpha1 metrics/v1alpha1"
VERSIONS=${VERSIONS:-$DEFAULT_GROUP_VERSIONS}
for ver in $VERSIONS; do
# Ensure that the version being processed is registered by setting
Expand Down
4 changes: 2 additions & 2 deletions hack/after-build/update-generated-deep-copies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ function generate_deep_copies() {
for ver in ${group_versions}; do
# Ensure that the version being processed is registered by setting
# KUBE_API_VERSIONS.
if [ -z ${ver##*/} ]; then
if [ -z ${ver##*/} ]; then
apiVersions=""
fi
KUBE_API_VERSIONS="${apiVersions}" generate_version "${ver}"
done
}

# v1 is in the group ""
DEFAULT_VERSIONS="/ v1 extensions/ extensions/v1beta1 componentconfig/ componentconfig/v1alpha1"
DEFAULT_VERSIONS="/ v1 extensions/ extensions/v1beta1 componentconfig/ componentconfig/v1alpha1 metrics/ metrics/v1alpha1"
VERSIONS=${VERSIONS:-$DEFAULT_VERSIONS}
generate_deep_copies "$VERSIONS"
2 changes: 1 addition & 1 deletion hack/after-build/verify-generated-conversions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ source "${KUBE_ROOT}/hack/lib/init.sh"

kube::golang::setup_env

APIROOTS=${APIROOTS:-pkg/api pkg/apis/extensions}
APIROOTS=${APIROOTS:-pkg/api pkg/apis/extensions pkg/apis/metrics}
_tmp="${KUBE_ROOT}/_tmp"

cleanup() {
Expand Down
2 changes: 1 addition & 1 deletion hack/after-build/verify-generated-deep-copies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ kube::golang::setup_env

gendeepcopy=$(kube::util::find-binary "gendeepcopy")

APIROOTS=${APIROOTS:-pkg/api pkg/apis/extensions}
APIROOTS=${APIROOTS:-pkg/api pkg/apis/extensions pkg/apis/metrics}
_tmp="${KUBE_ROOT}/_tmp"

cleanup() {
Expand Down
6 changes: 2 additions & 4 deletions hack/test-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-}
# Lists of API Versions of each groups that should be tested, groups are
# separated by comma, lists are separated by semicolon. e.g.,
# "v1,compute/v1alpha1,experimental/v1alpha2;v1,compute/v2,experimental/v1alpha3"
# TODO: It's going to be:
# KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,extensions/v1beta1"}
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,extensions/v1beta1"}
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,extensions/v1beta1,metrics/v1alpha1"}
# once we have multiple group supports
# Run tests with the standard (registry) and a custom etcd prefix
# (kubernetes.io/registry).
Expand Down Expand Up @@ -315,7 +313,7 @@ for (( i=0, j=0; ; )); do
# KUBE_TEST_API sets the version of each group to be tested. KUBE_API_VERSIONS
# register the groups/versions as supported by k8s. So KUBE_API_VERSIONS
# needs to be the superset of KUBE_TEST_API.
KUBE_TEST_API="${apiVersion}" KUBE_API_VERSIONS="v1,extensions/v1beta1,componentconfig/v1alpha1" ETCD_PREFIX=${etcdPrefix} runTests "$@"
KUBE_TEST_API="${apiVersion}" KUBE_API_VERSIONS="v1,extensions/v1beta1,componentconfig/v1alpha1,metrics/v1alpha1" ETCD_PREFIX=${etcdPrefix} runTests "$@"
i=${i}+1
j=${j}+1
if [[ i -eq ${apiVersionsCount} ]] && [[ j -eq ${etcdPrefixesCount} ]]; then
Expand Down
1 change: 1 addition & 0 deletions pkg/api/registered/registered.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func init() {
"v1": true,
"extensions/v1beta1": true,
"componentconfig/v1alpha1": true,
"metrics/v1alpha1": true,
}

// The default list of supported api versions, in order of most preferred to the least.
Expand Down
19 changes: 5 additions & 14 deletions pkg/api/testapi/testapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/kubernetes/pkg/api"
_ "k8s.io/kubernetes/pkg/api/install"
_ "k8s.io/kubernetes/pkg/apis/extensions/install"
_ "k8s.io/kubernetes/pkg/apis/metrics/install"

"k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/meta"
Expand Down Expand Up @@ -90,21 +91,11 @@ func (g TestGroup) GroupAndVersion() string {
// KUBE_TEST_API env var.
func (g TestGroup) Codec() runtime.Codec {
// TODO: caesarxuchao: Restructure the body once we have a central `latest`.
if g.Group == "" {
interfaces, err := latest.GroupOrDie("").InterfacesFor(g.GroupVersionUnderTest)
if err != nil {
panic(err)
}
return interfaces.Codec
}
if g.Group == "extensions" {
interfaces, err := latest.GroupOrDie("extensions").InterfacesFor(g.GroupVersionUnderTest)
if err != nil {
panic(err)
}
return interfaces.Codec
interfaces, err := latest.GroupOrDie(g.Group).InterfacesFor(g.GroupVersionUnderTest)
if err != nil {
panic(err)
}
panic(fmt.Errorf("cannot test group %s", g.Group))
return interfaces.Codec
}

// Converter returns the api.Scheme for the API version to test against, as set by the
Expand Down
57 changes: 57 additions & 0 deletions pkg/apis/metrics/deep_copy_generated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
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.
*/

// DO NOT EDIT. THIS FILE IS AUTO-GENERATED BY $KUBEROOT/hack/update-generated-deep-copies.sh.

package metrics

import (
api "k8s.io/kubernetes/pkg/api"
unversioned "k8s.io/kubernetes/pkg/api/unversioned"
conversion "k8s.io/kubernetes/pkg/conversion"
)

func deepCopy_unversioned_TypeMeta(in unversioned.TypeMeta, out *unversioned.TypeMeta, c *conversion.Cloner) error {
out.Kind = in.Kind
out.APIVersion = in.APIVersion
return nil
}

func deepCopy_metrics_RawNode(in RawNode, out *RawNode, c *conversion.Cloner) error {
if err := deepCopy_unversioned_TypeMeta(in.TypeMeta, &out.TypeMeta, c); err != nil {
return err
}
return nil
}

func deepCopy_metrics_RawPod(in RawPod, out *RawPod, c *conversion.Cloner) error {
if err := deepCopy_unversioned_TypeMeta(in.TypeMeta, &out.TypeMeta, c); err != nil {
return err
}
return nil
}

func init() {
err := api.Scheme.AddGeneratedDeepCopyFuncs(
deepCopy_unversioned_TypeMeta,
deepCopy_metrics_RawNode,
deepCopy_metrics_RawPod,
)
if err != nil {
// if one of the deep copy functions is malformed, detect it immediately.
panic(err)
}
}
92 changes: 92 additions & 0 deletions pkg/apis/metrics/install/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
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 install installs the metrics API group, making it available as
// an option to all of the API encoding/decoding machinery.
package install

import (
"fmt"
"strings"

"github.com/golang/glog"

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/registered"
apiutil "k8s.io/kubernetes/pkg/api/util"
_ "k8s.io/kubernetes/pkg/apis/metrics"
"k8s.io/kubernetes/pkg/apis/metrics/v1alpha1"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/sets"
)

const importPrefix = "k8s.io/kubernetes/pkg/apis/metrics"

var accessor = meta.NewAccessor()

func init() {
groupMeta, err := latest.RegisterGroup("metrics")
if err != nil {
glog.V(4).Infof("%v", err)
return
}
registeredGroupVersions := registered.GroupVersionsForGroup("metrics")
groupVersion := registeredGroupVersions[0]
*groupMeta = latest.GroupMeta{
GroupVersion: groupVersion,
Group: apiutil.GetGroup(groupVersion),
Version: apiutil.GetVersion(groupVersion),
Codec: runtime.CodecFor(api.Scheme, groupVersion),
}
var versions []string
var groupVersions []string
for i := len(registeredGroupVersions) - 1; i >= 0; i-- {
versions = append(versions, apiutil.GetVersion(registeredGroupVersions[i]))
groupVersions = append(groupVersions, registeredGroupVersions[i])
}
groupMeta.Versions = versions
groupMeta.GroupVersions = groupVersions

groupMeta.SelfLinker = runtime.SelfLinker(accessor)

// the list of kinds that are scoped at the root of the api hierarchy
// if a kind is not enumerated here, it is assumed to have a namespace scope
rootScoped := sets.NewString()

ignoredKinds := sets.NewString()

groupMeta.RESTMapper = api.NewDefaultRESTMapper("metrics", groupVersions, interfacesFor, importPrefix, ignoredKinds, rootScoped)
api.RegisterRESTMapper(groupMeta.RESTMapper)
groupMeta.InterfacesFor = interfacesFor
}

// InterfacesFor returns the default Codec and ResourceVersioner for a given version
// string, or an error if the version is not known.
func interfacesFor(version string) (*meta.VersionInterfaces, error) {
switch version {
case "metrics/v1alpha1":
return &meta.VersionInterfaces{
Codec: v1alpha1.Codec,
ObjectConvertor: api.Scheme,
MetadataAccessor: accessor,
}, nil
default:
g, _ := latest.Group("metrics")
return nil, fmt.Errorf("unsupported storage version: %s (valid: %s)", version, strings.Join(g.Versions, ", "))
}
}
37 changes: 37 additions & 0 deletions pkg/apis/metrics/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
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 metrics

import (
"k8s.io/kubernetes/pkg/api"
)

func init() {
// Register the API.
addKnownTypes()
}

// Adds the list of known types to api.Scheme.
func addKnownTypes() {
api.Scheme.AddKnownTypes("",
&RawNode{},
&RawPod{},
)
}

func (*RawNode) IsAnAPIObject() {}
func (*RawPod) IsAnAPIObject() {}
Loading

0 comments on commit 5cd5b80

Please sign in to comment.