Skip to content
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

Check for new member webhook config names #950

Merged
merged 22 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion make/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ get-and-publish-operators: clean-e2e-files get-and-publish-host-operator get-and
# The reason is that when the host operator is installed, then the logic creates ToolchainConfig CR which
# defines that the webhook should be deployed from the first member instance (and not from the second one).
# This is important to set before the member operators are installed, otherwise, it can lead to flaky e2e tests.
get-publish-install-and-register-operators: get-and-publish-host-operator setup-toolchainclusters create-host-resources get-and-publish-member-operator
get-publish-install-and-register-operators: get-and-publish-host-operator get-and-publish-member-operator setup-toolchainclusters create-host-resources
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed since now we are deploying the toolchaincluster-member SA from the member-operator deployment, thus we need to run setup-toolchainclusters only after deploying the member operator deployment.

In order to invert those make targets I had todo some changes in member operator, see paired PR for those.


.PHONY: get-publish-and-install-operators
# IMPORTANT: The host operator needs to be installed first.
Expand Down
2 changes: 2 additions & 0 deletions testsupport/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ func WaitForDeployments(t *testing.T) wait.Awaitilities {
// Also verify the autoscaling buffer in both members
webhookImage := initMemberAwait.GetContainerEnv(t, "MEMBER_OPERATOR_WEBHOOK_IMAGE")
require.NotEmpty(t, webhookImage, "The value of the env var MEMBER_OPERATOR_WEBHOOK_IMAGE wasn't found in the deployment of the member operator.")
err = initMember2Await.WaitUntilWebhookDeleted(t) // webhook on member2 should be deleted
require.NoError(t, err)
mfrancisc marked this conversation as resolved.
Show resolved Hide resolved
initMemberAwait.WaitForMemberWebhooks(t, webhookImage)

// wait for autoscaler buffer apps
Expand Down
33 changes: 28 additions & 5 deletions testsupport/wait/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,21 @@ func checkPriorityClass(pod *corev1.Pod, name string, priority int) bool {
return pod.Spec.PriorityClassName == name && *pod.Spec.Priority == int32(priority)
}

// WaitUntilWebhookDeleted waits until the webhook app in member namespace is deleted (ie, is not found)
func (a *MemberAwaitility) WaitUntilWebhookDeleted(t *testing.T) error {
t.Logf("waiting until webhook member-operator-webhook in namespace '%s' is deleted", a.Namespace)
deployment := &appsv1.Deployment{}
return wait.Poll(a.RetryInterval, a.Timeout, func() (done bool, err error) {
if err := a.Client.Get(context.TODO(), test.NamespacedName(a.Namespace, "member-operator-webhook"), deployment); err != nil {
if errors.IsNotFound(err) {
return true, nil
}
return false, err
}
return false, nil
})
}

// WaitUntilNamespaceDeleted waits until the namespace with the given name is deleted (ie, is not found)
func (a *MemberAwaitility) WaitUntilNamespaceDeleted(t *testing.T, username, typeName string) error {
t.Logf("waiting until namespace for user '%s' and type '%s' is deleted", username, typeName)
Expand Down Expand Up @@ -2197,7 +2212,6 @@ func (a *MemberAwaitility) waitForUsersPodPriorityClass(t *testing.T) {
t.Logf("checking PrioritiyClass resource '%s'", "sandbox-users-pods")
actualPrioClass := &schedulingv1.PriorityClass{}
a.waitForResource(t, "", "sandbox-users-pods", actualPrioClass)

assert.Equal(t, codereadyToolchainProviderLabel, actualPrioClass.Labels)
assert.Equal(t, int32(-3), actualPrioClass.Value)
assert.False(t, actualPrioClass.GlobalDefault)
Expand Down Expand Up @@ -2279,9 +2293,14 @@ func (a *MemberAwaitility) verifySecret(t *testing.T) []byte {
func (a *MemberAwaitility) verifyMutatingWebhookConfig(t *testing.T, ca []byte) {
t.Logf("checking MutatingWebhookConfiguration")
actualMutWbhConf := &admv1.MutatingWebhookConfiguration{}
a.waitForResource(t, "", "member-operator-webhook", actualMutWbhConf)
a.waitForResource(t, "", "member-operator-webhook-"+a.Namespace, actualMutWbhConf)
assert.Equal(t, bothWebhookLabels, actualMutWbhConf.Labels)
require.Len(t, actualMutWbhConf.Webhooks, 2)
//check that there is only 1 MutatingWebhookConfiguration
allMutatingWebhooks := &admv1.MutatingWebhookConfigurationList{}
err := a.Client.List(context.TODO(), allMutatingWebhooks, client.MatchingLabels(appMemberOperatorWebhookLabel))
require.NoError(t, err)
require.Len(t, allMutatingWebhooks.Items, 1)

type Rule struct {
Operations []admv1.OperationType
Expand Down Expand Up @@ -2351,11 +2370,15 @@ func (a *MemberAwaitility) verifyMutatingWebhookConfig(t *testing.T, ca []byte)
}

func (a *MemberAwaitility) verifyValidatingWebhookConfig(t *testing.T, ca []byte) {
t.Logf("checking ValidatingWebhookConfiguration '%s'", "member-operator-validating-webhook")
t.Logf("checking ValidatingWebhookConfiguration '%s'", "member-operator-validating-webhook"+a.Namespace)
actualValWbhConf := &admv1.ValidatingWebhookConfiguration{}
a.waitForResource(t, "", "member-operator-validating-webhook", actualValWbhConf)
a.waitForResource(t, "", "member-operator-validating-webhook-"+a.Namespace, actualValWbhConf)
assert.Equal(t, bothWebhookLabels, actualValWbhConf.Labels)
// require.Len(t, actualValWbhConf.Webhooks, 2)
//check that there is only 1 ValidatingWebhookConfiguration
allValidatingWebhooks := &admv1.ValidatingWebhookConfigurationList{}
err := a.Client.List(context.TODO(), allValidatingWebhooks, client.MatchingLabels(appMemberOperatorWebhookLabel))
require.NoError(t, err)
require.Len(t, allValidatingWebhooks.Items, 1)

rolebindingWebhook := actualValWbhConf.Webhooks[0]
assert.Equal(t, "users.rolebindings.webhook.sandbox", rolebindingWebhook.Name)
Expand Down
Loading