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

Update common libraries to use PropagatedClaims #345

Merged
merged 12 commits into from
Dec 13, 2023
26 changes: 14 additions & 12 deletions pkg/test/masteruserrecord/masteruserrecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/toolchain-common/pkg/condition"
"github.com/codeready-toolchain/toolchain-common/pkg/test"
"github.com/gofrs/uuid"
"github.com/redhat-cop/operator-utils/pkg/util"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -42,22 +41,18 @@ func NewMasterUserRecords(t *testing.T, size int, nameFmt string, modifiers ...M
}

func NewMasterUserRecord(t *testing.T, userName string, modifiers ...MurModifier) *toolchainv1alpha1.MasterUserRecord {
userID := uuid.Must(uuid.NewV4()).String()
mur := &toolchainv1alpha1.MasterUserRecord{
ObjectMeta: metav1.ObjectMeta{
Namespace: test.HostOperatorNs,
Name: userName,
Labels: map[string]string{},
Annotations: map[string]string{
toolchainv1alpha1.MasterUserRecordEmailAnnotationKey: "[email protected]",
},
Namespace: test.HostOperatorNs,
Name: userName,
Labels: map[string]string{},
Annotations: map[string]string{},
},
Spec: toolchainv1alpha1.MasterUserRecordSpec{
TierName: "deactivate30",
UserID: userID,
UserAccounts: []toolchainv1alpha1.UserAccountEmbedded{newEmbeddedUa(test.MemberClusterName)},
PropagatedClaims: toolchainv1alpha1.PropagatedClaims{
Sub: "44332211",
Sub: "UserID123",
UserID: "135246",
AccountID: "357468",
OriginalSub: "11223344",
Expand Down Expand Up @@ -93,7 +88,14 @@ func ModifyUaInMur(mur *toolchainv1alpha1.MasterUserRecord, targetCluster string

func UserID(userID string) MurModifier {
return func(mur *toolchainv1alpha1.MasterUserRecord) error {
mur.Spec.UserID = userID
mur.Spec.PropagatedClaims.UserID = userID
return nil
}
}

func Sub(sub string) MurModifier {
return func(mur *toolchainv1alpha1.MasterUserRecord) error {
mur.Spec.PropagatedClaims.Sub = sub
return nil
}
}
Expand Down Expand Up @@ -208,7 +210,7 @@ func ProvisionedMur(provisionedTime *metav1.Time) MurModifier {
// UserIDFromUserSignup creates a MurModifier to change the userID value to match the provided usersignup
func UserIDFromUserSignup(userSignup *toolchainv1alpha1.UserSignup) MurModifier {
return func(mur *toolchainv1alpha1.MasterUserRecord) error {
mur.Spec.UserID = userSignup.Name
mur.Spec.PropagatedClaims.UserID = userSignup.Name
return nil
}
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/test/masteruserrecord/masteruserrecord_assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,6 @@ func (a *MasterUserRecordAssertion) HasAnnotationWithValue(key, value string) *M
return a
}

func (a *MasterUserRecordAssertion) HasOriginalSub(sub string) *MasterUserRecordAssertion {
err := a.loadMasterUserRecord()
require.NoError(a.t, err)
assert.Equal(a.t, sub, a.mur.Spec.OriginalSub)
return a
}

Comment on lines -205 to -211
Copy link
Contributor

Choose a reason for hiding this comment

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

btw, why did you drop this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MatousJobanek

the description still contains "WIP" so not sure if it's already ready for review or not.

Anyway, I got a bit lost in the changes you have made and you are planning to do. I'm also not sure when you want to drop the fields from the CRDs.

Apart from that, you missed a few cases:

the usersignup.go file still uses the UserSignupUserEmailAnnotationKey
the same for notification_builder.go
plus there is also one in the useraccount_test.go 

The PR is indeed ready for review. Fields won't be dropped from the CRDs until everything has been refactored to only use the PropagatedClaims.

The cases mentioned in usersignup.go and notification_builder.go are not missed, they are not within the scope of this PR and will be updated when the UserSignupController is refactored (these changes are limited to only the MasterUserRecordController).

I've updated useraccount_test.go to perform an equality check of the entire PropagatedClaims instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

cool, thanks for the explanation 👍 I was missing the description in the PR - what the PR is changing and what are the next steps.

I've updated useraccount_test.go to perform an equality check of the entire PropagatedClaims instead.

I don't see any changes in the file. Apart from that, it's still using the UserId from spec

assert.Equal(t, mur.Spec.UserID, userAcc.Spec.UserID)

func (a *MasterUserRecordAssertion) HasTargetCluster(targetcluster string) *MasterUserRecordAssertion {
err := a.loadMasterUserRecord()
require.NoError(a.t, err)
Expand Down
4 changes: 0 additions & 4 deletions pkg/test/useraccount/useraccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ func NewUserAccountFromMur(mur *toolchainv1alpha1.MasterUserRecord, modifiers ..
Labels: map[string]string{
toolchainv1alpha1.TierLabelKey: mur.Spec.TierName,
},
Annotations: map[string]string{
toolchainv1alpha1.UserEmailAnnotationKey: mur.Annotations[toolchainv1alpha1.MasterUserRecordEmailAnnotationKey],
},
},
Spec: toolchainv1alpha1.UserAccountSpec{
UserID: mur.Spec.UserID,
Disabled: mur.Spec.Disabled,
PropagatedClaims: mur.Spec.PropagatedClaims,
},
Expand Down
5 changes: 1 addition & 4 deletions pkg/test/useraccount/useraccount_assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ func (a *Assertion) HasNoFinalizer() *Assertion {
func (a *Assertion) MatchMasterUserRecord(mur *toolchainv1alpha1.MasterUserRecord) *Assertion {
err := a.loadUaAssertion()
require.NoError(a.t, err)
assert.Equal(a.t, mur.Spec.UserID, a.userAccount.Spec.UserID)
assert.Equal(a.t, mur.Spec.PropagatedClaims, a.userAccount.Spec.PropagatedClaims)
assert.Equal(a.t, mur.Spec.Disabled, a.userAccount.Spec.Disabled)
assert.Equal(a.t, mur.Spec.OriginalSub, a.userAccount.Spec.OriginalSub)
assert.NotNil(a.t, a.userAccount.Annotations)
assert.Equal(a.t, mur.Annotations[toolchainv1alpha1.MasterUserRecordEmailAnnotationKey], a.userAccount.Annotations[toolchainv1alpha1.UserEmailAnnotationKey])
return a
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/test/useraccount/useraccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestUserAccountFromMur(t *testing.T) {
userAcc := uatest.NewUserAccountFromMur(mur)

// when & then
assert.Equal(t, mur.Spec.UserID, userAcc.Spec.UserID)
assert.Equal(t, mur.Spec.PropagatedClaims, userAcc.Spec.PropagatedClaims)
assert.Equal(t, mur.Spec.Disabled, userAcc.Spec.Disabled)
})
}