github.com/deemoprobe/k8s-first-commit@v0.0.0-20230430165612-a541f1982be3/cmd/controller-manager/controller-manager.go (about) 1 /* 2 Copyright 2014 Google Inc. All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 // The controller manager is responsible for monitoring replication controllers, and creating corresponding 17 // tasks to achieve the desired state. It listens for new controllers in etcd, and it sends requests to the 18 // master to create/delete tasks. 19 // 20 // TODO: Refactor the etcd watch code so that it is a pluggable interface. 21 package main 22 23 import ( 24 "flag" 25 "log" 26 "os" 27 "time" 28 29 kube_client "github.com/GoogleCloudPlatform/kubernetes/pkg/client" 30 "github.com/GoogleCloudPlatform/kubernetes/pkg/registry" 31 "github.com/GoogleCloudPlatform/kubernetes/pkg/util" 32 "github.com/coreos/go-etcd/etcd" 33 ) 34 35 var ( 36 etcd_servers = flag.String("etcd_servers", "", "Servers for the etcd (http://ip:port).") 37 master = flag.String("master", "", "The address of the Kubernetes API server") 38 ) 39 40 func main() { 41 flag.Parse() 42 43 if len(*etcd_servers) == 0 || len(*master) == 0 { 44 log.Fatal("usage: controller-manager -etcd_servers <servers> -master <master>") 45 } 46 47 // Set up logger for etcd client 48 etcd.SetLogger(log.New(os.Stderr, "etcd ", log.LstdFlags)) 49 50 controllerManager := registry.MakeReplicationManager(etcd.NewClient([]string{*etcd_servers}), 51 kube_client.Client{ 52 Host: "http://" + *master, 53 }) 54 55 go util.Forever(func() { controllerManager.Synchronize() }, 20*time.Second) 56 go util.Forever(func() { controllerManager.WatchControllers() }, 20*time.Second) 57 select {} 58 }