diff --git a/pkg/apis/metrics/doc.go b/pkg/apis/metrics/doc.go new file mode 100644 index 00000000..3980ef37 --- /dev/null +++ b/pkg/apis/metrics/doc.go @@ -0,0 +1,19 @@ +// Copyright 2016 Google Inc. 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. + +// TODO: this needs to be cross-registered as metrics.metrics.k8s.io + +// +k8s:deepcopy-gen=package,register + +package metrics // import "k8s.io/metrics/pkg/apis/metrics" diff --git a/pkg/apis/metrics/install/install.go b/pkg/apis/metrics/install/install.go new file mode 100644 index 00000000..957d7793 --- /dev/null +++ b/pkg/apis/metrics/install/install.go @@ -0,0 +1,51 @@ +/* +Copyright 2017 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 install installs the experimental API group, making it available as +// an option to all of the API encoding/decoding machinery. +package install + +import ( + "k8s.io/apimachinery/pkg/apimachinery/announced" + "k8s.io/apimachinery/pkg/apimachinery/registered" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/client-go/pkg/api" + "k8s.io/metrics/pkg/apis/metrics" + "k8s.io/metrics/pkg/apis/metrics/v1alpha1" +) + +func init() { + Install(api.GroupFactoryRegistry, api.Registry, api.Scheme) +} + +// Install registers the API group and adds types to a scheme +func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) { + if err := announced.NewGroupMetaFactory( + &announced.GroupMetaFactoryArgs{ + GroupName: metrics.GroupName, + VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version}, + ImportPrefix: "k8s.io/metrics/pkg/apis/metrics", + RootScopedKinds: sets.NewString("NodeMetrics"), + AddInternalObjectsToScheme: metrics.AddToScheme, + }, + announced.VersionToSchemeFunc{ + v1alpha1.SchemeGroupVersion.Version: v1alpha1.AddToScheme, + }, + ).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil { + panic(err) + } +} diff --git a/pkg/apis/metrics/install/install_test.go b/pkg/apis/metrics/install/install_test.go new file mode 100644 index 00000000..4ad67b47 --- /dev/null +++ b/pkg/apis/metrics/install/install_test.go @@ -0,0 +1,12 @@ +package install + +import ( + "testing" + + apitesting "k8s.io/apimachinery/pkg/api/testing" +) + +func TestRoundTripTypes(t *testing.T) { + apitesting.RoundTripTestForAPIGroup(t, Install, nil) +} + diff --git a/pkg/apis/metrics/register.go b/pkg/apis/metrics/register.go new file mode 100644 index 00000000..9a952808 --- /dev/null +++ b/pkg/apis/metrics/register.go @@ -0,0 +1,51 @@ +// Copyright 2016 Google Inc. 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/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the group name use in this package +const GroupName = "metrics" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns back a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &NodeMetrics{}, + &NodeMetricsList{}, + &PodMetrics{}, + &PodMetricsList{}, + ) + return nil +} diff --git a/pkg/apis/metrics/types.go b/pkg/apis/metrics/types.go new file mode 100644 index 00000000..a5027d63 --- /dev/null +++ b/pkg/apis/metrics/types.go @@ -0,0 +1,87 @@ +// Copyright 2016 Google Inc. 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 ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/pkg/api" +) + +// +genclient=true +// +resourceName=nodes +// +readonly=true +// +nonNamespaced=true + +// resource usage metrics of a node. +type NodeMetrics struct { + metav1.TypeMeta + metav1.ObjectMeta + + // The following fields define time interval from which metrics were + // collected from the interval [Timestamp-Window, Timestamp]. + Timestamp metav1.Time + Window metav1.Duration + + // The memory usage is the memory working set. + Usage api.ResourceList +} + +// NodeMetricsList is a list of NodeMetrics. +type NodeMetricsList struct { + metav1.TypeMeta + // Standard list metadata. + // More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds + metav1.ListMeta + + // List of node metrics. + Items []NodeMetrics +} + +// +genclient=true +// +resourceName=pods +// +readonly=true + +// resource usage metrics of a pod. +type PodMetrics struct { + metav1.TypeMeta + metav1.ObjectMeta + + // The following fields define time interval from which metrics were + // collected from the interval [Timestamp-Window, Timestamp]. + Timestamp metav1.Time + Window metav1.Duration + + // Metrics for all containers are collected within the same time window. + Containers []ContainerMetrics +} + +// PodMetricsList is a list of PodMetrics. +type PodMetricsList struct { + metav1.TypeMeta + // Standard list metadata. + // More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds + metav1.ListMeta + + // List of pod metrics. + Items []PodMetrics +} + +// resource usage metrics of a container. +type ContainerMetrics struct { + // Container name corresponding to the one from pod.spec.containers. + Name string + // The memory usage is the memory working set. + Usage api.ResourceList +} diff --git a/pkg/apis/metrics/v1alpha1/doc.go b/pkg/apis/metrics/v1alpha1/doc.go new file mode 100644 index 00000000..c711ed96 --- /dev/null +++ b/pkg/apis/metrics/v1alpha1/doc.go @@ -0,0 +1,19 @@ +// Copyright 2016 Google Inc. 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. + +// +k8s:deepcopy-gen=package,register +// +k8s:conversion-gen=k8s.io/metrics/pkg/apis/metrics +// +k8s:openapi-gen=true + +package v1alpha1 // import "k8s.io/metrics/pkg/apis/metrics/v1alpha1" diff --git a/pkg/apis/metrics/v1alpha1/register.go b/pkg/apis/metrics/v1alpha1/register.go new file mode 100644 index 00000000..1249a974 --- /dev/null +++ b/pkg/apis/metrics/v1alpha1/register.go @@ -0,0 +1,48 @@ +// Copyright 2016 Google Inc. 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 v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the group name use in this package +const GroupName = "metrics" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &NodeMetrics{}, + &NodeMetricsList{}, + &PodMetrics{}, + &PodMetricsList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/metrics/v1alpha1/types.go b/pkg/apis/metrics/v1alpha1/types.go new file mode 100644 index 00000000..93a4e92b --- /dev/null +++ b/pkg/apis/metrics/v1alpha1/types.go @@ -0,0 +1,87 @@ +// Copyright 2016 Google Inc. 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 v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/pkg/api/v1" +) + +// +genclient=true +// +resourceName=nodes +// +readonly=true +// +nonNamespaced=true + +// resource usage metrics of a node. +type NodeMetrics struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // The following fields define time interval from which metrics were + // collected from the interval [Timestamp-Window, Timestamp]. + Timestamp metav1.Time `json:"timestamp"` + Window metav1.Duration `json:"window"` + + // The memory usage is the memory working set. + Usage v1.ResourceList `json:"usage"` +} + +// NodeMetricsList is a list of NodeMetrics. +type NodeMetricsList struct { + metav1.TypeMeta `json:",inline"` + // Standard list metadata. + // More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds + metav1.ListMeta `json:"metadata,omitempty"` + + // List of node metrics. + Items []NodeMetrics `json:"items"` +} + +// +genclient=true +// +resourceName=pods +// +readonly=true + +// resource usage metrics of a pod. +type PodMetrics struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // The following fields define time interval from which metrics were + // collected from the interval [Timestamp-Window, Timestamp]. + Timestamp metav1.Time `json:"timestamp"` + Window metav1.Duration `json:"window"` + + // Metrics for all containers are collected within the same time window. + Containers []ContainerMetrics `json:"containers"` +} + +// PodMetricsList is a list of PodMetrics. +type PodMetricsList struct { + metav1.TypeMeta `json:",inline"` + // Standard list metadata. + // More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds + metav1.ListMeta `json:"metadata,omitempty"` + + // List of pod metrics. + Items []PodMetrics `json:"items"` +} + +// resource usage metrics of a container. +type ContainerMetrics struct { + // Container name corresponding to the one from pod.spec.containers. + Name string `json:"name"` + // The memory usage is the memory working set. + Usage v1.ResourceList `json:"usage"` +} diff --git a/repo-infra-config.sh b/repo-infra-config.sh index 3eb8a0b9..6c84be03 100644 --- a/repo-infra-config.sh +++ b/repo-infra-config.sh @@ -1,4 +1,4 @@ -REPO_AVAILABLE_GROUP_VERSIONS=custom_metrics/v1alpha1 +REPO_AVAILABLE_GROUP_VERSIONS="custom_metrics/v1alpha1 metrics/v1alpha1" REPO_NO_CLIENT_GROUP_VERSIONS=custom_metrics/v1alpha1 REPO_EXTRA_PROTO_IMPORTS="k8s.io/client-go/pkg/api/v1" REPO_GO_PACKAGE=k8s.io/metrics