Skip to content

Commit

Permalink
Check for new member webhook config names (#950)
Browse files Browse the repository at this point in the history
* check for new webhook config names
---------

Co-authored-by: Matous Jobanek <[email protected]>
  • Loading branch information
mfrancisc and MatousJobanek authored Jun 3, 2024
1 parent 00b1296 commit f353401
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
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

.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)
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

0 comments on commit f353401

Please sign in to comment.