Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Fargher <proglottis@gmail.com>2019-03-21 11:06:47 +0300
committerRémy Coutable <remy@rymai.me>2019-03-21 11:06:47 +0300
commit01aa1ef77beee21a588f8b6b27bd372fc7ed7c8d (patch)
treeaa7054c30e2b4172d0d0d2b18ec9d09e064f3e92 /lib/gitlab/kubernetes.rb
parent6a0702fe9382c2b3c4a72421054d46821a95c781 (diff)
Update dashboards to additionally use new environment selector
Deploy boards now will check for app.gitlab.com/env and app.gitlab.com/app
Diffstat (limited to 'lib/gitlab/kubernetes.rb')
-rw-r--r--lib/gitlab/kubernetes.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/gitlab/kubernetes.rb b/lib/gitlab/kubernetes.rb
index a9957a85d48..d46b5e3aee3 100644
--- a/lib/gitlab/kubernetes.rb
+++ b/lib/gitlab/kubernetes.rb
@@ -24,6 +24,30 @@ module Gitlab
end
end
+ # Filters an array of pods (as returned by the kubernetes API) by their annotations
+ def filter_by_annotation(items, annotations = {})
+ items.select do |item|
+ metadata = item.fetch("metadata", {})
+ item_annotations = metadata.fetch("annotations", nil)
+ next unless item_annotations
+
+ annotations.all? { |k, v| item_annotations[k.to_s] == v }
+ end
+ end
+
+ # Filters an array of pods (as returned by the kubernetes API) by their project and environment
+ def filter_by_project_environment(items, app, env)
+ pods = filter_by_annotation(items, {
+ 'app.gitlab.com/app' => app,
+ 'app.gitlab.com/env' => env
+ })
+ return pods unless pods.empty?
+
+ filter_by_label(items, {
+ 'app' => env, # deprecated: replaced by app.gitlab.com/env
+ })
+ end
+
# Converts a pod (as returned by the kubernetes API) into a terminal
def terminals_for_pod(api_url, namespace, pod)
metadata = pod.fetch("metadata", {})