Lowercase hostnames when used as node names in k8s
This commit is contained in:
		@@ -157,7 +157,7 @@ def shutdown():
 | 
				
			|||||||
    '''
 | 
					    '''
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        if os.path.isfile(kubeconfig_path):
 | 
					        if os.path.isfile(kubeconfig_path):
 | 
				
			||||||
            kubectl('delete', 'node', gethostname())
 | 
					            kubectl('delete', 'node', gethostname().lower())
 | 
				
			||||||
    except CalledProcessError:
 | 
					    except CalledProcessError:
 | 
				
			||||||
        hookenv.log('Failed to unregister node.')
 | 
					        hookenv.log('Failed to unregister node.')
 | 
				
			||||||
    service_stop('snap.kubelet.daemon')
 | 
					    service_stop('snap.kubelet.daemon')
 | 
				
			||||||
@@ -906,7 +906,8 @@ class ApplyNodeLabelFailed(Exception):
 | 
				
			|||||||
def _apply_node_label(label, delete=False, overwrite=False):
 | 
					def _apply_node_label(label, delete=False, overwrite=False):
 | 
				
			||||||
    ''' Invoke kubectl to apply node label changes '''
 | 
					    ''' Invoke kubectl to apply node label changes '''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    hostname = gethostname()
 | 
					    # k8s lowercases hostnames and uses them as node names
 | 
				
			||||||
 | 
					    hostname = gethostname().lower()
 | 
				
			||||||
    # TODO: Make this part of the kubectl calls instead of a special string
 | 
					    # TODO: Make this part of the kubectl calls instead of a special string
 | 
				
			||||||
    cmd_base = 'kubectl --kubeconfig={0} label node {1} {2}'
 | 
					    cmd_base = 'kubectl --kubeconfig={0} label node {1} {2}'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user