-
Notifications
You must be signed in to change notification settings - Fork 198
/
main.go
59 lines (48 loc) · 1.41 KB
/
main.go
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
package main
import (
"errors"
"fmt"
"log"
"os"
"github.com/sirupsen/logrus"
helm_v3 "helm.sh/helm/v3/cmd/helm"
"github.com/werf/logboek"
"github.com/werf/nelm/pkg/resrcchangcalc"
"github.com/werf/werf/v2/cmd/werf/common"
"github.com/werf/werf/v2/cmd/werf/root"
"github.com/werf/werf/v2/pkg/process_exterminator"
)
func main() {
ctx := common.GetContextWithLogger()
shouldTerminate, err := common.ContainerBackendProcessStartupHook()
if err != nil {
common.TerminateWithError(err.Error(), 1)
}
if shouldTerminate {
return
}
common.EnableTerminationSignalsTrap()
log.SetOutput(logboek.OutStream())
logrus.StandardLogger().SetOutput(logboek.OutStream())
if err := process_exterminator.Init(); err != nil {
common.TerminateWithError(fmt.Sprintf("process exterminator initialization failed: %s", err), 1)
}
rootCmd, err := root.ConstructRootCmd(ctx)
if err != nil {
common.TerminateWithError(err.Error(), 1)
}
root.SetupTelemetryInit(rootCmd)
if err := rootCmd.Execute(); err != nil {
if helm_v3.IsPluginError(err) {
common.ShutdownTelemetry(ctx, helm_v3.PluginErrorCode(err))
common.TerminateWithError(err.Error(), helm_v3.PluginErrorCode(err))
} else if errors.Is(err, resrcchangcalc.ErrChangesPlanned) {
common.ShutdownTelemetry(ctx, 2)
os.Exit(2)
} else {
common.ShutdownTelemetry(ctx, 1)
common.TerminateWithError(err.Error(), 1)
}
}
common.ShutdownTelemetry(ctx, 0)
}