Bumping k8s dependencies to 1.13
This commit is contained in:
435
vendor/k8s.io/kubernetes/pkg/printers/internalversion/describe_test.go
generated
vendored
435
vendor/k8s.io/kubernetes/pkg/printers/internalversion/describe_test.go
generated
vendored
@@ -43,7 +43,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
||||
"k8s.io/kubernetes/pkg/printers"
|
||||
utilpointer "k8s.io/kubernetes/pkg/util/pointer"
|
||||
utilpointer "k8s.io/utils/pointer"
|
||||
)
|
||||
|
||||
type describeClient struct {
|
||||
@@ -54,10 +54,14 @@ type describeClient struct {
|
||||
}
|
||||
|
||||
func TestDescribePod(t *testing.T) {
|
||||
deletionTimestamp := metav1.Time{Time: time.Now().UTC().AddDate(10, 0, 0)}
|
||||
gracePeriod := int64(1234)
|
||||
fake := fake.NewSimpleClientset(&api.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
Namespace: "foo",
|
||||
Name: "bar",
|
||||
Namespace: "foo",
|
||||
DeletionTimestamp: &deletionTimestamp,
|
||||
DeletionGracePeriodSeconds: &gracePeriod,
|
||||
},
|
||||
})
|
||||
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
||||
@@ -69,6 +73,9 @@ func TestDescribePod(t *testing.T) {
|
||||
if !strings.Contains(out, "bar") || !strings.Contains(out, "Status:") {
|
||||
t.Errorf("unexpected out: %s", out)
|
||||
}
|
||||
if !strings.Contains(out, "Terminating (lasts 10y)") || !strings.Contains(out, "1234s") {
|
||||
t.Errorf("unexpected out: %s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDescribePodNode(t *testing.T) {
|
||||
@@ -458,14 +465,12 @@ func VerifyDatesInOrder(
|
||||
func TestDescribeContainers(t *testing.T) {
|
||||
trueVal := true
|
||||
testCases := []struct {
|
||||
name string
|
||||
container api.Container
|
||||
status api.ContainerStatus
|
||||
expectedElements []string
|
||||
}{
|
||||
// Running state.
|
||||
{
|
||||
name: "test1",
|
||||
container: api.Container{Name: "test", Image: "image"},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
@@ -481,7 +486,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
},
|
||||
// Waiting state.
|
||||
{
|
||||
name: "test2",
|
||||
container: api.Container{Name: "test", Image: "image"},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
@@ -497,7 +501,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
},
|
||||
// Terminated state.
|
||||
{
|
||||
name: "test3",
|
||||
container: api.Container{Name: "test", Image: "image"},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
@@ -516,7 +519,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
},
|
||||
// Last Terminated
|
||||
{
|
||||
name: "test4",
|
||||
container: api.Container{Name: "test", Image: "image"},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
@@ -540,7 +542,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
},
|
||||
// No state defaults to waiting.
|
||||
{
|
||||
name: "test5",
|
||||
container: api.Container{Name: "test", Image: "image"},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
@@ -551,7 +552,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
},
|
||||
// Env
|
||||
{
|
||||
name: "test6",
|
||||
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{ConfigMapRef: &api.ConfigMapEnvSource{LocalObjectReference: api.LocalObjectReference{Name: "a123"}}}}},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
@@ -561,7 +561,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz", "a123\tConfigMap\tOptional: false"},
|
||||
},
|
||||
{
|
||||
name: "test7",
|
||||
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{Prefix: "p_", ConfigMapRef: &api.ConfigMapEnvSource{LocalObjectReference: api.LocalObjectReference{Name: "a123"}}}}},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
@@ -571,7 +570,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz", "a123\tConfigMap with prefix 'p_'\tOptional: false"},
|
||||
},
|
||||
{
|
||||
name: "test8",
|
||||
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{ConfigMapRef: &api.ConfigMapEnvSource{Optional: &trueVal, LocalObjectReference: api.LocalObjectReference{Name: "a123"}}}}},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
@@ -581,7 +579,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz", "a123\tConfigMap\tOptional: true"},
|
||||
},
|
||||
{
|
||||
name: "test9",
|
||||
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{SecretRef: &api.SecretEnvSource{LocalObjectReference: api.LocalObjectReference{Name: "a123"}, Optional: &trueVal}}}},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
@@ -591,7 +588,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz", "a123\tSecret\tOptional: true"},
|
||||
},
|
||||
{
|
||||
name: "test10",
|
||||
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{Prefix: "p_", SecretRef: &api.SecretEnvSource{LocalObjectReference: api.LocalObjectReference{Name: "a123"}}}}},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
@@ -602,7 +598,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
},
|
||||
// Command
|
||||
{
|
||||
name: "test11",
|
||||
container: api.Container{Name: "test", Image: "image", Command: []string{"sleep", "1000"}},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
@@ -611,9 +606,18 @@ func TestDescribeContainers(t *testing.T) {
|
||||
},
|
||||
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "sleep", "1000"},
|
||||
},
|
||||
// Command with newline
|
||||
{
|
||||
container: api.Container{Name: "test", Image: "image", Command: []string{"sleep", "1000\n2000"}},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
Ready: true,
|
||||
RestartCount: 7,
|
||||
},
|
||||
expectedElements: []string{"1000\n 2000"},
|
||||
},
|
||||
// Args
|
||||
{
|
||||
name: "test12",
|
||||
container: api.Container{Name: "test", Image: "image", Args: []string{"time", "1000"}},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
@@ -622,9 +626,18 @@ func TestDescribeContainers(t *testing.T) {
|
||||
},
|
||||
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "time", "1000"},
|
||||
},
|
||||
// Args with newline
|
||||
{
|
||||
container: api.Container{Name: "test", Image: "image", Args: []string{"time", "1000\n2000"}},
|
||||
status: api.ContainerStatus{
|
||||
Name: "test",
|
||||
Ready: true,
|
||||
RestartCount: 7,
|
||||
},
|
||||
expectedElements: []string{"1000\n 2000"},
|
||||
},
|
||||
// Using limits.
|
||||
{
|
||||
name: "test13",
|
||||
container: api.Container{
|
||||
Name: "test",
|
||||
Image: "image",
|
||||
@@ -645,7 +658,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
},
|
||||
// Using requests.
|
||||
{
|
||||
name: "test14",
|
||||
container: api.Container{
|
||||
Name: "test",
|
||||
Image: "image",
|
||||
@@ -661,7 +673,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
},
|
||||
// volumeMounts read/write
|
||||
{
|
||||
name: "test15",
|
||||
container: api.Container{
|
||||
Name: "test",
|
||||
Image: "image",
|
||||
@@ -676,7 +687,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
},
|
||||
// volumeMounts readonly
|
||||
{
|
||||
name: "test16",
|
||||
container: api.Container{
|
||||
Name: "test",
|
||||
Image: "image",
|
||||
@@ -693,7 +703,6 @@ func TestDescribeContainers(t *testing.T) {
|
||||
|
||||
// volumeDevices
|
||||
{
|
||||
name: "test17",
|
||||
container: api.Container{
|
||||
Name: "test",
|
||||
Image: "image",
|
||||
@@ -709,7 +718,7 @@ func TestDescribeContainers(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||
out := new(bytes.Buffer)
|
||||
pod := api.Pod{
|
||||
Spec: api.PodSpec{
|
||||
@@ -892,6 +901,7 @@ func TestGetPodsTotalRequests(t *testing.T) {
|
||||
func TestPersistentVolumeDescriber(t *testing.T) {
|
||||
block := api.PersistentVolumeBlock
|
||||
file := api.PersistentVolumeFilesystem
|
||||
deletionTimestamp := metav1.Time{Time: time.Now().UTC().AddDate(10, 0, 0)}
|
||||
testCases := []struct {
|
||||
name string
|
||||
plugin string
|
||||
@@ -1137,6 +1147,96 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
||||
"foo in [val1, val2]",
|
||||
"foo exists"},
|
||||
},
|
||||
{
|
||||
name: "test15",
|
||||
plugin: "local",
|
||||
pv: &api.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
DeletionTimestamp: &deletionTimestamp,
|
||||
},
|
||||
Spec: api.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||
Local: &api.LocalVolumeSource{},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedElements: []string{"Terminating (lasts 10y)"},
|
||||
},
|
||||
{
|
||||
name: "test16",
|
||||
plugin: "local",
|
||||
pv: &api.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
GenerateName: "test-GenerateName",
|
||||
UID: "test-UID",
|
||||
CreationTimestamp: metav1.Time{Time: time.Now()},
|
||||
DeletionTimestamp: &metav1.Time{Time: time.Now()},
|
||||
DeletionGracePeriodSeconds: new(int64),
|
||||
Labels: map[string]string{"label1": "label1", "label2": "label2", "label3": "label3"},
|
||||
Annotations: map[string]string{"annotation1": "annotation1", "annotation2": "annotation2", "annotation3": "annotation3"},
|
||||
},
|
||||
Spec: api.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||
Local: &api.LocalVolumeSource{},
|
||||
},
|
||||
NodeAffinity: &api.VolumeNodeAffinity{
|
||||
Required: &api.NodeSelector{
|
||||
NodeSelectorTerms: []api.NodeSelectorTerm{
|
||||
{
|
||||
MatchExpressions: []api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "foo",
|
||||
Operator: "In",
|
||||
Values: []string{"val1", "val2"},
|
||||
},
|
||||
{
|
||||
Key: "foo",
|
||||
Operator: "Exists",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedElements: []string{"Node Affinity", "Required Terms", "Term 0",
|
||||
"foo in [val1, val2]",
|
||||
"foo exists"},
|
||||
},
|
||||
{
|
||||
name: "test17",
|
||||
plugin: "local",
|
||||
pv: &api.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
GenerateName: "test-GenerateName",
|
||||
UID: "test-UID",
|
||||
CreationTimestamp: metav1.Time{Time: time.Now()},
|
||||
DeletionTimestamp: &metav1.Time{Time: time.Now()},
|
||||
DeletionGracePeriodSeconds: new(int64),
|
||||
Labels: map[string]string{"label1": "label1", "label2": "label2", "label3": "label3"},
|
||||
Annotations: map[string]string{"annotation1": "annotation1", "annotation2": "annotation2", "annotation3": "annotation3"},
|
||||
},
|
||||
Spec: api.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||
CSI: &api.CSIPersistentVolumeSource{
|
||||
Driver: "drive",
|
||||
VolumeHandle: "handler",
|
||||
ReadOnly: true,
|
||||
VolumeAttributes: map[string]string{
|
||||
"Attribute1": "Value1",
|
||||
"Attribute2": "Value2",
|
||||
"Attribute3": "Value3",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedElements: []string{"Driver", "VolumeHandle", "ReadOnly", "VolumeAttributes"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
@@ -1169,6 +1269,7 @@ func TestPersistentVolumeClaimDescriber(t *testing.T) {
|
||||
file := api.PersistentVolumeFilesystem
|
||||
goldClassName := "gold"
|
||||
now := time.Now()
|
||||
deletionTimestamp := metav1.Time{Time: time.Now().UTC().AddDate(10, 0, 0)}
|
||||
testCases := []struct {
|
||||
name string
|
||||
pvc *api.PersistentVolumeClaim
|
||||
@@ -1316,6 +1417,22 @@ func TestPersistentVolumeClaimDescriber(t *testing.T) {
|
||||
},
|
||||
expectedElements: []string{"Conditions", "Message", "User request resize"},
|
||||
},
|
||||
{
|
||||
name: "deletion-timestamp",
|
||||
pvc: &api.PersistentVolumeClaim{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: "foo",
|
||||
Name: "bar",
|
||||
DeletionTimestamp: &deletionTimestamp,
|
||||
},
|
||||
Spec: api.PersistentVolumeClaimSpec{
|
||||
VolumeName: "volume10",
|
||||
StorageClassName: &goldClassName,
|
||||
},
|
||||
Status: api.PersistentVolumeClaimStatus{},
|
||||
},
|
||||
expectedElements: []string{"Terminating (lasts 10y)"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
@@ -1390,6 +1507,32 @@ func TestDescribeStorageClass(t *testing.T) {
|
||||
},
|
||||
ReclaimPolicy: &reclaimPolicy,
|
||||
VolumeBindingMode: &bindingMode,
|
||||
AllowedTopologies: []api.TopologySelectorTerm{
|
||||
{
|
||||
MatchLabelExpressions: []api.TopologySelectorLabelRequirement{
|
||||
{
|
||||
Key: "failure-domain.beta.kubernetes.io/zone",
|
||||
Values: []string{"zone1"},
|
||||
},
|
||||
{
|
||||
Key: "kubernetes.io/hostname",
|
||||
Values: []string{"node1"},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
MatchLabelExpressions: []api.TopologySelectorLabelRequirement{
|
||||
{
|
||||
Key: "failure-domain.beta.kubernetes.io/zone",
|
||||
Values: []string{"zone2"},
|
||||
},
|
||||
{
|
||||
Key: "kubernetes.io/hostname",
|
||||
Values: []string{"node2"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
s := StorageClassDescriber{f}
|
||||
out, err := s.Describe("", "foo", printers.DescriberSettings{ShowEvents: true})
|
||||
@@ -1403,7 +1546,13 @@ func TestDescribeStorageClass(t *testing.T) {
|
||||
!strings.Contains(out, "value1") ||
|
||||
!strings.Contains(out, "value2") ||
|
||||
!strings.Contains(out, "Retain") ||
|
||||
!strings.Contains(out, "bindingmode") {
|
||||
!strings.Contains(out, "bindingmode") ||
|
||||
!strings.Contains(out, "failure-domain.beta.kubernetes.io/zone") ||
|
||||
!strings.Contains(out, "zone1") ||
|
||||
!strings.Contains(out, "kubernetes.io/hostname") ||
|
||||
!strings.Contains(out, "node1") ||
|
||||
!strings.Contains(out, "zone2") ||
|
||||
!strings.Contains(out, "node2") {
|
||||
t.Errorf("unexpected out: %s", out)
|
||||
}
|
||||
}
|
||||
@@ -1440,6 +1589,10 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
minReplicasVal := int32(2)
|
||||
targetUtilizationVal := int32(80)
|
||||
currentUtilizationVal := int32(50)
|
||||
metricLabelSelector, err := metav1.ParseToLabelSelector("label=value")
|
||||
if err != nil {
|
||||
t.Errorf("unable to parse label selector: %v", err)
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
hpa autoscaling.HorizontalPodAutoscaler
|
||||
@@ -1474,13 +1627,14 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-external-metric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
MetricName: "some-external-metric",
|
||||
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1505,13 +1659,14 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-external-metric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
MetricName: "some-external-metric",
|
||||
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1523,13 +1678,13 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricStatus{
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-external-metric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Current: autoscaling.MetricValueStatus{
|
||||
AverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
|
||||
},
|
||||
MetricName: "some-external-metric",
|
||||
CurrentAverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1550,13 +1705,14 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-external-metric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
MetricName: "some-external-metric",
|
||||
TargetValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1581,13 +1737,14 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricSource{
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-external-metric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
MetricName: "some-external-metric",
|
||||
TargetValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1599,13 +1756,13 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ExternalMetricSourceType,
|
||||
External: &autoscaling.ExternalMetricStatus{
|
||||
MetricSelector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"label": "value",
|
||||
},
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-external-metric",
|
||||
Selector: metricLabelSelector,
|
||||
},
|
||||
Current: autoscaling.MetricValueStatus{
|
||||
Value: resource.NewMilliQuantity(50, resource.DecimalSI),
|
||||
},
|
||||
MetricName: "some-external-metric",
|
||||
CurrentValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1626,8 +1783,13 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.PodsMetricSourceType,
|
||||
Pods: &autoscaling.PodsMetricSource{
|
||||
MetricName: "some-pods-metric",
|
||||
TargetAverageValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-pods-metric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1652,8 +1814,13 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.PodsMetricSourceType,
|
||||
Pods: &autoscaling.PodsMetricSource{
|
||||
MetricName: "some-pods-metric",
|
||||
TargetAverageValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-pods-metric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1665,8 +1832,12 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.PodsMetricSourceType,
|
||||
Pods: &autoscaling.PodsMetricStatus{
|
||||
MetricName: "some-pods-metric",
|
||||
CurrentAverageValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-pods-metric",
|
||||
},
|
||||
Current: autoscaling.MetricValueStatus{
|
||||
AverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1687,12 +1858,17 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ObjectMetricSourceType,
|
||||
Object: &autoscaling.ObjectMetricSource{
|
||||
Target: autoscaling.CrossVersionObjectReference{
|
||||
DescribedObject: autoscaling.CrossVersionObjectReference{
|
||||
Name: "some-service",
|
||||
Kind: "Service",
|
||||
},
|
||||
MetricName: "some-service-metric",
|
||||
TargetValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-service-metric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1717,12 +1893,17 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ObjectMetricSourceType,
|
||||
Object: &autoscaling.ObjectMetricSource{
|
||||
Target: autoscaling.CrossVersionObjectReference{
|
||||
DescribedObject: autoscaling.CrossVersionObjectReference{
|
||||
Name: "some-service",
|
||||
Kind: "Service",
|
||||
},
|
||||
MetricName: "some-service-metric",
|
||||
TargetValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-service-metric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.ValueMetricType,
|
||||
Value: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1734,12 +1915,16 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ObjectMetricSourceType,
|
||||
Object: &autoscaling.ObjectMetricStatus{
|
||||
Target: autoscaling.CrossVersionObjectReference{
|
||||
DescribedObject: autoscaling.CrossVersionObjectReference{
|
||||
Name: "some-service",
|
||||
Kind: "Service",
|
||||
},
|
||||
MetricName: "some-service-metric",
|
||||
CurrentValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-service-metric",
|
||||
},
|
||||
Current: autoscaling.MetricValueStatus{
|
||||
Value: resource.NewMilliQuantity(50, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1760,8 +1945,11 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Name: api.ResourceCPU,
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1786,8 +1974,11 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Name: api.ResourceCPU,
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1799,8 +1990,10 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricStatus{
|
||||
Name: api.ResourceCPU,
|
||||
CurrentAverageValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
|
||||
Name: api.ResourceCPU,
|
||||
Current: autoscaling.MetricValueStatus{
|
||||
AverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1822,7 +2015,10 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageUtilization: &targetUtilizationVal,
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.UtilizationMetricType,
|
||||
AverageUtilization: &targetUtilizationVal,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1848,7 +2044,10 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageUtilization: &targetUtilizationVal,
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.UtilizationMetricType,
|
||||
AverageUtilization: &targetUtilizationVal,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1861,8 +2060,10 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricStatus{
|
||||
Name: api.ResourceCPU,
|
||||
CurrentAverageUtilization: ¤tUtilizationVal,
|
||||
CurrentAverageValue: *resource.NewMilliQuantity(40, resource.DecimalSI),
|
||||
Current: autoscaling.MetricValueStatus{
|
||||
AverageUtilization: ¤tUtilizationVal,
|
||||
AverageValue: resource.NewMilliQuantity(40, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1883,22 +2084,35 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.PodsMetricSourceType,
|
||||
Pods: &autoscaling.PodsMetricSource{
|
||||
MetricName: "some-pods-metric",
|
||||
TargetAverageValue: *resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-pods-metric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(100, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricSource{
|
||||
Name: api.ResourceCPU,
|
||||
TargetAverageUtilization: &targetUtilizationVal,
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.UtilizationMetricType,
|
||||
AverageUtilization: &targetUtilizationVal,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: autoscaling.PodsMetricSourceType,
|
||||
Pods: &autoscaling.PodsMetricSource{
|
||||
MetricName: "other-pods-metric",
|
||||
TargetAverageValue: *resource.NewMilliQuantity(400, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "other-pods-metric",
|
||||
},
|
||||
Target: autoscaling.MetricTarget{
|
||||
Type: autoscaling.AverageValueMetricType,
|
||||
AverageValue: resource.NewMilliQuantity(400, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1910,16 +2124,22 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
||||
{
|
||||
Type: autoscaling.PodsMetricSourceType,
|
||||
Pods: &autoscaling.PodsMetricStatus{
|
||||
MetricName: "some-pods-metric",
|
||||
CurrentAverageValue: *resource.NewMilliQuantity(50, resource.DecimalSI),
|
||||
Metric: autoscaling.MetricIdentifier{
|
||||
Name: "some-pods-metric",
|
||||
},
|
||||
Current: autoscaling.MetricValueStatus{
|
||||
AverageValue: resource.NewMilliQuantity(50, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: autoscaling.ResourceMetricSourceType,
|
||||
Resource: &autoscaling.ResourceMetricStatus{
|
||||
Name: api.ResourceCPU,
|
||||
CurrentAverageUtilization: ¤tUtilizationVal,
|
||||
CurrentAverageValue: *resource.NewMilliQuantity(40, resource.DecimalSI),
|
||||
Current: autoscaling.MetricValueStatus{
|
||||
AverageUtilization: ¤tUtilizationVal,
|
||||
AverageValue: resource.NewMilliQuantity(40, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2101,22 +2321,31 @@ func TestDescribeEvents(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPrintLabelsMultiline(t *testing.T) {
|
||||
var maxLenAnnotationStr string = "MaxLenAnnotation=Multicast addressing can be used in the link layer (Layer 2 in the OSI model), such as Ethernet multicast, and at the internet layer (Layer 3 for OSI) for Internet Protocol Version 4 "
|
||||
key := "MaxLenAnnotation"
|
||||
value := strings.Repeat("a", maxAnnotationLen-len(key)-2)
|
||||
testCases := []struct {
|
||||
annotations map[string]string
|
||||
expectPrint string
|
||||
}{
|
||||
{
|
||||
annotations: map[string]string{"col1": "asd", "COL2": "zxc"},
|
||||
expectPrint: "Annotations:\tCOL2=zxc\n\tcol1=asd\n",
|
||||
expectPrint: "Annotations:\tCOL2: zxc\n\tcol1: asd\n",
|
||||
},
|
||||
{
|
||||
annotations: map[string]string{"MaxLenAnnotation": maxLenAnnotationStr[17:]},
|
||||
expectPrint: "Annotations:\t" + maxLenAnnotationStr + "\n",
|
||||
annotations: map[string]string{"MaxLenAnnotation": value},
|
||||
expectPrint: fmt.Sprintf("Annotations:\t%s: %s\n", key, value),
|
||||
},
|
||||
{
|
||||
annotations: map[string]string{"MaxLenAnnotation": maxLenAnnotationStr[17:] + "1"},
|
||||
expectPrint: "Annotations:\t" + maxLenAnnotationStr + "...\n",
|
||||
annotations: map[string]string{"MaxLenAnnotation": value + "1"},
|
||||
expectPrint: fmt.Sprintf("Annotations:\t%s:\n\t %s\n", key, value+"1"),
|
||||
},
|
||||
{
|
||||
annotations: map[string]string{"MaxLenAnnotation": value + value},
|
||||
expectPrint: fmt.Sprintf("Annotations:\t%s:\n\t %s\n", key, strings.Repeat("a", maxAnnotationLen-2)+"..."),
|
||||
},
|
||||
{
|
||||
annotations: map[string]string{"key": "value\nwith\nnewlines\n"},
|
||||
expectPrint: "Annotations:\tkey:\n\t value\n\t with\n\t newlines\n",
|
||||
},
|
||||
{
|
||||
annotations: map[string]string{},
|
||||
@@ -2124,13 +2353,13 @@ func TestPrintLabelsMultiline(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for i, testCase := range testCases {
|
||||
t.Run(testCase.expectPrint, func(t *testing.T) {
|
||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||
out := new(bytes.Buffer)
|
||||
writer := NewPrefixWriter(out)
|
||||
printAnnotationsMultiline(writer, "Annotations", testCase.annotations)
|
||||
output := out.String()
|
||||
if output != testCase.expectPrint {
|
||||
t.Errorf("Test case %d: expected to find %q in output: %q", i, testCase.expectPrint, output)
|
||||
t.Errorf("Test case %d: expected to match:\n%q\nin output:\n%q", i, testCase.expectPrint, output)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -2228,6 +2457,8 @@ func TestDescribePodSecurityPolicy(t *testing.T) {
|
||||
"Required Drop Capabilities:\\s*<none>",
|
||||
"Allowed Capabilities:\\s*<none>",
|
||||
"Allowed Volume Types:\\s*<none>",
|
||||
"Allowed Unsafe Sysctls:\\s*kernel\\.\\*,net\\.ipv4.ip_local_port_range",
|
||||
"Forbidden Sysctls:\\s*net\\.ipv4\\.ip_default_ttl",
|
||||
"Allow Host Network:\\s*false",
|
||||
"Allow Host Ports:\\s*<none>",
|
||||
"Allow Host PID:\\s*false",
|
||||
@@ -2248,6 +2479,8 @@ func TestDescribePodSecurityPolicy(t *testing.T) {
|
||||
Name: "mypsp",
|
||||
},
|
||||
Spec: policy.PodSecurityPolicySpec{
|
||||
AllowedUnsafeSysctls: []string{"kernel.*", "net.ipv4.ip_local_port_range"},
|
||||
ForbiddenSysctls: []string{"net.ipv4.ip_default_ttl"},
|
||||
SELinux: policy.SELinuxStrategyOptions{
|
||||
Rule: policy.SELinuxStrategyRunAsAny,
|
||||
},
|
||||
|
Reference in New Issue
Block a user