Skip to content
Permalink
Browse files

Remove confusion between k8s-args `node-labels` and bosh spec `Labels` (

#305)

* Preference k8s-args setting flags over bosh specs
* End users who used k8s-args to set labels would be broken
  • Loading branch information...
henderjm authored and tvs committed Feb 27, 2019
1 parent 9c1522e commit cea69999be1e96bd2fc0f0fc9da118a085d67a4c
Showing with 25 additions and 8 deletions.
  1. +0 −3 jobs/kubelet/spec
  2. +13 −5 jobs/kubelet/templates/bin/kubelet_ctl.erb
  3. +12 −0 spec/kubelet_ctl_spec.rb
@@ -47,9 +47,6 @@ properties:
docker-only: null
no_proxy:
description: no_proxy env var for cloud provider interactions, i.e. for the kubelet
labels:
description: '<Warning: Alpha feature> Labels to add when registering the node
in the cluster. Labels must be key=value pairs separated by '',''.'
tls.kubelet:
description: Certificate and private key for the Kubernetes worker
parameters:
@@ -33,9 +33,6 @@ DATA_DIR=/var/vcap/store/kubernetes
if iaas=="vsphere"
labels << "failure-domain.beta.kubernetes.io/zone=#{spec.az}"
end
if_p("labels") do |node_labels|
labels += node_labels.map {|k,v| "#{k}=#{v}"}
end
labels = labels.join(',')
%>
@@ -104,11 +101,19 @@ start_kubelet() {
kubelet \
<%-
if_p('k8s-args') do |args|
node_labels = args.select { |f,_| f == 'node-labels' }
if node_labels.empty?
args['node-labels'] = labels
else
node_labels = "#{node_labels['node-labels']},#{labels}"
end
args.each do |flag, value|
valueString = ""
if value.nil?
# Do nothing to supports args-less flags (--example)
elsif flag == 'node-labels'
valueString = "=#{node_labels}" # << labels
elsif value.is_a? Array
valueString = "=#{value.join(",")}"
elsif value.is_a? Hash
@@ -120,12 +125,15 @@ start_kubelet() {
<%= "--#{flag}#{valueString}" %> \
<%-
end
end
end.else do
-%>
<%= "--node-labels=#{labels}" %> \
<%-
end
-%>
<% if include_config -%>--cloud-config=${cloud_config}<% end %> \
<% if !iaas.nil? -%>--cloud-provider=${cloud_provider}<% end %> \
--hostname-override=$(get_hostname_override) \
--node-labels=<%= labels %> \
--config="/var/vcap/jobs/kubelet/config/kubeletconfig.yml" \
1>> $LOG_DIR/kubelet.stdout.log \
2>> $LOG_DIR/kubelet.stderr.log
@@ -22,6 +22,18 @@
expect(rendered_template).to include(',bosh.id=fake-bosh-id')
end

it 'labels the kubelet with custom labels' do
manifest_properties = {
'k8s-args' => {
'node-labels' => 'foo=bar,k8s.node=custom'
}
}
rendered_kubelet_ctl = compiled_template('kubelet', 'bin/kubelet_ctl', manifest_properties, {}, {}, 'z1', 'fake-bosh-ip', 'fake-bosh-id')
expect(rendered_kubelet_ctl).to include(',bosh.id=fake-bosh-id')
expect(rendered_kubelet_ctl).to include(',k8s.node=custom')
expect(rendered_kubelet_ctl).to include('foo=bar')
end

it 'has no http proxy when no proxy is defined' do
rendered_kubelet_ctl = compiled_template(
'kubelet',

0 comments on commit cea6999

Please sign in to comment.
You can’t perform that action at this time.