kubeadm: make the active timeouts structure accessible from anywhere

Currently, timeouts are only accessible if a kubeadm runtime.Object{}
like InitConfiguration is passed around.

Any time a config is loaded or defaulted, store the Timeouts
structure in a thread-safe way in the main kubeadm API package
with SetActiveTimeouts(). Optionally, a deep-copy can be
performed before calling SetActiveTimeouts(). Make this struct
accessible with GetActiveTimeouts(). Ensure these functions
are thread safe.

On init() make sure the struct is defaulted, so that unit
tests can work with these values.
This commit is contained in:
Lubomir I. Ivanov
2023-12-31 20:09:03 +02:00
parent ea0fa41445
commit d9e48705ff
5 changed files with 72 additions and 13 deletions

View File

@@ -62,13 +62,20 @@ func SetJoinControlPlaneDefaults(cfg *kubeadmapi.JoinControlPlane) error {
// Right thereafter, the configuration is defaulted again with dynamic values (like IP addresses of a machine, etc)
// Lastly, the internal config is validated and returned.
func LoadOrDefaultJoinConfiguration(cfgPath string, defaultversionedcfg *kubeadmapiv1.JoinConfiguration, opts LoadOrDefaultConfigurationOptions) (*kubeadmapi.JoinConfiguration, error) {
var (
config *kubeadmapi.JoinConfiguration
err error
)
if cfgPath != "" {
// Loads configuration from config file, if provided
// Nb. --config overrides command line flags, TODO: fix this
return LoadJoinConfigurationFromFile(cfgPath, opts)
config, err = LoadJoinConfigurationFromFile(cfgPath, opts)
} else {
config, err = DefaultedJoinConfiguration(defaultversionedcfg, opts)
}
return DefaultedJoinConfiguration(defaultversionedcfg, opts)
if err == nil {
prepareStaticVariables(config)
}
return config, err
}
// LoadJoinConfigurationFromFile loads versioned JoinConfiguration from file, converts it to internal, defaults and validates it