Skip to content

Commit

Permalink
api: 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 26, 2024
1 parent e9adefa commit a470835
Show file tree
Hide file tree
Showing 40 changed files with 6,359 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
snapapi "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
nbapis "github.com/noobaa/noobaa-operator/v5/pkg/apis"
configv1 "github.com/openshift/api/config/v1"
consolev1 "github.com/openshift/api/console/v1"
quotav1 "github.com/openshift/api/quota/v1"
Expand Down Expand Up @@ -71,6 +72,7 @@ func init() {
utilruntime.Must(opv1a1.AddToScheme(scheme))
utilruntime.Must(extv1.AddToScheme(scheme))
utilruntime.Must(quotav1.AddToScheme(scheme))
utilruntime.Must(nbapis.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

Expand Down
11 changes: 11 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ rules:
- list
- update
- watch
- apiGroups:
- noobaa.io
resources:
- noobaas
verbs:
- create
- delete
- get
- list
- update
- watch
- apiGroups:
- ocs.openshift.io
resources:
Expand Down
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ require (
sigs.k8s.io/controller-runtime v0.18.4
)

require (
github.com/kube-object-storage/lib-bucket-provisioner v0.0.0-20221122204822-d1a8c34382f1 // indirect
github.com/openshift/custom-resource-status v1.1.2 // indirect
sigs.k8s.io/container-object-storage-interface-api v0.1.0 // indirect
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
Expand Down Expand Up @@ -60,6 +66,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/noobaa/noobaa-operator/v5 v5.15.4
github.com/nxadm/tail v1.4.8 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
Expand Down
550 changes: 550 additions & 0 deletions go.sum

Large diffs are not rendered by default.

49 changes: 48 additions & 1 deletion internal/controller/storageclient_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/red-hat-storage/ocs-client-operator/api/v1alpha1"
"github.com/red-hat-storage/ocs-client-operator/pkg/utils"

nbv1 "github.com/noobaa/noobaa-operator/v5/pkg/apis/noobaa/v1alpha1"
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"
Expand Down Expand Up @@ -98,6 +99,8 @@ func (r *StorageClientReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&v1alpha1.StorageClaim{}).
Owns(&batchv1.CronJob{}).
Owns(&quotav1.ClusterResourceQuota{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Owns(&nbv1.NooBaa{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Owns(&corev1.Secret{}).
Complete(r)
}

Expand All @@ -108,6 +111,8 @@ func (r *StorageClientReconciler) SetupWithManager(mgr ctrl.Manager) error {
//+kubebuilder:rbac:groups=config.openshift.io,resources=clusterversions,verbs=get;list;watch
//+kubebuilder:rbac:groups=batch,resources=cronjobs,verbs=get;list;create;update;watch;delete
//+kubebuilder:rbac:groups=operators.coreos.com,resources=clusterserviceversions,verbs=get;list;watch
//+kubebuilder:rbac:groups=noobaa.io,resources=noobaas,verbs=get;list;watch;create;update;delete
//+kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create;update;delete

func (r *StorageClientReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
var err error
Expand Down Expand Up @@ -210,9 +215,51 @@ func (r *StorageClientReconciler) reconcilePhases() (ctrl.Result, error) {
if err := r.reconcileClusterResourceQuota(clusterResourceQuotaSpec); err != nil {
return reconcile.Result{}, err
}
case "Secret":
data := &corev1.Secret{}
if err := json.Unmarshal(eResource.Data, &data); err != nil {
return reconcile.Result{}, fmt.Errorf("failed to unmarshall secret: %v", err)
}
secret := &corev1.Secret{}
secret.Name = eResource.Name
secret.Namespace = r.storageClient.Namespace
_, err := controllerutil.CreateOrUpdate(r.ctx, r.Client, secret, func() error {
if err := r.own(secret); err != nil {
return err
}
secret.Data = data.Data
return nil
})
if err != nil {
return reconcile.Result{}, fmt.Errorf(
"failed to create or update secret %v: %v",
client.ObjectKeyFromObject(secret),
err,
)
}
case "Noobaa":
noobaaSpec := &nbv1.NooBaaSpec{}
if err := json.Unmarshal(eResource.Data, &noobaaSpec); err != nil {
return reconcile.Result{}, fmt.Errorf("failed to unmarshall noobaa spec data: %v", err)
}
nb := &nbv1.NooBaa{}
nb.Name = eResource.Name
nb.Namespace = r.storageClient.Namespace

_, err = controllerutil.CreateOrUpdate(r.ctx, r.Client, nb, func() error {
if err := r.own(nb); err != nil {
return err
}
utils.AddAnnotation(nb, "remote-client-noobaa", "true")
noobaaSpec.JoinSecret.Namespace = r.storageClient.Namespace
nb.Spec = *noobaaSpec
return nil
})
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to create remote noobaa: %v", err)
}
}
}

if r.storageClient.GetAnnotations()[storageClaimProcessedAnnotationKey] != "true" {
if err := r.reconcileBlockStorageClaim(); err != nil {
return reconcile.Result{}, err
Expand Down
201 changes: 201 additions & 0 deletions vendor/github.com/kube-object-storage/lib-bucket-provisioner/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a470835

Please sign in to comment.