forked from haproxytech/kubernetes-ingress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
106 lines (91 loc) · 3.24 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2019 HAProxy Technologies LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
c "github.com/haproxytech/kubernetes-ingress/controller"
"github.com/haproxytech/kubernetes-ingress/controller/utils"
"github.com/jessevdk/go-flags"
)
var cfgDir string
func main() {
var osArgs utils.OSArgs
var parser = flags.NewParser(&osArgs, flags.IgnoreUnknown)
_, err := parser.Parse()
exitCode := 0
defer func() {
os.Exit(exitCode)
}()
if err != nil {
fmt.Println(err)
exitCode = 1
return
}
logger := utils.GetLogger()
logger.SetLevel(osArgs.LogLevel.LogLevel)
defaultBackendSvc := fmt.Sprintf("%s/%s", osArgs.DefaultBackendService.Namespace, osArgs.DefaultBackendService.Name)
defaultCertificate := fmt.Sprintf("%s/%s", osArgs.DefaultBackendService.Namespace, osArgs.DefaultCertificate.Name)
c.SetDefaultAnnotation("default-backend-service", defaultBackendSvc)
c.SetDefaultAnnotation("ssl-certificate", defaultCertificate)
c.SetDefaultAnnotation("sync-period", osArgs.SyncPeriod.String())
if len(osArgs.Version) > 0 {
fmt.Printf("HAProxy Ingress Controller %s %s%s\n\n", GitTag, GitCommit, GitDirty)
fmt.Printf("Build from: %s\n", GitRepo)
fmt.Printf("Build date: %s\n\n", BuildTime)
if len(osArgs.Version) > 1 {
fmt.Printf("ConfigMap: %s/%s\n", osArgs.ConfigMap.Namespace, osArgs.ConfigMap.Name)
fmt.Printf("Ingress class: %s\n", osArgs.IngressClass)
}
return
}
if len(osArgs.Help) > 0 && osArgs.Help[0] {
parser.WriteHelp(os.Stdout)
return
}
logger.FileName = false
logger.Print(IngressControllerInfo)
logger.Printf("HAProxy Ingress Controller %s %s%s\n", GitTag, GitCommit, GitDirty)
logger.Printf("Build from: %s", GitRepo)
logger.Printf("Build date: %s\n", BuildTime)
logger.Printf("ConfigMap: %s/%s", osArgs.ConfigMap.Namespace, osArgs.ConfigMap.Name)
logger.Printf("Ingress class: %s", osArgs.IngressClass)
logger.Printf("Publish service: %s", osArgs.PublishService)
logger.Printf("Default backend service: %s", defaultBackendSvc)
logger.Printf("Default ssl certificate: %s", defaultCertificate)
logger.Printf("Controller sync period: %s", osArgs.SyncPeriod.String())
if osArgs.ConfigMapTCPServices.Name != "" {
logger.Printf("TCP Services defined in %s/%s", osArgs.ConfigMapTCPServices.Namespace, osArgs.ConfigMapTCPServices.Name)
}
logger.FileName = true
ctx, cancel := context.WithCancel(context.Background())
signalC := make(chan os.Signal, 1)
signal.Notify(signalC, os.Interrupt, syscall.SIGTERM, syscall.SIGUSR1)
go func() {
<-signalC
cancel()
}()
cfgDir = "/etc/haproxy/"
if osArgs.Test {
setupTestEnv()
}
controller := c.HAProxyController{
HAProxyCfgDir: cfgDir,
Logger: logger,
}
controller.Start(ctx, osArgs)
}