From 4797be3ee5355782f12d8ee745c5be3cd4db0eb3 Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Wed, 12 Jun 2019 13:01:51 +0530 Subject: [PATCH] CRD Spec: add option to configure HostNetwork and DNSPolicy this allows the network plugins like CNI to use etcd-cluster as kv when bootstrapping the cluster fixes #1929 --- Gopkg.lock | 1 + pkg/apis/etcd/v1beta2/cluster.go | 6 ++++++ pkg/util/k8sutil/k8sutil.go | 9 +++++++++ 3 files changed, 16 insertions(+) diff --git a/Gopkg.lock b/Gopkg.lock index a346563b0..03218b871 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1004,6 +1004,7 @@ "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1", "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset", "k8s.io/apimachinery/pkg/api/errors", + "k8s.io/apimachinery/pkg/api/meta", "k8s.io/apimachinery/pkg/api/resource", "k8s.io/apimachinery/pkg/apis/meta/v1", "k8s.io/apimachinery/pkg/fields", diff --git a/pkg/apis/etcd/v1beta2/cluster.go b/pkg/apis/etcd/v1beta2/cluster.go index 889534b6b..9e9ba88f6 100644 --- a/pkg/apis/etcd/v1beta2/cluster.go +++ b/pkg/apis/etcd/v1beta2/cluster.go @@ -162,6 +162,12 @@ type PodPolicy struct { // '.cluster.local'. // The default is to not set a cluster domain explicitly. ClusterDomain string `json:"ClusterDomain"` + + // hostNetwork will set HostNetwork: true in podspec + HostNetwork bool `json:"hostNetwork,omitempty"` + + // dnsPolicy will set dnsPolicy: in podspec + DNSPolicy v1.DNSPolicy `json:"dnsPolicy,omitempty"` } // TODO: move this to initializer diff --git a/pkg/util/k8sutil/k8sutil.go b/pkg/util/k8sutil/k8sutil.go index 8db36f18a..fff99d1ad 100644 --- a/pkg/util/k8sutil/k8sutil.go +++ b/pkg/util/k8sutil/k8sutil.go @@ -402,6 +402,15 @@ func newEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state, SecurityContext: podSecurityContext(cs.Pod), }, } + + if cs.Pod.DNSPolicy != "" { + pod.Spec.DNSPolicy = cs.Pod.DNSPolicy + } + + if cs.Pod.HostNetwork { + pod.Spec.HostNetwork = true + } + SetEtcdVersion(pod, cs.Version) return pod }