Skip to content

Commit

Permalink
Make DM teardown state label public (#62)
Browse files Browse the repository at this point in the history
Signed-off-by: Nate Roiger <[email protected]>
  • Loading branch information
Nate Roiger authored Sep 9, 2022
1 parent 017e544 commit 48559b7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
16 changes: 16 additions & 0 deletions api/v1alpha1/nnf_datamovement_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ func (n *NnfDataMovementList) GetObjectList() []client.Object {
return objectList
}

const (
// DataMovementTeardownStateLabel is the label applied to Data Movement and related resources that describes
// the workflow state when the resource is no longer need and can be safely deleted.
DataMovementTeardownStateLabel = "nnf.cray.hpe.com/teardown_state"
)

func AddDataMovementTeardownStateLabel(object metav1.Object, state string) {
labels := object.GetLabels()
if labels == nil {
labels = make(map[string]string)
}

labels[DataMovementTeardownStateLabel] = state
object.SetLabels(labels)
}

func init() {
SchemeBuilder.Register(&NnfDataMovement{}, &NnfDataMovementList{})
}
2 changes: 1 addition & 1 deletion controllers/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ var _ = Describe("Integration Test", func() {
}
dwsv1alpha1.AddWorkflowLabels(dm, workflow)
dwsv1alpha1.AddOwnerLabels(dm, workflow)
addTeardownStateLabel(dm, dwsv1alpha1.StatePostRun.String())
nnfv1alpha1.AddDataMovementTeardownStateLabel(dm, dwsv1alpha1.StatePostRun.String())

Expect(k8sClient.Create(context.TODO(), dm)).To(Succeed())

Expand Down
15 changes: 5 additions & 10 deletions controllers/nnf_workflow_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ const (
// prevents the system from deleting the custom resource until the
// reconciler has finished in using the resource.
finalizerNnfWorkflow = "nnf.cray.hpe.com/nnf_workflow"

// teardownStateLabel is a label applied to NnfAccess resources to determine when
// they should be deleted. The delete code filters by the current workflow state
// to only delete the correct NnfAccess resources
teardownStateLabel = "nnf.cray.hpe.com/teardown_state"
)

type nnfResourceState int
Expand Down Expand Up @@ -969,8 +964,8 @@ func (r *NnfWorkflowReconciler) startDataInOutState(ctx context.Context, workflo

dwsv1alpha1.AddWorkflowLabels(dm, workflow)
dwsv1alpha1.AddOwnerLabels(dm, workflow)
nnfv1alpha1.AddDataMovementTeardownStateLabel(dm, workflow.Status.State)
addDirectiveIndexLabel(dm, index)
addTeardownStateLabel(dm, workflow.Status.State)

log.Info("Creating NNF Data Movement", "name", client.ObjectKeyFromObject(dm).String())
if err := r.Create(ctx, dm); err != nil {
Expand Down Expand Up @@ -1005,8 +1000,8 @@ func (r *NnfWorkflowReconciler) startDataInOutState(ctx context.Context, workflo

dwsv1alpha1.AddWorkflowLabels(dm, workflow)
dwsv1alpha1.AddOwnerLabels(dm, workflow)
nnfv1alpha1.AddDataMovementTeardownStateLabel(dm, workflow.Status.State)
addDirectiveIndexLabel(dm, index)
addTeardownStateLabel(dm, workflow.Status.State)

log.Info("Creating NNF Data Movement", "name", client.ObjectKeyFromObject(dm).String())
if err := r.Create(ctx, dm); err != nil {
Expand Down Expand Up @@ -1053,8 +1048,8 @@ func (r *NnfWorkflowReconciler) setupNnfAccessForServers(ctx context.Context, st
func() error {
dwsv1alpha1.AddWorkflowLabels(access, workflow)
dwsv1alpha1.AddOwnerLabels(access, workflow)
nnfv1alpha1.AddDataMovementTeardownStateLabel(access, teardownState)
addDirectiveIndexLabel(access, index)
addTeardownStateLabel(access, teardownState)

access.Spec = nnfv1alpha1.NnfAccessSpec{
DesiredState: "mounted",
Expand Down Expand Up @@ -1095,7 +1090,7 @@ func (r *NnfWorkflowReconciler) finishDataInOutState(ctx context.Context, workfl

matchingLabels := dwsv1alpha1.MatchingOwner(workflow)
matchingLabels[nnfv1alpha1.DirectiveIndexLabel] = strconv.Itoa(index)
matchingLabels[teardownStateLabel] = workflow.Status.State
matchingLabels[nnfv1alpha1.DataMovementTeardownStateLabel] = workflow.Status.State

dataMovementList := &nnfv1alpha1.NnfDataMovementList{}
if err := r.List(ctx, dataMovementList, matchingLabels); err != nil {
Expand Down Expand Up @@ -1336,7 +1331,7 @@ func (r *NnfWorkflowReconciler) startPostRunState(ctx context.Context, workflow

// Wait for data movement resources to complete
matchingLabels := dwsv1alpha1.MatchingOwner(workflow)
matchingLabels[teardownStateLabel] = workflow.Status.State
matchingLabels[nnfv1alpha1.DataMovementTeardownStateLabel] = workflow.Status.State

dataMovementList := &nnfv1alpha1.NnfDataMovementList{}
if err := r.List(ctx, dataMovementList, matchingLabels); err != nil {
Expand Down
12 changes: 1 addition & 11 deletions controllers/nnf_workflow_controller_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,4 @@ func addDirectiveIndexLabel(object metav1.Object, index int) {

labels[nnfv1alpha1.DirectiveIndexLabel] = strconv.Itoa(index)
object.SetLabels(labels)
}

func addTeardownStateLabel(object metav1.Object, state string) {
labels := object.GetLabels()
if labels == nil {
labels = make(map[string]string)
}

labels[teardownStateLabel] = state
object.SetLabels(labels)
}
}

0 comments on commit 48559b7

Please sign in to comment.