Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions tests/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"strconv"
"strings"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -66,6 +67,16 @@ func CheckDeployments(kubeconfigFile, namespace string, deployments ...string) e
return nil
}

// GetDaemonsetReady returns the number of ready pods for the given daemonset
func GetDaemonsetReady(daemonset string, kubeConfigFile string) (int, error) {
cmd := "kubectl get ds " + daemonset + " -o jsonpath='{range .items[*]}{.status.numberReady}' --kubeconfig=" + kubeConfigFile
out, err := RunCommand(cmd)
if err != nil {
return 0, err
}
return strconv.Atoi(out)
}

func ParseNodes(kubeconfigFile string) ([]corev1.Node, error) {
clientSet, err := K8sClient(kubeconfigFile)
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions tests/docker/hardened/hardened_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ kubelet-arg:
It("applies network policies", func() {
_, err := config.DeployWorkload("hardened-ingress.yaml")
Expect(err).NotTo(HaveOccurred())
Eventually(func() (string, error) {
cmd := "kubectl get daemonset -n default example -o jsonpath='{.status.numberReady}'"
return tests.RunCommand(cmd)
}, "60s", "5s").Should(Equal("2"))
Eventually(func() (int, error) {
return tests.GetDaemonsetReady("example", config.KubeconfigFile)
}, "60s", "5s").Should(Equal(2))
_, err = config.DeployWorkload("hardened-netpool.yaml")
Expect(err).NotTo(HaveOccurred())
})
Expand Down
18 changes: 18 additions & 0 deletions tests/docker/resources/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: test-daemonset
spec:
selector:
matchLabels:
k8s-app: test-daemonset
template:
metadata:
labels:
k8s-app: test-daemonset
spec:
containers:
- name: webserver
image: rancher/mirrored-library-nginx:1.29.1-alpine
ports:
- containerPort: 80
14 changes: 14 additions & 0 deletions tests/docker/resources/dnsutils.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Pod
metadata:
name: dnsutils
namespace: default
spec:
containers:
- name: dnsutils
image: registry.k8s.io/e2e-test-images/jessie-dnsutils:1.7
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
restartPolicy: Always
53 changes: 53 additions & 0 deletions tests/docker/resources/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-ingress
spec:
rules:
- host: foo1.bar.com
http:
paths:
- backend:
service:
name: nginx-ingress-svc
port:
number: 80
path: /
pathType: ImplementationSpecific
---
apiVersion: v1
kind: Service
metadata:
name: nginx-ingress-svc
labels:
k8s-app: nginx-app-ingress
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
name: http
selector:
k8s-app: nginx-app-ingress
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-ingress
spec:
replicas: 2
selector:
matchLabels:
k8s-app: nginx-app-ingress
template:
metadata:
labels:
k8s-app: nginx-app-ingress
spec:
terminationGracePeriodSeconds: 60
containers:
- name: testcontainer
image: rancher/mirrored-library-busybox:1.37.0
args: ['sh', '-c', 'echo Welcome to nginx! > index.html; hostname > name.html; httpd -vvf']
ports:
- containerPort: 80
14 changes: 2 additions & 12 deletions tests/docker/test-helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,7 @@ func (config *TestConfig) ProvisionServers(numOfServers int) error {
}

// Get the IP address of the container
var cmd string
if config.DualStack {
cmd = "docker inspect --format '{{range $k,$v := .NetworkSettings.Networks}}{{printf \"%s\" $v.IPAddress}}{{end}}' " + name
} else {
cmd = "docker inspect --format '{{ .NetworkSettings.IPAddress }}' " + name
}
cmd := "docker inspect --format '{{range $k,$v := .NetworkSettings.Networks}}{{printf \"%s\" $v.IPAddress}}{{end}}' " + name
ipOutput, err := tests.RunCommand(cmd)
if err != nil {
return fmt.Errorf("failed to get container IP address: %s: %v", ipOutput, err)
Expand Down Expand Up @@ -397,12 +392,7 @@ func (config *TestConfig) ProvisionAgents(numOfAgents int) error {
}

// Get the IP address of the container
var cmd string
if config.DualStack {
cmd = "docker inspect --format '{{range $k,$v := .NetworkSettings.Networks}}{{printf \"%s\" $v.IPAddress}}{{end}}' " + name
} else {
cmd = "docker inspect --format '{{ .NetworkSettings.IPAddress }}' " + name
}
cmd := "docker inspect --format '{{range $k,$v := .NetworkSettings.Networks}}{{printf \"%s\" $v.IPAddress}}{{end}}' " + name
ipOutput, err := tests.RunCommand(cmd)
if err != nil {
return err
Expand Down
Loading