Skip to content

Commit

Permalink
pull storage obj as best i can
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Lombardi committed Mar 6, 2025
1 parent 9c0c2ad commit 7f62e59
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 177 deletions.
1 change: 1 addition & 0 deletions bin/delete_workers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ echo "Deleting redis keys..."
if kubectl get sts redis-master &> /dev/null; then
replicas=$(kubectl get sts redis-master -o jsonpath='{.spec.replicas}')
for i in $(seq 0 $((replicas-1))); do
kubectl exec redis-master-$i -- bash -c 'for k in $(redis-cli keys workspace:*); do redis-cli -c del $k; done' &
kubectl exec redis-master-$i -- bash -c 'for k in $(redis-cli keys provider:*); do redis-cli -c del $k; done' &
kubectl exec redis-master-$i -- bash -c 'for k in $(redis-cli keys scheduler:worker:worker_index); do redis-cli -c del $k; done' &
kubectl exec redis-master-$i -- bash -c 'for k in $(redis-cli keys scheduler:worker:state:*); do redis-cli -c del $k; done' &
Expand Down
10 changes: 6 additions & 4 deletions pkg/repository/backend_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (r *PostgresBackendRepository) CreateWorkspace(ctx context.Context) (types.
func (r *PostgresBackendRepository) GetWorkspaceByExternalId(ctx context.Context, externalId string) (types.Workspace, error) {
var workspace types.Workspace

query := `SELECT id, name, created_at, concurrency_limit_id, volume_cache_enabled, multi_gpu_enabled FROM workspace WHERE external_id = $1;`
query := `SELECT id, name, created_at, concurrency_limit_id, volume_cache_enabled, multi_gpu_enabled, storage_id FROM workspace WHERE external_id = $1;`
err := r.client.GetContext(ctx, &workspace, query, externalId)
if err != nil {
return types.Workspace{}, err
Expand Down Expand Up @@ -253,7 +253,7 @@ func (r *PostgresBackendRepository) AuthorizeToken(ctx context.Context, tokenKey
query := `
SELECT t.id, t.external_id, t.key, t.created_at, t.updated_at, t.active, t.disabled_by_cluster_admin , t.token_type, t.reusable, t.workspace_id,
w.id "workspace.id", w.name "workspace.name", w.external_id "workspace.external_id", w.signing_key "workspace.signing_key", w.created_at "workspace.created_at",
w.updated_at "workspace.updated_at", w.volume_cache_enabled "workspace.volume_cache_enabled", w.multi_gpu_enabled "workspace.multi_gpu_enabled"
w.updated_at "workspace.updated_at", w.volume_cache_enabled "workspace.volume_cache_enabled", w.multi_gpu_enabled "workspace.multi_gpu_enabled", w.storage_id "workspace.storage_id"
FROM token t
INNER JOIN workspace w ON t.workspace_id = w.id
WHERE t.key = $1 AND t.active = TRUE;
Expand Down Expand Up @@ -861,12 +861,14 @@ func (r *PostgresBackendRepository) GetStubByExternalId(ctx context.Context, ext
var stub types.StubWithRelated
qb := squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar).Select(
`s.id, s.external_id, s.name, s.type, s.config, s.config_version, s.object_id, s.workspace_id, s.created_at, s.updated_at,
w.id AS "workspace.id", w.external_id AS "workspace.external_id", w.name AS "workspace.name", w.created_at AS "workspace.created_at", w.updated_at AS "workspace.updated_at", w.signing_key AS "workspace.signing_key", w.volume_cache_enabled AS "workspace.volume_cache_enabled", w.multi_gpu_enabled AS "workspace.multi_gpu_enabled",
o.id AS "object.id", o.external_id AS "object.external_id", o.hash AS "object.hash", o.size AS "object.size", o.workspace_id AS "object.workspace_id", o.created_at AS "object.created_at"`,
w.id AS "workspace.id", w.external_id AS "workspace.external_id", w.name AS "workspace.name", w.created_at AS "workspace.created_at", w.updated_at AS "workspace.updated_at", w.signing_key AS "workspace.signing_key", w.volume_cache_enabled AS "workspace.volume_cache_enabled", w.multi_gpu_enabled AS "workspace.multi_gpu_enabled", w.storage_id AS "workspace.storage_id",
o.id AS "object.id", o.external_id AS "object.external_id", o.hash AS "object.hash", o.size AS "object.size", o.workspace_id AS "object.workspace_id", o.created_at AS "object.created_at",
ws.id AS "storage.id", ws.external_id AS "storage.external_id", ws.access_key AS "storage.access_key", ws.secret_key AS "storage.secret_key", ws.endpoint_url AS "storage.endpoint_url", ws.region AS "storage.region", ws.created_at AS "storage.created_at", ws.updated_at AS "storage.updated_at"`,
).
From("stub s").
Join("workspace w ON s.workspace_id = w.id").
LeftJoin("object o ON s.object_id = o.id").
LeftJoin("workspace_storage ws ON w.storage_id = ws.id").
Where(squirrel.Eq{"s.external_id": externalId})

var stubFilters types.StubFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func upAddWorkspaceStorage(ctx context.Context, tx *sql.Tx) error {
_, err := tx.Exec(`
CREATE TABLE workspace_storage (
id SERIAL PRIMARY KEY,
external_id TEXT NOT NULL,
bucket_name TEXT NOT NULL,
access_key TEXT NOT NULL,
secret_key TEXT NOT NULL,
Expand Down
12 changes: 10 additions & 2 deletions pkg/types/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Workspace struct {
MultiGpuEnabled bool `db:"multi_gpu_enabled" json:"multi_gpu_enabled"`
ConcurrencyLimitId *uint `db:"concurrency_limit_id" json:"concurrency_limit_id,omitempty"`
ConcurrencyLimit *ConcurrencyLimit `db:"concurrency_limit" json:"concurrency_limit"`
StorageId *uint `db:"storage_id" json:"storage_id,omitempty"`
Storage *WorkspaceStorage `db:"storage" json:"storage"`
}

Expand Down Expand Up @@ -90,6 +91,8 @@ func NewWorkspaceFromProto(in *pb.Workspace) *Workspace {

// @go2proto
type WorkspaceStorage struct {
Id uint `db:"id" json:"id"`
ExternalId string `db:"external_id" json:"external_id"`
BucketName string `db:"bucket_name" json:"bucket_name"`
AccessKey string `db:"access_key" json:"access_key"`
SecretKey string `db:"secret_key" json:"secret_key"`
Expand All @@ -101,6 +104,8 @@ type WorkspaceStorage struct {

func NewWorkspaceStorageFromProto(in *pb.WorkspaceStorage) *WorkspaceStorage {
return &WorkspaceStorage{
Id: uint(in.Id),
ExternalId: in.ExternalId,
BucketName: in.BucketName,
AccessKey: in.AccessKey,
SecretKey: in.SecretKey,
Expand All @@ -113,6 +118,8 @@ func NewWorkspaceStorageFromProto(in *pb.WorkspaceStorage) *WorkspaceStorage {

func (w *WorkspaceStorage) ToProto() *pb.WorkspaceStorage {
return &pb.WorkspaceStorage{
Id: uint32(w.Id),
ExternalId: w.ExternalId,
BucketName: w.BucketName,
AccessKey: w.AccessKey,
SecretKey: w.SecretKey,
Expand Down Expand Up @@ -454,8 +461,9 @@ func NewStubFromProto(in *pb.Stub) *Stub {
// @go2proto
type StubWithRelated struct {
Stub
Workspace Workspace `db:"workspace" json:"workspace"`
Object Object `db:"object" json:"object"`
Workspace Workspace `db:"workspace" json:"workspace"`
Object Object `db:"object" json:"object"`
Storage WorkspaceStorage `db:"storage" json:"storage"`
}

func (s *StubWithRelated) ToProto() *pb.StubWithRelated {
Expand Down
20 changes: 12 additions & 8 deletions pkg/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ message StubWithRelated {
Stub stub = 1;
Workspace workspace = 2;
Object object = 3;
WorkspaceStorage storage = 4;
}

message Worker {
Expand Down Expand Up @@ -171,17 +172,20 @@ message Workspace {
bool multi_gpu_enabled = 8;
uint32 concurrency_limit_id = 9;
ConcurrencyLimit concurrency_limit = 10;
WorkspaceStorage storage = 11;
uint32 storage_id = 11;
WorkspaceStorage storage = 12;
}

message WorkspaceStorage {
string bucket_name = 1;
string access_key = 2;
string secret_key = 3;
string endpoint_url = 4;
string region = 5;
google.protobuf.Timestamp created_at = 6;
google.protobuf.Timestamp updated_at = 7;
uint32 id = 1;
string external_id = 2;
string bucket_name = 3;
string access_key = 4;
string secret_key = 5;
string endpoint_url = 6;
string region = 7;
google.protobuf.Timestamp created_at = 8;
google.protobuf.Timestamp updated_at = 9;
}

message WorkspaceWithRelated {
Expand Down
Loading

0 comments on commit 7f62e59

Please sign in to comment.