Skip to content

Commit

Permalink
Added support to join external noobaa system from hosted clusters
Browse files Browse the repository at this point in the history
Signed-off-by: Kaustav Majumder <[email protected]>
  • Loading branch information
Kaustav Majumder authored and bernerhat committed Aug 18, 2024
1 parent e2a4fb9 commit c285607
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 31 deletions.
47 changes: 34 additions & 13 deletions pkg/noobaaaccount/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"reflect"
"strings"
"time"

nbv1 "github.com/noobaa/noobaa-operator/v5/pkg/apis/noobaa/v1alpha1"
Expand All @@ -24,6 +25,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

const (
strTrue string = "true"
)

// Reconciler is the context for loading or reconciling a noobaa system
type Reconciler struct {
Request types.NamespacedName
Expand Down Expand Up @@ -351,22 +356,38 @@ func (r *Reconciler) CreateNooBaaAccount() error {
return err
}

var accessKeys nb.S3AccessKeys
// if we didn't get the access keys in the create_account reply we might be talking to an older noobaa version (prior to 5.1)
// in that case try to get it using read account
if len(accountInfo.AccessKeys) == 0 {
log.Info("CreateAccountAPI did not return access keys. calling ReadAccountAPI to get keys..")
readAccountReply, err := r.NBClient.ReadAccountAPI(nb.ReadAccountParams{Email: r.NooBaaAccount.Name})
if err != nil {
return err
annotationValue, exists := util.GetAnnotationValue(r.NooBaa.GetAnnotations(), "remote-operator")
if exists {
if strings.ToLower(annotationValue) == strTrue {
// create join secret conatining auth token for remote noobaa account
res, err := r.NBClient.CreateAuthAPI(nb.CreateAuthParams{
System: r.Request.Name,
Role: "operator",
Email: options.OperatorAccountEmail,
})
if err != nil {
return fmt.Errorf("cannot create an auth token for remote operator, error: %v", err)
}
r.Secret.StringData["auth_token"] = res.Token
}
accessKeys = readAccountReply.AccessKeys[0]
} else {
accessKeys = accountInfo.AccessKeys[0]
var accessKeys nb.S3AccessKeys
// if we didn't get the access keys in the create_account reply we might be talking to an older noobaa version (prior to 5.1)
// in that case try to get it using read account
if len(accountInfo.AccessKeys) == 0 {
log.Info("CreateAccountAPI did not return access keys. calling ReadAccountAPI to get keys..")
readAccountReply, err := r.NBClient.ReadAccountAPI(nb.ReadAccountParams{Email: r.NooBaaAccount.Name})
if err != nil {
return err
}
accessKeys = readAccountReply.AccessKeys[0]
} else {
accessKeys = accountInfo.AccessKeys[0]
}
r.Secret.StringData = map[string]string{}
r.Secret.StringData["AWS_ACCESS_KEY_ID"] = string(accessKeys.AccessKey)
r.Secret.StringData["AWS_SECRET_ACCESS_KEY"] = string(accessKeys.SecretKey)
}
r.Secret.StringData = map[string]string{}
r.Secret.StringData["AWS_ACCESS_KEY_ID"] = string(accessKeys.AccessKey)
r.Secret.StringData["AWS_SECRET_ACCESS_KEY"] = string(accessKeys.SecretKey)
r.Own(r.Secret)
err = r.Client.Create(r.Ctx, r.Secret)
if err != nil {
Expand Down
27 changes: 15 additions & 12 deletions pkg/system/phase1_verifying.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,25 @@ func (r *Reconciler) CheckJoinSecret() error {
return util.NewPersistentError("InvalidJoinSecert",
"JoinSecret is missing mgmt_addr")
}
if r.JoinSecret.StringData["bg_addr"] == "" {
return util.NewPersistentError("InvalidJoinSecert",
"JoinSecret is missing bg_addr")
}
if r.JoinSecret.StringData["md_addr"] == "" {
return util.NewPersistentError("InvalidJoinSecert",
"JoinSecret is missing md_addr")
}
if r.JoinSecret.StringData["hosted_agents_addr"] == "" {
return util.NewPersistentError("InvalidJoinSecert",
"JoinSecret is missing hosted_agents_addr")
}
if r.JoinSecret.StringData["auth_token"] == "" {
return util.NewPersistentError("InvalidJoinSecert",
"JoinSecret is missing auth_token")
}

if !util.IsRemoteClientNoobaa(r.NooBaa.GetAnnotations()) {
if r.JoinSecret.StringData["bg_addr"] == "" {
return util.NewPersistentError("InvalidJoinSecert",
"JoinSecret is missing bg_addr")
}
if r.JoinSecret.StringData["md_addr"] == "" {
return util.NewPersistentError("InvalidJoinSecert",
"JoinSecret is missing md_addr")
}
if r.JoinSecret.StringData["hosted_agents_addr"] == "" {
return util.NewPersistentError("InvalidJoinSecert",
"JoinSecret is missing hosted_agents_addr")
}
}
return nil
}

Expand Down
18 changes: 12 additions & 6 deletions pkg/system/phase4_configuring.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ func (r *Reconciler) ReconcilePhaseConfiguring() error {
if err := r.ReconcileSystemSecrets(); err != nil {
return err
}
util.KubeCreateOptional(util.KubeObject(bundle.File_deploy_scc_endpoint_yaml).(*secv1.SecurityContextConstraints))
if err := r.ReconcileObject(r.DeploymentEndpoint, r.SetDesiredDeploymentEndpoint); err != nil {
return err
}
if err := r.ReconcileHPAEndpoint(); err != nil {
return err
// No endpoint creation is required for remote noobaa client
if !util.IsRemoteClientNoobaa(r.NooBaa.GetAnnotations()) {
util.KubeCreateOptional(util.KubeObject(bundle.File_deploy_scc_endpoint_yaml).(*secv1.SecurityContextConstraints))
if err := r.ReconcileObject(r.DeploymentEndpoint, r.SetDesiredDeploymentEndpoint); err != nil {
return err
}
if err := r.ReconcileHPAEndpoint(); err != nil {
return err
}
}
if err := r.RegisterToCluster(); err != nil {
return err
Expand Down Expand Up @@ -1644,6 +1647,9 @@ func (r *Reconciler) UpdateBucketClassesPhase(Buckets []nb.BucketInfo) {

// ReconcileDeploymentEndpointStatus creates/updates the endpoints deployment
func (r *Reconciler) ReconcileDeploymentEndpointStatus() error {
if !util.IsRemoteClientNoobaa(r.NooBaa.GetAnnotations()) {
return nil
}
if !util.KubeCheck(r.DeploymentEndpoint) {
return fmt.Errorf("Could not load endpoint deployment")
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,17 @@ func GetAnnotationValue(annotations map[string]string, name string) (string, boo
return "", false
}

// IsRemoteClientNoobaa checks for the existance and value of the remote-client-noobaa annotation
// within an annotation map, if the annotation doesnt exist it's the same as if its value is false.
func IsRemoteClientNoobaa(annotations map[string]string) bool {
annotationValue, exists := GetAnnotationValue(annotations, "remote-client-noobaa")
annotationBoolVal := false
if exists {
annotationBoolVal = strings.ToLower(annotationValue) == strconv.FormatBool(true)
}
return annotationBoolVal
}

// ReflectEnvVariable will add, update or remove an env variable base on the existence and value of an
// env variable with the same name on the container running this function.
func ReflectEnvVariable(env *[]corev1.EnvVar, name string) {
Expand Down

0 comments on commit c285607

Please sign in to comment.