-
Notifications
You must be signed in to change notification settings - Fork 143
[WIP]CNTRLPLANE-2273:Add operator health E2E tests #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wangke19
wants to merge
2
commits into
openshift:main
Choose a base branch
from
wangke19:add-operator-health-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+197,081
−14
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package main | ||
|
|
||
| // This file imports test packages to ensure they are registered with the OTE framework. | ||
| // The blank import causes the test's init() functions to run, which registers Ginkgo specs. | ||
|
|
||
| import ( | ||
| _ "github.com/openshift/cluster-config-operator/test/e2e" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| "k8s.io/client-go/kubernetes" | ||
| "k8s.io/client-go/rest" | ||
| "k8s.io/client-go/tools/clientcmd" | ||
| ) | ||
|
|
||
| const ( | ||
| operatorNamespace = "openshift-config-operator" | ||
| operatorName = "openshift-config-operator" | ||
| clusterOperatorName = "config-operator" | ||
| pollTimeout = 2 * time.Minute | ||
| pollInterval = 5 * time.Second | ||
| ) | ||
|
|
||
| // getKubernetesClient returns a Kubernetes client for interacting with the cluster. | ||
| func getKubernetesClient() (kubernetes.Interface, error) { | ||
| config, err := getRestConfig() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return kubernetes.NewForConfig(config) | ||
| } | ||
|
|
||
| // getRestConfig returns a REST config for the cluster. | ||
| func getRestConfig() (*rest.Config, error) { | ||
| loadingRules := clientcmd.NewDefaultClientConfigLoadingRules() | ||
| configOverrides := &clientcmd.ConfigOverrides{} | ||
| kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides) | ||
| return kubeConfig.ClientConfig() | ||
| } | ||
|
|
||
| // testContext returns a context for test operations. | ||
| func testContext() context.Context { | ||
| return context.Background() | ||
| } | ||
|
|
||
| // int64Ptr returns a pointer to an int64 value. | ||
| func int64Ptr(i int64) *int64 { | ||
| return &i | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| g "github.com/onsi/ginkgo/v2" | ||
| o "github.com/onsi/gomega" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| var _ = g.Describe("[Operator][Serial] Operator Health", func() { | ||
| var ( | ||
| ctx = testContext() | ||
| ) | ||
|
|
||
| g.Context("Deployment Verification", func() { | ||
| g.It("should have a running deployment with ready replicas", func() { | ||
| k8sClient, err := getKubernetesClient() | ||
| o.Expect(err).NotTo(o.HaveOccurred(), "failed to create kubernetes client") | ||
|
|
||
| o.Eventually(func() error { | ||
| deployment, err := k8sClient.AppsV1().Deployments(operatorNamespace).Get(ctx, operatorName, metav1.GetOptions{}) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get deployment: %w", err) | ||
| } | ||
|
|
||
| if deployment.Status.ReadyReplicas < 1 { | ||
| return fmt.Errorf("deployment has %d ready replicas, expected at least 1", deployment.Status.ReadyReplicas) | ||
| } | ||
|
|
||
| return nil | ||
| }, pollTimeout, pollInterval).Should(o.Succeed()) | ||
| }) | ||
| }) | ||
|
|
||
| g.Context("Pod Health", func() { | ||
| g.It("should have running pods without fatal errors in logs", func() { | ||
| k8sClient, err := getKubernetesClient() | ||
| o.Expect(err).NotTo(o.HaveOccurred(), "failed to create kubernetes client") | ||
|
|
||
| // First, verify pods are running | ||
| var pods *corev1.PodList | ||
| o.Eventually(func() error { | ||
| podList, err := k8sClient.CoreV1().Pods(operatorNamespace).List(ctx, metav1.ListOptions{ | ||
| LabelSelector: "app=openshift-config-operator", | ||
| }) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to list pods: %w", err) | ||
| } | ||
|
|
||
| if len(podList.Items) == 0 { | ||
| return fmt.Errorf("no pods found with label app=openshift-config-operator") | ||
| } | ||
|
|
||
| for _, pod := range podList.Items { | ||
| if pod.Status.Phase != corev1.PodRunning { | ||
| return fmt.Errorf("pod %s is in phase %s, expected Running", pod.Name, pod.Status.Phase) | ||
| } | ||
| } | ||
|
|
||
| pods = podList | ||
| return nil | ||
| }, pollTimeout, pollInterval).Should(o.Succeed()) | ||
|
|
||
| // Check pod logs for fatal errors | ||
| for _, pod := range pods.Items { | ||
| podLogs, err := k8sClient.CoreV1().Pods(operatorNamespace).GetLogs(pod.Name, &corev1.PodLogOptions{ | ||
| Container: operatorName, | ||
| TailLines: int64Ptr(100), | ||
| }).DoRaw(ctx) | ||
| o.Expect(err).NotTo(o.HaveOccurred(), "failed to get logs for pod %s", pod.Name) | ||
|
|
||
| // Check for fatal errors in logs | ||
| scanner := bufio.NewScanner(strings.NewReader(string(podLogs))) | ||
| for scanner.Scan() { | ||
| line := scanner.Text() | ||
| if strings.Contains(strings.ToLower(line), "fatal") || | ||
| strings.Contains(strings.ToLower(line), "panic") { | ||
| g.Fail(fmt.Sprintf("found fatal error in pod %s logs: %s", pod.Name, line)) | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| }) | ||
| }) | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log scanning may produce false positives.
The case-insensitive substring match for "fatal" and "panic" could flag benign log lines such as
"no fatal errors found"or"panic recovery handler registered". Consider tightening the pattern—for example, matching common structured log prefixes like"F"or"level=fatal", or using a regex that checks for word boundaries.🔎 Example of a tighter check
for scanner.Scan() { line := scanner.Text() - if strings.Contains(strings.ToLower(line), "fatal") || - strings.Contains(strings.ToLower(line), "panic") { + lower := strings.ToLower(line) + // Match klog fatal prefix or explicit panic indicators + if strings.HasPrefix(line, "F") || // klog fatal lines start with F + strings.Contains(lower, "level=fatal") || + strings.Contains(lower, "panic:") { g.Fail(fmt.Sprintf("found fatal error in pod %s logs: %s", pod.Name, line)) } }📝 Committable suggestion
🤖 Prompt for AI Agents