-
Notifications
You must be signed in to change notification settings - Fork 28
/
app.go
76 lines (61 loc) · 2.03 KB
/
app.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
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package app
import (
"context"
"fmt"
"os"
"github.com/spf13/cobra"
ctrl "sigs.k8s.io/controller-runtime"
"github.com/gardener/test-infra/pkg/testmachinery"
"github.com/gardener/test-infra/pkg/testmachinery/controller"
"github.com/gardener/test-infra/pkg/testmachinery/controller/health"
"github.com/gardener/test-infra/pkg/version"
)
func NewTestMachineryControllerCommand(ctx context.Context) *cobra.Command {
options := NewOptions()
cmd := &cobra.Command{
Use: "testmachinery-controller",
Short: "TestMachinery controller manages the orchestration of test in multiple testruns",
Run: func(cmd *cobra.Command, args []string) {
if err := options.Complete(); err != nil {
fmt.Print(err)
os.Exit(1)
}
options.run(ctx)
},
}
options.AddFlags(cmd.Flags())
return cmd
}
func (o *options) run(ctx context.Context) {
o.log.Info(fmt.Sprintf("start Test Machinery with version %s", version.Get().String()))
fmt.Println(testmachinery.GetConfig().String())
if testmachinery.IsRunInsecure() {
o.log.Info("testmachinery is running in insecure mode")
}
o.log.Info("setting up manager")
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), o.GetManagerOptions())
if err != nil {
o.log.Error(err, "unable to setup manager")
os.Exit(1)
}
mgr.GetClient()
if err := controller.RegisterTestMachineryController(mgr, ctrl.Log, o.configwatcher.GetConfiguration()); err != nil {
o.log.Error(err, "unable to create controller", "controllers", "Testrun")
os.Exit(1)
}
if len(o.configwatcher.GetConfiguration().Controller.HealthAddr) != 0 {
if err := mgr.AddHealthzCheck("default", health.Healthz()); err != nil {
o.log.Error(err, "unable to register default health check")
os.Exit(1)
}
}
o.ApplyWebhooks(ctx, mgr)
o.log.Info("starting the controller", "controllers", "Testrun")
if err := mgr.Start(ctx); err != nil {
o.log.Error(err, "error while running manager")
os.Exit(1)
}
}