k8s.io/kubernetes@v1.29.3/pkg/controller/volume/persistentvolume/config/v1alpha1/defaults.go (about)

     1  /*
     2  Copyright 2019 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 v1alpha1
    18  
    19  import (
    20  	"time"
    21  
    22  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    23  	kubectrlmgrconfigv1alpha1 "k8s.io/kube-controller-manager/config/v1alpha1"
    24  	"k8s.io/utils/pointer"
    25  )
    26  
    27  // RecommendedDefaultPersistentVolumeBinderControllerConfiguration defaults a pointer to a
    28  // PersistentVolumeBinderControllerConfiguration struct. This will set the recommended default
    29  // values, but they may be subject to change between API versions. This function
    30  // is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo`
    31  // function to allow consumers of this type to set whatever defaults for their
    32  // embedded configs. Forcing consumers to use these defaults would be problematic
    33  // as defaulting in the scheme is done as part of the conversion, and there would
    34  // be no easy way to opt-out. Instead, if you want to use this defaulting method
    35  // run it in your wrapper struct of this type in its `SetDefaults_` method.
    36  func RecommendedDefaultPersistentVolumeBinderControllerConfiguration(obj *kubectrlmgrconfigv1alpha1.PersistentVolumeBinderControllerConfiguration) {
    37  	zero := metav1.Duration{}
    38  	if obj.PVClaimBinderSyncPeriod == zero {
    39  		obj.PVClaimBinderSyncPeriod = metav1.Duration{Duration: 15 * time.Second}
    40  	}
    41  
    42  	if obj.VolumeHostAllowLocalLoopback == nil {
    43  		trueValue := true
    44  		obj.VolumeHostAllowLocalLoopback = &trueValue
    45  	}
    46  
    47  	// Use the default VolumeConfiguration options.
    48  	RecommendedDefaultVolumeConfiguration(&obj.VolumeConfiguration)
    49  }
    50  
    51  // RecommendedDefaultVolumeConfiguration defaults a pointer to a VolumeConfiguration
    52  // struct. This will set the recommended default values, but they may be subject to
    53  // change between API versions. This function is intentionally not registered in the
    54  // scheme as a "normal" `SetDefaults_Foo` function to allow consumers of this type to
    55  // set whatever defaults for their embedded configs. Forcing consumers to use these
    56  // defaults would be problematic as defaulting in the scheme is done as part of the
    57  // conversion, and there would be no easy way to opt-out. Instead, if you want to use
    58  // this defaulting method run it in your wrapper struct of this type in its `SetDefaults_` method.
    59  func RecommendedDefaultVolumeConfiguration(obj *kubectrlmgrconfigv1alpha1.VolumeConfiguration) {
    60  	if obj.EnableHostPathProvisioning == nil {
    61  		obj.EnableHostPathProvisioning = pointer.Bool(false)
    62  	}
    63  	if obj.EnableDynamicProvisioning == nil {
    64  		obj.EnableDynamicProvisioning = pointer.Bool(true)
    65  	}
    66  	if obj.FlexVolumePluginDir == "" {
    67  		obj.FlexVolumePluginDir = "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/"
    68  	}
    69  	// Use the default PersistentVolumeRecyclerConfiguration options.
    70  	RecommendedDefaultPersistentVolumeRecyclerConfiguration(&obj.PersistentVolumeRecyclerConfiguration)
    71  }
    72  
    73  // RecommendedDefaultPersistentVolumeRecyclerConfiguration defaults a pointer to a
    74  // PersistentVolumeRecyclerConfiguration struct. This will set the recommended default
    75  // values, but they may be subject to change between API versions. This function
    76  // is intentionally not registered in the scheme as a "normal" `SetDefaults_Foo`
    77  // function to allow consumers of this type to set whatever defaults for their
    78  // embedded configs. Forcing consumers to use these defaults would be problematic
    79  // as defaulting in the scheme is done as part of the conversion, and there would
    80  // be no easy way to opt-out. Instead, if you want to use this defaulting method
    81  // run it in your wrapper struct of this type in its `SetDefaults_` method.
    82  func RecommendedDefaultPersistentVolumeRecyclerConfiguration(obj *kubectrlmgrconfigv1alpha1.PersistentVolumeRecyclerConfiguration) {
    83  	if obj.MaximumRetry == 0 {
    84  		obj.MaximumRetry = 3
    85  	}
    86  	if obj.MinimumTimeoutNFS == 0 {
    87  		obj.MinimumTimeoutNFS = 300
    88  	}
    89  	if obj.IncrementTimeoutNFS == 0 {
    90  		obj.IncrementTimeoutNFS = 30
    91  	}
    92  	if obj.MinimumTimeoutHostPath == 0 {
    93  		obj.MinimumTimeoutHostPath = 60
    94  	}
    95  	if obj.IncrementTimeoutHostPath == 0 {
    96  		obj.IncrementTimeoutHostPath = 30
    97  	}
    98  }