mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Merge pull request #101598 from neolit123/1.22-kubeadm-remove-clusterconfiguration-defaulting
kubeadm: simplify fuzzing of ClusterConfiguration
This commit is contained in:
commit
3dd0597843
@ -21,7 +21,6 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
)
|
||||
|
||||
@ -45,42 +44,16 @@ func fuzzInitConfiguration(obj *kubeadm.InitConfiguration, c fuzz.Continue) {
|
||||
|
||||
// Pinning values for fields that get defaults if fuzz value is empty string or nil (thus making the round trip test fail)
|
||||
|
||||
// Since ClusterConfiguration never get serialized in the external variant of InitConfiguration,
|
||||
// it is necessary to apply external api defaults here to get the round trip internal->external->internal working.
|
||||
// More specifically:
|
||||
// internal with manually applied defaults -> external object : loosing ClusterConfiguration) -> internal object with automatically applied defaults
|
||||
obj.ClusterConfiguration = kubeadm.ClusterConfiguration{
|
||||
APIServer: kubeadm.APIServer{
|
||||
TimeoutForControlPlane: &metav1.Duration{
|
||||
Duration: constants.DefaultControlPlaneTimeout,
|
||||
},
|
||||
},
|
||||
DNS: kubeadm.DNS{
|
||||
Type: kubeadm.CoreDNS,
|
||||
},
|
||||
CertificatesDir: kubeadmapiv1.DefaultCertificatesDir,
|
||||
ClusterName: kubeadmapiv1.DefaultClusterName,
|
||||
Etcd: kubeadm.Etcd{
|
||||
Local: &kubeadm.LocalEtcd{
|
||||
DataDir: kubeadmapiv1.DefaultEtcdDataDir,
|
||||
},
|
||||
},
|
||||
ImageRepository: kubeadmapiv1.DefaultImageRepository,
|
||||
KubernetesVersion: kubeadmapiv1.DefaultKubernetesVersion,
|
||||
Networking: kubeadm.Networking{
|
||||
ServiceSubnet: kubeadmapiv1.DefaultServicesSubnet,
|
||||
DNSDomain: kubeadmapiv1.DefaultServiceDNSDomain,
|
||||
},
|
||||
}
|
||||
// Adds the default bootstrap token to get the round working
|
||||
// Avoid round tripping the ClusterConfiguration embedded in the InitConfiguration, since it is
|
||||
// only present in the internal version and not in public versions
|
||||
obj.ClusterConfiguration = kubeadm.ClusterConfiguration{}
|
||||
|
||||
// Adds the default bootstrap token to get the round trip working
|
||||
obj.BootstrapTokens = []kubeadm.BootstrapToken{
|
||||
{
|
||||
// Description
|
||||
// Expires
|
||||
Groups: []string{"foo"},
|
||||
// Token
|
||||
TTL: &metav1.Duration{Duration: 1234},
|
||||
Usages: []string{"foo"},
|
||||
TTL: &metav1.Duration{Duration: 1234},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,5 @@ func Convert_v1beta2_InitConfiguration_To_kubeadm_InitConfiguration(in *InitConf
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Keep the fuzzer test happy by setting out.ClusterConfiguration to defaults
|
||||
clusterCfg := &ClusterConfiguration{}
|
||||
SetDefaults_ClusterConfiguration(clusterCfg)
|
||||
return Convert_v1beta2_ClusterConfiguration_To_kubeadm_ClusterConfiguration(clusterCfg, &out.ClusterConfiguration, s)
|
||||
return Convert_v1beta2_ClusterConfiguration_To_kubeadm_ClusterConfiguration(&ClusterConfiguration{}, &out.ClusterConfiguration, s)
|
||||
}
|
||||
|
@ -30,9 +30,5 @@ func Convert_v1beta3_InitConfiguration_To_kubeadm_InitConfiguration(in *InitConf
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Keep the fuzzer test happy by setting out.ClusterConfiguration to defaults
|
||||
clusterCfg := &ClusterConfiguration{}
|
||||
SetDefaults_ClusterConfiguration(clusterCfg)
|
||||
return Convert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(clusterCfg, &out.ClusterConfiguration, s)
|
||||
return Convert_v1beta3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(&ClusterConfiguration{}, &out.ClusterConfiguration, s)
|
||||
}
|
||||
|
@ -340,6 +340,13 @@ func documentMapToInitConfiguration(gvkmap kubeadmapi.DocumentMap, allowDeprecat
|
||||
// If ClusterConfiguration was given, populate it in the InitConfiguration struct
|
||||
if clustercfg != nil {
|
||||
initcfg.ClusterConfiguration = *clustercfg
|
||||
} else {
|
||||
// Populate the internal InitConfiguration.ClusterConfiguration with defaults
|
||||
extclustercfg := &kubeadmapiv1.ClusterConfiguration{}
|
||||
kubeadmscheme.Scheme.Default(extclustercfg)
|
||||
if err := kubeadmscheme.Scheme.Convert(extclustercfg, &initcfg.ClusterConfiguration, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Load any component configs
|
||||
|
Loading…
Reference in New Issue
Block a user