Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Commit

Permalink
Use k8s-args.root-dir in drain script when watching for PVC detach (#314
Browse files Browse the repository at this point in the history
)

Added a spec test to verify the behavior.
  • Loading branch information
tvs authored and altonf4 committed Mar 21, 2019
1 parent d201df8 commit e7374cf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion jobs/kubelet/templates/bin/drain.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ drain_node() {
}

get_k8s_disks() {
disks=$(lsblk -dnl -o NAME,TYPE,MOUNTPOINT | awk '/var\/lib\/kubelet/ {print $1}')
<%-
root_dir = p('k8s-args', {}).fetch('root-dir', "/var/lib/kubelet").gsub("/", "\\/")
-%>
disks=$(lsblk -dnl -o NAME,TYPE,MOUNTPOINT | awk '/<%= root_dir %>/ {print $1}')
echo ${disks[@]} | tr " " "|"
}

Expand Down
31 changes: 31 additions & 0 deletions spec/kubelet_drain_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'rspec'
require 'spec_helper'

def get_k8s_disks_dir(rendered_drain)
lsblk_line = rendered_drain.split("\n").select { |line| line[/MOUNTPOINT/i] }
expect(lsblk_line.length).to be(1)
lsblk_line[0].match(/awk '\/(.+)\/ {print \$1}'/).captures[0]
end

describe 'kubelet drain' do

it 'substitutes in the k8s-args.root-dir property for get_k8s_disks()' do
manifest_properties = {
'k8s-args' => {
'root-dir' => '/var/vcap/data/kubelet'
}
}

rendered_drain = compiled_template('kubelet', 'bin/drain', manifest_properties, {}, {}, nil, nil, nil)
k8s_disks_dir = get_k8s_disks_dir(rendered_drain)
expect(k8s_disks_dir).to eq(manifest_properties['k8s-args']['root-dir'].gsub("/", "\\/"))
end

it 'uses /var/lib/kubelet for get_k8s_disks() by default' do
rendered_drain = compiled_template('kubelet', 'bin/drain', {}, {}, {}, nil, nil, nil)
k8s_disks_dir = get_k8s_disks_dir(rendered_drain)
expect(k8s_disks_dir).to eq("/var/lib/kubelet".gsub("/", "\\/"))
end
end

0 comments on commit e7374cf

Please sign in to comment.