Work out situation with KUBERNETES_NODE_NAME
This reverts commit f0cde86ee6
as it turns
out that variable is actually used by kuryr-daemon and fixes the way
kuryr-controller detects its identity to match how leader-elector is
doing it.
Change-Id: I95c2d3e1760a938d40d57a99fb87b6f02ca7f64a
Closes-Bug: 1798835
This commit is contained in:
parent
99a71d909a
commit
65e05c3b6d
|
@ -569,11 +569,6 @@ EOF
|
|||
imagePullPolicy: Never
|
||||
name: controller
|
||||
terminationMessagePath: "/dev/termination-log"
|
||||
env:
|
||||
- name: KUBERNETES_NODE_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: spec.nodeName
|
||||
volumeMounts:
|
||||
- name: config-volume
|
||||
mountPath: "/etc/kuryr/kuryr.conf"
|
||||
|
@ -642,6 +637,10 @@ spec:
|
|||
imagePullPolicy: Never
|
||||
command: [ "cni_ds_init" ]
|
||||
env:
|
||||
- name: KUBERNETES_NODE_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: spec.nodeName
|
||||
- name: KURYR_CNI_POD_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import mock
|
||||
import os
|
||||
|
||||
from os_vif import objects
|
||||
from oslo_config import cfg
|
||||
|
@ -27,25 +26,12 @@ CONF = cfg.CONF
|
|||
|
||||
class TestUtils(test_base.TestCase):
|
||||
@mock.patch('socket.gethostname')
|
||||
def test_get_node_name_socket(self, m_gethostname):
|
||||
try:
|
||||
del os.environ['KUBERNETES_NODE_NAME']
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
def test_get_node_name(self, m_gethostname):
|
||||
m_gethostname.return_value = 'foo'
|
||||
res = utils.get_node_name()
|
||||
self.assertEqual('foo', res)
|
||||
m_gethostname.assert_called_once_with()
|
||||
|
||||
@mock.patch('socket.gethostname')
|
||||
def test_get_node_name_envvar(self, m_gethostname):
|
||||
os.environ['KUBERNETES_NODE_NAME'] = 'bar'
|
||||
m_gethostname.return_value = 'foo'
|
||||
res = utils.get_node_name()
|
||||
self.assertEqual('bar', res)
|
||||
m_gethostname.assert_not_called()
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_get_leader_name(self, m_get):
|
||||
m_get.return_value = mock.Mock(json=mock.Mock(
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
import random
|
||||
import socket
|
||||
import time
|
||||
|
@ -129,10 +128,10 @@ def exponential_sleep(deadline, attempt, interval=DEFAULT_INTERVAL):
|
|||
|
||||
|
||||
def get_node_name():
|
||||
try:
|
||||
return os.environ['KUBERNETES_NODE_NAME']
|
||||
except KeyError:
|
||||
return socket.gethostname()
|
||||
# leader-elector container based on K8s way of doing leader election is
|
||||
# assuming that hostname it sees is the node id. Containers within a pod
|
||||
# are sharing the hostname, so this will match what leader-elector returns.
|
||||
return socket.gethostname()
|
||||
|
||||
|
||||
def get_leader_name():
|
||||
|
|
Loading…
Reference in New Issue