Skip to content

Added support to join external noobaa system from hosted clusters#1405

Merged
liranmauda merged 1 commit intonoobaa:masterfrom
bernerhat:nb-remote
Aug 21, 2024
Merged

Added support to join external noobaa system from hosted clusters#1405
liranmauda merged 1 commit intonoobaa:masterfrom
bernerhat:nb-remote

Conversation

@bernerhat
Copy link
Contributor

Explain the changes

  1. continuation of Kaustav's PR

Issues: Fixed #xxx / Gap #xxx

Testing Instructions:

  • Doc added/updated
  • Tests added

nbremoteAuthToken := &corev1.Secret{}
nbremoteAuthToken.Name = r.NooBaaAccount.Name
nbremoteAuthToken.Namespace = r.NooBaaAccount.Namespace
err = r.Client.Delete(r.Ctx, r.Secret)
Copy link
Member

Choose a reason for hiding this comment

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

If I'm not mistaken, R.Secret is deleted automtically, since it's owned by the noobaaAccount CR. I don't think that anything is changed in this PR with respect to deletion. Can you please verify it?

// create join secret conatining auth token for remote noobaa account
annotationValue, exists := util.GetAnnotationValue(r.NooBaa.GetAnnotations(), "remote-operator")
if exists {
if strings.ToLower(annotationValue) != strconv.FormatBool(false) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if strings.ToLower(annotationValue) != strconv.FormatBool(false) {
if strings.ToLower(annotationValue) == "true" {

if err != nil {
return fmt.Errorf("cannot create an auth token for remote operator, error: %v", err)
}
if res.Token == "" {
Copy link
Member

Choose a reason for hiding this comment

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

Is an empty token somthing that can be returned by noobaa-core in case there is no error? did you encounter this?

Comment on lines +200 to +201
annotationValue, exists := util.GetAnnotationValue(r.NooBaa.GetAnnotations(), "remote-client-noobaa")
annotationBoolVal := true
Copy link
Member

Choose a reason for hiding this comment

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

I suggest giving clearer names to the variables. annotationVal and annotationBoolVal are too generic

annotationValue, exists := util.GetAnnotationValue(r.NooBaa.GetAnnotations(), "remote-client-noobaa")
annotationBoolVal := true
if exists {
annotationBoolVal = strings.ToLower(annotationValue) == strconv.FormatBool(true)
Copy link
Member

Choose a reason for hiding this comment

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

Again, unless I'm missing somthing, I don't see a reason to use strconv.FormatBool(true) and not "true"

Comment on lines +70 to +75
annotationValue, exists := util.GetAnnotationValue(r.NooBaa.GetAnnotations(), "remote-client-noobaa")
annotationBoolVal := true
if exists {
annotationBoolVal = strings.ToLower(annotationValue) == strconv.FormatBool(true)
}
if !exists || !annotationBoolVal {
Copy link
Member

Choose a reason for hiding this comment

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

since you repeat this code more than once, mayb extract this to a function isRemoteClientNoobaa

return err
}
// create join secret conatining auth token for remote noobaa account
annotationValue, exists := util.GetAnnotationValue(r.NooBaa.GetAnnotations(), "remote-operator")
Copy link
Member

Choose a reason for hiding this comment

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

If the remote-operator annotation exist, do you need to also create access keys (r.Secret)?

Maybe just reuse the same r.Secret and populate it with the relevant values according to the annotatioin?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's a valid point but since it was Kaustav's decision to use a new secret, i'm not sure what led to him creating a new secret.
Lets leave the new secret in place and when Kaustav returns from his leave we can change this. i'll open an issue for it as well (since changing it will most likely cause changes to code in other repos such as ocs-operator which uses this secret)

Copy link
Member

Choose a reason for hiding this comment

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

I prefer to make the code simpler and not to create 2 secrets for a single noobaa account. I suggest that for now add an "auth_token" key on r.Secret. If there is a reason to create a separate secret than we can make this change later

nbremoteAuthToken.StringData["auth_token"] = res.Token
r.Own(nbremoteAuthToken)

err = r.Client.Create(r.Ctx, r.Secret)
Copy link
Member

Choose a reason for hiding this comment

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

did you mean to create nbremoteAuthToken?

Suggested change
err = r.Client.Create(r.Ctx, r.Secret)
err = r.Client.Create(r.Ctx, nbremoteAuthToken)

return err
}
// create join secret conatining auth token for remote noobaa account
annotationValue, exists := util.GetAnnotationValue(r.NooBaa.GetAnnotations(), "remote-operator")
Copy link
Member

Choose a reason for hiding this comment

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

I prefer to make the code simpler and not to create 2 secrets for a single noobaa account. I suggest that for now add an "auth_token" key on r.Secret. If there is a reason to create a separate secret than we can make this change later

return err
}
// create join secret conatining auth token for remote noobaa account
annotationValue, exists := util.GetAnnotationValue(r.NooBaa.GetAnnotations(), "remote-operator")
Copy link
Member

Choose a reason for hiding this comment

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

I see now that the annotation is on the noobaa CR and not the noobaaAccount CR. In that case, what's the difference between remote-operator and MulticloudObjectGatewayProviderMode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The remote-operator is an annotation which is being added to the account CR by the ocs-operator while we are on the provider side in order to indicate when we onboard a new consumer and therefore need a new auth token to be added to the account. The MulticloudObjectGatewayProviderMode annotation is being added to the Noobaa CR while we are running remotely and need to indicate that we only wish to deploy the operator and connect to a remote cluster.

Copy link
Member

Choose a reason for hiding this comment

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

But here you check the annotaion on the noobaa CR and not the account CR (r.NooBaa.GetAnnotations())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are correct it's a mistake, will fix.

@pull-request-size pull-request-size bot added size/L and removed size/M labels Aug 18, 2024
@bernerhat bernerhat force-pushed the nb-remote branch 2 times, most recently from c3e5779 to e02bf8c Compare August 20, 2024 06:48
@bernerhat bernerhat requested a review from dannyzaken August 20, 2024 14:46
@bernerhat
Copy link
Contributor Author

@dannyzaken everything is done and tested can you please re-review

pkg/util/util.go Outdated
annotationValue, exists := GetAnnotationValue(annotations, "remote-client-noobaa")
annotationBoolVal := false
if exists {
annotationBoolVal = strings.ToLower(annotationValue) == strconv.FormatBool(true)
Copy link
Member

Choose a reason for hiding this comment

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

trueStr instead of strconv

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Signed-off-by: Kaustav Majumder <kaustav.majumder@ibm.com>
@bernerhat
Copy link
Contributor Author

i've rebased, can we merge? i dont have permissions to merge myself. @dannyzaken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants