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

94 lines
2.4 KiB
Go
Raw Permalink Normal View History

2018-03-05 09:00:23 +00:00
//
// DISCLAIMER
//
2022-01-10 11:35:49 +00:00
// Copyright 2016-2022 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
//
package cmd
2018-03-05 09:00:23 +00:00
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/storage/provisioner"
"github.com/arangodb/kube-arangodb/pkg/storage/provisioner/service"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/version"
2018-03-05 10:06:53 +00:00
)
2018-03-05 09:00:23 +00:00
var (
cmdStorage = &cobra.Command{
Use: "storage",
Run: executeUsage,
2018-03-05 09:00:23 +00:00
}
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) {
var err error
2018-03-05 09:00:23 +00:00
// Log version
2021-07-08 10:11:39 +00:00
2022-06-14 07:26:07 +00:00
logger.Info("Starting arangodb local storage provisioner (%s), version %s build %s", version.GetVersionV1().Edition.Title(), version.GetVersionV1().Version, version.GetVersionV1().Build)
2018-03-05 09:00:23 +00:00
// Get environment
nodeName := os.Getenv(constants.EnvOperatorNodeName)
2018-03-06 09:54:12 +00:00
if len(nodeName) == 0 {
2022-06-14 07:26:07 +00:00
logger.Fatal("%s environment variable missing", constants.EnvOperatorNodeName)
2018-03-05 09:00:23 +00:00
}
2022-06-14 07:26:07 +00:00
config := newProvisionerConfigAndDeps(nodeName)
p, err := service.New(config)
2018-03-05 09:00:23 +00:00
if err != nil {
2022-06-14 07:26:07 +00:00
logger.Err(err).Fatal("Failed to create provisioner")
2018-03-05 09:00:23 +00:00
}
ctx := context.TODO()
p.Run(ctx)
}
// newProvisionerConfigAndDeps creates storage provisioner config & dependencies.
2022-06-14 07:26:07 +00:00
func newProvisionerConfigAndDeps(nodeName string) service.Config {
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
}
2022-06-14 07:26:07 +00:00
return cfg
2018-03-05 09:00:23 +00:00
}