mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Test dropped round-trip annotations in HPA conversion
This commit is contained in:
parent
eb69ac30da
commit
79f3f6e9b1
@ -30,10 +30,13 @@ go_test(
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//pkg/api/legacyscheme:go_default_library",
|
||||
"//pkg/apis/autoscaling:go_default_library",
|
||||
"//pkg/apis/autoscaling/install:go_default_library",
|
||||
"//pkg/apis/core/install:go_default_library",
|
||||
"//staging/src/k8s.io/api/autoscaling/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
||||
"//vendor/k8s.io/utils/pointer:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@ -21,9 +21,11 @@ import (
|
||||
"testing"
|
||||
|
||||
autoscalingv1 "k8s.io/api/autoscaling/v1"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
||||
_ "k8s.io/kubernetes/pkg/apis/autoscaling/install"
|
||||
. "k8s.io/kubernetes/pkg/apis/autoscaling/v1"
|
||||
_ "k8s.io/kubernetes/pkg/apis/core/install"
|
||||
@ -67,6 +69,71 @@ func TestSetDefaultHPA(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHorizontalPodAutoscalerAnnotations(t *testing.T) {
|
||||
tests := []struct {
|
||||
hpa autoscalingv1.HorizontalPodAutoscaler
|
||||
test string
|
||||
}{
|
||||
{
|
||||
hpa: autoscalingv1.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
autoscaling.HorizontalPodAutoscalerConditionsAnnotation: "",
|
||||
autoscaling.MetricSpecsAnnotation: "",
|
||||
autoscaling.BehaviorSpecsAnnotation: "",
|
||||
autoscaling.MetricStatusesAnnotation: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
test: "test empty value for Annotations",
|
||||
},
|
||||
{
|
||||
hpa: autoscalingv1.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
autoscaling.HorizontalPodAutoscalerConditionsAnnotation: "abc",
|
||||
autoscaling.MetricSpecsAnnotation: "abc",
|
||||
autoscaling.BehaviorSpecsAnnotation: "abc",
|
||||
autoscaling.MetricStatusesAnnotation: "abc",
|
||||
},
|
||||
},
|
||||
},
|
||||
test: "test random value for Annotations",
|
||||
},
|
||||
{
|
||||
hpa: autoscalingv1.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
autoscaling.HorizontalPodAutoscalerConditionsAnnotation: "[]",
|
||||
autoscaling.MetricSpecsAnnotation: "[]",
|
||||
autoscaling.BehaviorSpecsAnnotation: "[]",
|
||||
autoscaling.MetricStatusesAnnotation: "[]",
|
||||
},
|
||||
},
|
||||
},
|
||||
test: "test empty array value for Annotations",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
hpa := &test.hpa
|
||||
hpaBeforeMuatate := *hpa.DeepCopy()
|
||||
obj := roundTrip(t, runtime.Object(hpa))
|
||||
final_obj, ok := obj.(*autoscalingv1.HorizontalPodAutoscaler)
|
||||
if !ok {
|
||||
t.Fatalf("unexpected object: %v", obj)
|
||||
}
|
||||
if !reflect.DeepEqual(*hpa, hpaBeforeMuatate) {
|
||||
t.Errorf("diff: %v", diff.ObjectDiff(*hpa, hpaBeforeMuatate))
|
||||
t.Errorf("expected: %#v\n actual: %#v", *hpa, hpaBeforeMuatate)
|
||||
}
|
||||
|
||||
if len(final_obj.ObjectMeta.Annotations) != 0 {
|
||||
t.Fatalf("unexpected annotations: %v", final_obj.ObjectMeta.Annotations)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
|
||||
data, err := runtime.Encode(legacyscheme.Codecs.LegacyCodec(SchemeGroupVersion), obj)
|
||||
if err != nil {
|
||||
|
@ -39,7 +39,9 @@ go_test(
|
||||
"//staging/src/k8s.io/api/autoscaling/v2beta1:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
||||
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
||||
"//vendor/k8s.io/utils/pointer:go_default_library",
|
||||
],
|
||||
|
@ -20,9 +20,12 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
|
||||
autoscalingv2beta1 "k8s.io/api/autoscaling/v2beta1"
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
||||
@ -105,6 +108,71 @@ func TestSetDefaultHPA(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHorizontalPodAutoscalerAnnotations(t *testing.T) {
|
||||
tests := []struct {
|
||||
hpa autoscalingv2beta1.HorizontalPodAutoscaler
|
||||
test string
|
||||
}{
|
||||
{
|
||||
hpa: autoscalingv2beta1.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
autoscaling.HorizontalPodAutoscalerConditionsAnnotation: "",
|
||||
autoscaling.MetricSpecsAnnotation: "",
|
||||
autoscaling.BehaviorSpecsAnnotation: "",
|
||||
autoscaling.MetricStatusesAnnotation: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
test: "test empty value for Annotations",
|
||||
},
|
||||
{
|
||||
hpa: autoscalingv2beta1.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
autoscaling.HorizontalPodAutoscalerConditionsAnnotation: "abc",
|
||||
autoscaling.MetricSpecsAnnotation: "abc",
|
||||
autoscaling.BehaviorSpecsAnnotation: "abc",
|
||||
autoscaling.MetricStatusesAnnotation: "abc",
|
||||
},
|
||||
},
|
||||
},
|
||||
test: "test random value for Annotations",
|
||||
},
|
||||
{
|
||||
hpa: autoscalingv2beta1.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
autoscaling.HorizontalPodAutoscalerConditionsAnnotation: "[]",
|
||||
autoscaling.MetricSpecsAnnotation: "[]",
|
||||
autoscaling.BehaviorSpecsAnnotation: "[]",
|
||||
autoscaling.MetricStatusesAnnotation: "[]",
|
||||
},
|
||||
},
|
||||
},
|
||||
test: "test empty array value for Annotations",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
hpa := &test.hpa
|
||||
hpaBeforeMuatate := *hpa.DeepCopy()
|
||||
obj := roundTrip(t, runtime.Object(hpa))
|
||||
final_obj, ok := obj.(*autoscalingv2beta1.HorizontalPodAutoscaler)
|
||||
if !ok {
|
||||
t.Fatalf("unexpected object: %v", obj)
|
||||
}
|
||||
if !reflect.DeepEqual(*hpa, hpaBeforeMuatate) {
|
||||
t.Errorf("diff: %v", diff.ObjectDiff(*hpa, hpaBeforeMuatate))
|
||||
t.Errorf("expected: %#v\n actual: %#v", *hpa, hpaBeforeMuatate)
|
||||
}
|
||||
|
||||
if len(final_obj.ObjectMeta.Annotations) != 0 {
|
||||
t.Fatalf("unexpected annotations: %v", final_obj.ObjectMeta.Annotations)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
|
||||
data, err := runtime.Encode(legacyscheme.Codecs.LegacyCodec(SchemeGroupVersion), obj)
|
||||
if err != nil {
|
||||
|
@ -44,7 +44,14 @@ go_test(
|
||||
srcs = ["defaults_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//pkg/api/legacyscheme:go_default_library",
|
||||
"//pkg/apis/autoscaling:go_default_library",
|
||||
"//pkg/apis/autoscaling/install:go_default_library",
|
||||
"//pkg/apis/core/install:go_default_library",
|
||||
"//staging/src/k8s.io/api/autoscaling/v2beta2:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
||||
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
||||
"//vendor/k8s.io/utils/pointer:go_default_library",
|
||||
],
|
||||
|
@ -17,13 +17,21 @@ limitations under the License.
|
||||
package v2beta2_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
|
||||
. "k8s.io/kubernetes/pkg/apis/autoscaling/v2beta2"
|
||||
utilpointer "k8s.io/utils/pointer"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
||||
_ "k8s.io/kubernetes/pkg/apis/autoscaling/install"
|
||||
. "k8s.io/kubernetes/pkg/apis/autoscaling/v2beta2"
|
||||
_ "k8s.io/kubernetes/pkg/apis/core/install"
|
||||
utilpointer "k8s.io/utils/pointer"
|
||||
)
|
||||
|
||||
func TestGenerateScaleDownRules(t *testing.T) {
|
||||
@ -229,3 +237,88 @@ func TestGenerateScaleUpRules(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHorizontalPodAutoscalerAnnotations(t *testing.T) {
|
||||
tests := []struct {
|
||||
hpa autoscalingv2.HorizontalPodAutoscaler
|
||||
test string
|
||||
}{
|
||||
{
|
||||
hpa: autoscalingv2.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
autoscaling.HorizontalPodAutoscalerConditionsAnnotation: "",
|
||||
autoscaling.MetricSpecsAnnotation: "",
|
||||
autoscaling.BehaviorSpecsAnnotation: "",
|
||||
autoscaling.MetricStatusesAnnotation: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
test: "test empty value for Annotations",
|
||||
},
|
||||
{
|
||||
hpa: autoscalingv2.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
autoscaling.HorizontalPodAutoscalerConditionsAnnotation: "abc",
|
||||
autoscaling.MetricSpecsAnnotation: "abc",
|
||||
autoscaling.BehaviorSpecsAnnotation: "abc",
|
||||
autoscaling.MetricStatusesAnnotation: "abc",
|
||||
},
|
||||
},
|
||||
},
|
||||
test: "test random value for Annotations",
|
||||
},
|
||||
{
|
||||
hpa: autoscalingv2.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
autoscaling.HorizontalPodAutoscalerConditionsAnnotation: "[]",
|
||||
autoscaling.MetricSpecsAnnotation: "[]",
|
||||
autoscaling.BehaviorSpecsAnnotation: "[]",
|
||||
autoscaling.MetricStatusesAnnotation: "[]",
|
||||
},
|
||||
},
|
||||
},
|
||||
test: "test empty array value for Annotations",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
hpa := &test.hpa
|
||||
hpaBeforeMuatate := *hpa.DeepCopy()
|
||||
obj := roundTrip(t, runtime.Object(hpa))
|
||||
final_obj, ok := obj.(*autoscalingv2.HorizontalPodAutoscaler)
|
||||
if !ok {
|
||||
t.Fatalf("unexpected object: %v", obj)
|
||||
}
|
||||
if !reflect.DeepEqual(*hpa, hpaBeforeMuatate) {
|
||||
t.Errorf("diff: %v", diff.ObjectDiff(*hpa, hpaBeforeMuatate))
|
||||
t.Errorf("expected: %#v\n actual: %#v", *hpa, hpaBeforeMuatate)
|
||||
}
|
||||
|
||||
if len(final_obj.ObjectMeta.Annotations) != 0 {
|
||||
t.Fatalf("unexpected annotations: %v", final_obj.ObjectMeta.Annotations)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
|
||||
data, err := runtime.Encode(legacyscheme.Codecs.LegacyCodec(SchemeGroupVersion), obj)
|
||||
if err != nil {
|
||||
t.Errorf("%v\n %#v", err, obj)
|
||||
return nil
|
||||
}
|
||||
obj2, err := runtime.Decode(legacyscheme.Codecs.UniversalDecoder(), data)
|
||||
if err != nil {
|
||||
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
|
||||
return nil
|
||||
}
|
||||
obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
|
||||
err = legacyscheme.Scheme.Convert(obj2, obj3, nil)
|
||||
if err != nil {
|
||||
t.Errorf("%v\nSource: %#v", err, obj2)
|
||||
return nil
|
||||
}
|
||||
return obj3
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user