You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ya...@apache.org on 2026/10/17 18:23:39 UTC
(airavata-custos) 01/03: ensure allocation folders are created only after unix group is provisioned
This is an automated email from the ASF dual-hosted git repository.
yasithdev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit c57865ff14fa03a62b2c67f6ee600da67fa66585
Author: Yasith Jayawardana <ya...@icloud.com>
AuthorDate: Sat Oct 17 14:19:52 2026 -0400
ensure allocation folders are created only after unix group is provisioned
---
api/core.openapi.yaml | 4 +++
.../internal/operations/ensure_allocation_group.go | 7 +++-
.../operations/ensure_allocation_group_test.go | 3 ++
.../internal/operations/mocks_test.go | 6 ++++
.../internal/operations/orchestrator.go | 1 +
connectors/Storage/VAST-Provisioner/README.md | 2 +-
.../internal/subscribers/subscriber.go | 18 +++-------
.../internal/subscribers/subscriber_test.go | 40 +++++++++++-----------
internal/db/migrations/000004_allocations.up.sql | 1 +
internal/store/compute_allocation_store.go | 16 +++++++--
internal/store/store.go | 2 ++
pkg/events/compute_allocation_subscribe.go | 6 ++++
pkg/events/types.go | 7 ++--
pkg/models/allocation.go | 3 +-
pkg/service/compute_allocation.go | 20 +++++++++++
15 files changed, 93 insertions(+), 43 deletions(-)
diff --git a/api/core.openapi.yaml b/api/core.openapi.yaml
index d2144ad12..dc1e7205f 100644
--- a/api/core.openapi.yaml
+++ b/api/core.openapi.yaml
@@ -164,6 +164,10 @@ definitions:
type: string
end_time:
type: string
+ group_provisioned_at:
+ description: When the group gained its first member and so reached the
+ cluster; nil until then.
+ type: string
id:
type: string
initial_su_amount:
diff --git a/connectors/COmanage/Identity-Provisioner/internal/operations/ensure_allocation_group.go b/connectors/COmanage/Identity-Provisioner/internal/operations/ensure_allocation_group.go
index 2e9e320cb..325b9e850 100644
--- a/connectors/COmanage/Identity-Provisioner/internal/operations/ensure_allocation_group.go
+++ b/connectors/COmanage/Identity-Provisioner/internal/operations/ensure_allocation_group.go
@@ -83,6 +83,7 @@ func (o *Orchestrator) EnsureAllocationGroup(ctx context.Context, a *models.Comp
want[id] = true
}
}
+ held := len(want)
rows, err := o.c.ListCoGroupMembers(groupID)
if err != nil {
return err
@@ -103,7 +104,11 @@ func (o *Orchestrator) EnsureAllocationGroup(ctx context.Context, a *models.Comp
}
o.auditAllocation(ctx, a, "ComanageAllocationGroupMemberAdded", fmt.Sprintf("group=%s co_person_id=%d", *a.PosixGroup, id))
}
- return nil
+ // COmanage pushes a group to LDAP only once it has a member.
+ if held == 0 {
+ return nil
+ }
+ return o.core.MarkComputeAllocationGroupProvisioned(ctx, a.ID)
}
func (o *Orchestrator) auditAllocation(ctx context.Context, a *models.ComputeAllocation, eventType, details string) {
diff --git a/connectors/COmanage/Identity-Provisioner/internal/operations/ensure_allocation_group_test.go b/connectors/COmanage/Identity-Provisioner/internal/operations/ensure_allocation_group_test.go
index 2f366864d..b4bac2261 100644
--- a/connectors/COmanage/Identity-Provisioner/internal/operations/ensure_allocation_group_test.go
+++ b/connectors/COmanage/Identity-Provisioner/internal/operations/ensure_allocation_group_test.go
@@ -48,6 +48,9 @@ func TestEnsureAllocationGroup_RemovesExtraAndDuplicateMemberRows(t *testing.T)
if !slices.Equal(reg.deleted, []string{"/co_group_members/10.json", "/co_group_members/11.json"}) || len(reg.posted) != 0 {
t.Fatalf("deleted %v, posted %v; want rows 10 and 11 deleted, nothing posted", reg.deleted, reg.posted)
}
+ if !slices.Equal(core.markedGroups, []string{"alloc-1"}) {
+ t.Fatalf("marked groups %v, want alloc-1 once it holds a member", core.markedGroups)
+ }
var removed []string
for _, e := range core.auditEvents {
if e.EventType == "ComanageAllocationGroupMemberRemoved" && e.EntityID == "alloc-1" {
diff --git a/connectors/COmanage/Identity-Provisioner/internal/operations/mocks_test.go b/connectors/COmanage/Identity-Provisioner/internal/operations/mocks_test.go
index 7bab3fb56..7b2b62449 100644
--- a/connectors/COmanage/Identity-Provisioner/internal/operations/mocks_test.go
+++ b/connectors/COmanage/Identity-Provisioner/internal/operations/mocks_test.go
@@ -48,6 +48,7 @@ type fakeCore struct {
auditEvents []models.AuditEvent
writtenIdentity *models.UserIdentity
markedProvisioned []string
+ markedGroups []string
members []store.MembershipWithUser
}
@@ -76,6 +77,11 @@ func (f *fakeCore) MarkComputeClusterUserProvisioned(_ context.Context, id strin
return nil
}
+func (f *fakeCore) MarkComputeAllocationGroupProvisioned(_ context.Context, id string) error {
+ f.markedGroups = append(f.markedGroups, id)
+ return nil
+}
+
func (f *fakeCore) ListMembersForAllocation(_ context.Context, _ string) ([]store.MembershipWithUser, error) {
return f.members, nil
}
diff --git a/connectors/COmanage/Identity-Provisioner/internal/operations/orchestrator.go b/connectors/COmanage/Identity-Provisioner/internal/operations/orchestrator.go
index c185c95cb..f3a2bbbac 100644
--- a/connectors/COmanage/Identity-Provisioner/internal/operations/orchestrator.go
+++ b/connectors/COmanage/Identity-Provisioner/internal/operations/orchestrator.go
@@ -41,6 +41,7 @@ type CoreService interface {
UpdateUserIdentity(ctx context.Context, ui *models.UserIdentity) error
CreateAuditEvent(ctx context.Context, e *models.AuditEvent) (*models.AuditEvent, error)
MarkComputeClusterUserProvisioned(ctx context.Context, id string) error
+ MarkComputeAllocationGroupProvisioned(ctx context.Context, id string) error
ListMembersForAllocation(ctx context.Context, allocationID string) ([]store.MembershipWithUser, error)
}
diff --git a/connectors/Storage/VAST-Provisioner/README.md b/connectors/Storage/VAST-Provisioner/README.md
index 304175f76..5579dddab 100644
--- a/connectors/Storage/VAST-Provisioner/README.md
+++ b/connectors/Storage/VAST-Provisioner/README.md
@@ -34,7 +34,7 @@ fields on a view. The policy is looked up once at startup, and Custos does not s
| Trigger | Runs |
|---|---|
| `compute_cluster_user::provision` | The account's directories, then its directory in each of its projects |
-| `compute_allocation::create` and `::update` | The project's directories; retried until LDAP has the group |
+| `compute_allocation::group_provision` | The project's directories and each provisioned member's, once the group's first member puts it on the cluster |
| `compute_allocation_membership::create` and `::update` | That member's project directory, once their account is provisioned |
| Startup, then every 24 hours | Everything, for every account and allocation on each cluster |
diff --git a/connectors/Storage/VAST-Provisioner/internal/subscribers/subscriber.go b/connectors/Storage/VAST-Provisioner/internal/subscribers/subscriber.go
index 69e0787fa..b78efc87e 100644
--- a/connectors/Storage/VAST-Provisioner/internal/subscribers/subscriber.go
+++ b/connectors/Storage/VAST-Provisioner/internal/subscribers/subscriber.go
@@ -73,8 +73,7 @@ func NewStorageSubscriber(bus *events.Bus, core service.CoreService, clusters ma
// names the right user and can be retried alone. The reconciler does the rest.
func (s *StorageSubscriber) RegisterSubscribers(subscriber string) {
s.bus.SubscribeComputeClusterUserProvisioned(subscriber, s.ensureUser)
- s.bus.SubscribeComputeAllocationCreated(subscriber, s.ensureGroup)
- s.bus.SubscribeComputeAllocationUpdated(subscriber, s.ensureGroup)
+ s.bus.SubscribeComputeAllocationGroupProvisioned(subscriber, s.ensureAllocation)
s.bus.SubscribeComputeAllocationMembershipCreated(subscriber, s.ensureMember)
s.bus.SubscribeComputeAllocationMembershipUpdated(subscriber, s.ensureMember)
}
@@ -133,19 +132,10 @@ func (s *StorageSubscriber) ensureMember(ctx context.Context, m models.ComputeAl
return nil
}
-// ensureGroup creates an allocation's group mounts. Members' mounts come from their own events.
-func (s *StorageSubscriber) ensureGroup(ctx context.Context, a models.ComputeAllocation) error {
- c, ok := s.cluster(a)
- if !ok {
- return nil
- }
- return s.ensure(ctx, c, "", *a.PosixGroup)
-}
-
-// cluster returns the allocation's cluster when the allocation is active, has a group, and the cluster is configured.
+// cluster returns the allocation's cluster when the allocation is active, its group is on the cluster, and the cluster is configured.
func (s *StorageSubscriber) cluster(a models.ComputeAllocation) (Cluster, bool) {
c, ok := s.clusters[a.ComputeClusterID]
- return c, ok && a.Status == models.ACTIVE && a.PosixGroup != nil
+ return c, ok && a.Status == models.ACTIVE && a.PosixGroup != nil && a.GroupProvisionedAt != nil
}
// activeAllocation loads the allocation and its cluster, nil when there is nothing to create for it.
@@ -172,7 +162,7 @@ func (s *StorageSubscriber) ensureMemberMounts(ctx context.Context, c Cluster, u
return s.ensure(ctx, c, user, group)
}
-// ensureAllocation creates an active allocation's mounts, then those of each member its POSIX group holds. Used by the reconciler.
+// ensureAllocation creates an allocation's mounts once its group is on the cluster, then each provisioned member's.
func (s *StorageSubscriber) ensureAllocation(ctx context.Context, a models.ComputeAllocation) error {
c, ok := s.cluster(a)
if !ok {
diff --git a/connectors/Storage/VAST-Provisioner/internal/subscribers/subscriber_test.go b/connectors/Storage/VAST-Provisioner/internal/subscribers/subscriber_test.go
index 542fb0fd2..16ea5cdc0 100644
--- a/connectors/Storage/VAST-Provisioner/internal/subscribers/subscriber_test.go
+++ b/connectors/Storage/VAST-Provisioner/internal/subscribers/subscriber_test.go
@@ -61,7 +61,7 @@ func allocationWithMembers() *service.CoreServiceMock {
return []models.ComputeAllocationMembership{{ComputeAllocationID: "a1", MembershipStatus: models.ACTIVE}}, nil
},
GetComputeAllocationFunc: func(context.Context, string) (*models.ComputeAllocation, error) {
- return &models.ComputeAllocation{ID: "a1", ComputeClusterID: "c1", Status: models.ACTIVE, PosixGroup: &group}, nil
+ return &models.ComputeAllocation{ID: "a1", ComputeClusterID: "c1", Status: models.ACTIVE, PosixGroup: &group, GroupProvisionedAt: &provisioned}, nil
},
ListMembersForAllocationFunc: func(context.Context, string) ([]store.MembershipWithUser, error) {
return []store.MembershipWithUser{member("u1", "custos-jdoe", &provisioned), member("u2", "custos-asmith", &provisioned), member("u3", "custos-pending", nil)}, nil
@@ -146,25 +146,25 @@ func TestEnsureMember(t *testing.T) {
}
}
-// Make sure an allocation event creates the project's directories and no member's.
-func TestEnsureGroup(t *testing.T) {
- c, log := recordingVMS(t)
- group := "proj-a"
- s := NewStorageSubscriber(nil, allocationWithMembers(), map[string]Cluster{"c1": c})
- a := models.ComputeAllocation{ID: "a1", ComputeClusterID: "c1", Status: models.ACTIVE, PosixGroup: &group}
- if err := s.ensureGroup(context.Background(), a); err != nil || !slices.Equal(*log, groupMounts) {
- t.Fatalf("err=%v calls=%v, want %v", err, *log, groupMounts)
- }
-}
-
-// Make sure the reconciler's sweep creates the project's directories and every provisioned member's.
+// Make sure an allocation creates nothing until its group is on the cluster, then the project's and every provisioned member's directories.
func TestEnsureAllocation(t *testing.T) {
- c, log := recordingVMS(t)
- group := "proj-a"
- s := NewStorageSubscriber(nil, allocationWithMembers(), map[string]Cluster{"c1": c})
- a := models.ComputeAllocation{ID: "a1", ComputeClusterID: "c1", Status: models.ACTIVE, PosixGroup: &group}
- want := join(groupMounts, jdoeMember, asmithMember)
- if err := s.ensureAllocation(context.Background(), a); err != nil || !slices.Equal(*log, want) {
- t.Fatalf("err=%v calls=%v, want %v", err, *log, want)
+ group, now := "proj-a", time.Now()
+ tests := []struct {
+ name string
+ groupProvisionedAt *time.Time
+ want []string
+ }{
+ {name: "nothing before the group is provisioned"},
+ {name: "project and members once provisioned", groupProvisionedAt: &now, want: join(groupMounts, jdoeMember, asmithMember)},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ c, log := recordingVMS(t)
+ s := NewStorageSubscriber(nil, allocationWithMembers(), map[string]Cluster{"c1": c})
+ a := models.ComputeAllocation{ID: "a1", ComputeClusterID: "c1", Status: models.ACTIVE, PosixGroup: &group, GroupProvisionedAt: tt.groupProvisionedAt}
+ if err := s.ensureAllocation(context.Background(), a); err != nil || !slices.Equal(*log, tt.want) {
+ t.Fatalf("err=%v calls=%v, want %v", err, *log, tt.want)
+ }
+ })
}
}
diff --git a/internal/db/migrations/000004_allocations.up.sql b/internal/db/migrations/000004_allocations.up.sql
index b87e0db84..2369b4fd6 100644
--- a/internal/db/migrations/000004_allocations.up.sql
+++ b/internal/db/migrations/000004_allocations.up.sql
@@ -26,6 +26,7 @@ CREATE TABLE IF NOT EXISTS compute_allocations
start_time TIMESTAMPTZ(6) NOT NULL,
end_time TIMESTAMPTZ(6) NOT NULL,
posix_group VARCHAR(32) NULL,
+ group_provisioned_at TIMESTAMPTZ(6) NULL,
created_at TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
updated_at TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
PRIMARY KEY (id),
diff --git a/internal/store/compute_allocation_store.go b/internal/store/compute_allocation_store.go
index f2ee2ac7a..b32a4c95a 100644
--- a/internal/store/compute_allocation_store.go
+++ b/internal/store/compute_allocation_store.go
@@ -22,6 +22,7 @@ import (
"database/sql"
"errors"
"strings"
+ "time"
"github.com/jmoiron/sqlx"
@@ -37,7 +38,7 @@ func NewComputeAllocationStore(db *sqlx.DB) ComputeAllocationStore {
return &pgComputeAllocationStore{db: db}
}
-const computeAllocationColumns = `id, project_id, name, status, compute_cluster_id, initial_su_amount, start_time, end_time, posix_group`
+const computeAllocationColumns = `id, project_id, name, status, compute_cluster_id, initial_su_amount, start_time, end_time, posix_group, group_provisioned_at`
func (s *pgComputeAllocationStore) FindByID(ctx context.Context, id string) (*models.ComputeAllocation, error) {
var a models.ComputeAllocation
@@ -75,8 +76,8 @@ func (s *pgComputeAllocationStore) FindByCluster(ctx context.Context, clusterID
func (s *pgComputeAllocationStore) Create(ctx context.Context, tx *sql.Tx, a *models.ComputeAllocation) error {
_, err := tx.ExecContext(ctx,
`INSERT INTO compute_allocations (`+computeAllocationColumns+`)
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
- a.ID, a.ProjectID, a.Name, string(a.Status), a.ComputeClusterID, a.InitialSUAmount, a.StartTime, a.EndTime, a.PosixGroup)
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`,
+ a.ID, a.ProjectID, a.Name, string(a.Status), a.ComputeClusterID, a.InitialSUAmount, a.StartTime, a.EndTime, a.PosixGroup, a.GroupProvisionedAt)
return err
}
@@ -96,6 +97,15 @@ func (s *pgComputeAllocationStore) Delete(ctx context.Context, tx *sql.Tx, id st
return err
}
+func (s *pgComputeAllocationStore) MarkGroupProvisioned(ctx context.Context, tx *sql.Tx, id string, at time.Time) (bool, error) {
+ res, err := tx.ExecContext(ctx, `UPDATE compute_allocations SET group_provisioned_at = $1 WHERE id = $2 AND group_provisioned_at IS NULL`, at, id)
+ if err != nil {
+ return false, err
+ }
+ n, err := res.RowsAffected()
+ return n == 1, err
+}
+
// FindByParticipant returns the allocations where the user holds an active
// membership, or a governance role on the parent project. Ordered like List
// (start_time descending).
diff --git a/internal/store/store.go b/internal/store/store.go
index b865cc55b..56898f55e 100644
--- a/internal/store/store.go
+++ b/internal/store/store.go
@@ -182,6 +182,8 @@ type ComputeAllocationStore interface {
Create(ctx context.Context, tx *sql.Tx, a *models.ComputeAllocation) error
// Update replaces mutable fields of an existing allocation within the provided transaction.
Update(ctx context.Context, tx *sql.Tx, a *models.ComputeAllocation) error
+ // MarkGroupProvisioned stamps group_provisioned_at within the provided transaction and returns true only the first time.
+ MarkGroupProvisioned(ctx context.Context, tx *sql.Tx, id string, at time.Time) (bool, error)
// Delete removes an allocation by ID within the provided transaction.
Delete(ctx context.Context, tx *sql.Tx, id string) error
// List returns a paginated, filtered slice of allocations plus the total
diff --git a/pkg/events/compute_allocation_subscribe.go b/pkg/events/compute_allocation_subscribe.go
index 07a27b045..7dea8595d 100644
--- a/pkg/events/compute_allocation_subscribe.go
+++ b/pkg/events/compute_allocation_subscribe.go
@@ -40,6 +40,12 @@ func (b *Bus) SubscribeComputeAllocationUpdated(subscriber string, handler Compu
subscribeTyped(b, subscriber, ComputeAllocationUpdateEvent, handler)
}
+// SubscribeComputeAllocationGroupProvisioned registers a typed handler invoked whenever a
+// compute_allocation::group_provision event is published, once the group's first member puts it on the cluster.
+func (b *Bus) SubscribeComputeAllocationGroupProvisioned(subscriber string, handler ComputeAllocationHandler) {
+ subscribeTyped(b, subscriber, ComputeAllocationGroupProvisionEvent, handler)
+}
+
// SubscribeComputeAllocationDeleted registers a typed handler invoked whenever a
// compute_allocation::delete event is published.
func (b *Bus) SubscribeComputeAllocationDeleted(subscriber string, handler ComputeAllocationHandler) {
diff --git a/pkg/events/types.go b/pkg/events/types.go
index 46e9c8154..620e3ff9e 100644
--- a/pkg/events/types.go
+++ b/pkg/events/types.go
@@ -78,9 +78,10 @@ const (
// ComputeAllocation lifecycle message types.
const (
- ComputeAllocationCreateEvent EventType = "compute_allocation::create"
- ComputeAllocationUpdateEvent EventType = "compute_allocation::update"
- ComputeAllocationDeleteEvent EventType = "compute_allocation::delete"
+ ComputeAllocationCreateEvent EventType = "compute_allocation::create"
+ ComputeAllocationUpdateEvent EventType = "compute_allocation::update"
+ ComputeAllocationDeleteEvent EventType = "compute_allocation::delete"
+ ComputeAllocationGroupProvisionEvent EventType = "compute_allocation::group_provision"
)
// CreateComputeAllocationDiff lifecycle message types.
diff --git a/pkg/models/allocation.go b/pkg/models/allocation.go
index eb898ce67..dec188822 100644
--- a/pkg/models/allocation.go
+++ b/pkg/models/allocation.go
@@ -74,7 +74,8 @@ type ComputeAllocation struct {
StartTime time.Time `json:"start_time" db:"start_time"`
EndTime time.Time `json:"end_time" db:"end_time"`
- PosixGroup *string `json:"posix_group" db:"posix_group"` // Fixed at creation; the group's name everywhere.
+ PosixGroup *string `json:"posix_group" db:"posix_group"` // Fixed at creation; the group's name everywhere.
+ GroupProvisionedAt *time.Time `json:"group_provisioned_at" db:"group_provisioned_at"` // When the group gained its first member and so reached the cluster; nil until then.
}
// Typically store the a paritition information
diff --git a/pkg/service/compute_allocation.go b/pkg/service/compute_allocation.go
index 32b93f734..50d6bf442 100644
--- a/pkg/service/compute_allocation.go
+++ b/pkg/service/compute_allocation.go
@@ -175,6 +175,26 @@ func (s *Service) UpdateComputeAllocation(ctx context.Context, alloc *models.Com
return nil
}
+// MarkComputeAllocationGroupProvisioned stamps group_provisioned_at and publishes the group provision event the first time only.
+func (s *Service) MarkComputeAllocationGroupProvisioned(ctx context.Context, id string) error {
+ if err := s.inTx(ctx, func(tx *sql.Tx) error {
+ now := nowUTC()
+ firstTime, err := s.allocs.MarkGroupProvisioned(ctx, tx, id, now)
+ if err != nil || !firstTime {
+ return err
+ }
+ alloc, err := s.allocs.FindByID(ctx, id)
+ if err != nil || alloc == nil {
+ return err
+ }
+ alloc.GroupProvisionedAt = &now
+ return s.eventBus.Publish(ctx, tx, events.ComputeAllocationGroupProvisionEvent, alloc)
+ }); err != nil {
+ return fmt.Errorf("mark compute allocation group provisioned: %w", err)
+ }
+ return nil
+}
+
// DeleteComputeAllocation removes a compute allocation by ID.
func (s *Service) DeleteComputeAllocation(ctx context.Context, id string) error {
if id == "" {