Skip to content

Commit

Permalink
Fetch Noobaa remote info and create the join secret
Browse files Browse the repository at this point in the history
Signed-off-by: Kaustav Majumder <[email protected]>
  • Loading branch information
Kaustav Majumder committed Jul 16, 2024
1 parent 3165a1b commit 86cb5f4
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions service/status-report/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package main

import (
"context"
"encoding/json"
"fmt"
"os"
"strings"
"time"
Expand All @@ -31,6 +33,7 @@ import (
configv1 "github.com/openshift/api/config/v1"
opv1a1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
providerclient "github.com/red-hat-storage/ocs-operator/v4/services/provider/client"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -123,6 +126,7 @@ func main() {
if err != nil {
klog.Exitf("Failed to get StorageConfig of storageClient %v: %v", storageClient.Status.ConsumerID, err)
}
var noobaaAuthToken, noobaaMgmtAddress string
for _, eResource := range scResponse.ExternalResource {
if eResource.Kind == "ConfigMap" && eResource.Name == "rook-ceph-mon-endpoints" {
monitorIps, err := csi.ExtractMonitor(eResource.Data)
Expand All @@ -131,6 +135,12 @@ func main() {
}
csiClusterConfigEntry.Monitors = append(csiClusterConfigEntry.Monitors, monitorIps...)
}
if eResource.Kind == "Secret" && eResource.Name == storageClientName {
noobaaAuthToken, noobaaMgmtAddress, err = extractNoobaaResouces(eResource.Data)
if err != nil {
klog.Exitf("Failed to extract data for remote noobaa secret %v", err)
}
}
}
cc := csi.ClusterConfig{
Client: cl,
Expand All @@ -141,6 +151,16 @@ func main() {
if err != nil {
klog.Exitf("Failed to update mon configmap for storageClient %v: %v", storageClient.Status.ConsumerID, err)
}
joinSecret := &corev1.Secret{}
joinSecret.Name = "noobaa-remote-join-secret"
joinSecret.Namespace = operatorNamespace
joinSecret.Data = map[string][]byte{
"auth_token": []byte(noobaaAuthToken),
"mgmt_addr": []byte(noobaaMgmtAddress),
}
if err = cl.Create(ctx, joinSecret); err != nil {
klog.Exitf("Failed to create join secret %s in namespace %s: %v", joinSecret.Name, joinSecret.Namespace, err)
}
}

func setClusterInformation(ctx context.Context, cl client.Client, status interfaces.StorageClientStatus) {
Expand Down Expand Up @@ -206,3 +226,21 @@ func setPlatformInformation(ctx context.Context, cl client.Client, status interf
}
status.SetPlatformVersion(platformVersion)
}

func extractNoobaaResouces(noobaaData []byte) (string, string, error) {
data := map[string]string{}
err := json.Unmarshal(noobaaData, &data)
if err != nil {
return "", "", fmt.Errorf("failed to unmarshall data: %v", err)
}
noobaaAuthToken, ok := data["auth_token"]
if !ok {
return "", "", fmt.Errorf("noobaa auth token not found")
}
noobaaMgmtAddress, ok := data["mgmt_addr"]
if !ok {
return "", "", fmt.Errorf("noobaa mgmt address not found")
}

return noobaaAuthToken, noobaaMgmtAddress, nil
}

0 comments on commit 86cb5f4

Please sign in to comment.