sigs.k8s.io/kueue@v0.6.2/pkg/features/kube_features.go (about)

     1  /*
     2  Copyright 2023 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  	"fmt"
    21  	"testing"
    22  
    23  	"k8s.io/apimachinery/pkg/util/runtime"
    24  	utilfeature "k8s.io/apiserver/pkg/util/feature"
    25  	"k8s.io/component-base/featuregate"
    26  	featuregatetesting "k8s.io/component-base/featuregate/testing"
    27  )
    28  
    29  const (
    30  	// owner: @trasc
    31  	// kep: https://github.com/kubernetes-sigs/kueue/tree/main/keps/420-partial-admission
    32  	// alpha: v0.4
    33  	// beta: v0.5
    34  	//
    35  	// Enables partial admission.
    36  	PartialAdmission featuregate.Feature = "PartialAdmission"
    37  
    38  	// owner: @stuton
    39  	// kep: https://github.com/kubernetes-sigs/kueue/tree/main/keps/168-pending-workloads-visibility
    40  	// alpha: v0.5
    41  	//
    42  	// Enables queue visibility.
    43  	QueueVisibility featuregate.Feature = "QueueVisibility"
    44  
    45  	// owner: @KunWuLuan
    46  	// kep: https://github.com/kubernetes-sigs/kueue/tree/main/keps/582-preempt-based-on-flavor-order
    47  	// beta: v0.5
    48  	//
    49  	// Enables flavor fungibility.
    50  	FlavorFungibility featuregate.Feature = "FlavorFungibility"
    51  
    52  	// owner: @trasc
    53  	// kep: https://github.com/kubernetes-sigs/kueue/tree/main/keps/1136-provisioning-request-support
    54  	// alpha: v0.5
    55  	//
    56  	// Enables Provisioning Admission Check Controller.
    57  	ProvisioningACC featuregate.Feature = "ProvisioningACC"
    58  
    59  	// owner: @pbundyra
    60  	// kep: https://github.com/kubernetes-sigs/kueue/pull/1300
    61  	// alpha: v0.6
    62  	//
    63  	// Enables Kueue visibility on demand
    64  	VisibilityOnDemand featuregate.Feature = "VisibilityOnDemand"
    65  
    66  	// owner: @yaroslava-serdiuk
    67  	// kep: https://github.com/kubernetes-sigs/kueue/issues/1283
    68  	// beta: v0.6
    69  	//
    70  	// Enable priority sorting within the cohort.
    71  	PrioritySortingWithinCohort featuregate.Feature = "PrioritySortingWithinCohort"
    72  
    73  	// owner: @trasc
    74  	// kep: https://github.com/kubernetes-sigs/kueue/tree/main/keps/693-multikueue
    75  	// alpha: v0.6
    76  	//
    77  	// Enables MultiKueue support.
    78  	MultiKueue featuregate.Feature = "MultiKueue"
    79  
    80  	// owners: @B1F030, @kerthcet
    81  	// kep: https://github.com/kubernetes-sigs/kueue/tree/main/keps/1224-lending-limit
    82  	// alpha: v0.6
    83  	//
    84  	// Enables lending limit.
    85  	LendingLimit featuregate.Feature = "LendingLimit"
    86  )
    87  
    88  func init() {
    89  	runtime.Must(utilfeature.DefaultMutableFeatureGate.Add(defaultFeatureGates))
    90  }
    91  
    92  // defaultFeatureGates consists of all known Kueue-specific feature keys.
    93  // To add a new feature, define a key for it above and add it here. The features will be
    94  // available throughout Kueue binaries.
    95  //
    96  // Entries are separated from each other with blank lines to avoid sweeping gofmt changes
    97  // when adding or removing one entry.
    98  var defaultFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
    99  	PartialAdmission:            {Default: true, PreRelease: featuregate.Beta},
   100  	QueueVisibility:             {Default: false, PreRelease: featuregate.Alpha},
   101  	FlavorFungibility:           {Default: true, PreRelease: featuregate.Beta},
   102  	ProvisioningACC:             {Default: false, PreRelease: featuregate.Alpha},
   103  	VisibilityOnDemand:          {Default: false, PreRelease: featuregate.Alpha},
   104  	PrioritySortingWithinCohort: {Default: true, PreRelease: featuregate.Beta},
   105  	MultiKueue:                  {Default: false, PreRelease: featuregate.Alpha},
   106  	LendingLimit:                {Default: false, PreRelease: featuregate.Alpha},
   107  }
   108  
   109  func SetFeatureGateDuringTest(tb testing.TB, f featuregate.Feature, value bool) func() {
   110  	return featuregatetesting.SetFeatureGateDuringTest(tb, utilfeature.DefaultFeatureGate, f, value)
   111  }
   112  
   113  // Enabled is helper for `utilfeature.DefaultFeatureGate.Enabled()`
   114  func Enabled(f featuregate.Feature) bool {
   115  	return utilfeature.DefaultFeatureGate.Enabled(f)
   116  }
   117  
   118  // SetEnable helper function that can be used to set the enabled value of a feature gate,
   119  // it should only be used in integration test pending the merge of
   120  // https://github.com/kubernetes/kubernetes/pull/118346
   121  func SetEnable(f featuregate.Feature, v bool) error {
   122  	return utilfeature.DefaultMutableFeatureGate.Set(fmt.Sprintf("%s=%v", f, v))
   123  }