Use ClientConfig to configure connection
This commit is contained in:
parent
1abf443742
commit
0f70b80745
3 changed files with 15 additions and 22 deletions
|
@ -56,10 +56,6 @@ var (
|
|||
nxgConfigMap = flags.String("nginx-configmap", "",
|
||||
`Name of the ConfigMap that containes the custom nginx configuration to use`)
|
||||
|
||||
inCluster = flags.Bool("running-in-cluster", true,
|
||||
`Optional, if this controller is running in a kubernetes cluster, use the
|
||||
pod secrets for creating a Kubernetes client.`)
|
||||
|
||||
tcpConfigMapName = flags.String("tcp-services-configmap", "",
|
||||
`Name of the ConfigMap that containes the definition of the TCP services to expose.
|
||||
The key in the map indicates the external port to be used. The value is the name of the
|
||||
|
@ -91,7 +87,6 @@ var (
|
|||
)
|
||||
|
||||
func main() {
|
||||
var kubeClient *unversioned.Client
|
||||
flags.AddGoFlagSet(flag.CommandLine)
|
||||
flags.Parse(os.Args)
|
||||
clientConfig := kubectl_util.DefaultClientConfig(flags)
|
||||
|
@ -107,26 +102,20 @@ func main() {
|
|||
glog.Fatalf("Please specify --default-backend-service")
|
||||
}
|
||||
|
||||
var err error
|
||||
if *inCluster {
|
||||
kubeClient, err = unversioned.NewInCluster()
|
||||
} else {
|
||||
config, connErr := clientConfig.ClientConfig()
|
||||
if connErr != nil {
|
||||
glog.Fatalf("error connecting to the client: %v", err)
|
||||
}
|
||||
kubeClient, err = unversioned.New(config)
|
||||
config, err := clientConfig.ClientConfig()
|
||||
if err != nil {
|
||||
glog.Fatalf("error connecting to the client: %v", err)
|
||||
}
|
||||
kubeClient, err := unversioned.New(config)
|
||||
|
||||
if err != nil {
|
||||
glog.Fatalf("failed to create client: %v", err)
|
||||
}
|
||||
|
||||
runtimePodInfo := &podInfo{NodeIP: "127.0.0.1"}
|
||||
if *inCluster {
|
||||
runtimePodInfo, err = getPodDetails(kubeClient)
|
||||
if err != nil {
|
||||
glog.Fatalf("unexpected error getting runtime information: %v", err)
|
||||
}
|
||||
runtimePodInfo, err := getPodDetails(kubeClient)
|
||||
if err != nil {
|
||||
runtimePodInfo = &podInfo{NodeIP: "127.0.0.1"}
|
||||
glog.Warningf("unexpected error getting runtime information: %v", err)
|
||||
}
|
||||
if err := isValidService(kubeClient, *defaultSvc); err != nil {
|
||||
glog.Fatalf("no service with name %v found: %v", *defaultSvc, err)
|
||||
|
|
|
@ -228,7 +228,7 @@ func diff(b1, b2 []byte) (data []byte, err error) {
|
|||
func sysctlSomaxconn() int {
|
||||
maxConns, err := sysctl.GetSysctl("net/core/somaxconn")
|
||||
if err != nil || maxConns < 512 {
|
||||
glog.Warningf("system net.core.somaxconn=%v. Using NGINX default (511)", maxConns)
|
||||
glog.V(3).Infof("system net.core.somaxconn=%v. Using NGINX default (511)", maxConns)
|
||||
return 511
|
||||
}
|
||||
|
||||
|
|
|
@ -119,6 +119,10 @@ func getPodDetails(kubeClient *unversioned.Client) (*podInfo, error) {
|
|||
podName := os.Getenv("POD_NAME")
|
||||
podNs := os.Getenv("POD_NAMESPACE")
|
||||
|
||||
if podName == "" && podNs == "" {
|
||||
return nil, fmt.Errorf("unable to get POD information (missing POD_NAME or POD_NAMESPACE environment variable")
|
||||
}
|
||||
|
||||
err := waitForPodRunning(kubeClient, podNs, podName, time.Millisecond*200, time.Second*30)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -126,7 +130,7 @@ func getPodDetails(kubeClient *unversioned.Client) (*podInfo, error) {
|
|||
|
||||
pod, _ := kubeClient.Pods(podNs).Get(podName)
|
||||
if pod == nil {
|
||||
return nil, fmt.Errorf("Unable to get POD information")
|
||||
return nil, fmt.Errorf("unable to get POD information")
|
||||
}
|
||||
|
||||
node, err := kubeClient.Nodes().Get(pod.Spec.NodeName)
|
||||
|
|
Loading…
Reference in a new issue