1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00
kube-arangodb/storage.go

106 lines
2.8 KiB
Go
Raw Normal View History

2018-03-05 09:00:23 +00:00
//
// DISCLAIMER
//
// Copyright 2018 ArangoDB GmbH, Cologne, Germany
//
// 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
logService, err = logging.NewService(logLevel)
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
}