From 056f0a5f259112d5c8c308d52d8c87f78c12082d Mon Sep 17 00:00:00 2001 From: Wei Tie Date: Tue, 16 Jan 2018 15:33:03 -0800 Subject: [PATCH] Hard code k8s api endpoint Hard code K8S API endpoints in all cases becuase netplugin is not able to handle the service ip correctly for daemonset --- install/k8s/cluster/k8smaster_centos.sh | 2 +- install/k8s/contiv/contiv-compose | 30 +++++++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/install/k8s/cluster/k8smaster_centos.sh b/install/k8s/cluster/k8smaster_centos.sh index 1d77d9f86..b4a4bc654 100644 --- a/install/k8s/cluster/k8smaster_centos.sh +++ b/install/k8s/cluster/k8smaster_centos.sh @@ -14,7 +14,7 @@ if [ -n "$CONTIV_TEST" ]; then else # update to use released version cd /opt/gopath/src/github.com/contiv/netplugin/install/k8s/contiv/ - ./contiv-compose use-release -v $(cat /opt/gopath/src/github.com/contiv/netplugin/version/CURRENT_VERSION) ./contiv-base.yaml > /shared/contiv.yaml + ./contiv-compose use-release --k8s-api https://$2:$3 -v $(cat /opt/gopath/src/github.com/contiv/netplugin/version/CURRENT_VERSION) ./contiv-base.yaml > /shared/contiv.yaml fi kubectl apply -f /shared/contiv.yaml diff --git a/install/k8s/contiv/contiv-compose b/install/k8s/contiv/contiv-compose index a2dca9974..1cff1c233 100755 --- a/install/k8s/contiv/contiv-compose +++ b/install/k8s/contiv/contiv-compose @@ -4,6 +4,10 @@ import argparse from contextlib import contextmanager import os import sys +try: + from urlparse import urlparse +except ImportError: + from urllib.parse import urlparse import yaml @@ -64,13 +68,6 @@ class ContivComposer(object): 'hostPath': {'path': '/var/log/contiv'} }) - if self._is_resource(resource, 'ConfigMap', 'contiv-config', - 'kube-system'): - if args['k8s_api'] is not None: - k8s_config = resource['data']['contiv_k8s_config'] - resource['data']['contiv_k8s_config'] = k8s_config.replace( - 'https://__KUBERNETES_SERVICE_HOST__:__KUBERNETES_SERVICE_PORT__', - args['k8s_api']) def add_prometheus(self, resource, args): if (self._is_resource(resource, 'DaemonSet', 'contiv-netplugin', @@ -178,6 +175,21 @@ class ContivComposer(object): for resource in data: func(resource, args) self._update_images(resource, args) + # update k8s api because netplugin doesn't work with service vip + # TODO: fix it in netplugin + self._update_k8s_api_config(resource, args) + + def _update_k8s_api_config(self, resource, args): + if self._is_resource(resource, 'ConfigMap', 'contiv-config', + 'kube-system'): + if args['k8s_api'] is not None: + k8s_config = resource['data']['contiv_k8s_config'] + + resource['data']['contiv_k8s_config'] = k8s_config.replace( + 'https://__KUBERNETES_SERVICE_HOST__:__KUBERNETES_SERVICE_PORT__', + args['k8s_api']) + resource['data']['contiv_etcd'] = "http://%s:6666" % urlparse( + args['k8s_api']).hostname def _is_resource(self, resource, kind, name, namespace=None): return (resource['kind'] == kind and @@ -249,6 +261,7 @@ class ContivComposer(object): def _add_common_args(parser): + parser.add_argument('--k8s-api', help='k8s api endpoint') parser.add_argument('-i', '--in-place', action='store_true', @@ -284,7 +297,7 @@ def create_cli_args(): description="Add system test required updates") _add_common_args(systest_parser) _add_image_args(systest_parser) - systest_parser.add_argument('--k8s-api', help='k8s api endpoint') + # add prometheus prometheus_parser = subclis.add_parser( @@ -331,7 +344,6 @@ def create_cli_args(): '--version', default='latest', help='the release version to use') - return parser