Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubeadm - addon configuration in the kubeadm config API. #70024

Merged
merged 2 commits into from Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion cmd/kubeadm/app/apis/kubeadm/fuzzer/fuzzer.go
Expand Up @@ -18,7 +18,6 @@ package fuzzer

import (
fuzz "github.com/google/gofuzz"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
Expand All @@ -34,6 +33,7 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
fuzzAuditPolicyConfiguration,
fuzzComponentConfigs,
fuzzNodeRegistration,
fuzzDNS,
fuzzLocalEtcd,
fuzzNetworking,
fuzzJoinConfiguration,
Expand All @@ -59,6 +59,9 @@ func fuzzInitConfiguration(obj *kubeadm.InitConfiguration, c fuzz.Continue) {
LogDir: constants.StaticPodAuditPolicyLogDir,
LogMaxAge: &v1beta1.DefaultAuditPolicyLogMaxAge,
},
DNS: kubeadm.DNS{
Type: kubeadm.CoreDNS,
},
CertificatesDir: v1beta1.DefaultCertificatesDir,
ClusterName: v1beta1.DefaultClusterName,
Etcd: kubeadm.Etcd{
Expand Down Expand Up @@ -107,6 +110,14 @@ func fuzzClusterConfiguration(obj *kubeadm.ClusterConfiguration, c fuzz.Continue
}
}

func fuzzDNS(obj *kubeadm.DNS, c fuzz.Continue) {
// This is intentionally not calling c.FuzzNoCustom because DNS struct does not exists in v1alpha3 api
// (so no random value will be applied, and this is necessary for getting roundtrip passing)

// Pinning values for fields that get defaults if fuzz value is empty string or nil
obj.Type = kubeadm.CoreDNS
}

func fuzzAuditPolicyConfiguration(obj *kubeadm.AuditPolicyConfiguration, c fuzz.Continue) {
c.FuzzNoCustom(obj)

Expand All @@ -125,6 +136,10 @@ func fuzzLocalEtcd(obj *kubeadm.LocalEtcd, 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)
obj.DataDir = "foo"

// Pinning values for fields that does not exists in v1alpha3 api
obj.ImageRepository = ""
obj.ImageTag = ""
}

func fuzzNetworking(obj *kubeadm.Networking, c fuzz.Continue) {
Expand Down
51 changes: 45 additions & 6 deletions cmd/kubeadm/app/apis/kubeadm/types.go
Expand Up @@ -95,10 +95,16 @@ type ClusterConfiguration struct {
// Scheduler contains extra settings for the scheduler control plane component
Scheduler ControlPlaneComponent

// DNS defines the options for the DNS add-on installed in the cluster.
DNS DNS

// CertificatesDir specifies where to store or look for all required certificates.
CertificatesDir string

// ImageRepository is the container registry to pull control plane images from.
// ImageRepository sets the container registry to pull images from.
// If empty, `k8s.gcr.io` will be used by default; in case of kubernetes version is a CI build (kubernetes version starts with `ci/` or `ci-cross/`)
// `gcr.io/kubernetes-ci-images` will be used as a default for control plane components and for kube-proxy, while `k8s.gcr.io`
// will be used for all the other images.
ImageRepository string

// CIImageRepository is the container registry for core images generated by CI.
Expand All @@ -122,6 +128,8 @@ type ClusterConfiguration struct {
// ControlPlaneComponent holds settings common to control plane component of the cluster
type ControlPlaneComponent struct {
// ExtraArgs is an extra set of flags to pass to the control plane component.
// TODO: This is temporary and ideally we would like to switch all components to
// use ComponentConfig + ConfigMaps.
ExtraArgs map[string]string

// ExtraVolumes is an extra set of host volumes, mounted to the control plane component.
Expand All @@ -139,6 +147,40 @@ type APIServer struct {
TimeoutForControlPlane *metav1.Duration
}

// DNSAddOnType defines string identifying DNS add-on types
type DNSAddOnType string

const (
// CoreDNS add-on type
CoreDNS DNSAddOnType = "CoreDNS"

// KubeDNS add-on type
KubeDNS DNSAddOnType = "kube-dns"
)

// DNS defines the DNS addon that should be used in the cluster
type DNS struct {
// Type defines the DNS add-on to be used
Type DNSAddOnType

// ImageMeta allows to customize the image used for the DNS component
ImageMeta `json:",inline"`
}

// ImageMeta allows to customize the image used for components that are not
// originated from the Kubernetes/Kubernetes release process
type ImageMeta struct {
// ImageRepository sets the container registry to pull images from.
// if not set, the ImageRepository defined in ClusterConfiguration will be used instead.
ImageRepository string

// ImageTag allows to specify a tag for the image.
// In case this value is set, kubeadm does not change automatically the version of the above components during upgrades.
ImageTag string

//TODO: evaluate if we need also a ImageName based on user feedbacks
}

// ComponentConfigs holds known internal ComponentConfig types for other components
type ComponentConfigs struct {
// Kubelet holds the ComponentConfiguration for the kubelet
Expand Down Expand Up @@ -239,11 +281,8 @@ type Etcd struct {

// LocalEtcd describes that kubeadm should run an etcd cluster locally
type LocalEtcd struct {

// Image specifies which container image to use for running etcd.
// If empty, automatically populated by kubeadm using the image
// repository and default etcd version.
Image string
// ImageMeta allows to customize the container used for etcd
ImageMeta `json:",inline"`

// DataDir is the directory etcd will place its data.
// Defaults to "/var/lib/etcd".
Expand Down
3 changes: 1 addition & 2 deletions cmd/kubeadm/app/apis/kubeadm/v1alpha3/BUILD
Expand Up @@ -20,6 +20,7 @@ go_library(
deps = [
"//cmd/kubeadm/app/apis/kubeadm:go_default_library",
"//cmd/kubeadm/app/constants:go_default_library",
"//cmd/kubeadm/app/features:go_default_library",
"//cmd/kubeadm/app/images:go_default_library",
"//cmd/kubeadm/app/util:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
Expand Down Expand Up @@ -56,8 +57,6 @@ go_test(
embed = [":go_default_library"],
deps = [
"//cmd/kubeadm/app/apis/kubeadm:go_default_library",
"//cmd/kubeadm/app/apis/kubeadm/scheme:go_default_library",
"//cmd/kubeadm/test:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
],
)
72 changes: 70 additions & 2 deletions cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion.go
Expand Up @@ -17,16 +17,21 @@ limitations under the License.
package v1alpha3

import (
"github.com/pkg/errors"
"regexp"
"strings"

"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/kubernetes/cmd/kubeadm/app/features"
"k8s.io/kubernetes/cmd/kubeadm/app/images"
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
)

var imageRegEx = regexp.MustCompile(`(?P<repository>.+/)(?P<image>[^:]+)(?P<tag>:.+)`)

func Convert_v1alpha3_InitConfiguration_To_kubeadm_InitConfiguration(in *InitConfiguration, out *kubeadm.InitConfiguration, s conversion.Scope) error {
if err := autoConvert_v1alpha3_InitConfiguration_To_kubeadm_InitConfiguration(in, out, s); err != nil {
return err
Expand Down Expand Up @@ -133,6 +138,14 @@ func Convert_v1alpha3_ClusterConfiguration_To_kubeadm_ClusterConfiguration(in *C
return err
}

// converting v1alpha3 featureGate CoreDNS to internal DNS.Type
if features.Enabled(in.FeatureGates, features.CoreDNS) {
out.DNS.Type = kubeadm.CoreDNS
} else {
out.DNS.Type = kubeadm.KubeDNS
}
delete(out.FeatureGates, features.CoreDNS)

return nil
}

Expand Down Expand Up @@ -174,11 +187,19 @@ func Convert_kubeadm_ClusterConfiguration_To_v1alpha3_ClusterConfiguration(in *k
}

if in.UseHyperKubeImage {
out.UnifiedControlPlaneImage = images.GetKubeControlPlaneImage("", in)
out.UnifiedControlPlaneImage = images.GetKubernetesImage("", in)
} else {
out.UnifiedControlPlaneImage = ""
}

// converting internal DNS.Type to v1alpha3 featureGate CoreDNS (this is only for getting roundtrip passing, but it is never used in reality)
if out.FeatureGates == nil {
out.FeatureGates = map[string]bool{}
}
if in.DNS.Type == kubeadm.KubeDNS {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have this as just:

out.FeatureGates["CoreDNS"] = (in.DNS.Type == kubeadm.CoreDNS)

out.FeatureGates[features.CoreDNS] = false
}

return nil
}

Expand Down Expand Up @@ -225,5 +246,52 @@ func convertSlice_kubeadm_HostPathMount_To_v1alpha3_HostPathMount(in *[]kubeadm.
} else {
*out = nil
}

return nil
}

func Convert_v1alpha3_LocalEtcd_To_kubeadm_LocalEtcd(in *LocalEtcd, out *kubeadm.LocalEtcd, s conversion.Scope) error {
if err := autoConvert_v1alpha3_LocalEtcd_To_kubeadm_LocalEtcd(in, out, s); err != nil {
return err
}

var err error
out.ImageMeta, err = etcdImageToImageMeta(in.Image)
return err
}

func etcdImageToImageMeta(image string) (kubeadm.ImageMeta, error) {
// empty image -> empty image meta
if image == "" {
return kubeadm.ImageMeta{}, nil
}

matches := imageRegEx.FindStringSubmatch(image)
if len(matches) != 4 {
return kubeadm.ImageMeta{}, errors.New("Conversion Error: kubeadm does not support converting v1alpha3 configurations with etcd image without explicit repository or tag definition. Please fix the image name")
}

imageRepository := strings.TrimSuffix(matches[1], "/")
imageName := matches[2]
imageTag := strings.TrimPrefix(matches[3], ":")

if imageName != constants.Etcd {
return kubeadm.ImageMeta{}, errors.New("Conversion Error: kubeadm does not support converting v1alpha3 configurations with etcd imageName different than etcd. Please fix the image name")
}

return kubeadm.ImageMeta{
ImageRepository: imageRepository,
ImageTag: imageTag,
}, nil
}

func Convert_kubeadm_LocalEtcd_To_v1alpha3_LocalEtcd(in *kubeadm.LocalEtcd, out *LocalEtcd, s conversion.Scope) error {
if err := autoConvert_kubeadm_LocalEtcd_To_v1alpha3_LocalEtcd(in, out, s); err != nil {
return err
}

// converting internal LocalEtcd.ImageMeta to v1alpha3 LocalEtcd.Image (this is only for getting roundtrip passing, but it is
// never used in reality)

return nil
}