-
Notifications
You must be signed in to change notification settings - Fork 209
NO-JIRA: add more rotation tests scenarios #2149
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |
| "testing" | ||
| "time" | ||
|
|
||
| operatorv1 "github.com/openshift/api/operator/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
@@ -81,3 +82,23 @@ func SecretOfLife(t testing.TB, namespace string) runtime.Object { | |
| }, | ||
| } | ||
| } | ||
|
|
||
| func UpdateUnsupportedConfig(t *testing.T, raw []byte) error { | ||
| operatorClient := GetOperator(t) | ||
| apiServerOperator, err := operatorClient.Get(context.TODO(), "cluster", metav1.GetOptions{}) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| apiServerOperator.Spec.UnsupportedConfigOverrides.Raw = raw | ||
| _, err = operatorClient.Update(context.TODO(), apiServerOperator, metav1.UpdateOptions{}) | ||
| return err | ||
|
Comment on lines
+93
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Verify whether update helpers in this file already use retry-on-conflict.
rg -n -C2 'func UpdateUnsupportedConfig|RetryOnConflict|operatorClient\.Update\(' test/library/encryption/helpers.goRepository: openshift/cluster-kube-apiserver-operator Length of output: 481 🏁 Script executed: # Check the full file content to understand context and imports
head -30 test/library/encryption/helpers.goRepository: openshift/cluster-kube-apiserver-operator Length of output: 939 🏁 Script executed: # Look for all Update calls in the file
rg -n '\.Update\(' test/library/encryption/helpers.goRepository: openshift/cluster-kube-apiserver-operator Length of output: 179 🏁 Script executed: # Check if retry pattern is used elsewhere in the file or related test utilities
rg -n 'RetryOnConflict|retry\.Retry' test/library/encryption/helpers.goRepository: openshift/cluster-kube-apiserver-operator Length of output: 67 🏁 Script executed: # Search for similar update patterns in other test helper files
fd -e go -path "*/test/library/*" | head -10Repository: openshift/cluster-kube-apiserver-operator Length of output: 254 🏁 Script executed: # Check if k8s.io/client-go/util/retry is used anywhere in the codebase
rg -n 'client-go/util/retry|RetryOnConflict' --type goRepository: openshift/cluster-kube-apiserver-operator Length of output: 3188 🏁 Script executed: # Look for similar Update patterns in other test files
rg -n -B2 'operatorClient.*Update' --type go test/Repository: openshift/cluster-kube-apiserver-operator Length of output: 813 🏁 Script executed: # Check if there are any retry patterns in the broader codebase
rg -n 'retry\.Retry|retry\.DefaultRetry' --type go | head -20Repository: openshift/cluster-kube-apiserver-operator Length of output: 2696 🏁 Script executed: # Check what exists in the vendor code - DefaultRetry vs DefaultBackoff
rg -n 'var DefaultRetry|var DefaultBackoff|DefaultRetry =|DefaultBackoff =' vendor/k8s.io/client-go/util/retry/ --type goRepository: openshift/cluster-kube-apiserver-operator Length of output: 245 🏁 Script executed: # Check the library-go encryption helpers that are imported
rg -n -A10 'func UpdateUnsupportedConfig' vendor/github.com/openshift/library-go/test/library/encryption/helpers.goRepository: openshift/cluster-kube-apiserver-operator Length of output: 67 🏁 Script executed: # Check the exact signature of RetryOnConflict in vendor
rg -n -A5 'func RetryOnConflict' vendor/k8s.io/client-go/util/retry/util.goRepository: openshift/cluster-kube-apiserver-operator Length of output: 215 🏁 Script executed: # Check the difference between DefaultRetry and DefaultBackoff
rg -n -A10 'var DefaultRetry = wait.Backoff|var DefaultBackoff = wait.Backoff' vendor/k8s.io/client-go/util/retry/util.goRepository: openshift/cluster-kube-apiserver-operator Length of output: 877 🏁 Script executed: # Check if the library-go helpers are actually being used by this file
rg -n 'library\.|library-go' test/library/encryption/helpers.goRepository: openshift/cluster-kube-apiserver-operator Length of output: 429 🏁 Script executed: # Look more broadly for any UpdateUnsupportedConfig patterns in library-go test helpers
rg -n 'UpdateUnsupportedConfig\|UnsupportedConfigOverrides' vendor/github.com/openshift/library-go/test/library/encryption/Repository: openshift/cluster-kube-apiserver-operator Length of output: 67 🏁 Script executed: # Check what the recommended pattern is in similar test helpers
rg -n 'RetryOnConflict.*DefaultRetry|RetryOnConflict.*DefaultBackoff' --type go | head -15Repository: openshift/cluster-kube-apiserver-operator Length of output: 1410 Use retry-on-conflict when updating operator resources. Line 93 performs a single Proposed fix import (
"context"
"fmt"
"testing"
"time"
@@
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
+ "k8s.io/client-go/util/retry"
@@
func UpdateUnsupportedConfig(t *testing.T, raw []byte) error {
operatorClient := GetOperator(t)
- apiServerOperator, err := operatorClient.Get(context.TODO(), "cluster", metav1.GetOptions{})
- if err != nil {
- return err
- }
- apiServerOperator.Spec.UnsupportedConfigOverrides.Raw = raw
- _, err = operatorClient.Update(context.TODO(), apiServerOperator, metav1.UpdateOptions{})
- return err
+ return retry.RetryOnConflict(retry.DefaultBackoff, func() error {
+ apiServerOperator, err := operatorClient.Get(context.TODO(), "cluster", metav1.GetOptions{})
+ if err != nil {
+ return err
+ }
+ apiServerOperator.Spec.UnsupportedConfigOverrides.Raw = raw
+ _, err = operatorClient.Update(context.TODO(), apiServerOperator, metav1.UpdateOptions{})
+ return err
+ })
}Note: Use 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| func GetClusterOperatorConditions(t testing.TB) ([]operatorv1.OperatorCondition, error) { | ||
| operatorClient := GetOperator(t) | ||
| apiServerOperator, err := operatorClient.Get(context.TODO(), "cluster", metav1.GetOptions{}) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return apiServerOperator.Status.Conditions, nil | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Guard new rotation tests for MicroShift incompatibility.
These new tests depend on
ClusterOperatorconditions (GetClusterOperatorConditions), which are not available on MicroShift. Add the usual MicroShift protection (label/tag or runtime skip) so they don’t run in unsupported environments.As per coding guidelines, “Flag tests referencing unavailable APIs: … ClusterOperator … Use [apigroup:...] tags for API-specific tests, add [Skipped:MicroShift] label, or use exutil.IsMicroShiftCluster() runtime checks.”
Also applies to: 64-83
🧰 Tools
🪛 golangci-lint (2.12.2)
[error] 56-56: : # github.com/openshift/cluster-kube-apiserver-operator/test/e2e-encryption [github.com/openshift/cluster-kube-apiserver-operator/test/e2e-encryption.test]
test/e2e-encryption/encryption_test.go:56:35: cannot use configv1.APIServerEncryption{…} (value of struct type "github.com/openshift/api/config/v1".APIServerEncryption) as "github.com/openshift/library-go/test/library/encryption".EncryptionProvider value in struct literal
(typecheck)
🤖 Prompt for AI Agents