mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-15 06:43:54 +00:00
cleanup v1alpha3 conversion to internal
This commit is contained in:
parent
db1d1c8674
commit
8e887e1eee
@ -1,112 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2018 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package v1alpha3
|
|
||||||
|
|
||||||
import (
|
|
||||||
"k8s.io/apimachinery/pkg/conversion"
|
|
||||||
kubeproxyconfigv1alpha1 "k8s.io/kube-proxy/config/v1alpha1"
|
|
||||||
kubeletconfigv1beta1 "k8s.io/kubelet/config/v1beta1"
|
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
|
||||||
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
|
|
||||||
kubeletconfigscheme "k8s.io/kubernetes/pkg/kubelet/apis/config/scheme"
|
|
||||||
kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config"
|
|
||||||
kubeproxyconfigscheme "k8s.io/kubernetes/pkg/proxy/apis/config/scheme"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Convert_v1alpha3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(in *ClusterConfiguration, out *kubeadm.ClusterConfiguration, s conversion.Scope) error {
|
|
||||||
if err := autoConvert_v1alpha3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(in, out, s); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: This conversion code is here ONLY for fuzzing tests. When we remove the v1alpha2 API, we can remove this (unnecessary)
|
|
||||||
// code. Right now this defaulting code has to be kept in sync with the defaulting code in cmd/kubeadm/app/apis/kubeadm/v1alpha2 and cmd/kubeadm/app/componentconfig
|
|
||||||
if out.ComponentConfigs.Kubelet == nil {
|
|
||||||
// Set the Kubelet ComponentConfig to an empty, defaulted struct
|
|
||||||
out.ComponentConfigs.Kubelet = &kubeletconfig.KubeletConfiguration{}
|
|
||||||
extkubeletconfig := &kubeletconfigv1beta1.KubeletConfiguration{}
|
|
||||||
|
|
||||||
scheme, _, err := kubeletconfigscheme.NewSchemeAndCodecs()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
scheme.Default(extkubeletconfig)
|
|
||||||
scheme.Convert(extkubeletconfig, out.ComponentConfigs.Kubelet, nil)
|
|
||||||
defaultKubeletConfiguration(in, out.ComponentConfigs.Kubelet)
|
|
||||||
}
|
|
||||||
if out.ComponentConfigs.KubeProxy == nil {
|
|
||||||
// Set the KubeProxy ComponentConfig to an empty, defaulted struct
|
|
||||||
out.ComponentConfigs.KubeProxy = &kubeproxyconfig.KubeProxyConfiguration{}
|
|
||||||
extkubeproxyconfig := &kubeproxyconfigv1alpha1.KubeProxyConfiguration{}
|
|
||||||
kubeproxyconfigscheme.Scheme.Default(extkubeproxyconfig)
|
|
||||||
kubeproxyconfigscheme.Scheme.Convert(extkubeproxyconfig, out.ComponentConfigs.KubeProxy, nil)
|
|
||||||
defaultKubeProxyConfiguration(in, out.ComponentConfigs.KubeProxy)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultKubeProxyConfiguration(internalcfg *ClusterConfiguration, obj *kubeproxyconfig.KubeProxyConfiguration) {
|
|
||||||
// NOTE: This code should be mirrored from cmd/kubeadm/app/apis/kubeadm/v1alpha2/defaults.go and cmd/kubeadm/app/componentconfig/defaults.go
|
|
||||||
if obj.ClusterCIDR == "" && internalcfg.Networking.PodSubnet != "" {
|
|
||||||
obj.ClusterCIDR = internalcfg.Networking.PodSubnet
|
|
||||||
}
|
|
||||||
|
|
||||||
if obj.ClientConnection.Kubeconfig == "" {
|
|
||||||
obj.ClientConnection.Kubeconfig = "/var/lib/kube-proxy/kubeconfig.conf"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultKubeletConfiguration(internalcfg *ClusterConfiguration, obj *kubeletconfig.KubeletConfiguration) {
|
|
||||||
// NOTE: This code should be mirrored from cmd/kubeadm/app/apis/kubeadm/v1alpha2/defaults.go and cmd/kubeadm/app/componentconfig/defaults.go
|
|
||||||
if obj.StaticPodPath == "" {
|
|
||||||
obj.StaticPodPath = DefaultManifestsDir
|
|
||||||
}
|
|
||||||
if obj.ClusterDNS == nil {
|
|
||||||
dnsIP, err := constants.GetDNSIP(internalcfg.Networking.ServiceSubnet)
|
|
||||||
if err != nil {
|
|
||||||
obj.ClusterDNS = []string{DefaultClusterDNSIP}
|
|
||||||
} else {
|
|
||||||
obj.ClusterDNS = []string{dnsIP.String()}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if obj.ClusterDomain == "" {
|
|
||||||
obj.ClusterDomain = internalcfg.Networking.DNSDomain
|
|
||||||
}
|
|
||||||
// Enforce security-related kubelet options
|
|
||||||
|
|
||||||
// Require all clients to the kubelet API to have client certs signed by the cluster CA
|
|
||||||
obj.Authentication.X509.ClientCAFile = DefaultCACertPath
|
|
||||||
obj.Authentication.Anonymous.Enabled = false
|
|
||||||
|
|
||||||
// On every client request to the kubelet API, execute a webhook (SubjectAccessReview request) to the API server
|
|
||||||
// and ask it whether the client is authorized to access the kubelet API
|
|
||||||
obj.Authorization.Mode = kubeletconfig.KubeletAuthorizationModeWebhook
|
|
||||||
|
|
||||||
// Let clients using other authentication methods like ServiceAccount tokens also access the kubelet API
|
|
||||||
obj.Authentication.Webhook.Enabled = true
|
|
||||||
|
|
||||||
// Disable the readonly port of the kubelet, in order to not expose unnecessary information
|
|
||||||
obj.ReadOnlyPort = 0
|
|
||||||
|
|
||||||
// Enables client certificate rotation for the kubelet
|
|
||||||
obj.RotateCertificates = true
|
|
||||||
|
|
||||||
// Serve a /healthz webserver on localhost:10248 that kubeadm can talk to
|
|
||||||
obj.HealthzBindAddress = "127.0.0.1"
|
|
||||||
obj.HealthzPort = constants.KubeletHealthzPort
|
|
||||||
}
|
|
@ -34,12 +34,12 @@ const (
|
|||||||
|
|
||||||
// DefaultKubeProxyConfiguration assigns default values for the kube-proxy ComponentConfig
|
// DefaultKubeProxyConfiguration assigns default values for the kube-proxy ComponentConfig
|
||||||
func DefaultKubeProxyConfiguration(internalcfg *kubeadmapi.ClusterConfiguration) {
|
func DefaultKubeProxyConfiguration(internalcfg *kubeadmapi.ClusterConfiguration) {
|
||||||
// IMPORTANT NOTE: If you're changing this code you should mirror it to cmd/kubeadm/app/apis/kubeadm/v1alpha2/defaults.go
|
|
||||||
// and cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion.go. TODO: Remove this requirement when v1alpha2 is removed.
|
|
||||||
externalproxycfg := &kubeproxyconfigv1alpha1.KubeProxyConfiguration{}
|
externalproxycfg := &kubeproxyconfigv1alpha1.KubeProxyConfiguration{}
|
||||||
|
|
||||||
// Do a roundtrip to the external version for defaulting
|
// Do a roundtrip to the external version for defaulting
|
||||||
|
if internalcfg.ComponentConfigs.KubeProxy != nil {
|
||||||
Scheme.Convert(internalcfg.ComponentConfigs.KubeProxy, externalproxycfg, nil)
|
Scheme.Convert(internalcfg.ComponentConfigs.KubeProxy, externalproxycfg, nil)
|
||||||
|
}
|
||||||
|
|
||||||
if externalproxycfg.ClusterCIDR == "" && internalcfg.Networking.PodSubnet != "" {
|
if externalproxycfg.ClusterCIDR == "" && internalcfg.Networking.PodSubnet != "" {
|
||||||
externalproxycfg.ClusterCIDR = internalcfg.Networking.PodSubnet
|
externalproxycfg.ClusterCIDR = internalcfg.Networking.PodSubnet
|
||||||
@ -63,12 +63,12 @@ func DefaultKubeProxyConfiguration(internalcfg *kubeadmapi.ClusterConfiguration)
|
|||||||
|
|
||||||
// DefaultKubeletConfiguration assigns default values for the kubelet ComponentConfig
|
// DefaultKubeletConfiguration assigns default values for the kubelet ComponentConfig
|
||||||
func DefaultKubeletConfiguration(internalcfg *kubeadmapi.ClusterConfiguration) {
|
func DefaultKubeletConfiguration(internalcfg *kubeadmapi.ClusterConfiguration) {
|
||||||
// IMPORTANT NOTE: If you're changing this code you should mirror it to cmd/kubeadm/app/apis/kubeadm/v1alpha2/defaults.go
|
|
||||||
// and cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion.go. TODO: Remove this requirement when v1alpha2 is removed.
|
|
||||||
externalkubeletcfg := &kubeletconfigv1beta1.KubeletConfiguration{}
|
externalkubeletcfg := &kubeletconfigv1beta1.KubeletConfiguration{}
|
||||||
|
|
||||||
// Do a roundtrip to the external version for defaulting
|
// Do a roundtrip to the external version for defaulting
|
||||||
|
if internalcfg.ComponentConfigs.Kubelet != nil {
|
||||||
Scheme.Convert(internalcfg.ComponentConfigs.Kubelet, externalkubeletcfg, nil)
|
Scheme.Convert(internalcfg.ComponentConfigs.Kubelet, externalkubeletcfg, nil)
|
||||||
|
}
|
||||||
|
|
||||||
if externalkubeletcfg.StaticPodPath == "" {
|
if externalkubeletcfg.StaticPodPath == "" {
|
||||||
externalkubeletcfg.StaticPodPath = kubeadmapiv1alpha3.DefaultManifestsDir
|
externalkubeletcfg.StaticPodPath = kubeadmapiv1alpha3.DefaultManifestsDir
|
||||||
|
@ -27,7 +27,9 @@ import (
|
|||||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
||||||
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
|
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
|
||||||
|
kubeletconfigv1beta1scheme "k8s.io/kubernetes/pkg/kubelet/apis/config/v1beta1"
|
||||||
kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config"
|
kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config"
|
||||||
|
kubeproxyconfigv1alpha1scheme "k8s.io/kubernetes/pkg/proxy/apis/config/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddToSchemeFunc is a function that adds known types and API GroupVersions to a scheme
|
// AddToSchemeFunc is a function that adds known types and API GroupVersions to a scheme
|
||||||
@ -96,7 +98,8 @@ var Known Registrations = map[RegistrationKind]Registration{
|
|||||||
KubeProxyConfigurationKind: {
|
KubeProxyConfigurationKind: {
|
||||||
// TODO: When a beta version of the kube-proxy ComponentConfig API is available, start using it
|
// TODO: When a beta version of the kube-proxy ComponentConfig API is available, start using it
|
||||||
MarshalGroupVersion: kubeproxyconfigv1alpha1.SchemeGroupVersion,
|
MarshalGroupVersion: kubeproxyconfigv1alpha1.SchemeGroupVersion,
|
||||||
AddToSchemeFuncs: []AddToSchemeFunc{kubeproxyconfig.AddToScheme, kubeproxyconfigv1alpha1.AddToScheme},
|
// AddToSchemeFuncs must use v1alpha1scheme defined in k8s.io/kubernetes, because the schema defined in k8s.io/kube-proxy doesn't have defaulting functions
|
||||||
|
AddToSchemeFuncs: []AddToSchemeFunc{kubeproxyconfig.AddToScheme, kubeproxyconfigv1alpha1scheme.AddToScheme},
|
||||||
DefaulterFunc: DefaultKubeProxyConfiguration,
|
DefaulterFunc: DefaultKubeProxyConfiguration,
|
||||||
ValidateFunc: ValidateKubeProxyConfiguration,
|
ValidateFunc: ValidateKubeProxyConfiguration,
|
||||||
EmptyValue: &kubeproxyconfig.KubeProxyConfiguration{},
|
EmptyValue: &kubeproxyconfig.KubeProxyConfiguration{},
|
||||||
@ -114,7 +117,8 @@ var Known Registrations = map[RegistrationKind]Registration{
|
|||||||
},
|
},
|
||||||
KubeletConfigurationKind: {
|
KubeletConfigurationKind: {
|
||||||
MarshalGroupVersion: kubeletconfigv1beta1.SchemeGroupVersion,
|
MarshalGroupVersion: kubeletconfigv1beta1.SchemeGroupVersion,
|
||||||
AddToSchemeFuncs: []AddToSchemeFunc{kubeletconfig.AddToScheme, kubeletconfigv1beta1.AddToScheme},
|
// PAddToSchemeFuncs must use v1alpha1scheme defined in k8s.io/kubernetes, because the schema defined in k8s.io/kubelet doesn't have defaulting functions
|
||||||
|
AddToSchemeFuncs: []AddToSchemeFunc{kubeletconfig.AddToScheme, kubeletconfigv1beta1scheme.AddToScheme},
|
||||||
DefaulterFunc: DefaultKubeletConfiguration,
|
DefaulterFunc: DefaultKubeletConfiguration,
|
||||||
ValidateFunc: ValidateKubeletConfiguration,
|
ValidateFunc: ValidateKubeletConfiguration,
|
||||||
EmptyValue: &kubeletconfig.KubeletConfiguration{},
|
EmptyValue: &kubeletconfig.KubeletConfiguration{},
|
||||||
|
@ -88,6 +88,10 @@ func TestUploadConfiguration(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
cfg, err := configutil.ConfigFileAndDefaultsToInternalConfig("", initialcfg)
|
cfg, err := configutil.ConfigFileAndDefaultsToInternalConfig("", initialcfg)
|
||||||
|
|
||||||
|
// cleans up component config to make cfg and decodedcfg comparable (now component config are not stored anymore in kubeadm-config config map)
|
||||||
|
cfg.ComponentConfigs = kubeadmapi.ComponentConfigs{}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t2.Fatalf("UploadConfiguration() error = %v", err)
|
t2.Fatalf("UploadConfiguration() error = %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user