2017-02-01 15:41:46 -08:00
|
|
|
/*
|
|
|
|
|
Copyright 2016 The Rook Authors. All rights reserved.
|
|
|
|
|
|
|
|
|
|
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 (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2017-12-04 08:33:19 -08:00
|
|
|
"github.com/rook/rook/pkg/daemon/api"
|
|
|
|
|
"github.com/rook/rook/pkg/daemon/ceph/mon"
|
2017-12-13 10:12:09 -08:00
|
|
|
"github.com/rook/rook/pkg/operator/k8sutil"
|
2017-02-01 15:41:46 -08:00
|
|
|
"github.com/rook/rook/pkg/util/flags"
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
)
|
|
|
|
|
|
2017-04-12 11:36:26 -07:00
|
|
|
var (
|
|
|
|
|
apiCmd = &cobra.Command{
|
|
|
|
|
Use: "api",
|
|
|
|
|
Short: "Runs the Rook API service",
|
|
|
|
|
}
|
2017-09-09 17:33:28 +02:00
|
|
|
apiPort int
|
|
|
|
|
repoPrefix string
|
|
|
|
|
namespace string
|
|
|
|
|
hostNetwork bool
|
2017-04-12 11:36:26 -07:00
|
|
|
)
|
2017-02-01 15:41:46 -08:00
|
|
|
|
|
|
|
|
func init() {
|
2017-03-30 12:45:11 -07:00
|
|
|
apiCmd.Flags().IntVar(&apiPort, "port", 0, "port on which the api is listening")
|
2017-04-12 11:36:26 -07:00
|
|
|
apiCmd.Flags().StringVar(&namespace, "namespace", "", "the namespace in which the api service is running")
|
2017-09-09 17:33:28 +02:00
|
|
|
apiCmd.Flags().BoolVar(&hostNetwork, "hostnetwork", false, "if the hostnetwork should be used")
|
2017-03-30 12:45:11 -07:00
|
|
|
addCephFlags(apiCmd)
|
2017-02-01 15:41:46 -08:00
|
|
|
|
2017-08-23 22:20:14 -07:00
|
|
|
flags.SetFlagsFromEnv(apiCmd.Flags(), RookEnvVarPrefix)
|
2017-02-01 15:41:46 -08:00
|
|
|
|
2017-02-07 08:38:36 -08:00
|
|
|
apiCmd.RunE = startAPI
|
2017-02-01 15:41:46 -08:00
|
|
|
}
|
|
|
|
|
|
2017-02-07 08:38:36 -08:00
|
|
|
func startAPI(cmd *cobra.Command, args []string) error {
|
2017-12-13 10:12:09 -08:00
|
|
|
required := []string{"namespace", "config-dir", "cluster-name", "mon-endpoints", "mon-secret", "admin-secret", "public-ipv4", "private-ipv4"}
|
2017-08-01 22:33:00 -07:00
|
|
|
if err := flags.VerifyRequiredFlags(apiCmd, required); err != nil {
|
2017-02-01 15:41:46 -08:00
|
|
|
return err
|
|
|
|
|
}
|
2017-02-07 08:38:36 -08:00
|
|
|
if apiPort == 0 {
|
2017-03-30 12:45:11 -07:00
|
|
|
return fmt.Errorf("port is required")
|
2017-02-01 15:41:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setLogLevel()
|
|
|
|
|
|
2017-08-23 22:20:14 -07:00
|
|
|
logStartupInfo(apiCmd.Flags())
|
|
|
|
|
|
2017-12-04 08:37:39 -08:00
|
|
|
clientset, _, rookClientset, err := getClientset()
|
2017-02-01 15:41:46 -08:00
|
|
|
if err != nil {
|
2017-10-31 17:00:04 -07:00
|
|
|
terminateFatal(fmt.Errorf("failed to init k8s client. %+v\n", err))
|
2017-02-01 15:41:46 -08:00
|
|
|
}
|
|
|
|
|
|
2017-12-13 10:12:09 -08:00
|
|
|
// Using the rook-operator image to deploy other rook pods
|
|
|
|
|
rookImage, err := k8sutil.GetContainerImage(clientset)
|
|
|
|
|
if err != nil {
|
|
|
|
|
terminateFatal(fmt.Errorf("failed to get container image. %+v\n", err))
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-13 15:35:56 -07:00
|
|
|
clusterInfo.Monitors = mon.ParseMonEndpoints(cfg.monEndpoints)
|
2017-06-14 14:24:31 -07:00
|
|
|
context := createContext()
|
2017-06-02 13:44:54 -07:00
|
|
|
context.Clientset = clientset
|
2017-12-04 08:37:39 -08:00
|
|
|
context.RookClientset = rookClientset
|
2017-12-13 10:12:09 -08:00
|
|
|
c := api.NewConfig(context, apiPort, &clusterInfo, namespace, rookImage, hostNetwork)
|
2017-02-01 15:41:46 -08:00
|
|
|
|
2017-10-05 10:00:19 -07:00
|
|
|
err = api.Run(context, c)
|
2017-06-02 13:44:54 -07:00
|
|
|
if err != nil {
|
2017-10-31 17:00:04 -07:00
|
|
|
terminateFatal(err)
|
2017-06-02 13:44:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
2017-02-01 15:41:46 -08:00
|
|
|
}
|