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", "",
|
nxgConfigMap = flags.String("nginx-configmap", "",
|
||||||
`Name of the ConfigMap that containes the custom nginx configuration to use`)
|
`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", "",
|
tcpConfigMapName = flags.String("tcp-services-configmap", "",
|
||||||
`Name of the ConfigMap that containes the definition of the TCP services to expose.
|
`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
|
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() {
|
func main() {
|
||||||
var kubeClient *unversioned.Client
|
|
||||||
flags.AddGoFlagSet(flag.CommandLine)
|
flags.AddGoFlagSet(flag.CommandLine)
|
||||||
flags.Parse(os.Args)
|
flags.Parse(os.Args)
|
||||||
clientConfig := kubectl_util.DefaultClientConfig(flags)
|
clientConfig := kubectl_util.DefaultClientConfig(flags)
|
||||||
|
@ -107,26 +102,20 @@ func main() {
|
||||||
glog.Fatalf("Please specify --default-backend-service")
|
glog.Fatalf("Please specify --default-backend-service")
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
config, err := clientConfig.ClientConfig()
|
||||||
if *inCluster {
|
if err != nil {
|
||||||
kubeClient, err = unversioned.NewInCluster()
|
glog.Fatalf("error connecting to the client: %v", err)
|
||||||
} else {
|
|
||||||
config, connErr := clientConfig.ClientConfig()
|
|
||||||
if connErr != nil {
|
|
||||||
glog.Fatalf("error connecting to the client: %v", err)
|
|
||||||
}
|
|
||||||
kubeClient, err = unversioned.New(config)
|
|
||||||
}
|
}
|
||||||
|
kubeClient, err := unversioned.New(config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("failed to create client: %v", err)
|
glog.Fatalf("failed to create client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
runtimePodInfo := &podInfo{NodeIP: "127.0.0.1"}
|
runtimePodInfo, err := getPodDetails(kubeClient)
|
||||||
if *inCluster {
|
if err != nil {
|
||||||
runtimePodInfo, err = getPodDetails(kubeClient)
|
runtimePodInfo = &podInfo{NodeIP: "127.0.0.1"}
|
||||||
if err != nil {
|
glog.Warningf("unexpected error getting runtime information: %v", err)
|
||||||
glog.Fatalf("unexpected error getting runtime information: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if err := isValidService(kubeClient, *defaultSvc); err != nil {
|
if err := isValidService(kubeClient, *defaultSvc); err != nil {
|
||||||
glog.Fatalf("no service with name %v found: %v", *defaultSvc, err)
|
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 {
|
func sysctlSomaxconn() int {
|
||||||
maxConns, err := sysctl.GetSysctl("net/core/somaxconn")
|
maxConns, err := sysctl.GetSysctl("net/core/somaxconn")
|
||||||
if err != nil || maxConns < 512 {
|
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
|
return 511
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,10 @@ func getPodDetails(kubeClient *unversioned.Client) (*podInfo, error) {
|
||||||
podName := os.Getenv("POD_NAME")
|
podName := os.Getenv("POD_NAME")
|
||||||
podNs := os.Getenv("POD_NAMESPACE")
|
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)
|
err := waitForPodRunning(kubeClient, podNs, podName, time.Millisecond*200, time.Second*30)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -126,7 +130,7 @@ func getPodDetails(kubeClient *unversioned.Client) (*podInfo, error) {
|
||||||
|
|
||||||
pod, _ := kubeClient.Pods(podNs).Get(podName)
|
pod, _ := kubeClient.Pods(podNs).Get(podName)
|
||||||
if pod == nil {
|
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)
|
node, err := kubeClient.Nodes().Get(pod.Spec.NodeName)
|
||||||
|
|
Loading…
Reference in a new issue