Start implementing a logger
This commit is contained in:
parent
0cb8295df1
commit
bcd62301e3
@ -7,23 +7,30 @@ import (
|
||||
"git.badhouseplants.net/softplayer/softplayer-backend/internal/providers/infra"
|
||||
"git.badhouseplants.net/softplayer/softplayer-backend/internal/providers/kubernetes"
|
||||
proto "git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/environments"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
)
|
||||
|
||||
func NewapiGrpcImpl(controller ctrl.Manager) *EnvironmentsServer {
|
||||
func NewapiGrpcImpl(controller ctrl.Manager, log logr.Logger) *EnvironmentsServer {
|
||||
return &EnvironmentsServer{
|
||||
controller: controller,
|
||||
logInstance: log,
|
||||
}
|
||||
}
|
||||
|
||||
type EnvironmentsServer struct {
|
||||
proto.UnimplementedEnvironmentsServer
|
||||
controller ctrl.Manager
|
||||
logInstance logr.Logger
|
||||
}
|
||||
|
||||
// Create an environment
|
||||
func (e *EnvironmentsServer) Create(ctx context.Context, in *proto.CreateOptions) (*proto.EnvironmentFull, error) {
|
||||
log := e.logInstance
|
||||
log.WithValues("user_id", in.GetOwnerId().GetUuid())
|
||||
ctx = logr.NewContext(ctx, log)
|
||||
|
||||
provider, err := infra.GetProvider(in.GetSpec().GetProvider().String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
6
go.mod
6
go.mod
@ -5,9 +5,12 @@ go 1.22.1
|
||||
require (
|
||||
github.com/alecthomas/assert/v2 v2.8.1
|
||||
github.com/alecthomas/kong v0.9.0
|
||||
github.com/go-logr/logr v1.4.1
|
||||
github.com/go-logr/zapr v1.3.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
go.uber.org/zap v1.27.0
|
||||
golang.org/x/crypto v0.22.0
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
helm.sh/helm/v3 v3.14.4
|
||||
@ -52,7 +55,6 @@ require (
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-errors/errors v1.4.2 // indirect
|
||||
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
|
||||
github.com/go-logr/logr v1.4.1 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
||||
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
||||
@ -122,7 +124,7 @@ require (
|
||||
go.opentelemetry.io/otel/metric v1.19.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.19.0 // indirect
|
||||
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
|
||||
golang.org/x/oauth2 v0.19.0 // indirect
|
||||
golang.org/x/sync v0.7.0 // indirect
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/google/uuid"
|
||||
"github.com/joho/godotenv"
|
||||
|
||||
@ -225,6 +226,11 @@ func (env *Environemnt) Delete(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (env *Environemnt) ListEnvs(ctx context.Context, searchString string) ([]*Environemnt, error) {
|
||||
log, err := logr.FromContext(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Info("Test a new logger")
|
||||
env.Controller.GetClient()
|
||||
conf := &rest.Config{
|
||||
Host: "https://kubernetes.default.svc.cluster.local:443",
|
||||
|
14
main.go
14
main.go
@ -13,6 +13,9 @@ import (
|
||||
email_proto "git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/email"
|
||||
"git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/environments"
|
||||
"github.com/alecthomas/kong"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/go-logr/zapr"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/reflection"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
@ -53,6 +56,15 @@ func server(params Serve) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Init a logger
|
||||
var log logr.Logger
|
||||
|
||||
zapLog, err := zap.NewDevelopment()
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("who watches the watchmen (%v)?", err))
|
||||
}
|
||||
log = zapr.NewLogger(zapLog)
|
||||
|
||||
controller, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{})
|
||||
if err != nil {
|
||||
return err
|
||||
@ -82,7 +94,7 @@ func server(params Serve) error {
|
||||
reflection.Register(grpcServer)
|
||||
}
|
||||
|
||||
environments.RegisterEnvironmentsServer(grpcServer, v1.NewapiGrpcImpl(controller))
|
||||
environments.RegisterEnvironmentsServer(grpcServer, v1.NewapiGrpcImpl(controller, log))
|
||||
accounts.RegisterAccountsServer(grpcServer, v1.NewAccountRPCImpl(controller, params.HashCost))
|
||||
email_proto.RegisterEmailValidationServer(grpcServer, v1.InitEmailServer(controller, &emailConfig, params.DevMode))
|
||||
applications_proto.RegisterApplicationsServer(grpcServer, v1.NewApplicationsGrpcImpl(controller))
|
||||
|
Loading…
Reference in New Issue
Block a user