summaryrefslogtreecommitdiff
path: root/lib/quality/helm_client.rb
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2018-09-25 16:32:53 +0200
committerRémy Coutable <remy@rymai.me>2018-09-25 16:41:27 +0200
commit3299680cdd084746f85bcb662523ed6bfe2030f2 (patch)
tree97fe04bd6ed9f792dcebc2a28223b1c9f57c4aca /lib/quality/helm_client.rb
parentcb0f024cd4c4aa51c7824e4e1a6c4d0f307afad1 (diff)
downloadgitlab-ce-ce-improve-review-apps.tar.gz
[CE] Port review apps file to CEce-improve-review-apps
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/quality/helm_client.rb')
-rw-r--r--lib/quality/helm_client.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/quality/helm_client.rb b/lib/quality/helm_client.rb
new file mode 100644
index 00000000000..49d953da681
--- /dev/null
+++ b/lib/quality/helm_client.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'time'
+require_relative '../gitlab/popen' unless defined?(Gitlab::Popen)
+
+module Quality
+ class HelmClient
+ attr_reader :namespace
+
+ Release = Struct.new(:name, :revision, :last_update, :status, :chart, :namespace) do
+ def revision
+ @revision ||= self[:revision].to_i
+ end
+
+ def last_update
+ @last_update ||= Time.parse(self[:last_update])
+ end
+ end
+
+ def initialize(namespace: ENV['KUBE_NAMESPACE'])
+ @namespace = namespace
+ end
+
+ def releases(args: [])
+ command = ['list', %(--namespace "#{namespace}"), *args]
+
+ run_command(command)
+ .stdout
+ .lines
+ .select { |line| line.include?(namespace) }
+ .map { |line| Release.new(*line.split(/\t/).map(&:strip)) }
+ end
+
+ def delete(release_name:)
+ run_command(['delete', '--purge', release_name])
+ end
+
+ private
+
+ def run_command(command)
+ final_command = ['helm', *command].join(' ')
+ puts "Running command: `#{final_command}`" # rubocop:disable Rails/Output
+
+ Gitlab::Popen.popen_with_detail([final_command])
+ end
+ end
+end