Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
test: ensure hostPort routing (#4186)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfrancis authored Jan 25, 2021
1 parent 4c89510 commit ae4bb40
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/e2e/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,47 @@ var _ = Describe("Azure Container Cluster using the Kubernetes Orchestrator", fu
Expect(successes).To(Equal(cfg.StabilityIterations))
})

It("should be able to create and connect to a hostPort-configured pod", func() {
if eng.AnyAgentIsLinux() {
nodes, err := node.GetReadyWithRetry(1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
var numNodes int
controlPlaneNodeRegexString := fmt.Sprintf("^%s-.*", common.LegacyControlPlaneVMPrefix)
controlPlaneNodeRegexp, err := regexp.Compile(controlPlaneNodeRegexString)
Expect(err).NotTo(HaveOccurred())
for _, n := range nodes {
if n.IsLinux() && !controlPlaneNodeRegexp.MatchString(n.Metadata.Name) {
numNodes++
}
}
By("Creating a httpbin DaemonSet")
httpbinName := "httpbin"
httpbinNamespace := "default"
d, err := daemonset.CreateDaemonsetDeleteIfExists(filepath.Join(WorkloadDir, fmt.Sprintf("%s.yaml", httpbinName)), httpbinName, httpbinNamespace, "app", httpbinName, 5*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
_, err = pod.WaitForMinRunningByLabelWithRetry(numNodes, "app", httpbinName, httpbinNamespace, 1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
By("Ensuring that we have can connect locally using the configured httpbin container hostPort")
hostPortTestName := "hostport-test"
hostPortTestNamespace := "default"
j, err := job.CreateJobFromFileWithRetry(filepath.Join(WorkloadDir, fmt.Sprintf("%s.yaml", hostPortTestName)), hostPortTestName, hostPortTestNamespace, 3*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
ready, err := j.WaitOnSucceeded(5*time.Second, 1*time.Minute)
if err != nil {
pod.PrintPodsLogs(hostPortTestName, hostPortTestNamespace, 5*time.Second, 1*time.Minute)
}
Expect(err).NotTo(HaveOccurred())
Expect(ready).To(Equal(true))
By("Cleaning up after ourselves")
err = j.Delete(util.DefaultDeleteRetries)
Expect(err).NotTo(HaveOccurred())
err = d.Delete(util.DefaultDeleteRetries)
Expect(err).NotTo(HaveOccurred())
} else {
Skip("hostPort test requires a Linux node")
}
})

It("should be able to launch a long-running container networking DNS liveness pod", func() {
p, err := pod.CreatePodFromFileIfNotExist(filepath.Join(WorkloadDir, "dns-liveness.yaml"), "dns-liveness", "default", 1*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expand Down
22 changes: 22 additions & 0 deletions test/e2e/kubernetes/workloads/hostport-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: batch/v1
kind: Job
metadata:
name: hostport-test
spec:
completions: 1
backoffLimit: 0
template:
spec:
restartPolicy: Never
containers:
- image: mcr.microsoft.com/oss/tutum/curl:latest
name: hostport-test
env:
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
command: [ "/bin/sh", "-c", "--" ]
args: [ "curl -sS $(HOST_IP):8080/get" ]
nodeSelector:
beta.kubernetes.io/os: linux
22 changes: 22 additions & 0 deletions test/e2e/kubernetes/workloads/httpbin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: httpbin
spec:
selector:
matchLabels:
app: httpbin
template:
metadata:
labels:
app: httpbin
spec:
containers:
- image: docker.io/kennethreitz/httpbin
imagePullPolicy: IfNotPresent
name: httpbin
ports:
- containerPort: 80
hostPort: 8080
nodeSelector:
beta.kubernetes.io/os: linux

0 comments on commit ae4bb40

Please sign in to comment.