Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.
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
7 changes: 3 additions & 4 deletions cmd/rig/cmd/capsule/configure_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package capsule
import (
"context"
"encoding/json"
"log"
"os"

"github.com/bufbuild/connect-go"
Expand Down Expand Up @@ -32,16 +31,16 @@ func CapsuleConfigureNetwork(ctx context.Context, cmd *cobra.Command, args []str

var raw interface{}
if err := yaml.Unmarshal(bs, &raw); err != nil {
log.Fatal(err)
return err
}

if bs, err = json.Marshal(raw); err != nil {
log.Fatal(err)
return err
}

n := &capsule.Network{}
if err := protojson.Unmarshal(bs, n); err != nil {
log.Fatal(err)
return err
}

cmd.Println(n.GetInterfaces()[0])
Expand Down
28 changes: 28 additions & 0 deletions cmd/rig/cmd/cluster/getconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cluster

import (
"context"
"fmt"

"github.com/bufbuild/connect-go"
"github.com/rigdev/rig-go-api/api/v1/cluster"
"github.com/rigdev/rig-go-sdk"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
)

func GetConfig(ctx context.Context, cmd *cobra.Command, client rig.Client) error {
resp, err := client.Cluster().GetConfig(ctx, connect.NewRequest(&cluster.GetConfigRequest{}))
if err != nil {
return err
}
config := resp.Msg
bytes, err := yaml.Marshal(config)
if err != nil {
return err
}

fmt.Println(string(bytes))

return nil
}
22 changes: 22 additions & 0 deletions cmd/rig/cmd/cluster/setup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cluster

import (
"github.com/rigdev/rig/cmd/rig/cmd/base"
"github.com/spf13/cobra"
)

func Setup(parent *cobra.Command) {
cluster := &cobra.Command{
Use: "cluster",
}

getConfig := &cobra.Command{
Use: "get-config",
Short: "Returns the config of the Rig cluster",
Args: cobra.NoArgs,
RunE: base.Register(GetConfig),
}

cluster.AddCommand(getConfig)
parent.AddCommand(cluster)
}
2 changes: 2 additions & 0 deletions cmd/rig/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/rigdev/rig/cmd/rig/cmd/auth"
"github.com/rigdev/rig/cmd/rig/cmd/capsule"
"github.com/rigdev/rig/cmd/rig/cmd/cluster"
"github.com/rigdev/rig/cmd/rig/cmd/config"
"github.com/rigdev/rig/cmd/rig/cmd/database"
"github.com/rigdev/rig/cmd/rig/cmd/group"
Expand Down Expand Up @@ -33,6 +34,7 @@ func Execute() error {
group.Setup(rootCmd)
project.Setup(rootCmd)
config.Setup(rootCmd)
cluster.Setup(rootCmd)
rootCmd.AddCommand(build.VersionCommand())
return rootCmd.Execute()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ require (
github.com/google/go-containerregistry v0.16.1
github.com/jedib0t/go-pretty/v6 v6.4.6
github.com/rigdev/rig-go-api v0.0.0-20230918113547-85aa906e5160
github.com/rigdev/rig-go-sdk v0.0.0-20230902170251-18fbb97d0692
github.com/rigdev/rig-go-sdk v0.0.0-20230918110956-2301fcd9da11
k8s.io/metrics v0.28.0
sigs.k8s.io/controller-runtime v0.16.1
)
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ github.com/go-jose/go-jose/v3 v3.0.0/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxF
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down Expand Up @@ -303,6 +304,7 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/s2a-go v0.1.3 h1:FAgZmpLl/SXurPEZyCMPBIiiYeTbqfjlbdnCNTAkbGE=
github.com/google/s2a-go v0.1.3/go.mod h1:Ej+mSEMGRnqRzjc7VtF+jdBwYG5fuJfiZ8ELkjEwM0A=
Expand Down Expand Up @@ -342,13 +344,15 @@ github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHW
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand Down Expand Up @@ -429,6 +433,7 @@ github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1n
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9 h1:62uLwA3l2JMH84liO4ZhnjTH5PjFyCYxbHLgXPaJMtI=
github.com/mwitkow/grpc-proxy v0.0.0-20230212185441-f345521cb9c9/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
Expand Down Expand Up @@ -477,6 +482,8 @@ github.com/rigdev/rig-go-api v0.0.0-20230918113547-85aa906e5160 h1:kZS2rFkckK3Cs
github.com/rigdev/rig-go-api v0.0.0-20230918113547-85aa906e5160/go.mod h1:fraLUk9ekeQvvu5bOmUmpNAsBqG2QzqWU9wzGbPwB/w=
github.com/rigdev/rig-go-sdk v0.0.0-20230902170251-18fbb97d0692 h1:9K+F3uKbXaTC5iR6sy6tBodlmQVp8g+tB3o0hcWKtck=
github.com/rigdev/rig-go-sdk v0.0.0-20230902170251-18fbb97d0692/go.mod h1:mC8jVtKLH3RusvgTaHSn3lJTyaVdgsSizn8Sjb5xaoM=
github.com/rigdev/rig-go-sdk v0.0.0-20230918110956-2301fcd9da11 h1:cdW4OYPgzr+iMzsqPCLDTRa37rpTRD2OUxhbPApzHss=
github.com/rigdev/rig-go-sdk v0.0.0-20230918110956-2301fcd9da11/go.mod h1:CtN3BUZJfONEGNuVnoewrKHGSHF/XS5OsHxzkA9ToI4=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
Expand Down
1 change: 0 additions & 1 deletion internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ type Cluster struct {
type DevRegistry struct {
Host string `mapstructure:"host"`
ClusterHost string `mapstructure:"cluster_host"`
Size uint64 `mapstructure:"size"`
}

type ClusterType string
Expand Down
39 changes: 39 additions & 0 deletions internal/handler/api/cluster/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cluster

import (
"context"
"net/http"

connect "github.com/bufbuild/connect-go"
cluster_api "github.com/rigdev/rig-go-api/api/v1/cluster"
"github.com/rigdev/rig-go-api/api/v1/cluster/clusterconnect"
"github.com/rigdev/rig/internal/service/cluster"
)

type Handler struct {
cluster *cluster.Service
}

// New returns an impementation of the proto cluster.Service interface.
func New(cluster *cluster.Service) *Handler {
return &Handler{
cluster: cluster,
}
}

func (h *Handler) ServiceName() string {
return clusterconnect.ServiceName
}

func (h *Handler) Build(opts ...connect.HandlerOption) (string, http.Handler) {
return clusterconnect.NewServiceHandler(h, opts...)
}

func (h *Handler) GetConfig(ctx context.Context, req *connect.Request[cluster_api.GetConfigRequest]) (*connect.Response[cluster_api.GetConfigResponse], error) {
resp, err := h.cluster.GetConfig(ctx, req.Msg)
if err != nil {
return nil, err
}

return connect.NewResponse(resp), nil
}
12 changes: 7 additions & 5 deletions internal/handler/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"github.com/rigdev/rig/internal/handler/api/authentication"
"github.com/rigdev/rig/internal/handler/api/capsule"
"github.com/rigdev/rig/internal/handler/api/cluster"
"github.com/rigdev/rig/internal/handler/api/database"
"github.com/rigdev/rig/internal/handler/api/group"
"github.com/rigdev/rig/internal/handler/api/project"
Expand All @@ -22,16 +23,17 @@ import (
var Module = fx.Module(
"handler",
fx.Provide(
asGRPCHandler(user.New),
asGRPCHandler(authentication.New),
asGRPCHandler(capsule.New),
asGRPCHandler(cluster.New),
asGRPCHandler(database.New),
asGRPCHandler(group.New),
asGRPCHandler(project.New),
asGRPCHandler(capsule.New),
asGRPCHandler(authentication.New),
asGRPCHandler(project_settings.New),
asGRPCHandler(service_account.New),
asGRPCHandler(storage.New),
asGRPCHandler(database.New),
asGRPCHandler(user.New),
asGRPCHandler(user_settings.New),
asGRPCHandler(project_settings.New),
asHTTPHandler(http.New),
asHTTPHandler(storage_http.NewUploadHandler),
asHTTPHandler(storage_http.NewDownloadHandler),
Expand Down
62 changes: 62 additions & 0 deletions internal/service/cluster/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cluster

import (
"context"

"github.com/rigdev/rig-go-api/api/v1/cluster"
"github.com/rigdev/rig/internal/config"
"go.uber.org/zap"
)

type Service struct {
logger *zap.Logger
cfg config.Config
}

func NewService(cfg config.Config, logger *zap.Logger) *Service {
s := &Service{
cfg: cfg,
logger: logger,
}

return s
}

func (s *Service) GetConfig(ctx context.Context, req *cluster.GetConfigRequest) (*cluster.GetConfigResponse, error) {
resp := &cluster.GetConfigResponse{
ClusterType: typeToProto(s.cfg.Cluster.Type),
}
s.setDevRegistry(resp)
return resp, nil
}

func typeToProto(c config.ClusterType) cluster.ClusterType {
switch c {
case config.ClusterTypeDocker:
return cluster.ClusterType_CLUSTER_TYPE_DOCKER
case config.ClusterTypeKubernetes:
return cluster.ClusterType_CLUSTER_TYPE_KUBERNETES
default:
return cluster.ClusterType_CLUSTER_TYPE_UNSPECIFIED
}
}

func (s *Service) setDevRegistry(resp *cluster.GetConfigResponse) {
if s.cfg.Cluster.Type == config.ClusterTypeDocker {
resp.DevRegistry = &cluster.GetConfigResponse_Docker{
Docker: &cluster.DockerDaemon{},
}
return
}

registry := s.cfg.Cluster.DevRegistry
if registry.Host == "" {
return
}

resp.DevRegistry = &cluster.GetConfigResponse_Registry{
Registry: &cluster.Registry{
Host: registry.Host,
},
}
}
2 changes: 2 additions & 0 deletions internal/service/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"github.com/rigdev/rig/internal/service/auth"
"github.com/rigdev/rig/internal/service/capsule"
"github.com/rigdev/rig/internal/service/cluster"
"github.com/rigdev/rig/internal/service/database"
"github.com/rigdev/rig/internal/service/group"
"github.com/rigdev/rig/internal/service/metrics"
Expand All @@ -25,5 +26,6 @@ var Module = fx.Module(
storage.NewService,
metrics.NewService,
operator.New,
cluster.NewService,
),
)