...

Source file src/k8s.io/kubernetes/pkg/controlplane/import_known_versions_test.go

Documentation: k8s.io/kubernetes/pkg/controlplane

     1  /*
     2  Copyright 2016 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 controlplane
    18  
    19  import (
    20  	"reflect"
    21  	"testing"
    22  
    23  	v1 "k8s.io/api/core/v1"
    24  	apinamingtest "k8s.io/apimachinery/pkg/api/apitesting/naming"
    25  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    26  	"k8s.io/apimachinery/pkg/util/intstr"
    27  	"k8s.io/apimachinery/pkg/util/sets"
    28  	"k8s.io/kubernetes/pkg/api/legacyscheme"
    29  )
    30  
    31  func TestGroupVersions(t *testing.T) {
    32  	// legacyUnsuffixedGroups contains the groups released prior to deciding that kubernetes API groups should be dns-suffixed
    33  	// new groups should be suffixed with ".k8s.io" (https://github.com/kubernetes/kubernetes/pull/31887#issuecomment-244462396)
    34  	legacyUnsuffixedGroups := sets.NewString(
    35  		"",
    36  		"apps",
    37  		"autoscaling",
    38  		"batch",
    39  		"extensions",
    40  		"policy",
    41  	)
    42  
    43  	// No new groups should be added to the legacyUnsuffixedGroups exclusion list
    44  	if len(legacyUnsuffixedGroups) != 6 {
    45  		t.Errorf("No additional unnamespaced groups should be created")
    46  	}
    47  
    48  	if err := apinamingtest.VerifyGroupNames(legacyscheme.Scheme, legacyUnsuffixedGroups); err != nil {
    49  		t.Errorf("%v", err)
    50  	}
    51  }
    52  
    53  // These types are registered in external versions, and therefore include json tags,
    54  // but are also registered in internal versions (or referenced from internal types),
    55  // so we explicitly allow tags for them
    56  var typesAllowedTags = map[reflect.Type]bool{
    57  	reflect.TypeOf(intstr.IntOrString{}):          true,
    58  	reflect.TypeOf(metav1.Time{}):                 true,
    59  	reflect.TypeOf(metav1.MicroTime{}):            true,
    60  	reflect.TypeOf(metav1.Duration{}):             true,
    61  	reflect.TypeOf(metav1.TypeMeta{}):             true,
    62  	reflect.TypeOf(metav1.ListMeta{}):             true,
    63  	reflect.TypeOf(metav1.ObjectMeta{}):           true,
    64  	reflect.TypeOf(metav1.OwnerReference{}):       true,
    65  	reflect.TypeOf(metav1.LabelSelector{}):        true,
    66  	reflect.TypeOf(metav1.GetOptions{}):           true,
    67  	reflect.TypeOf(metav1.ListOptions{}):          true,
    68  	reflect.TypeOf(metav1.DeleteOptions{}):        true,
    69  	reflect.TypeOf(metav1.GroupVersionKind{}):     true,
    70  	reflect.TypeOf(metav1.GroupVersionResource{}): true,
    71  	reflect.TypeOf(metav1.Status{}):               true,
    72  	reflect.TypeOf(metav1.Condition{}):            true,
    73  }
    74  
    75  // These fields are limited exceptions to the standard JSON naming structure.
    76  // Additions should only be made if a non-standard field name was released and cannot be changed for compatibility reasons.
    77  var allowedNonstandardJSONNames = map[reflect.Type]string{
    78  	reflect.TypeOf(v1.DaemonEndpoint{}): "Port",
    79  }
    80  
    81  func TestTypeTags(t *testing.T) {
    82  	if err := apinamingtest.VerifyTagNaming(legacyscheme.Scheme, typesAllowedTags, allowedNonstandardJSONNames); err != nil {
    83  		t.Errorf("%v", err)
    84  	}
    85  }
    86  

View as plain text