Migrate test cases to Project API testing KubeAPI server functionality#31310
Migrate test cases to Project API testing KubeAPI server functionality#31310YamunadeviShanmugam wants to merge 1 commit into
Conversation
|
Pipeline controller notification For optional jobs, comment This repository is configured in: automatic mode |
|
Skipping CI for Draft Pull Request. |
WalkthroughAdds four new serialized Ginkgo e2e tests to ChangesProject E2E Tests
Sequence Diagram(s)sequenceDiagram
rect rgba(173, 216, 230, 0.5)
Note over GinkgoTest,ProjectAPI: project-request-template
GinkgoTest->>ProjectAPI: create pre-template project
GinkgoTest->>ConfigAPI: POST template to openshift-config
GinkgoTest->>ConfigAPI: PATCH project.config.openshift.io/cluster
ConfigAPI->>OpenShiftAPIServerOperator: observe projectRequestTemplate
GinkgoTest->>OpenShiftAPIServerOperator: poll observedConfig until template present
GinkgoTest->>ClusterOperator: poll until Available=true, Progressing=false
GinkgoTest->>ProjectAPI: create post-template project
ProjectAPI-->>GinkgoTest: project has LimitRange + ResourceQuota
GinkgoTest->>ProjectAPI: assert pre-template project has no quota/limits
end
rect rgba(144, 238, 144, 0.5)
Note over GinkgoTest,ProjectAPI: project-cascading-delete
GinkgoTest->>ProjectAPI: create project + resources (pods, configmap, secret)
GinkgoTest->>ProjectAPI: wait for pod readiness
GinkgoTest->>ProjectAPI: DELETE project
GinkgoTest->>ProjectAPI: poll until namespace gone
GinkgoTest->>ProjectAPI: assert all child resources removed
GinkgoTest->>ProjectAPI: recreate project, assert empty
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error, 4 warnings)
✅ Passed checks (10 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: YamunadeviShanmugam The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
test/extended/project/project.go (2)
764-784: 💤 Low valueRefactor: Use the helper function to avoid duplication.
This polling logic duplicates the
waitForOpenShiftAPIServerOperatorStableWithPollinghelper function defined later in this file (lines 967-991). Consider reusing the helper.♻️ Suggested refactor
- err = wait.PollUntilContextCancel(ctx, 30*time.Second, true, func(ctx context.Context) (bool, error) { - co, err := oc.AdminConfigClient().ConfigV1().ClusterOperators().Get(ctx, "openshift-apiserver", metav1.GetOptions{}) - if err != nil { - return false, nil - } - var available, progressing, degraded bool - for _, c := range co.Status.Conditions { - if c.Type == configv1.OperatorAvailable { - available = c.Status == configv1.ConditionTrue - } else if c.Type == configv1.OperatorProgressing { - progressing = c.Status == configv1.ConditionTrue - } else if c.Type == configv1.OperatorDegraded { - degraded = c.Status == configv1.ConditionTrue - } - } - if degraded { - return false, fmt.Errorf("openshift-apiserver operator is degraded") - } - return available && !progressing, nil - }) + err = waitForOpenShiftAPIServerOperatorStableWithPolling(ctx, oc)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/extended/project/project.go` around lines 764 - 784, The polling logic for checking the OpenShift API server operator status is duplicated inline in the code block starting at line 764. Remove the inline wait.PollUntilContextCancel block that checks cluster operator conditions (available, progressing, degraded) and replace it with a call to the existing helper function waitForOpenShiftAPIServerOperatorStableWithPolling which is defined later in the file and contains the same polling logic. This will eliminate the code duplication and improve maintainability.
884-895: ⚡ Quick winConsider detecting permanent pod failures to fail fast.
The pod readiness check only detects transitional states (
ContainerCreating,Init,Pending). If the image pull fails permanently (e.g.,ImagePullBackOff,ErrImagePull) or the container crashes (CrashLoopBackOff), the test will wait the full 3 minutes before timing out.♻️ Suggested improvement
err = wait.PollUntilContextTimeout(context.Background(), 10*time.Second, 3*time.Minute, false, func(ctx context.Context) (bool, error) { podOutput, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("pods", "-n", projectName, "--no-headers").Output() if err != nil { return false, nil } + // Fail fast on permanent errors + if matched, _ := regexp.MatchString(`(ImagePullBackOff|ErrImagePull|CrashLoopBackOff|Error)`, podOutput); matched { + return false, fmt.Errorf("pod entered failure state: %s", podOutput) + } if matched, _ := regexp.MatchString(`(ContainerCreating|Init|Pending)`, podOutput); matched { return false, nil } return strings.TrimSpace(podOutput) != "", nil })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/extended/project/project.go` around lines 884 - 895, The pod readiness check in the wait.PollUntilContextTimeout function with the regexp.MatchString call only detects transitional states (ContainerCreating, Init, Pending) but does not check for permanent failure states like ImagePullBackOff, ErrImagePull, or CrashLoopBackOff. Add an additional regexp.MatchString check within the same polling condition to detect these failure states, and return false immediately when such a state is found so the wait fails fast instead of continuing for the full 3-minute timeout duration.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/extended/project/project.go`:
- Around line 909-916: The deletion verification in the poll function currently
treats any error from the oc get project command as successful deletion by
returning true when getErr is not nil. This masks transient errors like network
or authentication problems. Instead of immediately returning true when getErr is
not nil, check if the error message specifically contains "not found" text using
regexp.MatchString (similar to how it's already checking the output), and only
return true if it matches that specific pattern. For other errors, either return
false to continue polling or propagate the actual error to distinguish deletion
from transient failures.
---
Nitpick comments:
In `@test/extended/project/project.go`:
- Around line 764-784: The polling logic for checking the OpenShift API server
operator status is duplicated inline in the code block starting at line 764.
Remove the inline wait.PollUntilContextCancel block that checks cluster operator
conditions (available, progressing, degraded) and replace it with a call to the
existing helper function waitForOpenShiftAPIServerOperatorStableWithPolling
which is defined later in the file and contains the same polling logic. This
will eliminate the code duplication and improve maintainability.
- Around line 884-895: The pod readiness check in the
wait.PollUntilContextTimeout function with the regexp.MatchString call only
detects transitional states (ContainerCreating, Init, Pending) but does not
check for permanent failure states like ImagePullBackOff, ErrImagePull, or
CrashLoopBackOff. Add an additional regexp.MatchString check within the same
polling condition to detect these failure states, and return false immediately
when such a state is found so the wait fails fast instead of continuing for the
full 3-minute timeout duration.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 560f4189-9491-4d9a-a6c7-4fde004881de
📒 Files selected for processing (3)
test/extended/project/project.gotest/extended/testdata/bindata.gotest/extended/testdata/project/project-request-limits-quota.yaml
Migrate four project API tests to OTE
26ba874 to
e642a80
Compare
Summary
Migrates project API test cases to the OpenShift Tests Extension (OTE) framework, following OTE integration guidelines and origin test standards.
Tests Added
1. Invalid Node Selector Validation
[OTP] should reject project creation when an invalid node selector is given2. Node Selector Display
[OTP] should allow a user to get the node selector from a projectoc describe projectcorrectly displays node selectors for projects with and without selectors3. Project Request Template Configuration
[OTP] should apply a customized project request template with ResourceQuota and LimitRange4. Cascading Project Deletion
[OTP] should delete all resources when the project is deletedSummary by CodeRabbit
Summary by CodeRabbit