k8s.io/kubernetes@v1.29.3/pkg/api/node/util_test.go (about)

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package node
    18  
    19  import (
    20  	"testing"
    21  
    22  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    23  	"k8s.io/apimachinery/pkg/util/sets"
    24  
    25  	"k8s.io/kubernetes/pkg/apis/node"
    26  )
    27  
    28  func TestWarnings(t *testing.T) {
    29  	testcases := []struct {
    30  		name     string
    31  		template *node.RuntimeClass
    32  		expected []string
    33  	}{
    34  		{
    35  			name:     "null",
    36  			template: nil,
    37  			expected: nil,
    38  		},
    39  		{
    40  			name: "no warning",
    41  			template: &node.RuntimeClass{
    42  				ObjectMeta: metav1.ObjectMeta{
    43  					Name: "foo",
    44  				},
    45  			},
    46  			expected: nil,
    47  		},
    48  		{
    49  			name: "warning",
    50  			template: &node.RuntimeClass{
    51  				ObjectMeta: metav1.ObjectMeta{
    52  					Name: "foo",
    53  				},
    54  				Scheduling: &node.Scheduling{
    55  					NodeSelector: map[string]string{
    56  						"beta.kubernetes.io/arch": "amd64",
    57  						"beta.kubernetes.io/os":   "linux",
    58  					},
    59  				},
    60  			},
    61  			expected: []string{
    62  				`scheduling.nodeSelector: deprecated since v1.14; use "kubernetes.io/arch" instead`,
    63  				`scheduling.nodeSelector: deprecated since v1.14; use "kubernetes.io/os" instead`,
    64  			},
    65  		},
    66  	}
    67  
    68  	for _, tc := range testcases {
    69  		t.Run("podspec_"+tc.name, func(t *testing.T) {
    70  			actual := sets.NewString(GetWarningsForRuntimeClass(tc.template)...)
    71  			expected := sets.NewString(tc.expected...)
    72  			for _, missing := range expected.Difference(actual).List() {
    73  				t.Errorf("missing: %s", missing)
    74  			}
    75  			for _, extra := range actual.Difference(expected).List() {
    76  				t.Errorf("extra: %s", extra)
    77  			}
    78  		})
    79  
    80  	}
    81  }