-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
102 lines (86 loc) · 3.13 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
Copyright 2017 The Kubernetes Authors.
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 (
"flag"
"os"
"github.com/kubernetes-incubator/external-storage/ceph/rbd/pkg/provision"
"github.com/kubernetes-sigs/sig-storage-lib-external-provisioner/controller"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
)
var (
master = flag.String("master", "", "Master URL")
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig")
id = flag.String("id", "", "Unique provisioner identity")
metricsPort = flag.Int("metrics-port", 0, "The port of the metrics server (set to non-zero to enable)")
commandTimeout = flag.Int("command-timeout", 5, "Timeout for command execution (in seconds)")
usePVName = flag.Bool("use-pv-name", false, "Defines which image name should be used: generated or PV name")
)
const (
provisionerNameKey = "PROVISIONER_NAME"
)
func main() {
klog.InitFlags(nil)
flag.Parse()
flag.Set("logtostderr", "true")
var config *rest.Config
var err error
if *master != "" || *kubeconfig != "" {
config, err = clientcmd.BuildConfigFromFlags(*master, *kubeconfig)
} else {
config, err = rest.InClusterConfig()
}
if err != nil {
klog.Fatalf("Failed to create config: %v", err)
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
klog.Fatalf("Failed to create client: %v", err)
}
prName := provision.ProvisionerName
prNameFromEnv := os.Getenv(provisionerNameKey)
if prNameFromEnv != "" {
prName = prNameFromEnv
}
// By default, we use provisioner name as provisioner identity.
// User may specify their own identity with `-id` flag to distinguish each
// others, if they deploy more than one RBD provisioners under same provisioner name.
prID := prName
if *id != "" {
prID = *id
}
// The controller needs to know what the server version is because out-of-tree
// provisioners aren't officially supported until 1.5
serverVersion, err := clientset.Discovery().ServerVersion()
if err != nil {
klog.Fatalf("Error getting server version: %v", err)
}
// Create the provisioner: it implements the Provisioner interface expected by
// the controller
klog.Infof("Creating RBD provisioner %s with identity: %s", prName, prID)
rbdProvisioner := provision.NewRBDProvisioner(clientset, prID, *commandTimeout, *usePVName)
// Start the provision controller which will dynamically provision rbd
// PVs
pc := controller.NewProvisionController(
clientset,
prName,
rbdProvisioner,
serverVersion.GitVersion,
controller.MetricsPort(int32(*metricsPort)),
)
pc.Run(wait.NeverStop)
}