Skip to content
5 changes: 4 additions & 1 deletion make/clean.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ clean-users:
$(Q)-oc delete spaces --all --all-namespaces
$(Q)-oc wait --for=delete namespaces -l toolchain.dev.openshift.com/type

clean-nstemplatetiers:
$(Q)-oc delete nstemplatetier --all --all-namespaces

.PHONY: clean-cluster-wide-config
## Delete all cluster-wide configuration resources like PriorityClass, MutatingWebhookConfiguration, and ClusterRoleBinding for e2e SA
clean-cluster-wide-config:
Expand Down Expand Up @@ -43,7 +46,7 @@ clean-toolchain-dev-sso-resources:
## * all user-related resources
## * operator namespaces created during both the dev and e2e test setup (for both operators host and member)
## * cluster-wide config
clean-e2e-resources: clean-users clean-toolchain-namespaces-in-e2e clean-cluster-wide-config
clean-e2e-resources: clean-users clean-nstemplatetiers clean-toolchain-namespaces-in-e2e clean-cluster-wide-config

.PHONY: clean-toolchain-namespaces-in-dev
## Delete dev namespaces
Expand Down
53 changes: 53 additions & 0 deletions test/migration/verify/verify_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package verify
import (
"context"
"fmt"
"reflect"
"sync"
"testing"
"time"
Expand All @@ -20,6 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -95,6 +97,7 @@ func runVerifyFunctions(t *testing.T, awaitilities wait.Awaitilities) {
func() { verifyDeactivatedSignup(t, awaitilities, deactivatedSignup) },
func() { verifyBannedSignup(t, awaitilities, bannedSignup) },
func() { verifyAdditionalDeploymentsCreatedUsingSSA(t, &awaitilities) },
func() { verifyResourcesDeployedUsingSSA(t, &awaitilities) },
}

// when & then - run all functions in parallel
Expand Down Expand Up @@ -270,6 +273,56 @@ func verifyAdditionalDeploymentsCreatedUsingSSA(t *testing.T, awaitilities *wait
})
}

func verifyResourcesDeployedUsingSSA(t *testing.T, awaitilities *wait.Awaitilities) {
testList := func(t *testing.T, a *wait.Awaitility, list client.ObjectList, originalFieldManager, expectedFieldManager string) {
assert.EventuallyWithT(t, func(t *assert.CollectT) {
assert.NoError(t, a.Client.List(context.TODO(), list, client.InNamespace("default")))

// I have yet to find a generic way of iterating over the list of
// any client.ObjectList without resorting to manual REST requests to the API.
// Let's not do it here and just hack our way using reflection.
listPtr := reflect.ValueOf(list)
listVal := listPtr.Elem()
itemsVal := listVal.FieldByName("Items")
itemsLen := itemsVal.Len()
for i := range itemsLen {
itemVal := itemsVal.Index(i)
itemPtr := itemVal.Addr()
item := itemPtr.Interface().(client.Object)
require.NotNil(t, item)
var applyEntry *metav1.ManagedFieldsEntry
var updateEntry *metav1.ManagedFieldsEntry
for _, mf := range item.GetManagedFields() {
if mf.Manager == expectedFieldManager {
applyEntry = &mf
}
if mf.Manager == originalFieldManager {
updateEntry = &mf
}
}

require.NotNil(t, applyEntry)
assert.Equal(t, metav1.ManagedFieldsOperationApply, applyEntry.Operation)
assert.Nil(t, updateEntry)
}
}, 1*time.Minute, 1*time.Second)
}

t.Run("verify bundled UserTiers deployed using SSA", func(t *testing.T) {
testList(t, awaitilities.Host().Awaitility,
&toolchainv1alpha1.UserTierList{},
"host-operator",
"kubesaw-host-operator")
})

t.Run("verify bundled NSTemplateTiers deployed using SSA", func(t *testing.T) {
testList(t, awaitilities.Host().Awaitility,
&toolchainv1alpha1.NSTemplateTierList{},
"host-operator",
"kubesaw-host-operator")
})
}

func checkMURMigratedAndGetSignup(t *testing.T, hostAwait *wait.HostAwaitility, murName string) *toolchainv1alpha1.UserSignup {
provisionedMur, err := hostAwait.WithRetryOptions(wait.TimeoutOption(time.Second*120)).WaitForMasterUserRecord(t, murName,
wait.UntilMasterUserRecordHasCondition(wait.Provisioned()),
Expand Down
Loading