Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
397 changes: 377 additions & 20 deletions .gen/go/agynio/api/identity/v1/identity.pb.go

Large diffs are not rendered by default.

122 changes: 122 additions & 0 deletions .gen/go/agynio/api/identity/v1/identity_grpc.pb.go

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

5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ RUN --mount=type=cache,target=/go/pkg/mod \
go mod download

COPY buf.gen.yaml buf.yaml ./
RUN buf generate buf.build/agynio/api --path agynio/api/agents/v1 --path agynio/api/authorization/v1
RUN buf generate buf.build/agynio/api \
--path agynio/api/agents/v1 \
--path agynio/api/authorization/v1 \
--path agynio/api/identity/v1

COPY . .

Expand Down
4 changes: 2 additions & 2 deletions devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ functions:
sleep 1; elapsed=$((elapsed + 1))
[ "$elapsed" -ge 120 ] && { echo "ERROR: sync timeout" >&2; exit 1; }
done
buf generate buf.build/agynio/api --path agynio/api/agents/v1 --path agynio/api/authorization/v1
buf generate buf.build/agynio/api --path agynio/api/agents/v1 --path agynio/api/authorization/v1 --path agynio/api/identity/v1
exec go run ./cmd/agents-service
volumeMounts:
- name: data
Expand Down Expand Up @@ -135,7 +135,7 @@ pipelines:
exec_container \
--label-selector "app.kubernetes.io/name=agents-e2e" \
-n ${AGENTS_NAMESPACE} \
-- bash -c 'cd /opt/app/data && buf generate buf.build/agynio/api --path agynio/api/agents/v1 --path agynio/api/authorization/v1 && go test -v -count=1 -tags e2e ./test/e2e/'
-- bash -c 'cd /opt/app/data && buf generate buf.build/agynio/api --path agynio/api/agents/v1 --path agynio/api/authorization/v1 --path agynio/api/identity/v1 && go test -v -count=1 -tags e2e ./test/e2e/'
EXIT_CODE=$?
stop_dev e2e-runner
purge_deployments e2e-runner
Expand Down
6 changes: 5 additions & 1 deletion internal/server/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ func toProtoAgent(agent store.Agent) *agentsv1.Agent {

func toProtoVolume(volume store.Volume) *agentsv1.Volume {
// TODO: Populate OrganizationId once included in Volume response proto.
return &agentsv1.Volume{
protoVolume := &agentsv1.Volume{
Meta: toProtoEntityMeta(volume.Meta),
Persistent: volume.Persistent,
MountPath: volume.MountPath,
Size: volume.Size,
Description: volume.Description,
}
if volume.TTL != nil {
protoVolume.Ttl = volume.TTL
}
return protoVolume
}

func toProtoVolumeAttachment(attachment store.VolumeAttachment) *agentsv1.VolumeAttachment {
Expand Down
52 changes: 52 additions & 0 deletions internal/server/converter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package server

import (
"testing"
"time"

"github.com/agynio/agents/internal/store"
"github.com/google/uuid"
)

func TestToProtoVolumeIncludesTTL(t *testing.T) {
ttl := "24h"
volume := store.Volume{
Meta: store.EntityMeta{
ID: uuid.New(),
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
},
Persistent: true,
MountPath: "/data",
Size: "1Gi",
Description: "volume",
TTL: &ttl,
}

protoVolume := toProtoVolume(volume)
if protoVolume.Ttl == nil {
t.Fatalf("expected ttl to be set")
}
if protoVolume.GetTtl() != ttl {
t.Fatalf("expected ttl %q, got %q", ttl, protoVolume.GetTtl())
}
}

func TestToProtoVolumeOmitsTTLWhenNil(t *testing.T) {
volume := store.Volume{
Meta: store.EntityMeta{
ID: uuid.New(),
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
},
Persistent: true,
MountPath: "/data",
Size: "1Gi",
Description: "volume",
}

protoVolume := toProtoVolume(volume)
if protoVolume.Ttl != nil {
t.Fatalf("expected ttl to be nil")
}
}
7 changes: 6 additions & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func (s *Server) CreateVolume(ctx context.Context, req *agentsv1.CreateVolumeReq
MountPath: req.GetMountPath(),
Size: req.GetSize(),
Description: req.GetDescription(),
TTL: req.Ttl,
})
if err != nil {
return nil, toStatusError(err)
Expand All @@ -257,7 +258,7 @@ func (s *Server) UpdateVolume(ctx context.Context, req *agentsv1.UpdateVolumeReq
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "id: %v", err)
}
if req.Persistent == nil && req.MountPath == nil && req.Size == nil && req.Description == nil {
if req.Persistent == nil && req.MountPath == nil && req.Size == nil && req.Description == nil && req.Ttl == nil {
return nil, status.Error(codes.InvalidArgument, "at least one field must be provided")
}

Expand All @@ -278,6 +279,10 @@ func (s *Server) UpdateVolume(ctx context.Context, req *agentsv1.UpdateVolumeReq
value := req.GetDescription()
update.Description = &value
}
if req.Ttl != nil {
value := req.GetTtl()
update.TTL = &value
}

volume, err := s.store.UpdateVolume(ctx, id, update)
if err != nil {
Expand Down
13 changes: 10 additions & 3 deletions internal/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

const (
agentColumns = `id, organization_id, name, role, model, description, configuration, image, init_image, idle_timeout, resources_requests_cpu, resources_requests_memory, resources_limits_cpu, resources_limits_memory, created_at, updated_at`
volumeColumns = `id, organization_id, persistent, mount_path, size, description, created_at, updated_at`
volumeColumns = `id, organization_id, persistent, mount_path, size, description, ttl, created_at, updated_at`
volumeAttachmentColumns = `id, volume_id, agent_id, mcp_id, hook_id, created_at, updated_at`
imagePullSecretAttachmentColumns = `id, image_pull_secret_id, agent_id, mcp_id, hook_id, created_at, updated_at`
mcpColumns = `id, agent_id, name, image, command, resources_requests_cpu, resources_requests_memory, resources_limits_cpu, resources_limits_memory, description, created_at, updated_at`
Expand Down Expand Up @@ -77,18 +77,21 @@ func scanAgent(row pgx.Row) (Agent, error) {

func scanVolume(row pgx.Row) (Volume, error) {
var volume Volume
var ttl pgtype.Text
if err := row.Scan(
&volume.Meta.ID,
&volume.OrganizationID,
&volume.Persistent,
&volume.MountPath,
&volume.Size,
&volume.Description,
&ttl,
&volume.Meta.CreatedAt,
&volume.Meta.UpdatedAt,
); err != nil {
return Volume{}, err
}
volume.TTL = stringPtrFromPg(ttl)
return volume, nil
}

Expand Down Expand Up @@ -373,14 +376,15 @@ func (s *Store) ListAgents(ctx context.Context, organizationID *uuid.UUID, _ Age

func (s *Store) CreateVolume(ctx context.Context, organizationID uuid.UUID, input VolumeInput) (Volume, error) {
row := s.pool.QueryRow(ctx,
fmt.Sprintf(`INSERT INTO volumes (organization_id, persistent, mount_path, size, description)
VALUES ($1, $2, $3, $4, $5)
fmt.Sprintf(`INSERT INTO volumes (organization_id, persistent, mount_path, size, description, ttl)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING %s`, volumeColumns),
organizationID,
input.Persistent,
input.MountPath,
input.Size,
input.Description,
input.TTL,
)
volume, err := scanVolume(row)
if err != nil {
Expand Down Expand Up @@ -418,6 +422,9 @@ func (s *Store) UpdateVolume(ctx context.Context, id uuid.UUID, update VolumeUpd
if update.Description != nil {
builder.add("description", *update.Description)
}
if update.TTL != nil {
builder.add("ttl", *update.TTL)
}

if builder.empty() {
return Volume{}, fmt.Errorf("volume update requires at least one field")
Expand Down
3 changes: 3 additions & 0 deletions internal/store/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Volume struct {
MountPath string
Size string
Description string
TTL *string
}

type VolumeAttachment struct {
Expand Down Expand Up @@ -135,13 +136,15 @@ type VolumeInput struct {
MountPath string
Size string
Description string
TTL *string
}

type VolumeUpdate struct {
Persistent *bool
MountPath *string
Size *string
Description *string
TTL *string
}

type VolumeAttachmentInput struct {
Expand Down
2 changes: 2 additions & 0 deletions migrations/0010_volume_ttl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE IF EXISTS volumes
ADD COLUMN IF NOT EXISTS ttl TEXT;
Loading
Loading