2018-03-05 09:00:23 +00:00
|
|
|
//
|
|
|
|
// DISCLAIMER
|
|
|
|
//
|
2020-03-04 10:25:14 +00:00
|
|
|
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
|
2018-03-05 09:00:23 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
|
|
|
//
|
|
|
|
// Author Ewout Prangsma
|
|
|
|
//
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-03-06 09:54:12 +00:00
|
|
|
"net"
|
2018-03-05 09:00:23 +00:00
|
|
|
"os"
|
2018-03-06 09:54:12 +00:00
|
|
|
"strconv"
|
2018-03-05 09:00:23 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2018-03-13 15:25:33 +00:00
|
|
|
"github.com/arangodb/kube-arangodb/pkg/logging"
|
|
|
|
"github.com/arangodb/kube-arangodb/pkg/storage/provisioner"
|
|
|
|
"github.com/arangodb/kube-arangodb/pkg/storage/provisioner/service"
|
|
|
|
"github.com/arangodb/kube-arangodb/pkg/util/constants"
|
2018-03-05 10:06:53 +00:00
|
|
|
)
|
|
|
|
|
2018-03-05 09:00:23 +00:00
|
|
|
var (
|
|
|
|
cmdStorage = &cobra.Command{
|
|
|
|
Use: "storage",
|
|
|
|
Run: cmdUsage,
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdStorageProvisioner = &cobra.Command{
|
|
|
|
Use: "provisioner",
|
|
|
|
Run: cmdStorageProvisionerRun,
|
|
|
|
}
|
|
|
|
|
|
|
|
storageProvisioner struct {
|
2018-03-06 09:54:12 +00:00
|
|
|
port int
|
2018-03-05 09:00:23 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmdMain.AddCommand(cmdStorage)
|
|
|
|
cmdStorage.AddCommand(cmdStorageProvisioner)
|
|
|
|
|
|
|
|
f := cmdStorageProvisioner.Flags()
|
2018-03-06 09:54:12 +00:00
|
|
|
f.IntVar(&storageProvisioner.port, "port", provisioner.DefaultPort, "Port to listen on")
|
2018-03-05 09:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run the provisioner
|
|
|
|
func cmdStorageProvisionerRun(cmd *cobra.Command, args []string) {
|
2018-03-06 09:54:12 +00:00
|
|
|
//goflag.CommandLine.Parse([]string{"-logtostderr"})
|
2018-03-05 09:00:23 +00:00
|
|
|
var err error
|
2020-11-23 07:58:40 +00:00
|
|
|
logService, err = logging.NewService(defaultLogLevel, logLevels)
|
2018-03-05 09:00:23 +00:00
|
|
|
if err != nil {
|
|
|
|
cliLog.Fatal().Err(err).Msg("Failed to initialize log service")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Log version
|
|
|
|
cliLog.Info().Msgf("Starting arangodb local storage provisioner, version %s build %s", projectVersion, projectBuild)
|
|
|
|
|
|
|
|
// Get environment
|
|
|
|
nodeName := os.Getenv(constants.EnvOperatorNodeName)
|
2018-03-06 09:54:12 +00:00
|
|
|
if len(nodeName) == 0 {
|
2018-03-05 09:00:23 +00:00
|
|
|
cliLog.Fatal().Msgf("%s environment variable missing", constants.EnvOperatorNodeName)
|
|
|
|
}
|
|
|
|
|
2018-03-06 09:54:12 +00:00
|
|
|
config, deps, err := newProvisionerConfigAndDeps(nodeName)
|
2018-03-05 09:00:23 +00:00
|
|
|
if err != nil {
|
|
|
|
cliLog.Fatal().Err(err).Msg("Failed to create provisioner config & dependencies")
|
|
|
|
}
|
2018-03-05 10:06:53 +00:00
|
|
|
p, err := service.New(config, deps)
|
2018-03-05 09:00:23 +00:00
|
|
|
if err != nil {
|
|
|
|
cliLog.Fatal().Err(err).Msg("Failed to create provisioner")
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.TODO()
|
|
|
|
p.Run(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// newProvisionerConfigAndDeps creates storage provisioner config & dependencies.
|
2018-03-06 09:54:12 +00:00
|
|
|
func newProvisionerConfigAndDeps(nodeName string) (service.Config, service.Dependencies, error) {
|
2018-03-05 10:06:53 +00:00
|
|
|
cfg := service.Config{
|
2018-03-06 09:54:12 +00:00
|
|
|
Address: net.JoinHostPort("0.0.0.0", strconv.Itoa(storageProvisioner.port)),
|
|
|
|
NodeName: nodeName,
|
2018-03-05 09:00:23 +00:00
|
|
|
}
|
2018-03-05 10:06:53 +00:00
|
|
|
deps := service.Dependencies{
|
2018-03-06 09:54:12 +00:00
|
|
|
Log: logService.MustGetLogger("provisioner"),
|
2018-03-05 09:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cfg, deps, nil
|
|
|
|
}
|