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

     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 options
    18  
    19  import (
    20  	"time"
    21  
    22  	"github.com/spf13/pflag"
    23  )
    24  
    25  // VolumeConfigFlags is used to bind CLI flags to variables.  This top-level struct contains *all* enumerated
    26  // CLI flags meant to configure all volume plugins.  From this config, the binary will create many instances
    27  // of volume.VolumeConfig which are then passed to the appropriate plugin. The ControllerManager binary is the only
    28  // part of the code which knows what plugins are supported and which CLI flags correspond to each plugin.
    29  type VolumeConfigFlags struct {
    30  	PersistentVolumeRecyclerMaximumRetry                int
    31  	PersistentVolumeRecyclerMinimumTimeoutNFS           int
    32  	PersistentVolumeRecyclerPodTemplateFilePathNFS      string
    33  	PersistentVolumeRecyclerIncrementTimeoutNFS         int
    34  	PersistentVolumeRecyclerPodTemplateFilePathHostPath string
    35  	PersistentVolumeRecyclerMinimumTimeoutHostPath      int
    36  	PersistentVolumeRecyclerIncrementTimeoutHostPath    int
    37  	EnableHostPathProvisioning                          bool
    38  	EnableDynamicProvisioning                           bool
    39  }
    40  
    41  // PersistentVolumeControllerOptions holds the PersistentVolumeController options.
    42  type PersistentVolumeControllerOptions struct {
    43  	PVClaimBinderSyncPeriod time.Duration
    44  	VolumeConfigFlags       VolumeConfigFlags
    45  }
    46  
    47  // NewPersistentVolumeControllerOptions creates a new PersistentVolumeControllerOptions with
    48  // default values.
    49  func NewPersistentVolumeControllerOptions() PersistentVolumeControllerOptions {
    50  	return PersistentVolumeControllerOptions{
    51  		PVClaimBinderSyncPeriod: 15 * time.Second,
    52  		VolumeConfigFlags: VolumeConfigFlags{
    53  			// default values here
    54  			PersistentVolumeRecyclerMaximumRetry:             3,
    55  			PersistentVolumeRecyclerMinimumTimeoutNFS:        300,
    56  			PersistentVolumeRecyclerIncrementTimeoutNFS:      30,
    57  			PersistentVolumeRecyclerMinimumTimeoutHostPath:   60,
    58  			PersistentVolumeRecyclerIncrementTimeoutHostPath: 30,
    59  			EnableHostPathProvisioning:                       false,
    60  			EnableDynamicProvisioning:                        true,
    61  		},
    62  	}
    63  }
    64  
    65  // AddFlags adds flags related to PersistentVolumeControllerOptions to the specified FlagSet.
    66  func (o *PersistentVolumeControllerOptions) AddFlags(fs *pflag.FlagSet) {
    67  	fs.DurationVar(&o.PVClaimBinderSyncPeriod, "pvclaimbinder-sync-period", o.PVClaimBinderSyncPeriod,
    68  		"The period for syncing persistent volumes and persistent volume claims")
    69  	fs.StringVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerPodTemplateFilePathNFS,
    70  		"pv-recycler-pod-template-filepath-nfs", o.VolumeConfigFlags.PersistentVolumeRecyclerPodTemplateFilePathNFS,
    71  		"The file path to a pod definition used as a template for NFS persistent volume recycling")
    72  	fs.IntVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerMinimumTimeoutNFS, "pv-recycler-minimum-timeout-nfs",
    73  		o.VolumeConfigFlags.PersistentVolumeRecyclerMinimumTimeoutNFS, "The minimum ActiveDeadlineSeconds to use for an NFS Recycler pod")
    74  	fs.IntVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerIncrementTimeoutNFS, "pv-recycler-increment-timeout-nfs",
    75  		o.VolumeConfigFlags.PersistentVolumeRecyclerIncrementTimeoutNFS, "the increment of time added per Gi to ActiveDeadlineSeconds for an NFS scrubber pod")
    76  	fs.StringVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerPodTemplateFilePathHostPath, "pv-recycler-pod-template-filepath-hostpath",
    77  		o.VolumeConfigFlags.PersistentVolumeRecyclerPodTemplateFilePathHostPath,
    78  		"The file path to a pod definition used as a template for HostPath persistent volume recycling. "+
    79  			"This is for development and testing only and will not work in a multi-node cluster.")
    80  	fs.IntVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerMinimumTimeoutHostPath, "pv-recycler-minimum-timeout-hostpath",
    81  		o.VolumeConfigFlags.PersistentVolumeRecyclerMinimumTimeoutHostPath,
    82  		"The minimum ActiveDeadlineSeconds to use for a HostPath Recycler pod. This is for development and testing only and will not work in a multi-node cluster.")
    83  	fs.IntVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerIncrementTimeoutHostPath, "pv-recycler-timeout-increment-hostpath",
    84  		o.VolumeConfigFlags.PersistentVolumeRecyclerIncrementTimeoutHostPath,
    85  		"the increment of time added per Gi to ActiveDeadlineSeconds for a HostPath scrubber pod. "+
    86  			"This is for development and testing only and will not work in a multi-node cluster.")
    87  	fs.IntVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerMaximumRetry, "pv-recycler-maximum-retry",
    88  		o.VolumeConfigFlags.PersistentVolumeRecyclerMaximumRetry,
    89  		"Maximum number of attempts to recycle or delete a persistent volume")
    90  	fs.BoolVar(&o.VolumeConfigFlags.EnableHostPathProvisioning, "enable-hostpath-provisioner", o.VolumeConfigFlags.EnableHostPathProvisioning,
    91  		"Enable HostPath PV provisioning when running without a cloud provider. This allows testing and development of provisioning features. "+
    92  			"HostPath provisioning is not supported in any way, won't work in a multi-node cluster, and should not be used for anything other than testing or development.")
    93  	fs.BoolVar(&o.VolumeConfigFlags.EnableDynamicProvisioning, "enable-dynamic-provisioning", o.VolumeConfigFlags.EnableDynamicProvisioning,
    94  		"Enable dynamic provisioning for environments that support it.")
    95  }