forked from rancher/backup-restore-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
87 lines (75 loc) · 2.93 KB
/
main.go
File metadata and controls
87 lines (75 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"flag"
"fmt"
"os"
"github.com/rancher/backup-restore-operator/pkg/version"
"github.com/rancher/wrangler/v3/pkg/kubeconfig"
"github.com/rancher/wrangler/v3/pkg/signals"
"github.com/sirupsen/logrus"
"github.com/rancher/backup-restore-operator/pkg/operator"
backuputil "github.com/rancher/backup-restore-operator/pkg/util"
)
const (
LogFormat = "2006/01/02 15:04:05"
)
var (
LocalBackupStorageLocation = "/var/lib/backups" // local within the pod, this is the mountPath for PVC
LocalEncryptionProviderLocation string
KubeConfig string
OperatorPVEnabled string
MetricsServerEnabled string
OperatorS3BackupStorageLocation string
ChartNamespace string
Debug bool
Trace bool
PrintVersion bool
)
func init() {
flag.StringVar(&KubeConfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
flag.BoolVar(&Debug, "debug", false, "Enable debug logging.")
flag.BoolVar(&Trace, "trace", false, "Enable trace logging.")
flag.BoolVar(&PrintVersion, "version", false, "Print version information and exit.")
flag.Parse()
OperatorPVEnabled = os.Getenv("DEFAULT_PERSISTENCE_ENABLED")
OperatorS3BackupStorageLocation = os.Getenv("DEFAULT_S3_BACKUP_STORAGE_LOCATION")
ChartNamespace = os.Getenv("CHART_NAMESPACE")
MetricsServerEnabled = os.Getenv("METRICS_SERVER")
LocalEncryptionProviderLocation = os.Getenv("ENCRYPTION_PROVIDER_LOCATION")
}
func main() {
if PrintVersion {
fmt.Println(version.FmtVersionInfo("backup-restore-operator"))
return
}
logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true, ForceColors: true, TimestampFormat: LogFormat})
if Debug {
logrus.SetLevel(logrus.DebugLevel)
logrus.Debugf("Loglevel set to [%v]", logrus.DebugLevel)
}
if Trace {
logrus.SetLevel(logrus.TraceLevel)
logrus.Tracef("Loglevel set to [%v]", logrus.TraceLevel)
}
logrus.Infof("Starting backup-restore-operator version %s (%s) [built at %s]", version.Version, version.GitCommit, version.Date)
ctx := signals.SetupSignalContext()
restKubeConfig, err := kubeconfig.GetNonInteractiveClientConfig(KubeConfig).ClientConfig()
if err != nil {
logrus.Fatalf("failed to find kubeconfig: %v", err)
}
dm := os.Getenv("CATTLE_DEV_MODE")
backuputil.SetDevMode(dm != "")
runOptions := operator.RunOptions{
OperatorPVCEnabled: OperatorPVEnabled != "",
MetricsServerEnabled: MetricsServerEnabled != "",
MetricsPort: 8080,
MetricsIntervalSeconds: 60,
OperatorS3BackupStorageLocation: OperatorS3BackupStorageLocation,
ChartNamespace: ChartNamespace,
LocalDriverPath: "",
LocalEncryptionProviderLocation: LocalEncryptionProviderLocation,
}
if err := operator.Run(ctx, restKubeConfig, runOptions); err != nil {
logrus.Fatalf("Error running operator: %s", err.Error())
}
}