[garden-op] Enable setting of log level
@@ -3,7 +3,9 @@ package main
import (
"context"
"github.com/sap/infrabox/src/services/garden/pkg/stub/shootOperations/common/operatorSdk"
+ "os"
"runtime"
+ "strings"
"github.com/operator-framework/operator-sdk/pkg/sdk"
"github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
@@ -19,35 +21,30 @@ func printVersion() {
logrus.Infof("operator-sdk Version: %v", sdkVersion.Version)
}
+const ENVLogLevel = "LOGLVL"
+
+func setLogLvl() {
+ logrus.SetLevel(logrus.WarnLevel)
+ lvl := os.Getenv(ENVLogLevel)
+
+ lvl = strings.ToLower(lvl)
+
+ switch lvl {
+ case "debug":
+ logrus.SetLevel(logrus.DebugLevel)
+ case "info":
+ logrus.SetLevel(logrus.InfoLevel)
+ case "warn":
+ logrus.SetLevel(logrus.WarnLevel)
+ case "error":
+ logrus.SetLevel(logrus.ErrorLevel)
+ }
+}
+
func main() {
+ setLogLvl()
printVersion()
- //gcpserviceaccount := "/var/run/infrabox.net/gcp/service_account.json"
- //
- //logrus.Info("Activating GCP service account")
- //authCmd := exec.Command("gcloud", "auth", "activate-service-account", "--key-file", gcpserviceaccount)
- //authOut, err := authCmd.CombinedOutput()
- //if err != nil {
- // logrus.Fatalf(string(authOut))
- //}
- //
- //logrus.Info("Setting GCP Project")
- //raw, err := ioutil.ReadFile(gcpserviceaccount)
- //
- //if err != nil {
- // logrus.Fatalf(err.Error())
- //}
- //
- //var sa map[string]interface{}
- //json.Unmarshal(raw, &sa)
- //
- //projectId := sa["project_id"].(string)
- //authCmd = exec.Command("gcloud", "config", "set", "core/project", projectId)
- //authOut, err = authCmd.CombinedOutput()
- //if err != nil {
- // logrus.Fatalf(string(authOut))
- //}
-
resource := "garden.service.infrabox.net/v1alpha1"
kind := "ShootCluster"
namespace, err := k8sutil.GetWatchNamespace()
@@ -56,6 +53,7 @@ func main() {
}
resyncPeriod := 5
logrus.Infof("Watching %s, %s, %s, %d", resource, kind, namespace, resyncPeriod)
+
sdk.Watch(resource, kind, namespace, resyncPeriod)
sdk.Handle(stub.NewHandler(&operatorSdk.Operations{}))
sdk.Run(context.TODO())
