-
Notifications
You must be signed in to change notification settings - Fork 115
CNTRLPLANE-2589: Migrate test/e2e-encryption to Ginkgo v2 framework #839
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
ropatil010
wants to merge
2
commits into
openshift:master
Choose a base branch
from
ropatil010:migrate-e2e-encryption
base: master
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.
+1,527
−1,324
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
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,114 @@ | ||
| package e2e_encryption_perf | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
| "time" | ||
|
|
||
| g "github.com/onsi/ginkgo/v2" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/client-go/kubernetes" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| oauthapiv1 "github.com/openshift/api/oauth/v1" | ||
| operatorv1 "github.com/openshift/api/operator/v1" | ||
| oauthclient "github.com/openshift/client-go/oauth/clientset/versioned/typed/oauth/v1" | ||
| operatorlibrary "github.com/openshift/cluster-authentication-operator/test/library" | ||
| operatorencryption "github.com/openshift/cluster-authentication-operator/test/library/encryption" | ||
| library "github.com/openshift/library-go/test/library/encryption" | ||
| ) | ||
|
|
||
| const ( | ||
| tokenStatsKey = "created oauthaccesstokens" | ||
| ) | ||
|
|
||
| var _ = g.Describe("[sig-auth] authentication operator", func() { | ||
| g.It("[Encryption][Serial] TestPerfEncryptionTypeAESCBC", func() { | ||
| testPerfEncryptionTypeAESCBC(g.GinkgoTB()) | ||
| }) | ||
| }) | ||
|
|
||
| func testPerfEncryptionTypeAESCBC(tt testing.TB) { | ||
| ctx := context.TODO() | ||
| clientSet := getPerfClients(tt) | ||
| operatorlibrary.TestPerfEncryption(tt, library.PerfScenario{ | ||
| BasicScenario: library.BasicScenario{ | ||
| Namespace: "openshift-config-managed", | ||
| LabelSelector: "encryption.apiserver.operator.openshift.io/component" + "=" + "openshift-oauth-apiserver", | ||
| EncryptionConfigSecretName: fmt.Sprintf("encryption-config-%s", "openshift-oauth-apiserver"), | ||
| EncryptionConfigSecretNamespace: "openshift-config-managed", | ||
| OperatorNamespace: "openshift-authentication-operator", | ||
| TargetGRs: operatorencryption.DefaultTargetGRs, | ||
| AssertFunc: operatorencryption.AssertTokens, | ||
| }, | ||
| GetOperatorConditionsFunc: func(t testing.TB) ([]operatorv1.OperatorCondition, error) { | ||
| apiServerOperator, err := clientSet.OperatorClient.Get(ctx, "cluster", metav1.GetOptions{}) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return apiServerOperator.Status.Conditions, nil | ||
| }, | ||
| AssertDBPopulatedFunc: func(t testing.TB, errorStore map[string]int, statStore map[string]int) { | ||
| tokenCount, ok := statStore[tokenStatsKey] | ||
| if !ok { | ||
| err := errors.New("missing oauth access tokens count stats, can't continue the test") | ||
| require.NoError(t, err) | ||
| } | ||
| if tokenCount < 14000 { | ||
| err := fmt.Errorf("expected to create at least 14000 tokens but %d were created", tokenCount) | ||
| require.NoError(t, err) | ||
| } | ||
| t.Logf("Created %d access tokens", tokenCount) | ||
| }, | ||
| AssertMigrationTime: func(t testing.TB, migrationTime time.Duration) { | ||
| t.Logf("migration took %v", migrationTime) | ||
| expectedMigrationTime := 10 * time.Minute | ||
| if migrationTime > expectedMigrationTime { | ||
| t.Errorf("migration took too long (%v), expected it to take no more than %v", migrationTime, expectedMigrationTime) | ||
| } | ||
| }, | ||
| DBLoaderWorkers: 3, | ||
| DBLoaderFunc: library.DBLoaderRepeat(1, false, | ||
| library.DBLoaderRepeatParallel(5010, 50, false, createAccessTokenWrapper(ctx, clientSet.TokenClient), reportSecret)), | ||
| EncryptionProvider: configv1.EncryptionType("aescbc"), | ||
| }) | ||
| } | ||
|
|
||
| func createAccessTokenWrapper(ctx context.Context, tokenClient oauthclient.OAuthAccessTokensGetter) library.DBLoaderFuncType { | ||
| return func(_ kubernetes.Interface, namespace string, errorCollector func(error), statsCollector func(string)) error { | ||
| _, tokenNameHash := operatorlibrary.GenerateOAuthTokenPair() | ||
| token := &oauthapiv1.OAuthAccessToken{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: tokenNameHash, | ||
| }, | ||
| RefreshToken: "I have no special talents. I am only passionately curious", | ||
| UserName: "kube:admin", | ||
| Scopes: []string{"user:full"}, | ||
| RedirectURI: "redirect.me.to.token.of.life", | ||
| ClientName: "console", | ||
| UserUID: "non-existing-user-id", | ||
| } | ||
| _, err := tokenClient.OAuthAccessTokens().Create(ctx, token, metav1.CreateOptions{}) | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| func reportSecret(_ kubernetes.Interface, _ string, _ func(error), statsCollector func(string)) error { | ||
| statsCollector(tokenStatsKey) | ||
| return nil | ||
| } | ||
|
|
||
| func getPerfClients(t testing.TB) operatorencryption.ClientSet { | ||
| t.Helper() | ||
|
|
||
| kubeConfig := operatorlibrary.NewClientConfigForTest(t) | ||
|
|
||
| kubeConfig.QPS = 300 | ||
| kubeConfig.Burst = 600 | ||
|
|
||
| return operatorencryption.GetClientsFor(t, kubeConfig) | ||
| } | ||
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 |
|---|---|---|
| @@ -1,107 +1,9 @@ | ||
| package e2e_encryption_perf | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/client-go/kubernetes" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| oauthapiv1 "github.com/openshift/api/oauth/v1" | ||
| operatorv1 "github.com/openshift/api/operator/v1" | ||
| oauthclient "github.com/openshift/client-go/oauth/clientset/versioned/typed/oauth/v1" | ||
| operatorlibrary "github.com/openshift/cluster-authentication-operator/test/library" | ||
| operatorencryption "github.com/openshift/cluster-authentication-operator/test/library/encryption" | ||
| library "github.com/openshift/library-go/test/library/encryption" | ||
| ) | ||
|
|
||
| const ( | ||
| tokenStatsKey = "created oauthaccesstokens" | ||
| ) | ||
|
|
||
| func TestPerfEncryptionTypeAESCBC(tt *testing.T) { | ||
| ctx := context.TODO() | ||
| clientSet := getPerfClients(tt) | ||
| library.TestPerfEncryption(tt, library.PerfScenario{ | ||
| BasicScenario: library.BasicScenario{ | ||
| Namespace: "openshift-config-managed", | ||
| LabelSelector: "encryption.apiserver.operator.openshift.io/component" + "=" + "openshift-oauth-apiserver", | ||
| EncryptionConfigSecretName: fmt.Sprintf("encryption-config-%s", "openshift-oauth-apiserver"), | ||
| EncryptionConfigSecretNamespace: "openshift-config-managed", | ||
| OperatorNamespace: "openshift-authentication-operator", | ||
| TargetGRs: operatorencryption.DefaultTargetGRs, | ||
| AssertFunc: operatorencryption.AssertTokens, | ||
| }, | ||
| GetOperatorConditionsFunc: func(t testing.TB) ([]operatorv1.OperatorCondition, error) { | ||
| apiServerOperator, err := clientSet.OperatorClient.Get(ctx, "cluster", metav1.GetOptions{}) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return apiServerOperator.Status.Conditions, nil | ||
| }, | ||
| AssertDBPopulatedFunc: func(t testing.TB, errorStore map[string]int, statStore map[string]int) { | ||
| tokenCount, ok := statStore[tokenStatsKey] | ||
| if !ok { | ||
| err := errors.New("missing oauth access tokens count stats, can't continue the test") | ||
| require.NoError(t, err) | ||
| } | ||
| if tokenCount < 14000 { | ||
| err := fmt.Errorf("expected to create at least 14000 tokens but %d were created", tokenCount) | ||
| require.NoError(t, err) | ||
| } | ||
| t.Logf("Created %d access tokens", tokenCount) | ||
| }, | ||
| AssertMigrationTime: func(t testing.TB, migrationTime time.Duration) { | ||
| t.Logf("migration took %v", migrationTime) | ||
| expectedMigrationTime := 10 * time.Minute | ||
| if migrationTime > expectedMigrationTime { | ||
| t.Errorf("migration took too long (%v), expected it to take no more than %v", migrationTime, expectedMigrationTime) | ||
| } | ||
| }, | ||
| DBLoaderWorkers: 3, | ||
| DBLoaderFunc: library.DBLoaderRepeat(1, false, | ||
| library.DBLoaderRepeatParallel(5010, 50, false, createAccessTokenWrapper(ctx, clientSet.TokenClient), reportSecret)), | ||
| EncryptionProvider: configv1.EncryptionType("aescbc"), | ||
| }) | ||
| } | ||
|
|
||
| func createAccessTokenWrapper(ctx context.Context, tokenClient oauthclient.OAuthAccessTokensGetter) library.DBLoaderFuncType { | ||
| return func(_ kubernetes.Interface, namespace string, errorCollector func(error), statsCollector func(string)) error { | ||
| _, tokenNameHash := operatorlibrary.GenerateOAuthTokenPair() | ||
| token := &oauthapiv1.OAuthAccessToken{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: tokenNameHash, | ||
| }, | ||
| RefreshToken: "I have no special talents. I am only passionately curious", | ||
| UserName: "kube:admin", | ||
| Scopes: []string{"user:full"}, | ||
| RedirectURI: "redirect.me.to.token.of.life", | ||
| ClientName: "console", | ||
| UserUID: "non-existing-user-id", | ||
| } | ||
| _, err := tokenClient.OAuthAccessTokens().Create(ctx, token, metav1.CreateOptions{}) | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| func reportSecret(_ kubernetes.Interface, _ string, _ func(error), statsCollector func(string)) error { | ||
| statsCollector(tokenStatsKey) | ||
| return nil | ||
| } | ||
|
|
||
| func getPerfClients(t *testing.T) operatorencryption.ClientSet { | ||
| t.Helper() | ||
|
|
||
| kubeConfig := operatorlibrary.NewClientConfigForTest(t) | ||
|
|
||
| kubeConfig.QPS = 300 | ||
| kubeConfig.Burst = 600 | ||
|
|
||
| return operatorencryption.GetClientsFor(t, kubeConfig) | ||
| testPerfEncryptionTypeAESCBC(tt) | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.