Skip to content

Commit 2993bfd

Browse files
committed
Added tests for containerstatus and livenssprobe
1 parent cf803fc commit 2993bfd

15 files changed

+1539
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package containerstatus_test
2+
3+
import (
4+
"testing"
5+
6+
"docker-provider/test/utils"
7+
8+
. "github.com/onsi/ginkgo/v2"
9+
. "github.com/onsi/gomega"
10+
"k8s.io/client-go/kubernetes"
11+
"k8s.io/client-go/rest"
12+
)
13+
14+
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
15+
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
16+
17+
var K8sClient *kubernetes.Clientset
18+
var Cfg *rest.Config
19+
20+
func TestContainerStatus(t *testing.T) {
21+
RegisterFailHandler(Fail)
22+
23+
RunSpecs(t, "Container Status Test Suite")
24+
}
25+
26+
var _ = BeforeSuite(func() {
27+
var err error
28+
K8sClient, Cfg, err = utils.SetupKubernetesClient()
29+
Expect(err).NotTo(HaveOccurred())
30+
})
31+
32+
var _ = AfterSuite(func() {
33+
By("tearing down the test environment")
34+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package containerstatus_test
2+
3+
import (
4+
. "github.com/onsi/ginkgo/v2"
5+
. "github.com/onsi/gomega"
6+
7+
"docker-provider/test/utils"
8+
)
9+
10+
/*
11+
* For each of the pods that we deploy, ensure each container within that pod has status 'Running'.
12+
* The replicaset, and daemonset are always deployed.
13+
* The label and values are provided to get a list of pods only with that label.
14+
*/
15+
var _ = DescribeTable("The containers should be running",
16+
func(namespace string, controllerLabelName string, controllerLabelValue string) {
17+
err := utils.CheckIfAllContainersAreRunning(K8sClient, namespace, controllerLabelName, controllerLabelValue)
18+
Expect(err).NotTo(HaveOccurred())
19+
},
20+
Entry("when checking the ama-logs", "kube-system", "component", "ama-logs-agent"),
21+
Entry("when checking the ama-logs-rs replica pod(s)", "kube-system", "rsName", "ama-logs-rs"),
22+
)
23+
24+
/*
25+
* For each of the DS pods that we deploy, ensure that all nodes have been used to schedule these pods.
26+
* The label and values are provided to get a list of pods only with that label.
27+
* The osLabel is provided to check on all DS pods based on the OS.
28+
*/
29+
var _ = DescribeTable("The pods should be scheduled in all nodes",
30+
func(namespace string, controllerLabelName string, controllerLabelValue string, osLabel string) {
31+
err := utils.CheckIfAllPodsScheduleOnNodes(K8sClient, namespace, controllerLabelName, controllerLabelValue, osLabel)
32+
Expect(err).NotTo(HaveOccurred())
33+
},
34+
Entry("when checking the ama-logs", "kube-system", "component", "ama-logs-agent", "linux"),
35+
Entry("when checking the ama-logs-win pod", "kube-system", "component", "ama-logs-agent-windows", "windows", Label(utils.WindowsLabel)),
36+
)
37+
38+
/*
39+
* For each of the DS pods that we deploy, ensure that all specific nodes like ARM64, FIPS have been used to schedule these pods.
40+
* The label and values are provided to get a list of pods only with that label.
41+
*/
42+
var _ = DescribeTable("The pods should be scheduled in all Fips and ARM64 nodes",
43+
func(namespace string, controllerLabelName string, controllerLabelValue string, nodeLabelKey string, nodeLabelValue string) {
44+
err := utils.CheckIfAllPodsScheduleOnSpecificNodesLabels(K8sClient, namespace, controllerLabelName, controllerLabelValue, nodeLabelKey, nodeLabelValue)
45+
Expect(err).NotTo(HaveOccurred())
46+
},
47+
Entry("when checking the ama-logs", "kube-system", "component", "ama-logs-agent", "kubernetes.azure.com/fips_enabled", "true", Label(utils.FIPSLabel)),
48+
Entry("when checking the ama-logs-win pod", "kube-system", "component", "ama-logs-agent-windows", "kubernetes.azure.com/fips_enabled", "true", Label(utils.WindowsLabel), Label(utils.FIPSLabel)),
49+
Entry("when checking the ama-logs", "kube-system", "component", "ama-logs-agent", "kubernetes.io/arch", "arm64", Label(utils.ARM64Label)),
50+
)
51+
52+
/*
53+
* For each of the pods that have the ama-logs container, check all expected processes are running.
54+
* The linux replicaset and daemonset should have the same processes running.
55+
*/
56+
var _ = DescribeTable("All processes are running",
57+
func(namespace, labelName, labelValue, containerName string, processes []string) {
58+
err := utils.CheckAllProcessesRunning(K8sClient, Cfg, labelName, labelValue, namespace, containerName, processes)
59+
Expect(err).NotTo(HaveOccurred())
60+
},
61+
Entry("when checking the ama-logs-rs replica pod", "kube-system", "rsName", "ama-logs-rs", "ama-logs",
62+
[]string{
63+
"fluent-bit",
64+
"fluentd",
65+
"mdsd -a -A -r",
66+
"inotifywait /etc/config/settings",
67+
"crond",
68+
},
69+
),
70+
Entry("when checking the ama-logs daemonset pods", "kube-system", "component", "ama-logs-agent", "ama-logs",
71+
[]string{
72+
"fluent-bit",
73+
"fluentd",
74+
"mdsd -a -A -r",
75+
"inotifywait /etc/config/settings",
76+
"crond",
77+
"telegraf",
78+
},
79+
),
80+
)
81+
82+
/*
83+
* For windows daemonset pods that have the ama-logs-windows container, check all expected processes are running.
84+
*/
85+
var _ = DescribeTable("All processes are running",
86+
func(namespace, labelName, labelValue, containerName string, processes []string) {
87+
err := utils.CheckAllWindowsProcessesRunning(K8sClient, Cfg, labelName, labelValue, namespace, containerName, processes)
88+
Expect(err).NotTo(HaveOccurred())
89+
},
90+
Entry("when checking the ama-logs-windows daemonset pods", "kube-system", "component", "ama-logs-agent-windows", "ama-logs-windows",
91+
[]string{
92+
"fluent-bit",
93+
"MonAgentLauncher",
94+
"MonAgentHost",
95+
"MonAgentManager",
96+
"MonAgentCore",
97+
"telegraf",
98+
},
99+
Label(utils.WindowsLabel),
100+
FlakeAttempts(3),
101+
),
102+
)
103+
104+
/*
105+
- For each of the pods that we deploy, ensure each container within that pod doesn't have errors in the logs.
106+
- The replicaset and daemonset are always deployed.
107+
- The label and values are provided to get a list of pods only with that label.
108+
*/
109+
var _ = DescribeTable("The container logs should not contain errors",
110+
func(namespace string, controllerLabelName string, controllerLabelValue string) {
111+
err := utils.CheckContainerLogsForErrors(K8sClient, namespace, controllerLabelName, controllerLabelValue)
112+
Expect(err).NotTo(HaveOccurred())
113+
},
114+
Entry("when checking the ama-logs-rs pods", "kube-system", "rsName", "ama-logs-rs"),
115+
Entry("when checking the ama-logs daemonset pods", "kube-system", "component", "ama-logs-agent"),
116+
Entry("when checking the ama-logs-rs pods", "kube-system", "rsName", "ama-logs-rs", Label(utils.ARM64Label)),
117+
Entry("when checking the ama-logs daemonset pods", "kube-system", "component", "ama-logs-agent", Label(utils.ARM64Label)),
118+
Entry("when checking the ama-logs-windows daemonset pods", "kube-system", "component", "ama-logs-agent-windows", Label(utils.WindowsLabel)),
119+
)
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module docker-provider/test/containerstatus
2+
3+
go 1.20
4+
5+
replace docker-provider/test/utils => ../utils
6+
7+
require (
8+
docker-provider/test/utils v0.0.0
9+
github.com/onsi/ginkgo/v2 v2.13.1
10+
github.com/onsi/gomega v1.30.0
11+
k8s.io/client-go v0.28.4
12+
)
13+
14+
require (
15+
github.com/davecgh/go-spew v1.1.1 // indirect
16+
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
17+
github.com/ghodss/yaml v1.0.0 // indirect
18+
github.com/go-logr/logr v1.3.0 // indirect
19+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
20+
github.com/go-openapi/jsonreference v0.20.2 // indirect
21+
github.com/go-openapi/swag v0.22.3 // indirect
22+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
23+
github.com/gogo/protobuf v1.3.2 // indirect
24+
github.com/golang/protobuf v1.5.3 // indirect
25+
github.com/google/gnostic-models v0.6.8 // indirect
26+
github.com/google/go-cmp v0.6.0 // indirect
27+
github.com/google/gofuzz v1.2.0 // indirect
28+
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
29+
github.com/google/uuid v1.6.0 // indirect
30+
github.com/imdario/mergo v0.3.6 // indirect
31+
github.com/josharian/intern v1.0.0 // indirect
32+
github.com/json-iterator/go v1.1.12 // indirect
33+
github.com/mailru/easyjson v0.7.7 // indirect
34+
github.com/moby/spdystream v0.2.0 // indirect
35+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
36+
github.com/modern-go/reflect2 v1.0.2 // indirect
37+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
38+
github.com/spf13/pflag v1.0.5 // indirect
39+
github.com/stretchr/testify v1.9.0 // indirect
40+
golang.org/x/net v0.24.0 // indirect
41+
golang.org/x/oauth2 v0.16.0 // indirect
42+
golang.org/x/sys v0.19.0 // indirect
43+
golang.org/x/term v0.19.0 // indirect
44+
golang.org/x/text v0.14.0 // indirect
45+
golang.org/x/time v0.3.0 // indirect
46+
golang.org/x/tools v0.14.0 // indirect
47+
google.golang.org/appengine v1.6.7 // indirect
48+
google.golang.org/protobuf v1.33.0 // indirect
49+
gopkg.in/inf.v0 v0.9.1 // indirect
50+
gopkg.in/yaml.v2 v2.4.0 // indirect
51+
gopkg.in/yaml.v3 v3.0.1 // indirect
52+
k8s.io/api v0.28.4 // indirect
53+
k8s.io/apimachinery v0.28.4 // indirect
54+
k8s.io/klog/v2 v2.100.1 // indirect
55+
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
56+
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
57+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
58+
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
59+
sigs.k8s.io/yaml v1.3.0 // indirect
60+
)

0 commit comments

Comments
 (0)