forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmd.go
114 lines (93 loc) · 3.38 KB
/
cmd.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
107
108
109
110
111
112
113
114
package openshift_controller_manager
import (
"errors"
"fmt"
"io"
"os"
"github.com/coreos/go-systemd/daemon"
"github.com/golang/glog"
"github.com/spf13/cobra"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
configapilatest "github.com/openshift/origin/pkg/cmd/server/apis/config/latest"
"github.com/openshift/origin/pkg/cmd/server/apis/config/validation"
"github.com/openshift/origin/pkg/cmd/server/origin"
)
const RecommendedStartControllerManagerName = "openshift-controller-manager"
type OpenShiftControllerManager struct {
ConfigFile string
KubeConfigFile string
Output io.Writer
}
var longDescription = templates.LongDesc(`
Start the OpenShift controllers`)
func NewOpenShiftControllerManagerCommand(name, basename string, out, errout io.Writer) *cobra.Command {
options := &OpenShiftControllerManager{Output: out}
cmd := &cobra.Command{
Use: name,
Short: "Start the OpenShift controllers",
Long: longDescription,
Run: func(c *cobra.Command, args []string) {
kcmdutil.CheckErr(options.Validate())
origin.StartProfiler()
if err := options.StartControllerManager(); err != nil {
if kerrors.IsInvalid(err) {
if details := err.(*kerrors.StatusError).ErrStatus.Details; details != nil {
fmt.Fprintf(errout, "Invalid %s %s\n", details.Kind, details.Name)
for _, cause := range details.Causes {
fmt.Fprintf(errout, " %s: %s\n", cause.Field, cause.Message)
}
os.Exit(255)
}
}
glog.Fatal(err)
}
},
}
flags := cmd.Flags()
// This command only supports reading from config
flags.StringVar(&options.ConfigFile, "config", options.ConfigFile, "Location of the master configuration file to run from.")
cmd.MarkFlagFilename("config", "yaml", "yml")
cmd.MarkFlagRequired("config")
flags.StringVar(&options.KubeConfigFile, "kubeconfig", options.KubeConfigFile, "Location of the master configuration file to run from.")
cmd.MarkFlagFilename("kubeconfig", "kubeconfig")
return cmd
}
func (o *OpenShiftControllerManager) Validate() error {
if len(o.ConfigFile) == 0 {
return errors.New("--config is required for this command")
}
return nil
}
// StartAPIServer calls RunAPIServer and then waits forever
func (o *OpenShiftControllerManager) StartControllerManager() error {
if err := o.RunControllerManager(); err != nil {
return err
}
go daemon.SdNotify(false, "READY=1")
select {}
}
// RunAPIServer takes the options and starts the etcd server
func (o *OpenShiftControllerManager) RunControllerManager() error {
masterConfig, err := configapilatest.ReadAndResolveMasterConfig(o.ConfigFile)
if err != nil {
return err
}
validationResults := validation.ValidateMasterConfig(masterConfig, nil)
if len(validationResults.Warnings) != 0 {
for _, warning := range validationResults.Warnings {
glog.Warningf("%v", warning)
}
}
if len(validationResults.Errors) != 0 {
return kerrors.NewInvalid(configapi.Kind("MasterConfig"), "master-config.yaml", validationResults.Errors)
}
config := ConvertMasterConfigToOpenshiftControllerConfig(masterConfig)
clientConfig, err := configapi.GetKubeConfigOrInClusterConfig(o.KubeConfigFile, config.ClientConnectionOverrides)
if err != nil {
return err
}
return RunOpenShiftControllerManager(config, clientConfig)
}