Skip to content

Commit

Permalink
Reuse clientmount get NnfServer to get lustre component counts
Browse files Browse the repository at this point in the history
  • Loading branch information
bdevcich committed Nov 27, 2024
1 parent 595b723 commit db062c2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 13 deletions.
51 changes: 49 additions & 2 deletions internal/controller/filesystem_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,58 @@ func newLustreFileSystem(ctx context.Context, c client.Client, nnfNodeStorage *n
fs.CommandArgs.PreDeactivate = cmdLines.PreDeactivate
fs.TempDir = fmt.Sprintf("/mnt/temp/%s-%d", nnfNodeStorage.Name, index)

server, err := getServerForClientMountOrNnfNodeStorage(ctx, c, nnfNodeStorage.Labels)
if err != nil {
return nil, dwsv1alpha2.NewResourceError("could not retrieve corresponding NnfServer resource for this NnfNodeStorage").WithError(err).WithMajor()
}

storages := make(map[string][]string)
rabbits := make(map[string]bool)
for _, allocationSet := range server.Spec.AllocationSets {
label := allocationSet.Label
for _, storage := range allocationSet.Storage {
node := storage.Name

if _, found := storages[label]; !found {
storages[label] = []string{}
}
storages[label] = append(storages[label], node)

if _, found := rabbits[node]; !found {
rabbits[node] = true
}
}
}

numMGTs := 0
if _, found := storages["mgt"]; found {
numMGTs = len(storages["mgt"])
}
numMDTs := 0
if _, found := storages["mdt"]; found {
numMDTs = len(storages["mdt"])
}
numOSTs := 0
if _, found := storages["ost"]; found {
numOSTs = len(storages["ost"])
}
numMGTMDTs := 0
if _, found := storages["mgtmdt"]; found {
numMGTMDTs = len(storages["mgtmdt"])
}

fs.CommandArgs.Vars = map[string]string{
"$USERID": fmt.Sprintf("%d", nnfNodeStorage.Spec.UserID),
"$GROUPID": fmt.Sprintf("%d", nnfNodeStorage.Spec.GroupID),
"$USERID": fmt.Sprintf("%d", nnfNodeStorage.Spec.UserID),
"$GROUPID": fmt.Sprintf("%d", nnfNodeStorage.Spec.GroupID),
"$NUM_MGTS": fmt.Sprintf("%d", numMGTs),
"$NUM_MDTS": fmt.Sprintf("%d", numMDTs),
"$NUM_OSTS": fmt.Sprintf("%d", numOSTs),
"$NUM_MGTMDTS": fmt.Sprintf("%d", numMGTMDTs),
"$NUM_RABBITS": fmt.Sprintf("%d", numMDTs),
}

log.Info("BLAKE", "Vars", fs.CommandArgs.Vars)

return &fs, nil
}

Expand Down
22 changes: 11 additions & 11 deletions internal/controller/nnf_clientmount_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func (r *NnfClientMountReconciler) changeMount(ctx context.Context, clientMount
func (r *NnfClientMountReconciler) dumpServersToFile(ctx context.Context, clientMount *dwsv1alpha2.ClientMount, path string, uid, gid uint32) error {

// Get the NnfServers Resource
server, err := r.getServerForClientMount(ctx, clientMount)
server, err := getServerForClientMountOrNnfNodeStorage(ctx, r.Client, clientMount.Labels)
if err != nil {
return dwsv1alpha2.NewResourceError("could not retrieve corresponding NnfServer resource for this ClientMount").WithError(err).WithMajor()
}
Expand Down Expand Up @@ -339,20 +339,20 @@ func (r *NnfClientMountReconciler) dumpServersToFile(ctx context.Context, client
// 2. PersistentStorageInstance (persistent storage case)
//
// Once we understand who owns the NnfStorage resource, we can then obtain the NnfServer resource through slightly different methods.
func (r *NnfClientMountReconciler) getServerForClientMount(ctx context.Context, clientMount *dwsv1alpha2.ClientMount) (*dwsv1alpha2.Servers, error) {
func getServerForClientMountOrNnfNodeStorage(ctx context.Context, c client.Client, labels map[string]string) (*dwsv1alpha2.Servers, error) {
storageKind := "NnfStorage"
persistentKind := "PersistentStorageInstance"
workflowKind := "Workflow"

// Get the owner and directive index from ClientMount's labels
ownerKind, ownerExists := clientMount.Labels[dwsv1alpha2.OwnerKindLabel]
ownerName, ownerNameExists := clientMount.Labels[dwsv1alpha2.OwnerNameLabel]
ownerNS, ownerNSExists := clientMount.Labels[dwsv1alpha2.OwnerNamespaceLabel]
_, idxExists := clientMount.Labels[nnfv1alpha4.DirectiveIndexLabel]
ownerKind, ownerExists := labels[dwsv1alpha2.OwnerKindLabel]
ownerName, ownerNameExists := labels[dwsv1alpha2.OwnerNameLabel]
ownerNS, ownerNSExists := labels[dwsv1alpha2.OwnerNamespaceLabel]
_, idxExists := labels[nnfv1alpha4.DirectiveIndexLabel]

// We should expect the owner of the ClientMount to be NnfStorage and have the expected labels
// We should expect the owner to be NnfStorage and have the expected labels
if !ownerExists || !ownerNameExists || !ownerNSExists || !idxExists || ownerKind != storageKind {
return nil, dwsv1alpha2.NewResourceError("expected ClientMount owner to be of kind NnfStorage and have the expected labels").WithMajor()
return nil, dwsv1alpha2.NewResourceError("expected owner to be of kind NnfStorage and have the expected labels").WithMajor()
}

// Retrieve the NnfStorage resource
Expand All @@ -362,7 +362,7 @@ func (r *NnfClientMountReconciler) getServerForClientMount(ctx context.Context,
Namespace: ownerNS,
},
}
if err := r.Get(ctx, client.ObjectKeyFromObject(storage), storage); err != nil {
if err := c.Get(ctx, client.ObjectKeyFromObject(storage), storage); err != nil {
return nil, dwsv1alpha2.NewResourceError("unable retrieve NnfStorage resource").WithError(err).WithMajor()
}

Expand All @@ -375,7 +375,7 @@ func (r *NnfClientMountReconciler) getServerForClientMount(ctx context.Context,
// We should expect the owner of the NnfStorage to be Workflow or PersistentStorageInstance and
// have the expected labels
if !ownerExists || !ownerNameExists || !ownerNSExists || !idxExists || (ownerKind != workflowKind && ownerKind != persistentKind) {
return nil, dwsv1alpha2.NewResourceError("expected NnfStorage owner to be of kind Workflow or PersistentStorageInstance and have the expected labels").WithMajor()
return nil, dwsv1alpha2.NewResourceError("expected owner to be of kind Workflow or PersistentStorageInstance and have the expected labels").WithMajor()
}

// If the owner is a workflow, then we can use the workflow labels and directive index to get
Expand All @@ -402,7 +402,7 @@ func (r *NnfClientMountReconciler) getServerForClientMount(ctx context.Context,
}

serversList := &dwsv1alpha2.ServersList{}
if err := r.List(ctx, serversList, listOptions...); err != nil {
if err := c.List(ctx, serversList, listOptions...); err != nil {
return nil, dwsv1alpha2.NewResourceError("unable retrieve NnfServers resource").WithError(err).WithMajor()
}

Expand Down

0 comments on commit db062c2

Please sign in to comment.