github.com/deemoprobe/k8s-first-commit@v0.0.0-20230430165612-a541f1982be3/cmd/proxy/proxy.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 package main 17 18 import ( 19 "flag" 20 "log" 21 "os" 22 23 "github.com/GoogleCloudPlatform/kubernetes/pkg/proxy" 24 "github.com/GoogleCloudPlatform/kubernetes/pkg/proxy/config" 25 "github.com/coreos/go-etcd/etcd" 26 ) 27 28 var ( 29 config_file = flag.String("configfile", "/tmp/proxy_config", "Configuration file for the proxy") 30 etcd_servers = flag.String("etcd_servers", "http://10.240.10.57:4001", "Servers for the etcd cluster (http://ip:port).") 31 ) 32 33 func main() { 34 flag.Parse() 35 36 // Set up logger for etcd client 37 etcd.SetLogger(log.New(os.Stderr, "etcd ", log.LstdFlags)) 38 39 log.Printf("Using configuration file %s and etcd_servers %s", *config_file, *etcd_servers) 40 41 proxyConfig := config.NewServiceConfig() 42 43 // Create a configuration source that handles configuration from etcd. 44 etcdClient := etcd.NewClient([]string{*etcd_servers}) 45 config.NewConfigSourceEtcd(etcdClient, 46 proxyConfig.GetServiceConfigurationChannel("etcd"), 47 proxyConfig.GetEndpointsConfigurationChannel("etcd")) 48 49 // And create a configuration source that reads from a local file 50 config.NewConfigSourceFile(*config_file, 51 proxyConfig.GetServiceConfigurationChannel("file"), 52 proxyConfig.GetEndpointsConfigurationChannel("file")) 53 54 loadBalancer := proxy.NewLoadBalancerRR() 55 proxier := proxy.NewProxier(loadBalancer) 56 // Wire proxier to handle changes to services 57 proxyConfig.RegisterServiceHandler(proxier) 58 // And wire loadBalancer to handle changes to endpoints to services 59 proxyConfig.RegisterEndpointsHandler(loadBalancer) 60 61 // Just loop forever for now... 62 select {} 63 64 }