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

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

Merged
merged 1 commit into from
Aug 21, 2024

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
Contributor

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
Contributor

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
Contributor

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
Contributor

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
Contributor

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
Contributor

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

@@ -373,6 +388,33 @@ func (r *Reconciler) CreateNooBaaAccount() error {
r.Logger.Errorf("got error on NooBaaAccount creation. error: %v", err)
return err
}
// create join secret conatining auth token for remote noobaa account
annotationValue, exists := util.GetAnnotationValue(r.NooBaa.GetAnnotations(), "remote-operator")
Copy link
Contributor

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
Contributor

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
Contributor

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)

@@ -373,6 +388,33 @@ func (r *Reconciler) CreateNooBaaAccount() error {
r.Logger.Errorf("got error on NooBaaAccount creation. error: %v", err)
return err
}
// create join secret conatining auth token for remote noobaa account
annotationValue, exists := util.GetAnnotationValue(r.NooBaa.GetAnnotations(), "remote-operator")
Copy link
Contributor

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

@@ -373,6 +375,30 @@ func (r *Reconciler) CreateNooBaaAccount() error {
r.Logger.Errorf("got error on NooBaaAccount creation. error: %v", err)
return err
}
// create join secret conatining auth token for remote noobaa account
annotationValue, exists := util.GetAnnotationValue(r.NooBaa.GetAnnotations(), "remote-operator")
Copy link
Contributor

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
Contributor

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.

@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
Contributor

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

@bernerhat
Copy link
Contributor Author

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

@liranmauda liranmauda merged commit 7c4efc4 into noobaa:master Aug 21, 2024
14 checks passed
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