-
Notifications
You must be signed in to change notification settings - Fork 741
Add PersistVolumne Support #1861
Changes from 6 commits
fcf0107
9f39fa1
3e42083
1b8aef4
2f8dc0d
296b27c
a5a0cb2
458bc6a
910c502
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -78,6 +78,11 @@ func GetPodNames(pods []*v1.Pod) []string { | |||
return res | ||||
} | ||||
|
||||
// PVCNameFromMemberName the way we get PVC name from the member name | ||||
func PVCNameFromMemberName(memberName string) string { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add doc string on public method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PVCNameFromMemberName -> PVCNameFromMember |
||||
return memberName | ||||
} | ||||
|
||||
func makeRestoreInitContainers(backupURL *url.URL, token, repo, version string, m *etcdutil.Member) []v1.Container { | ||||
return []v1.Container{ | ||||
{ | ||||
|
@@ -209,6 +214,19 @@ func newEtcdServiceManifest(svcName, clusterName, clusterIP string, ports []v1.S | |||
return svc | ||||
} | ||||
|
||||
// AddEtcdVolumeToPod abstract the process of appending volume spec to pod spec | ||||
func AddEtcdVolumeToPod(pod *v1.Pod, pvc *v1.PersistentVolumeClaim) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add doc string on public method. |
||||
vol := v1.Volume{Name: etcdVolumeName} | ||||
if pvc != nil { | ||||
vol.VolumeSource = v1.VolumeSource{ | ||||
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: pvc.Name}, | ||||
} | ||||
} else { | ||||
vol.VolumeSource = v1.VolumeSource{EmptyDir: &v1.EmptyDirVolumeSource{}} | ||||
} | ||||
pod.Spec.Volumes = append(pod.Spec.Volumes, vol) | ||||
} | ||||
|
||||
func addRecoveryToPod(pod *v1.Pod, token string, m *etcdutil.Member, cs api.ClusterSpec, backupURL *url.URL) { | ||||
pod.Spec.InitContainers = append(pod.Spec.InitContainers, | ||||
makeRestoreInitContainers(backupURL, token, cs.Repository, cs.Version, m)...) | ||||
|
@@ -223,6 +241,8 @@ func addOwnerRefToObject(o metav1.Object, r metav1.OwnerReference) { | |||
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) | ||||
// TODO: PVC datadir support for restore process | ||||
AddEtcdVolumeToPod(pod, nil) | ||||
if backupURL != nil { | ||||
addRecoveryToPod(pod, token, m, cs, backupURL) | ||||
} | ||||
|
@@ -231,6 +251,20 @@ func NewSeedMemberPod(clusterName string, ms etcdutil.MemberSet, m *etcdutil.Mem | |||
return pod | ||||
} | ||||
|
||||
// NewEtcdPodPVC create PVC object from etcd pod's PVC spec | ||||
func NewEtcdPodPVC(m *etcdutil.Member, pvcSpec v1.PersistentVolumeClaimSpec, clusterName, namespace string, owner metav1.OwnerReference) *v1.PersistentVolumeClaim { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add doc string on public method. |
||||
pvc := &v1.PersistentVolumeClaim{ | ||||
ObjectMeta: metav1.ObjectMeta{ | ||||
Name: PVCNameFromMemberName(m.Name), | ||||
Namespace: namespace, | ||||
Labels: LabelsForCluster(clusterName), | ||||
}, | ||||
Spec: pvcSpec, | ||||
} | ||||
addOwnerRefToObject(pvc.GetObjectMeta(), owner) | ||||
return pvc | ||||
} | ||||
|
||||
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 "+ | ||||
|
@@ -264,10 +298,12 @@ func newEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state, | |||
livenessProbe, | ||||
readinessProbe) | ||||
|
||||
volumes := []v1.Volume{ | ||||
{Name: "etcd-data", VolumeSource: v1.VolumeSource{EmptyDir: &v1.EmptyDirVolumeSource{}}}, | ||||
if cs.Pod != nil { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This changes aren't needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is taken care by function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry. I don't understand your comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is
If it is not PV, it will just append the EmptyDir. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't understand it.
It only deals with resources. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, i thought you are asking line 267 & 268. This line I don't think it has anything to do with this PR scope. It was there mostly because of my cherry pick from the old PR. I do think it is a nice thing to have. But not belong to this PR's scope. I can remove it though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this. etcd-operator/pkg/util/k8sutil/k8sutil.go Line 338 in 7880638
|
||||
container = containerWithRequirements(container, cs.Pod.Resources) | ||||
} | ||||
|
||||
volumes := []v1.Volume{} | ||||
|
||||
if m.SecurePeer { | ||||
container.VolumeMounts = append(container.VolumeMounts, v1.VolumeMount{ | ||||
MountPath: peerTLSDir, | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,14 +141,13 @@ done | |
Spec: v1.PodSpec{ | ||
// Self-hosted etcd pod need to endure node restart. | ||
// If we set it to Never, the pod won't restart. If etcd won't come up, nor does other k8s API components. | ||
RestartPolicy: v1.RestartPolicyAlways, | ||
Containers: []v1.Container{c}, | ||
Volumes: volumes, | ||
HostNetwork: true, | ||
DNSPolicy: v1.DNSClusterFirstWithHostNet, | ||
Hostname: m.Name, | ||
Subdomain: clusterName, | ||
AutomountServiceAccountToken: func(b bool) *bool { return &b }(false), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert this. It is not related to this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to delete There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What's the reason for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we want to
The comment from your previous review. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why AutomountServiceAccountToken is related to PV? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just get it back. I deleted it while I was trying to remove changes to AutomountServiceAccountToken. Apparently, it shouldn't be removed here. |
||
RestartPolicy: v1.RestartPolicyAlways, | ||
Containers: []v1.Container{c}, | ||
Volumes: volumes, | ||
HostNetwork: true, | ||
DNSPolicy: v1.DNSClusterFirstWithHostNet, | ||
Hostname: m.Name, | ||
Subdomain: clusterName, | ||
}, | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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 e2e | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
api "github.com/coreos/etcd-operator/pkg/apis/etcd/v1beta2" | ||
"k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
|
||
"github.com/coreos/etcd-operator/test/e2e/e2eutil" | ||
"github.com/coreos/etcd-operator/test/e2e/framework" | ||
) | ||
|
||
func TestCreateClusterWithPV(t *testing.T) { | ||
if os.Getenv(envParallelTest) == envParallelTestTrue { | ||
t.Parallel() | ||
} | ||
f := framework.Global | ||
c := e2eutil.NewCluster("test-etcd-", 3) | ||
c.Spec.Pod = &api.PodPolicy{ | ||
PersistentVolumeClaimSpec: &v1.PersistentVolumeClaimSpec{ | ||
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce}, | ||
Resources: v1.ResourceRequirements{ | ||
Requests: v1.ResourceList{v1.ResourceName(v1.ResourceStorage): resource.MustParse("512Mi")}, | ||
}, | ||
StorageClassName: func(s string) *string { return &s }("standard"), | ||
}, | ||
} | ||
|
||
testEtcd, err := e2eutil.CreateCluster(t, f.CRClient, f.Namespace, c) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
defer func() { | ||
if err := e2eutil.DeleteCluster(t, f.CRClient, f.KubeClient, testEtcd); err != nil { | ||
t.Fatal(err) | ||
} | ||
}() | ||
|
||
if _, err := e2eutil.WaitUntilSizeReached(t, f.CRClient, 3, 30, testEtcd); err != nil { | ||
t.Fatalf("failed to create 3 members etcd cluster: %v", err) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mention that this field is alpha, and not use PV as stable storage as it should yet.