Skip to content

Commit

Permalink
fix bugs, add test for node-exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
gracewehner committed Jan 29, 2024
1 parent b4957d9 commit baca9ee
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
19 changes: 16 additions & 3 deletions otelcollector/test/containerstatus/container_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import (
. "github.com/onsi/gomega"
)

var _ = DescribeTable("The containers should be running",
func(namespace string, controllerLabelName string, controllerLabelValue string) {
err := utils.CheckIfAllContainersAreRunning(K8sClient, namespace, controllerLabelName, controllerLabelValue)
Expect(err).NotTo(HaveOccurred())
},
Entry("when checking the ama-metrics replica pod(s)", "kube-system", "rsName", "ama-metrics"),
Entry("when checking the ama-metrics-node", "kube-system", "dsName", "ama-metrics-node"),
Entry("when checking the ama-metrics-ksm pod", "kube-system", "app.kubernetes.io/name", "ama-metrics-ksm"),
Entry("when checking the ama-metrics-operator-targets pod", "kube-system", "rsName", "ama-metrics-operator-targets", Label("operator")),
Entry("when checking the prometheus-node-exporter pod", "kube-system", "app", "prometheus-node-exporter", Label("arc-extension")),
)

var _ = DescribeTable("All processes are running",
func(namespace, labelName, labelValue, containerName string, processes []string) {
err := utils.CheckAllProcessesRunning(K8sClient, Cfg, labelName, labelValue, namespace, containerName, processes)
Expand All @@ -24,7 +36,7 @@ var _ = DescribeTable("All processes are running",
"crond",
},
),
Entry("when checking the ama-metrics-node daemonset pods", "kube-system", "dsName", "ama-metrics", "prometheus-collector",
Entry("when checking the ama-metrics-node daemonset pods", "kube-system", "dsName", "ama-metrics-node", "prometheus-collector",
[]string {
"fluent-bit",
"telegraf",
Expand All @@ -45,6 +57,7 @@ var _ = DescribeTable("The container logs should not contain errors",
},
Entry("when checking the ama-metrics replica pods", "kube-system", "rsName", "ama-metrics"),
Entry("when checking the ama-metrics-node", "kube-system", "dsName", "ama-metrics-node"),
Entry("when checking the ama-metrics-operator-targets pod", "kube-system", "rsName", "ama-metrics-operator-targets"),
Entry("when checking the ama-metrics-ksm pod", "kube-system", "rsName", "ama-metrics-ksm"),
Entry("when checking the ama-metrics-ksm pod", "kube-system", "app.kubernetes.io/name", "ama-metrics-ksm"),
Entry("when checking the ama-metrics-operator-targets pod", "kube-system", "rsName", "ama-metrics-operator-targets", Label("operator")),
Entry("when checking the prometheus-node-exporter pod", "kube-system", "app", "prometheus-node-exporter", Label("arc-extension")),
)
2 changes: 1 addition & 1 deletion otelcollector/test/utils/constants.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package utils

var(

// Slices can't be constants
LogLineErrorsToExclude = [...]string{
"\"filepath\":\"/MetricsExtensionConsoleDebugLog.log\"",
"create or renew cluster identity error"
}
)
24 changes: 22 additions & 2 deletions otelcollector/test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func CheckContainerLogsForErrors(clientset *kubernetes.Clientset, namespace, lab
return fmt.Errorf("Logs for container %s in pod %s contain errors:\n %s", container.Name, pod.Name, line)
}
}
return fmt.Errorf("Logs for container %s in pod %s contain errors", container.Name, pod.Name)
}
}
}
Expand All @@ -97,7 +96,7 @@ func GetPodsWithLabel(clientset *kubernetes.Clientset, namespace string, labelKe
if err != nil {
return nil, err
}
if podList == nil {
if podList == nil || len(podList.Items) == 0{
return nil, fmt.Errorf("no pods found with label %s=%s", labelKey, labelValue)
}

Expand Down Expand Up @@ -244,3 +243,24 @@ func CheckLivenessProbeRestartForProcess(K8sClient *kubernetes.Clientset, Cfg *r

return nil
}

func CheckIfAllContainersAreRunning(clientset *kubernetes.Clientset, namespace, labelKey string, labelValue string) (error) {
pods, err := GetPodsWithLabel(clientset, namespace, labelKey, labelValue)
if err != nil {
return errors.New(fmt.Sprintf("Error getting pods with the specified labels: %v", err))
}

for _, pod := range pods {
if pod.Status.Phase != corev1.PodRunning {
return errors.New(fmt.Sprintf("Pod is not runinng. Phase is: %v", pod.Status.Phase))
}

for _, containerStatus := range pod.Status.ContainerStatuses {
if containerStatus.State.Running == nil {
return errors.New(fmt.Sprintf("Container %s is not running", containerStatus.Name))
}
}
}

return nil
}

0 comments on commit baca9ee

Please sign in to comment.