|
| 1 | +package openshift_controller_manager |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "fmt" |
| 6 | + "io" |
| 7 | + "os" |
| 8 | + |
| 9 | + "github.com/coreos/go-systemd/daemon" |
| 10 | + "github.com/golang/glog" |
| 11 | + "github.com/spf13/cobra" |
| 12 | + |
| 13 | + kerrors "k8s.io/apimachinery/pkg/api/errors" |
| 14 | + "k8s.io/kubernetes/pkg/kubectl/cmd/templates" |
| 15 | + kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" |
| 16 | + |
| 17 | + configapilatest "github.com/openshift/origin/pkg/cmd/server/apis/config/latest" |
| 18 | + "github.com/openshift/origin/pkg/cmd/server/origin" |
| 19 | +) |
| 20 | + |
| 21 | +const RecommendedStartControllerManagerName = "openshift-controller-manager" |
| 22 | + |
| 23 | +type OpenShiftControllerManager struct { |
| 24 | + ConfigFile string |
| 25 | + Output io.Writer |
| 26 | +} |
| 27 | + |
| 28 | +var longDescription = templates.LongDesc(` |
| 29 | + Start the OpenShift controllers`) |
| 30 | + |
| 31 | +func NewOpenShiftControllerManagerCommand(name, basename string, out, errout io.Writer) *cobra.Command { |
| 32 | + options := &OpenShiftControllerManager{Output: out} |
| 33 | + |
| 34 | + cmd := &cobra.Command{ |
| 35 | + Use: name, |
| 36 | + Short: "Start the OpenShift controllers", |
| 37 | + Long: longDescription, |
| 38 | + Run: func(c *cobra.Command, args []string) { |
| 39 | + kcmdutil.CheckErr(options.Validate()) |
| 40 | + |
| 41 | + origin.StartProfiler() |
| 42 | + |
| 43 | + if err := options.StartControllerManager(); err != nil { |
| 44 | + if kerrors.IsInvalid(err) { |
| 45 | + if details := err.(*kerrors.StatusError).ErrStatus.Details; details != nil { |
| 46 | + fmt.Fprintf(errout, "Invalid %s %s\n", details.Kind, details.Name) |
| 47 | + for _, cause := range details.Causes { |
| 48 | + fmt.Fprintf(errout, " %s: %s\n", cause.Field, cause.Message) |
| 49 | + } |
| 50 | + os.Exit(255) |
| 51 | + } |
| 52 | + } |
| 53 | + glog.Fatal(err) |
| 54 | + } |
| 55 | + }, |
| 56 | + } |
| 57 | + |
| 58 | + flags := cmd.Flags() |
| 59 | + // This command only supports reading from config |
| 60 | + flags.StringVar(&options.ConfigFile, "config", "", "Location of the master configuration file to run from.") |
| 61 | + cmd.MarkFlagFilename("config", "yaml", "yml") |
| 62 | + cmd.MarkFlagRequired("config") |
| 63 | + |
| 64 | + return cmd |
| 65 | +} |
| 66 | + |
| 67 | +func (o *OpenShiftControllerManager) Validate() error { |
| 68 | + if len(o.ConfigFile) == 0 { |
| 69 | + return errors.New("--config is required for this command") |
| 70 | + } |
| 71 | + |
| 72 | + return nil |
| 73 | +} |
| 74 | + |
| 75 | +// StartAPIServer calls RunAPIServer and then waits forever |
| 76 | +func (o *OpenShiftControllerManager) StartControllerManager() error { |
| 77 | + if err := o.RunControllerManager(); err != nil { |
| 78 | + return err |
| 79 | + } |
| 80 | + |
| 81 | + go daemon.SdNotify(false, "READY=1") |
| 82 | + select {} |
| 83 | +} |
| 84 | + |
| 85 | +// RunAPIServer takes the options and starts the etcd server |
| 86 | +func (o *OpenShiftControllerManager) RunControllerManager() error { |
| 87 | + masterConfig, err := configapilatest.ReadAndResolveMasterConfig(o.ConfigFile) |
| 88 | + if err != nil { |
| 89 | + return err |
| 90 | + } |
| 91 | + |
| 92 | + return RunOpenShiftControllerManager(masterConfig) |
| 93 | +} |
0 commit comments