...

Source file src/k8s.io/kubernetes/pkg/features/kube_features_test.go

Documentation: k8s.io/kubernetes/pkg/features

     1  /*
     2  Copyright 2024 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 features
    18  
    19  import (
    20  	"testing"
    21  
    22  	utilfeature "k8s.io/apiserver/pkg/util/feature"
    23  	clientfeatures "k8s.io/client-go/features"
    24  	"k8s.io/component-base/featuregate"
    25  )
    26  
    27  // TestKubeFeaturesRegistered tests that all kube features are registered.
    28  func TestKubeFeaturesRegistered(t *testing.T) {
    29  	registeredFeatures := utilfeature.DefaultFeatureGate.DeepCopy().GetAll()
    30  
    31  	for featureName := range defaultKubernetesFeatureGates {
    32  		if _, ok := registeredFeatures[featureName]; !ok {
    33  			t.Errorf("The feature gate %q is not registered in the DefaultFeatureGate", featureName)
    34  		}
    35  	}
    36  }
    37  
    38  // TestClientFeaturesRegistered tests that all client features are registered.
    39  func TestClientFeaturesRegistered(t *testing.T) {
    40  	onlyClientFg := featuregate.NewFeatureGate()
    41  	if err := clientfeatures.AddFeaturesToExistingFeatureGates(&clientAdapter{onlyClientFg}); err != nil {
    42  		t.Fatal(err)
    43  	}
    44  	registeredFeatures := utilfeature.DefaultFeatureGate.DeepCopy().GetAll()
    45  
    46  	for featureName := range onlyClientFg.GetAll() {
    47  		if _, ok := registeredFeatures[featureName]; !ok {
    48  			t.Errorf("The client-go's feature gate %q is not registered in the DefaultFeatureGate", featureName)
    49  		}
    50  	}
    51  }
    52  
    53  // TestAllRegisteredFeaturesExpected tests that the set of features actually registered does not
    54  // include any features other than those on the list in this package or in client-go's feature
    55  // package.
    56  func TestAllRegisteredFeaturesExpected(t *testing.T) {
    57  	registeredFeatures := utilfeature.DefaultFeatureGate.DeepCopy().GetAll()
    58  	knownFeatureGates := featuregate.NewFeatureGate()
    59  	if err := clientfeatures.AddFeaturesToExistingFeatureGates(&clientAdapter{knownFeatureGates}); err != nil {
    60  		t.Fatal(err)
    61  	}
    62  	if err := knownFeatureGates.Add(defaultKubernetesFeatureGates); err != nil {
    63  		t.Fatal(err)
    64  	}
    65  	knownFeatures := knownFeatureGates.GetAll()
    66  
    67  	for registeredFeature := range registeredFeatures {
    68  		if _, ok := knownFeatures[registeredFeature]; !ok {
    69  			t.Errorf("The feature gate %q is not from known feature gates", registeredFeature)
    70  		}
    71  	}
    72  }
    73  

View as plain text