Skip to content

Commit

Permalink
Allow additional options for kubectl commands, closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
fabn committed Nov 13, 2019
1 parent c0617ab commit ee7bc09
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ configuration must be deployed. It supports plain branch names and also a regexp
* `services`: YAML array of services to update in Rancher/K8S
* `image`: Docker image used to update services, if not given a name will be built from repo/branch/commit.
* `login_options`: Additional `rancher login` options (e.g. `--skip-verify`)
* `kubectl_options`: optional, string, any additional flags to be passed to the kubectl command

It's advised to customize image name. Remember: you can use ERB in YAML config, so you can set this to something like

Expand Down Expand Up @@ -127,7 +128,6 @@ The plugin accepts the following settings:
* `action`: action to use in plugin, one of `[deploy, tag_check]`
* `enforce_branch_for_tag`: string, a branch name, used in `tag_check` action
* `enforce_head`: boolean any non empty string will be considered as `true`, used in `tag_check` action
* `kubectl_flags`: optional, string, any additional flags to be passed to the kubectl command

## Development

Expand Down
2 changes: 1 addition & 1 deletion lib/rancher_deployer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def deploy!
logger.info "Updating services: #{config['services']} with image '#{image_to_deploy}'"
config['services'].each do |service|
logger.debug "Updating service #{service}"
shell.run("rancher kubectl set image deployment #{service} #{service}=#{image_to_deploy} #{ENV['PLUGIN_KUBECTL_FLAGS']}", '-n', config['namespace'])
shell.run("rancher kubectl set image deployment #{service} #{service}=#{image_to_deploy}#{" #{config['kubectl_options']}" if config['kubectl_options']}", '-n', config['namespace'])
end
end
end
Expand Down
26 changes: 26 additions & 0 deletions spec/deployer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,32 @@
)
subject.deploy!
end

context 'with kubectl options' do
let(:config) do
{
'server_url' => "https://k8s.example.com",
'project' => 'MyCoolProject',
'namespace' => 'backend',
'access_key' => 'access_key',
'secret_key' => 'secret_key',
'services' => %w[web worker],
'kubectl_options' => '--insecure-skip-tls-verify'
}
end

it 'should update individual services' do
expect(shell).to receive(:run).with(
'rancher kubectl set image deployment web web=image:tag --insecure-skip-tls-verify',
'-n', 'backend'
)
expect(shell).to receive(:run).with(
'rancher kubectl set image deployment worker worker=image:tag --insecure-skip-tls-verify',
'-n', 'backend'
)
subject.deploy!
end
end
end
end

Expand Down

0 comments on commit ee7bc09

Please sign in to comment.