Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

cluster: add option to specify busybox repository #1928

Merged
merged 6 commits into from
Mar 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/apis/etcd/v1beta2/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ type PodPolicy struct {
// etcd cluster.
// The "etcd.version" annotation is reserved for the internal use of the etcd operator.
Annotations map[string]string `json:"annotations,omitempty"`

// busybox init container image. default is busybox:1.28.0-glibc
// busybox:latest uses uclibc which contains a bug that sometimes prevents name resolution
// More info: https://github.com/docker-library/busybox/issues/27
BusyboxImage string `json:"busyboxImage,omitempty"`
}

// TODO: move this to initializer
Expand Down
13 changes: 12 additions & 1 deletion pkg/util/k8sutil/k8sutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const (

defaultKubeAPIRequestTimeout = 30 * time.Second

defaultBusyboxImage = "busybox:1.28.0-glibc"

// AnnotationScope annotation name for defining instance scope. Used for specifing cluster wide clusters.
AnnotationScope = "etcd.database.coreos.com/scope"
//AnnotationClusterWide annotation value for cluster wide clusters.
Expand Down Expand Up @@ -134,6 +136,14 @@ func ImageName(repo, version string) string {
return fmt.Sprintf("%s:v%v", repo, version)
}

// imageNameBusybox returns the default image for busybox init container, or the image specified in the PodPolicy
func imageNameBusybox(policy *api.PodPolicy) string {
if policy != nil && len(policy.BusyboxImage) > 0 {
return policy.BusyboxImage
}
return defaultBusyboxImage
}

func PodWithNodeSelector(p *v1.Pod, ns map[string]string) *v1.Pod {
p.Spec.NodeSelector = ns
return p
Expand Down Expand Up @@ -355,7 +365,8 @@ func newEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state,
InitContainers: []v1.Container{{
// busybox:latest uses uclibc which contains a bug that sometimes prevents name resolution
// More info: https://github.com/docker-library/busybox/issues/27
Image: "busybox:1.28.0-glibc",
//Image default: "busybox:1.28.0-glibc",
Image: imageNameBusybox(cs.Pod),
Name: "check-dns",
// In etcd 3.2, TLS listener will do a reverse-DNS lookup for pod IP -> hostname.
// If DNS entry is not warmed up, it will return empty result and peer connection will be rejected.
Expand Down
49 changes: 49 additions & 0 deletions pkg/util/k8sutil/k8sutils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2017 The etcd-operator 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 k8sutil

import (
"testing"

api "github.com/coreos/etcd-operator/pkg/apis/etcd/v1beta2"
)

func TestDefaultBusyboxImageName(t *testing.T) {
policy := &api.PodPolicy{}
image := imageNameBusybox(policy)
expected := defaultBusyboxImage
if image != expected {
t.Errorf("expect image=%s, get=%s", expected, image)
}
}

func TestDefaultNilBusyboxImageName(t *testing.T) {
image := imageNameBusybox(nil)
expected := defaultBusyboxImage
if image != expected {
t.Errorf("expect image=%s, get=%s", expected, image)
}
}

func TestSetBusyboxImageName(t *testing.T) {
policy := &api.PodPolicy{
BusyboxImage: "myRepo/busybox:1.3.2",
}
image := imageNameBusybox(policy)
expected := "myRepo/busybox:1.3.2"
if image != expected {
t.Errorf("expect image=%s, get=%s", expected, image)
}
}