Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
fix(go-utils): Pass logger implementation from go-sdk to cp-connector (
Browse files Browse the repository at this point in the history
…#494)

Signed-off-by: warber <[email protected]>
  • Loading branch information
warber authored Jul 4, 2022
1 parent 9b0c779 commit 29e14a0
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions pkg/sdk/keptn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"context"
eventsource "github.com/keptn/go-utils/pkg/sdk/connector/eventsource/nats"
"github.com/keptn/go-utils/pkg/sdk/connector/logforwarder"
"github.com/keptn/go-utils/pkg/sdk/connector/logger"
"github.com/keptn/go-utils/pkg/sdk/connector/subscriptionsource"
"github.com/keptn/go-utils/pkg/sdk/connector/types"
sdk "github.com/keptn/go-utils/pkg/sdk/internal/api"
"github.com/keptn/go-utils/pkg/sdk/internal/config"
logger "github.com/sirupsen/logrus"
"log"
"os"
"os/signal"
"strings"
Expand Down Expand Up @@ -152,28 +151,21 @@ type Keptn struct {

// NewKeptn creates a new Keptn
func NewKeptn(source string, opts ...KeptnOption) *Keptn {
env := config.NewEnvConfig()
apiSet, controlPlane, eventSender := newControlPlaneFromEnv()
resourceHandler := newResourceHandlerFromEnv()
taskRegistry := newTaskMap()
logger := newDefaultLogger()
keptn := &Keptn{
controlPlane: controlPlane,
eventSender: eventSender,
source: source,
taskRegistry: taskRegistry,
resourceHandler: resourceHandler,
api: apiSet,
taskRegistry: newTaskMap(),
automaticEventResponse: true,
gracefulShutdown: true,
syncProcessing: false,
logger: logger,
env: env,
logger: newDefaultLogger(),
env: config.NewEnvConfig(),
healthEndpointRunner: newHealthEndpointRunner,
}
for _, opt := range opts {
opt(keptn)
}
keptn.api, keptn.controlPlane, keptn.eventSender = newControlPlaneFromEnv(keptn.logger)
keptn.resourceHandler = newResourceHandlerFromEnv(keptn.logger)
return keptn
}

Expand Down Expand Up @@ -377,35 +369,35 @@ func newHealthEndpointRunner(port string, cp *controlplane.ControlPlane) {
}()
}

func newResourceHandlerFromEnv() *api.ResourceHandler {
func newResourceHandlerFromEnv(logger logger.Logger) *api.ResourceHandler {
var env config.EnvConfig
if err := envconfig.Process("", &env); err != nil {
log.Fatalf("failed to process env var: %s", err)
logger.Fatalf("failed to process env var: %s", err)
}
return api.NewResourceHandler(env.ConfigurationServiceURL)
}

func newControlPlaneFromEnv() (api.KeptnInterface, *controlplane.ControlPlane, controlplane.EventSender) {
func newControlPlaneFromEnv(logger logger.Logger) (api.KeptnInterface, *controlplane.ControlPlane, controlplane.EventSender) {
var env config.EnvConfig
if err := envconfig.Process("", &env); err != nil {
log.Fatalf("failed to process env var: %s", err)
logger.Fatalf("failed to process env var: %s", err)
}

httpClient, err := sdk.CreateClientGetter(env).Get()
if err != nil {
logger.WithError(err).Fatal("Could not initialize http client.")
logger.Fatal("Could not initialize http client.", err)
}

apiSet, err := sdk.CreateKeptnAPI(httpClient, env)
if err != nil {
log.Fatal(err)
logger.Fatal(err)
}

natsConnector := nats.New(env.EventBrokerURL)
eventSource := eventsource.New(natsConnector)
natsConnector := nats.New(env.EventBrokerURL, nats.WithLogger(logger))
eventSource := eventsource.New(natsConnector, eventsource.WithLogger(logger))
eventSender := eventSource.Sender()
subscriptionSource := subscriptionsource.New(apiSet.UniformV1())
logForwarder := logforwarder.New(apiSet.LogsV1())
controlPlane := controlplane.New(subscriptionSource, eventSource, logForwarder)
subscriptionSource := subscriptionsource.New(apiSet.UniformV1(), subscriptionsource.WithLogger(logger))
logForwarder := logforwarder.New(apiSet.LogsV1(), logforwarder.WithLogger(logger))
controlPlane := controlplane.New(subscriptionSource, eventSource, logForwarder, controlplane.WithLogger(logger))
return apiSet, controlPlane, eventSender
}

0 comments on commit 29e14a0

Please sign in to comment.