Skip to content

Commit

Permalink
[metrics] Import API types
Browse files Browse the repository at this point in the history
This commit imports the resource metrics API types from Heapster.
The generated conversions and clients are in a separate commit.
  • Loading branch information
DirectXMan12 committed Feb 21, 2017
1 parent 65e6c8b commit e0430ff
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 1 deletion.
17 changes: 17 additions & 0 deletions pkg/apis/metrics/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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

package metrics // import "k8s.io/metrics/pkg/apis/metrics"
51 changes: 51 additions & 0 deletions pkg/apis/metrics/install/install.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
51 changes: 51 additions & 0 deletions pkg/apis/metrics/register.go
Original file line number Diff line number Diff line change
@@ -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
}
86 changes: 86 additions & 0 deletions pkg/apis/metrics/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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

// 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
}
19 changes: 19 additions & 0 deletions pkg/apis/metrics/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -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/custom_metrics
// +k8s:openapi-gen=true

package v1alpha1 // import "k8s.io/heapster/metrics/apis/metrics/v1alpha1"
48 changes: 48 additions & 0 deletions pkg/apis/metrics/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -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
}
86 changes: 86 additions & 0 deletions pkg/apis/metrics/v1alpha1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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

// 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"`
}
2 changes: 1 addition & 1 deletion repo-infra-config.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e0430ff

Please sign in to comment.