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
37 changes: 18 additions & 19 deletions admin/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"regexp"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -272,11 +271,11 @@ func (s *Service) StartDeploymentInner(ctx context.Context, depl *database.Deplo
return err
}

duckdbConfig, err := structpb.NewStruct(map[string]any{
"cpu": strconv.Itoa(cfg.CPU),
"memory_limit_gb": strconv.Itoa(cfg.MemoryGB),
"storage_limit_bytes": strconv.FormatInt(cfg.StorageBytes, 10),
})
duckdbConfig, err := cfg.DuckdbConfig().AsMap()
if err != nil {
return err
}
duckdbConfigPb, err := structpb.NewStruct(duckdbConfig)
if err != nil {
return err
}
Expand All @@ -291,7 +290,7 @@ func (s *Service) StartDeploymentInner(ctx context.Context, depl *database.Deplo
{
Name: "duckdb",
Type: "duckdb",
Config: duckdbConfig,
Config: duckdbConfigPb,
},
}

Expand Down Expand Up @@ -395,7 +394,7 @@ func (s *Service) UpdateDeploymentInner(ctx context.Context, d *database.Deploym
}

// Find the runtime provisioned for this deployment
pr, ok, err := s.findProvisionedRuntimeResource(ctx, d.ID)
pr, ok, err := s.FindProvisionedRuntimeResource(ctx, d.ID)
if err != nil {
return err
}
Expand Down Expand Up @@ -557,6 +556,17 @@ func (s *Service) NewDeploymentAnnotations(org *database.Organization, proj *dat
}
}

func (s *Service) FindProvisionedRuntimeResource(ctx context.Context, deploymentID string) (*database.ProvisionerResource, bool, error) {
pr, err := s.DB.FindProvisionerResourceByTypeAndName(ctx, deploymentID, string(provisioner.ResourceTypeRuntime), "")
if err != nil {
if errors.Is(err, database.ErrNotFound) {
return nil, false, nil
}
return nil, false, err
}
return pr, true, nil
}

type DeploymentAnnotations struct {
orgID string
orgName string
Expand Down Expand Up @@ -638,17 +648,6 @@ func (s *Service) provisionRuntime(ctx context.Context, opts *provisionRuntimeOp
return pr, nil
}

func (s *Service) findProvisionedRuntimeResource(ctx context.Context, deploymentID string) (*database.ProvisionerResource, bool, error) {
pr, err := s.DB.FindProvisionerResourceByTypeAndName(ctx, deploymentID, string(provisioner.ResourceTypeRuntime), "")
if err != nil {
if errors.Is(err, database.ErrNotFound) {
return nil, false, nil
}
return nil, false, err
}
return pr, true, nil
}

func (s *Service) resolveRillVersion() string {
if s.Version.Number != "" {
return s.Version.Number
Expand Down
24 changes: 24 additions & 0 deletions admin/provisioner/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provisioner

import (
"fmt"
"strconv"

"github.com/mitchellh/mapstructure"
)
Expand Down Expand Up @@ -77,6 +78,29 @@ func (r *RuntimeConfig) AsMap() map[string]any {
return res
}

func (r *RuntimeConfig) DuckdbConfig() *DuckdbConfig {
return &DuckdbConfig{
CPU: strconv.Itoa(r.CPU),
MemoryGB: strconv.Itoa(r.MemoryGB),
StorageBytes: strconv.FormatInt(r.StorageBytes, 10),
}
}

type DuckdbConfig struct {
CPU string `mapstructure:"cpu"`
MemoryGB string `mapstructure:"memory_limit_gb"`
StorageBytes string `mapstructure:"storage_limit_bytes"`
}

func (r *DuckdbConfig) AsMap() (map[string]any, error) {
res := make(map[string]any)
err := mapstructure.WeakDecode(r, &res)
if err != nil {
return nil, err
}
return res, nil
}

// ClickhouseConfig describes the expected config for a provisioned Clickhouse resource.
type ClickhouseConfig struct {
DSN string `mapstructure:"dsn"`
Expand Down
26 changes: 26 additions & 0 deletions admin/server/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/rilldata/rill/admin"
"github.com/rilldata/rill/admin/database"
"github.com/rilldata/rill/admin/provisioner"
"github.com/rilldata/rill/admin/server/auth"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
runtimev1 "github.com/rilldata/rill/proto/gen/rill/runtime/v1"
Expand All @@ -21,6 +22,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
)

Expand Down Expand Up @@ -856,6 +858,15 @@ func (s *Server) GetDeploymentConfig(ctx context.Context, req *adminv1.GetDeploy
return nil, err
}

// Find the runtime provisioned for this deployment
pr, ok, err := s.admin.FindProvisionedRuntimeResource(ctx, depl.ID)
if err != nil {
return nil, err
}
if !ok {
return nil, status.Errorf(codes.Internal, "can't update deployment %q because its runtime has not been initialized yet", depl.ID)
}

org, err := s.admin.DB.FindOrganization(ctx, proj.OrganizationID)
if err != nil {
return nil, err
Expand All @@ -882,6 +893,21 @@ func (s *Server) GetDeploymentConfig(ctx context.Context, req *adminv1.GetDeploy
}
resp.Variables = vars

// parsing duckdb connector config
rCfg, err := provisioner.NewRuntimeConfig(pr.Config)
if err != nil {
return nil, status.Errorf(codes.Internal, "invalid runtime config: %v", err)
}
configStruct, err := rCfg.DuckdbConfig().AsMap()
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to decode DuckDB connector config: %v", err)
}
configStructPb, err := structpb.NewStruct(configStruct)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to encode DuckDB connector config: %v", err)
}
resp.DuckdbConnectorConfig = configStructPb

annotations := s.admin.NewDeploymentAnnotations(org, proj)
resp.Annotations = annotations.ToMap()

Expand Down
3 changes: 3 additions & 0 deletions proto/gen/rill/admin/v1/admin.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5090,6 +5090,9 @@ definitions:
usesArchive:
type: boolean
description: Whether the deployment is git based or archive based.
duckdbConnectorConfig:
type: object
title: Duckdb connector config for the deployment
v1GetDeploymentCredentialsResponse:
type: object
properties:
Expand Down
Loading
Loading