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

k8sutil: add recovery container instead of overriding #1853

Merged
merged 1 commit into from
Jan 12, 2018
Merged
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
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

why changing NewEtcdPod to newEtcdPod?

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm, i saw there is a order change.

if backupURL != nil {
addRecoveryToPod(pod, token, m, cs, backupURL)
}
applyPodPolicy(clusterName, pod, cs.Pod)
addOwnerRefToObject(pod.GetObjectMeta(), owner)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me the order of calling applyPodPolicy is important because this code reasons about init containers.

I don't think order of addOwnerRefToObject matters in this case. correct me if i am wrong.

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think addOwnerRefToObject can stay in the newEtcdPod function. I don't think order of addOwnerRefToObject matters.

Copy link
Member Author

Choose a reason for hiding this comment

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

The addOwnerRefToObject() doesn't matter. But it's good to separate one param owner out of newEtcdPod().

Copy link
Contributor

Choose a reason for hiding this comment

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

fair enough.

return pod
}
Expand Down