mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Fix fake clientsets in metrics.k8s.io.
The generated fake clientsets were using the API group "metrics" instead of "metrics.k8s.io". This patch includes a test that fails without the fix. The `+groupName` annotation needed to be copied to the v1alpha1 and v1beta1 packages to fix it. As a result, tests using this fake clientset work as expected.
This commit is contained in:
parent
df2094b3d7
commit
ab7e2ff136
@ -13,6 +13,7 @@ filegroup(
|
|||||||
"//staging/src/k8s.io/metrics/pkg/apis/external_metrics:all-srcs",
|
"//staging/src/k8s.io/metrics/pkg/apis/external_metrics:all-srcs",
|
||||||
"//staging/src/k8s.io/metrics/pkg/apis/metrics:all-srcs",
|
"//staging/src/k8s.io/metrics/pkg/apis/metrics:all-srcs",
|
||||||
"//staging/src/k8s.io/metrics/pkg/client/clientset/versioned:all-srcs",
|
"//staging/src/k8s.io/metrics/pkg/client/clientset/versioned:all-srcs",
|
||||||
|
"//staging/src/k8s.io/metrics/pkg/client/clientset_test:all-srcs",
|
||||||
"//staging/src/k8s.io/metrics/pkg/client/custom_metrics:all-srcs",
|
"//staging/src/k8s.io/metrics/pkg/client/custom_metrics:all-srcs",
|
||||||
"//staging/src/k8s.io/metrics/pkg/client/external_metrics:all-srcs",
|
"//staging/src/k8s.io/metrics/pkg/client/external_metrics:all-srcs",
|
||||||
],
|
],
|
||||||
|
@ -18,5 +18,6 @@ limitations under the License.
|
|||||||
// +k8s:protobuf-gen=package
|
// +k8s:protobuf-gen=package
|
||||||
// +k8s:conversion-gen=k8s.io/metrics/pkg/apis/metrics
|
// +k8s:conversion-gen=k8s.io/metrics/pkg/apis/metrics
|
||||||
// +k8s:openapi-gen=true
|
// +k8s:openapi-gen=true
|
||||||
|
// +groupName=metrics.k8s.io
|
||||||
|
|
||||||
package v1alpha1
|
package v1alpha1
|
||||||
|
@ -18,5 +18,6 @@ limitations under the License.
|
|||||||
// +k8s:protobuf-gen=package
|
// +k8s:protobuf-gen=package
|
||||||
// +k8s:conversion-gen=k8s.io/metrics/pkg/apis/metrics
|
// +k8s:conversion-gen=k8s.io/metrics/pkg/apis/metrics
|
||||||
// +k8s:openapi-gen=true
|
// +k8s:openapi-gen=true
|
||||||
|
// +groupName=metrics.k8s.io
|
||||||
|
|
||||||
package v1beta1
|
package v1beta1
|
||||||
|
@ -32,9 +32,9 @@ type FakeNodeMetricses struct {
|
|||||||
Fake *FakeMetricsV1alpha1
|
Fake *FakeMetricsV1alpha1
|
||||||
}
|
}
|
||||||
|
|
||||||
var nodemetricsesResource = schema.GroupVersionResource{Group: "metrics", Version: "v1alpha1", Resource: "nodes"}
|
var nodemetricsesResource = schema.GroupVersionResource{Group: "metrics.k8s.io", Version: "v1alpha1", Resource: "nodes"}
|
||||||
|
|
||||||
var nodemetricsesKind = schema.GroupVersionKind{Group: "metrics", Version: "v1alpha1", Kind: "NodeMetrics"}
|
var nodemetricsesKind = schema.GroupVersionKind{Group: "metrics.k8s.io", Version: "v1alpha1", Kind: "NodeMetrics"}
|
||||||
|
|
||||||
// Get takes name of the nodeMetrics, and returns the corresponding nodeMetrics object, and an error if there is any.
|
// Get takes name of the nodeMetrics, and returns the corresponding nodeMetrics object, and an error if there is any.
|
||||||
func (c *FakeNodeMetricses) Get(name string, options v1.GetOptions) (result *v1alpha1.NodeMetrics, err error) {
|
func (c *FakeNodeMetricses) Get(name string, options v1.GetOptions) (result *v1alpha1.NodeMetrics, err error) {
|
||||||
|
@ -33,9 +33,9 @@ type FakePodMetricses struct {
|
|||||||
ns string
|
ns string
|
||||||
}
|
}
|
||||||
|
|
||||||
var podmetricsesResource = schema.GroupVersionResource{Group: "metrics", Version: "v1alpha1", Resource: "pods"}
|
var podmetricsesResource = schema.GroupVersionResource{Group: "metrics.k8s.io", Version: "v1alpha1", Resource: "pods"}
|
||||||
|
|
||||||
var podmetricsesKind = schema.GroupVersionKind{Group: "metrics", Version: "v1alpha1", Kind: "PodMetrics"}
|
var podmetricsesKind = schema.GroupVersionKind{Group: "metrics.k8s.io", Version: "v1alpha1", Kind: "PodMetrics"}
|
||||||
|
|
||||||
// Get takes name of the podMetrics, and returns the corresponding podMetrics object, and an error if there is any.
|
// Get takes name of the podMetrics, and returns the corresponding podMetrics object, and an error if there is any.
|
||||||
func (c *FakePodMetricses) Get(name string, options v1.GetOptions) (result *v1alpha1.PodMetrics, err error) {
|
func (c *FakePodMetricses) Get(name string, options v1.GetOptions) (result *v1alpha1.PodMetrics, err error) {
|
||||||
|
@ -31,7 +31,7 @@ type MetricsV1alpha1Interface interface {
|
|||||||
PodMetricsesGetter
|
PodMetricsesGetter
|
||||||
}
|
}
|
||||||
|
|
||||||
// MetricsV1alpha1Client is used to interact with features provided by the metrics group.
|
// MetricsV1alpha1Client is used to interact with features provided by the metrics.k8s.io group.
|
||||||
type MetricsV1alpha1Client struct {
|
type MetricsV1alpha1Client struct {
|
||||||
restClient rest.Interface
|
restClient rest.Interface
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@ type FakeNodeMetricses struct {
|
|||||||
Fake *FakeMetricsV1beta1
|
Fake *FakeMetricsV1beta1
|
||||||
}
|
}
|
||||||
|
|
||||||
var nodemetricsesResource = schema.GroupVersionResource{Group: "metrics", Version: "v1beta1", Resource: "nodes"}
|
var nodemetricsesResource = schema.GroupVersionResource{Group: "metrics.k8s.io", Version: "v1beta1", Resource: "nodes"}
|
||||||
|
|
||||||
var nodemetricsesKind = schema.GroupVersionKind{Group: "metrics", Version: "v1beta1", Kind: "NodeMetrics"}
|
var nodemetricsesKind = schema.GroupVersionKind{Group: "metrics.k8s.io", Version: "v1beta1", Kind: "NodeMetrics"}
|
||||||
|
|
||||||
// Get takes name of the nodeMetrics, and returns the corresponding nodeMetrics object, and an error if there is any.
|
// Get takes name of the nodeMetrics, and returns the corresponding nodeMetrics object, and an error if there is any.
|
||||||
func (c *FakeNodeMetricses) Get(name string, options v1.GetOptions) (result *v1beta1.NodeMetrics, err error) {
|
func (c *FakeNodeMetricses) Get(name string, options v1.GetOptions) (result *v1beta1.NodeMetrics, err error) {
|
||||||
|
@ -33,9 +33,9 @@ type FakePodMetricses struct {
|
|||||||
ns string
|
ns string
|
||||||
}
|
}
|
||||||
|
|
||||||
var podmetricsesResource = schema.GroupVersionResource{Group: "metrics", Version: "v1beta1", Resource: "pods"}
|
var podmetricsesResource = schema.GroupVersionResource{Group: "metrics.k8s.io", Version: "v1beta1", Resource: "pods"}
|
||||||
|
|
||||||
var podmetricsesKind = schema.GroupVersionKind{Group: "metrics", Version: "v1beta1", Kind: "PodMetrics"}
|
var podmetricsesKind = schema.GroupVersionKind{Group: "metrics.k8s.io", Version: "v1beta1", Kind: "PodMetrics"}
|
||||||
|
|
||||||
// Get takes name of the podMetrics, and returns the corresponding podMetrics object, and an error if there is any.
|
// Get takes name of the podMetrics, and returns the corresponding podMetrics object, and an error if there is any.
|
||||||
func (c *FakePodMetricses) Get(name string, options v1.GetOptions) (result *v1beta1.PodMetrics, err error) {
|
func (c *FakePodMetricses) Get(name string, options v1.GetOptions) (result *v1beta1.PodMetrics, err error) {
|
||||||
|
@ -31,7 +31,7 @@ type MetricsV1beta1Interface interface {
|
|||||||
PodMetricsesGetter
|
PodMetricsesGetter
|
||||||
}
|
}
|
||||||
|
|
||||||
// MetricsV1beta1Client is used to interact with features provided by the metrics group.
|
// MetricsV1beta1Client is used to interact with features provided by the metrics.k8s.io group.
|
||||||
type MetricsV1beta1Client struct {
|
type MetricsV1beta1Client struct {
|
||||||
restClient rest.Interface
|
restClient rest.Interface
|
||||||
}
|
}
|
||||||
|
24
staging/src/k8s.io/metrics/pkg/client/clientset_test/BUILD
Normal file
24
staging/src/k8s.io/metrics/pkg/client/clientset_test/BUILD
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_test")
|
||||||
|
|
||||||
|
go_test(
|
||||||
|
name = "go_default_test",
|
||||||
|
srcs = ["clientset_test.go"],
|
||||||
|
deps = [
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/metrics/pkg/client/clientset/versioned/fake:go_default_library",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "package-srcs",
|
||||||
|
srcs = glob(["**"]),
|
||||||
|
tags = ["automanaged"],
|
||||||
|
visibility = ["//visibility:private"],
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "all-srcs",
|
||||||
|
srcs = [":package-srcs"],
|
||||||
|
tags = ["automanaged"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2019 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 clientset_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/metrics/pkg/client/clientset/versioned/fake"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestFakeList is a basic sanity check that makes sure the fake Clientset is working properly.
|
||||||
|
func TestFakeList(t *testing.T) {
|
||||||
|
client := fake.NewSimpleClientset()
|
||||||
|
if _, err := client.MetricsV1alpha1().PodMetricses("").List(metav1.ListOptions{}); err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := client.MetricsV1alpha1().NodeMetricses().List(metav1.ListOptions{}); err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := client.MetricsV1beta1().PodMetricses("").List(metav1.ListOptions{}); err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := client.MetricsV1beta1().NodeMetricses().List(metav1.ListOptions{}); err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user