Skip to content

Commit

Permalink
Run components in separate goroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
szwedm committed May 7, 2024
1 parent 21d3779 commit 8b34bc2
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ package main

import (
"flag"
"log/slog"
"os"

//test

clusterobject "github.com/kyma-project/btp-manager/internal/cluster-object"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
"sigs.k8s.io/controller-runtime/pkg/client"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand Down Expand Up @@ -117,9 +120,40 @@ func main() {
os.Exit(1)
}

setupLog.Info("starting manager")
if err := mgr.Start(signalContext); err != nil {
setupLog.Error(err, "problem running manager")
// run manager with reconciler
go func() {
setupLog.Info("starting manager")
if err := mgr.Start(signalContext); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}()

k8sClient, err := client.New(restCfg, client.Options{})
if err != nil {
setupLog.Error(err, "unable to create k8s client")
os.Exit(1)
}
slogger := slog.Default()
namespaceProvider := clusterobject.NewNamespaceProvider(k8sClient, slogger)
serviceInstanceProvider := clusterobject.NewServiceInstanceProvider(k8sClient, slogger)
secretProvider := clusterobject.NewSecretProvider(k8sClient, namespaceProvider, serviceInstanceProvider, slogger)

// run SM client
go func() {
setupLog.Info("starting SM client")
secrets, err := secretProvider.All(signalContext)
if err != nil {
ctrl.Log.Error(err, "failed to fetch all secrets")
os.Exit(1)
}
for _, secret := range secrets.Items {
ctrl.Log.Info("secret", "name", secret.Name, "namespace", secret.Namespace)
}
}()

select {
case <-signalContext.Done():
setupLog.Info("shutting down btp-manager")
}
}

0 comments on commit 8b34bc2

Please sign in to comment.