Commit f6ff32d9 authored by Thong Kuah's avatar Thong Kuah

Port Helm::Api EE extensions to CE

We will need these utility level code in the future to help upgrade all
helm applications.
parent f03eb233
...@@ -17,6 +17,12 @@ module Gitlab ...@@ -17,6 +17,12 @@ module Gitlab
kubeclient.create_pod(command.pod_resource) kubeclient.create_pod(command.pod_resource)
end end
def update(command)
namespace.ensure_exists!
update_config_map(command)
kubeclient.create_pod(command.pod_resource)
end
## ##
# Returns Pod phase # Returns Pod phase
# #
...@@ -36,6 +42,12 @@ module Gitlab ...@@ -36,6 +42,12 @@ module Gitlab
kubeclient.delete_pod(pod_name, namespace.name) kubeclient.delete_pod(pod_name, namespace.name)
end end
def get_config_map(config_map_name)
namespace.ensure_exists!
kubeclient.get_config_map(config_map_name, namespace.name)
end
private private
attr_reader :kubeclient, :namespace attr_reader :kubeclient, :namespace
...@@ -46,6 +58,12 @@ module Gitlab ...@@ -46,6 +58,12 @@ module Gitlab
end end
end end
def update_config_map(command)
command.config_map_resource.tap do |config_map_resource|
kubeclient.update_config_map(config_map_resource)
end
end
def create_service_account(command) def create_service_account(command)
command.service_account_resource.tap do |service_account_resource| command.service_account_resource.tap do |service_account_resource|
break unless service_account_resource break unless service_account_resource
......
...@@ -150,6 +150,43 @@ describe Gitlab::Kubernetes::Helm::Api do ...@@ -150,6 +150,43 @@ describe Gitlab::Kubernetes::Helm::Api do
end end
end end
describe '#update' do
let(:rbac) { false }
let(:command) do
Gitlab::Kubernetes::Helm::UpgradeCommand.new(
application_name,
chart: 'chart-name',
files: files,
rbac: rbac
)
end
before do
allow(namespace).to receive(:ensure_exists!).once
allow(client).to receive(:update_config_map).and_return(nil)
allow(client).to receive(:create_pod).and_return(nil)
end
it 'ensures the namespace exists before creating the pod' do
expect(namespace).to receive(:ensure_exists!).once.ordered
expect(client).to receive(:create_pod).once.ordered
subject.update(command)
end
it 'updates the config map on kubeclient when one exists' do
resource = Gitlab::Kubernetes::ConfigMap.new(
application_name, files
).generate
expect(client).to receive(:update_config_map).with(resource).once
subject.update(command)
end
end
describe '#status' do describe '#status' do
let(:phase) { Gitlab::Kubernetes::Pod::RUNNING } let(:phase) { Gitlab::Kubernetes::Pod::RUNNING }
let(:pod) { Kubeclient::Resource.new(status: { phase: phase }) } # partial representation let(:pod) { Kubeclient::Resource.new(status: { phase: phase }) } # partial representation
...@@ -179,4 +216,25 @@ describe Gitlab::Kubernetes::Helm::Api do ...@@ -179,4 +216,25 @@ describe Gitlab::Kubernetes::Helm::Api do
subject.delete_pod!(command.pod_name) subject.delete_pod!(command.pod_name)
end end
end end
describe '#get_config_map' do
before do
allow(namespace).to receive(:ensure_exists!).once
allow(client).to receive(:get_config_map).and_return(nil)
end
it 'ensures the namespace exists before retrieving the config map' do
expect(namespace).to receive(:ensure_exists!).once
subject.get_config_map('example-config-map-name')
end
it 'gets the config map on kubeclient' do
expect(client).to receive(:get_config_map)
.with('example-config-map-name', namespace.name)
.once
subject.get_config_map('example-config-map-name')
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment