From a3daea69dcc1d0b64fcf53d2bab022fd5863c58a Mon Sep 17 00:00:00 2001 From: Alexander Trost Date: Sat, 23 Sep 2017 00:40:54 +0200 Subject: [PATCH] fix rook-api service clusterIP when hostNetwork is used allow ROOK_API_SERVER_ENDPOINT to be set by user toolbox: default to rook-api dns name when no k8s service env vars are given Added dnsPolicy to rook-tools (K8s required version >1.6) --- cluster/examples/kubernetes/rook-tools.yaml | 3 ++- images/toolbox/toolbox.sh | 17 ++++++++++++----- pkg/operator/api/api.go | 4 ++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cluster/examples/kubernetes/rook-tools.yaml b/cluster/examples/kubernetes/rook-tools.yaml index c8c06d4f8..fcde0f7d9 100644 --- a/cluster/examples/kubernetes/rook-tools.yaml +++ b/cluster/examples/kubernetes/rook-tools.yaml @@ -4,7 +4,7 @@ metadata: name: rook-tools namespace: rook spec: - hostNetwork: false + dnsPolicy: ClusterFirstWithHostNet containers: - name: rook-tools image: rook/toolbox:master @@ -25,6 +25,7 @@ spec: name: sysbus - mountPath: /lib/modules name: libmodules + hostNetwork: false volumes: - name: dev hostPath: diff --git a/images/toolbox/toolbox.sh b/images/toolbox/toolbox.sh index 9bdd996db..fdbbe5f8f 100755 --- a/images/toolbox/toolbox.sh +++ b/images/toolbox/toolbox.sh @@ -26,14 +26,21 @@ CEPH_CONFIG="/etc/ceph/ceph.conf" # without specifying any arguments if [[ -d ${ROOK_DIR} ]]; then # there is a rook directory, try to find one of rook's ceph config files and copy it - ROOK_CONFIG=`find ${ROOK_DIR} -regex '.*mon[0-9]+/.*\.config' | head -1` + ROOK_CONFIG=$(find ${ROOK_DIR} -regex '.*mon[0-9]+/.*\.config' | head -1) if [[ ! -z ${ROOK_CONFIG} ]]; then cp ${ROOK_CONFIG} ${CEPH_CONFIG} fi -elif [[ ! -z ${ROOK_API_SERVICE_HOST} ]] && [[ ! -z ${ROOK_API_SERVICE_PORT} ]]; then - # we have some rook env vars set, get client info from the rook API server and construct - # a ceph config file from that - ROOK_API_SERVER_ENDPOINT=${ROOK_API_SERVICE_HOST}:${ROOK_API_SERVICE_PORT} +else + if [[ -z ${ROOK_API_SERVER_ENDPOINT} ]]; then + if [[ ! -z ${ROOK_API_SERVICE_HOST} ]] && [[ ! -z ${ROOK_API_SERVICE_PORT} ]]; then + # we have some rook env vars set, get client info from the rook API server and construct + # a ceph config file from that + ROOK_API_SERVER_ENDPOINT=${ROOK_API_SERVICE_HOST}:${ROOK_API_SERVICE_PORT} + else + # default to the dns name of the rook-api svc + ROOK_API_SERVER_ENDPOINT="rook-api:8124" + fi + fi # append to the bashrc file so that the rook tool can find the API server easily cat <> ~/.bashrc diff --git a/pkg/operator/api/api.go b/pkg/operator/api/api.go index c17e23c6f..029bb7d97 100644 --- a/pkg/operator/api/api.go +++ b/pkg/operator/api/api.go @@ -238,6 +238,10 @@ func (c *Cluster) startService() error { }, } + if c.HostNetwork { + s.Spec.ClusterIP = v1.ClusterIPNone + } + s, err := c.context.Clientset.CoreV1().Services(c.Namespace).Create(s) if err != nil { if !errors.IsAlreadyExists(err) {