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

Commit

Permalink
k8sutil: add recovery container instead of overriding (#1853)
Browse files Browse the repository at this point in the history
Also fix the ordering to apply pod policy on recovery containers too
  • Loading branch information
hongchaodeng authored Jan 12, 2018
1 parent 5be810a commit f7b24d7
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pkg/util/k8sutil/k8sutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ func newEtcdServiceManifest(svcName, clusterName, clusterIP string, ports []v1.S
}

func addRecoveryToPod(pod *v1.Pod, token string, m *etcdutil.Member, cs api.ClusterSpec, backupURL *url.URL) {
pod.Spec.InitContainers = makeRestoreInitContainers(backupURL, token, cs.Repository, cs.Version, m)
pod.Spec.InitContainers = append(pod.Spec.InitContainers,
makeRestoreInitContainers(backupURL, token, cs.Repository, cs.Version, m)...)
}

func addOwnerRefToObject(o metav1.Object, r metav1.OwnerReference) {
Expand All @@ -221,14 +222,16 @@ func addOwnerRefToObject(o metav1.Object, r metav1.OwnerReference) {
// It's special that it has new token, and might need recovery init containers
func NewSeedMemberPod(clusterName string, ms etcdutil.MemberSet, m *etcdutil.Member, cs api.ClusterSpec, owner metav1.OwnerReference, backupURL *url.URL) *v1.Pod {
token := uuid.New()
pod := NewEtcdPod(m, ms.PeerURLPairs(), clusterName, "new", token, cs, owner)
pod := newEtcdPod(m, ms.PeerURLPairs(), clusterName, "new", token, cs)
if backupURL != nil {
addRecoveryToPod(pod, token, m, cs, backupURL)
}
applyPodPolicy(clusterName, pod, cs.Pod)
addOwnerRefToObject(pod.GetObjectMeta(), owner)
return pod
}

func NewEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state, token string, cs api.ClusterSpec, owner metav1.OwnerReference) *v1.Pod {
func newEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state, token string, cs api.ClusterSpec) *v1.Pod {
commands := fmt.Sprintf("/usr/local/bin/etcd --data-dir=%s --name=%s --initial-advertise-peer-urls=%s "+
"--listen-peer-urls=%s --listen-client-urls=%s --advertise-client-urls=%s "+
"--initial-cluster=%s --initial-cluster-state=%s",
Expand Down Expand Up @@ -318,11 +321,13 @@ func NewEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state,
AutomountServiceAccountToken: func(b bool) *bool { return &b }(false),
},
}

applyPodPolicy(clusterName, pod, cs.Pod)

SetEtcdVersion(pod, cs.Version)
return pod
}

func NewEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state, token string, cs api.ClusterSpec, owner metav1.OwnerReference) *v1.Pod {
pod := newEtcdPod(m, initialCluster, clusterName, state, token, cs)
applyPodPolicy(clusterName, pod, cs.Pod)
addOwnerRefToObject(pod.GetObjectMeta(), owner)
return pod
}
Expand Down

0 comments on commit f7b24d7

Please sign in to comment.