2014-06-06 23:40:48 +00:00
|
|
|
/*
|
|
|
|
Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2014-06-11 23:02:08 +00:00
|
|
|
|
2014-06-06 23:40:48 +00:00
|
|
|
// The controller manager is responsible for monitoring replication controllers, and creating corresponding
|
2014-06-09 05:38:45 +00:00
|
|
|
// pods to achieve the desired state. It listens for new controllers in etcd, and it sends requests to the
|
|
|
|
// master to create/delete pods.
|
2014-06-06 23:40:48 +00:00
|
|
|
//
|
|
|
|
// TODO: Refactor the etcd watch code so that it is a pluggable interface.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"time"
|
|
|
|
|
2014-06-15 17:24:36 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
2014-06-17 21:49:44 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
|
2014-06-25 03:51:57 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
2014-08-01 05:55:44 +00:00
|
|
|
verflag "github.com/GoogleCloudPlatform/kubernetes/pkg/version/flag"
|
2014-06-06 23:40:48 +00:00
|
|
|
"github.com/coreos/go-etcd/etcd"
|
2014-06-25 03:51:57 +00:00
|
|
|
"github.com/golang/glog"
|
2014-06-06 23:40:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2014-07-20 14:48:47 +00:00
|
|
|
etcdServerList util.StringList
|
|
|
|
master = flag.String("master", "", "The address of the Kubernetes API server")
|
2014-06-06 23:40:48 +00:00
|
|
|
)
|
|
|
|
|
2014-07-20 14:48:47 +00:00
|
|
|
func init() {
|
|
|
|
flag.Var(&etcdServerList, "etcd_servers", "List of etcd servers to watch (http://ip:port), comma separated")
|
|
|
|
}
|
|
|
|
|
2014-06-06 23:40:48 +00:00
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
2014-06-25 03:51:57 +00:00
|
|
|
util.InitLogs()
|
|
|
|
defer util.FlushLogs()
|
2014-06-06 23:40:48 +00:00
|
|
|
|
2014-08-01 05:55:44 +00:00
|
|
|
verflag.PrintAndExitIfRequested()
|
2014-07-30 22:21:34 +00:00
|
|
|
|
2014-07-20 14:48:47 +00:00
|
|
|
if len(etcdServerList) == 0 || len(*master) == 0 {
|
2014-06-25 03:51:57 +00:00
|
|
|
glog.Fatal("usage: controller-manager -etcd_servers <servers> -master <master>")
|
2014-06-06 23:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set up logger for etcd client
|
2014-06-25 03:51:57 +00:00
|
|
|
etcd.SetLogger(util.NewLogger("etcd "))
|
2014-06-06 23:40:48 +00:00
|
|
|
|
2014-06-22 21:18:01 +00:00
|
|
|
controllerManager := controller.MakeReplicationManager(
|
2014-07-20 14:48:47 +00:00
|
|
|
etcd.NewClient(etcdServerList),
|
2014-06-22 21:18:01 +00:00
|
|
|
client.New("http://"+*master, nil))
|
2014-06-06 23:40:48 +00:00
|
|
|
|
2014-06-17 23:42:29 +00:00
|
|
|
controllerManager.Run(10 * time.Second)
|
2014-06-06 23:40:48 +00:00
|
|
|
select {}
|
|
|
|
}
|