forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
master.go
180 lines (151 loc) · 6.58 KB
/
master.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package kubernetes
import (
"fmt"
"io/ioutil"
"net"
"os"
"github.com/emicklei/go-restful"
"github.com/golang/glog"
kctrl "github.com/GoogleCloudPlatform/kubernetes/cmd/kube-controller-manager/app"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/nodecontroller"
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
"github.com/GoogleCloudPlatform/kubernetes/pkg/namespace"
"github.com/GoogleCloudPlatform/kubernetes/pkg/resourcequota"
"github.com/GoogleCloudPlatform/kubernetes/pkg/service"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume/host_path"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume/nfs"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volumeclaimbinder"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler"
_ "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/algorithmprovider"
schedulerapi "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/api"
latestschedulerapi "github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/plugin/pkg/scheduler/factory"
)
const (
KubeAPIPrefix = "/api"
KubeAPIPrefixV1Beta3 = "/api/v1beta3"
KubeAPIPrefixV1 = "/api/v1"
)
// InstallAPI starts a Kubernetes master and registers the supported REST APIs
// into the provided mux, then returns an array of strings indicating what
// endpoints were started (these are format strings that will expect to be sent
// a single string value).
func (c *MasterConfig) InstallAPI(container *restful.Container) []string {
c.Master.RestfulContainer = container
_ = master.New(c.Master)
messages := []string{}
if !c.Master.DisableV1Beta3 {
messages = append(messages, fmt.Sprintf("Started Kubernetes API at %%s%s (deprecated)", KubeAPIPrefixV1Beta3))
}
if c.Master.EnableV1 {
messages = append(messages, fmt.Sprintf("Started Kubernetes API at %%s%s", KubeAPIPrefixV1))
}
return messages
}
// RunNamespaceController starts the Kubernetes Namespace Manager
func (c *MasterConfig) RunNamespaceController() {
namespaceController := namespace.NewNamespaceManager(c.KubeClient, c.ControllerManager.NamespaceSyncPeriod)
namespaceController.Run()
glog.Infof("Started Kubernetes Namespace Manager")
}
// RunPersistentVolumeClaimBinder starts the Kubernetes Persistent Volume Claim Binder
func (c *MasterConfig) RunPersistentVolumeClaimBinder() {
binder := volumeclaimbinder.NewPersistentVolumeClaimBinder(c.KubeClient, c.ControllerManager.PVClaimBinderSyncPeriod)
binder.Run()
glog.Infof("Started Kubernetes Persistent Volume Claim Binder")
}
func (c *MasterConfig) RunPersistentVolumeClaimRecycler(recyclerImageName string) {
hostPathRecycler := &volume.RecyclableVolumeConfig{
ImageName: recyclerImageName,
Command: []string{"/usr/share/openshift/scripts/volumes/recycle.sh"},
Args: []string{"/scrub"},
Timeout: int64(60),
}
nfsRecycler := &volume.RecyclableVolumeConfig{
ImageName: recyclerImageName,
Command: []string{"/usr/share/openshift/scripts/volumes/recycle.sh"},
Args: []string{"/scrub"},
Timeout: int64(300),
}
allPlugins := []volume.VolumePlugin{}
allPlugins = append(allPlugins, host_path.ProbeVolumePlugins(hostPathRecycler)...)
allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsRecycler)...)
recycler, err := volumeclaimbinder.NewPersistentVolumeRecycler(c.KubeClient, c.ControllerManager.PVClaimBinderSyncPeriod, kctrl.ProbeRecyclableVolumePlugins())
if err != nil {
glog.Fatalf("Could not start PersistentVolumeRecycler: %+v", err)
}
recycler.Run()
glog.Infof("Started Kubernetes PersistentVolumeRecycler")
}
// RunReplicationController starts the Kubernetes replication controller sync loop
func (c *MasterConfig) RunReplicationController(client *client.Client) {
controllerManager := controller.NewReplicationManager(client, controller.BurstReplicas)
go controllerManager.Run(c.ControllerManager.ConcurrentRCSyncs, util.NeverStop)
glog.Infof("Started Kubernetes Replication Manager")
}
// RunEndpointController starts the Kubernetes replication controller sync loop
func (c *MasterConfig) RunEndpointController() {
endpoints := service.NewEndpointController(c.KubeClient)
go endpoints.Run(c.ControllerManager.ConcurrentEndpointSyncs, util.NeverStop)
glog.Infof("Started Kubernetes Endpoint Controller")
}
// RunScheduler starts the Kubernetes scheduler
func (c *MasterConfig) RunScheduler() {
config, err := c.createSchedulerConfig()
if err != nil {
glog.Fatalf("Unable to start scheduler: %v", err)
}
eventcast := record.NewBroadcaster()
config.Recorder = eventcast.NewRecorder(kapi.EventSource{Component: "scheduler"})
eventcast.StartRecordingToSink(c.KubeClient.Events(""))
s := scheduler.New(config)
s.Run()
glog.Infof("Started Kubernetes Scheduler")
}
// RunResourceQuotaManager starts the resource quota manager
func (c *MasterConfig) RunResourceQuotaManager() {
resourceQuotaManager := resourcequota.NewResourceQuotaManager(c.KubeClient)
resourceQuotaManager.Run(c.ControllerManager.ResourceQuotaSyncPeriod)
}
// RunNodeController starts the node controller
func (c *MasterConfig) RunNodeController() {
s := c.ControllerManager
controller := nodecontroller.NewNodeController(
c.CloudProvider,
c.KubeClient,
s.RegisterRetryCount,
s.PodEvictionTimeout,
util.NewTokenBucketRateLimiter(s.DeletingPodsQps, s.DeletingPodsBurst),
s.NodeMonitorGracePeriod,
s.NodeStartupGracePeriod,
s.NodeMonitorPeriod,
(*net.IPNet)(&s.ClusterCIDR),
s.AllocateNodeCIDRs,
)
controller.Run(s.NodeSyncPeriod)
glog.Infof("Started Kubernetes Node Controller")
}
func (c *MasterConfig) createSchedulerConfig() (*scheduler.Config, error) {
var policy schedulerapi.Policy
var configData []byte
configFactory := factory.NewConfigFactory(c.KubeClient)
if _, err := os.Stat(c.Options.SchedulerConfigFile); err == nil {
configData, err = ioutil.ReadFile(c.Options.SchedulerConfigFile)
if err != nil {
return nil, fmt.Errorf("unable to read scheduler config: %v", err)
}
err = latestschedulerapi.Codec.DecodeInto(configData, &policy)
if err != nil {
return nil, fmt.Errorf("invalid scheduler configuration: %v", err)
}
return configFactory.CreateFromConfig(policy)
}
// if the config file isn't provided, use the default provider
return configFactory.CreateFromProvider(factory.DefaultProvider)
}