k8s.io/perf-tests/clusterloader2@v0.0.0-20240304094227-64bdb12da87e/api/default.go (about)

     1  /*
     2  Copyright 2018 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 api
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"k8s.io/perf-tests/clusterloader2/pkg/framework/client"
    23  	"k8s.io/perf-tests/clusterloader2/pkg/util"
    24  )
    25  
    26  // SetDefaults set the default configuration parameters.
    27  func (conf *Config) SetDefaults() {
    28  	conf.Namespace.SetDefaults()
    29  
    30  	// TODO(#1696): Clean up after removing automanagedNamespaces
    31  	if conf.Namespace.Number == 1 && conf.AutomanagedNamespaces > 1 {
    32  		conf.Namespace.Number = conf.AutomanagedNamespaces
    33  	}
    34  }
    35  
    36  // SetDefaults specifies the default values for namespace parameters.
    37  func (ns *NamespaceConfig) SetDefaults() {
    38  	if ns.Number == 0 {
    39  		ns.Number = 1
    40  	}
    41  
    42  	if ns.Prefix == "" {
    43  		ns.Prefix = fmt.Sprintf("test-%s", util.RandomDNS1123String(6))
    44  	}
    45  
    46  	defaultDeleteStaleNS := false
    47  	if ns.DeleteStaleNamespaces == nil {
    48  		ns.DeleteStaleNamespaces = &defaultDeleteStaleNS
    49  	}
    50  
    51  	defaultDeleteAutoNS := true
    52  	if ns.DeleteAutomanagedNamespaces == nil {
    53  		ns.DeleteAutomanagedNamespaces = &defaultDeleteAutoNS
    54  	}
    55  
    56  	defaultEnableExistingNS := false
    57  	if ns.EnableExistingNamespaces == nil {
    58  		ns.EnableExistingNamespaces = &defaultEnableExistingNS
    59  	}
    60  
    61  	defaultDeleteNamespaceTimeout := Duration(client.DefaultNamespaceDeletionTimeout)
    62  	if ns.DeleteNamespaceTimeout == nil {
    63  		ns.DeleteNamespaceTimeout = &defaultDeleteNamespaceTimeout
    64  	}
    65  }