Skip to content

Commit 6c30d23

Browse files
author
Ricardo Pchevuzinske Katz
committed
Remove watching Endpoints of Headless Services
Signed-off-by: Ricardo Pchevuzinske Katz <[email protected]>
1 parent e389237 commit 6c30d23

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

test/e2e/network/service.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,68 @@ var _ = SIGDescribe("Services", func() {
18651865
framework.ExpectNoError(e2eservice.VerifyServeHostnameServiceDown(cs, host, svcDisabledIP, servicePort))
18661866
})
18671867

1868+
ginkgo.It("should implement service.kubernetes.io/headless", func() {
1869+
// this test uses e2essh.NodeSSHHosts that does not work if a Node only reports LegacyHostIP
1870+
framework.SkipUnlessProviderIs(framework.ProvidersWithSSH...)
1871+
// this test does not work if the Node does not support SSH Key
1872+
framework.SkipUnlessSSHKeyPresent()
1873+
1874+
ns := f.Namespace.Name
1875+
numPods, servicePort := 3, defaultServeHostnameServicePort
1876+
serviceHeadlessLabels := map[string]string{v1.IsHeadlessService: ""}
1877+
1878+
// We will create 2 services to test creating services in both states and also dynamic updates
1879+
// svcHeadless: Created with the label, will always be disabled. We create this early and
1880+
// test again late to make sure it never becomes available.
1881+
// svcHeadlessToggled: Created without the label then the label is toggled verifying reachability at each step.
1882+
1883+
ginkgo.By("creating service-headless in namespace " + ns)
1884+
svcHeadless := getServeHostnameService("service-headless")
1885+
svcHeadless.ObjectMeta.Labels = serviceHeadlessLabels
1886+
// This should be improved, as we do not want a Headlesss Service to contain an IP...
1887+
_, svcHeadlessIP, err := e2eservice.StartServeHostnameService(cs, svcHeadless, ns, numPods)
1888+
framework.ExpectNoError(err, "failed to create replication controller with headless service: %s in the namespace: %s", svcHeadlessIP, ns)
1889+
1890+
ginkgo.By("creating service in namespace " + ns)
1891+
svcHeadlessToggled := getServeHostnameService("service-headless-toggled")
1892+
podHeadlessToggledNames, svcHeadlessToggledIP, err := e2eservice.StartServeHostnameService(cs, svcHeadlessToggled, ns, numPods)
1893+
framework.ExpectNoError(err, "failed to create replication controller with service: %s in the namespace: %s", svcHeadlessToggledIP, ns)
1894+
1895+
jig := e2eservice.NewTestJig(cs, svcHeadlessToggled.ObjectMeta.Name)
1896+
1897+
hosts, err := e2essh.NodeSSHHosts(cs)
1898+
framework.ExpectNoError(err, "failed to find external/internal IPs for every node")
1899+
if len(hosts) == 0 {
1900+
e2elog.Failf("No ssh-able nodes")
1901+
}
1902+
host := hosts[0]
1903+
1904+
ginkgo.By("verifying service is up")
1905+
framework.ExpectNoError(e2eservice.VerifyServeHostnameServiceUp(cs, ns, host, podHeadlessToggledNames, svcHeadlessToggledIP, servicePort))
1906+
1907+
ginkgo.By("verifying service-headless is not up")
1908+
framework.ExpectNoError(e2eservice.VerifyServeHostnameServiceDown(cs, host, svcHeadlessIP, servicePort))
1909+
1910+
ginkgo.By("adding service.kubernetes.io/headless label")
1911+
jig.UpdateServiceOrFail(ns, svcHeadlessToggled.ObjectMeta.Name, func(svc *v1.Service) {
1912+
svc.ObjectMeta.Labels = serviceHeadlessLabels
1913+
})
1914+
1915+
ginkgo.By("verifying service is not up")
1916+
framework.ExpectNoError(e2eservice.VerifyServeHostnameServiceDown(cs, host, svcHeadlessToggledIP, servicePort))
1917+
1918+
ginkgo.By("removing service.kubernetes.io/headless annotation")
1919+
jig.UpdateServiceOrFail(ns, svcHeadlessToggled.ObjectMeta.Name, func(svc *v1.Service) {
1920+
svc.ObjectMeta.Labels = nil
1921+
})
1922+
1923+
ginkgo.By("verifying service is up")
1924+
framework.ExpectNoError(e2eservice.VerifyServeHostnameServiceUp(cs, ns, host, podHeadlessToggledNames, svcHeadlessToggledIP, servicePort))
1925+
1926+
ginkgo.By("verifying service-headless is still not up")
1927+
framework.ExpectNoError(e2eservice.VerifyServeHostnameServiceDown(cs, host, svcHeadlessIP, servicePort))
1928+
})
1929+
18681930
ginkgo.It("should be rejected when no endpoints exist", func() {
18691931
namespace := f.Namespace.Name
18701932
serviceName := "no-pods"

0 commit comments

Comments
 (0)