Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StatefulSet e2e: verify stateful pod hostname #36022

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion test/e2e/petset.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,14 @@ var _ = framework.KubeDescribe("StatefulSet [Slow] [Feature:PetSet]", func() {
By("Verifying statefulset mounted data directory is usable")
ExpectNoError(pst.checkMount(ps, "/data"))

By("Verifying statefulset provides a stable hostname for each pod")
ExpectNoError(pst.checkHostname(ps))

cmd := "echo $(hostname) > /data/hostname; sync;"
By("Running " + cmd + " in all pets")
ExpectNoError(pst.execInPets(ps, cmd))

By("Restarting pet set " + ps.Name)
By("Restarting statefulset " + ps.Name)
pst.restart(ps)
pst.saturate(ps)

Expand Down Expand Up @@ -572,6 +575,20 @@ func (p *statefulSetTester) execInPets(ps *apps.StatefulSet, cmd string) error {
return nil
}

func (p *statefulSetTester) checkHostname(ps *apps.StatefulSet) error {
cmd := "printf $(hostname)"
podList := p.getPodList(ps)
for _, pet := range podList.Items {
hostname, err := framework.RunHostCmd(pet.Namespace, pet.Name, cmd)
if err != nil {
return err
}
if hostname != pet.Name {
return fmt.Errorf("unexpected hostname (%s) and stateful pod name (%s) not equal", hostname, pet.Name)
}
}
return nil
}
func (p *statefulSetTester) saturate(ps *apps.StatefulSet) {
// TODO: Watch events and check that creation timestamps don't overlap
var i int32
Expand Down