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:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-04-13 15:15:20 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-04-13 15:15:20 +0300
commit944a3a7b7e19354abdfcaa79129d0736c4b8565f (patch)
tree627802e84525946f11fdd6976ab5f04fb69e702c /tooling
parent62798ed33c878f936009da05fdddb707e1c7d58d (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'tooling')
-rw-r--r--tooling/lib/tooling/kubernetes_client.rb39
1 files changed, 2 insertions, 37 deletions
diff --git a/tooling/lib/tooling/kubernetes_client.rb b/tooling/lib/tooling/kubernetes_client.rb
index b373f5d6980..5579f130a84 100644
--- a/tooling/lib/tooling/kubernetes_client.rb
+++ b/tooling/lib/tooling/kubernetes_client.rb
@@ -9,20 +9,6 @@ module Tooling
K8S_ALLOWED_NAMESPACES_REGEX = /^review-(?!apps).+/.freeze
CommandFailedError = Class.new(StandardError)
- def cleanup_pvcs_by_created_at(created_before:)
- stale_pvcs = pvcs_created_before(created_before: created_before)
-
- # `kubectl` doesn't allow us to filter namespaces with a regexp. We therefore do the filtering in Ruby.
- review_apps_stale_pvcs = stale_pvcs.select do |stale_pvc_hash|
- K8S_ALLOWED_NAMESPACES_REGEX.match?(stale_pvc_hash[:namespace])
- end
- return if review_apps_stale_pvcs.empty?
-
- review_apps_stale_pvcs.each do |pvc_hash|
- delete_pvc(pvc_hash[:resource_name], pvc_hash[:namespace])
- end
- end
-
def cleanup_namespaces_by_created_at(created_before:)
stale_namespaces = namespaces_created_before(created_before: created_before)
@@ -33,12 +19,6 @@ module Tooling
delete_namespaces(review_apps_stale_namespaces)
end
- def delete_pvc(pvc, namespace)
- return unless K8S_ALLOWED_NAMESPACES_REGEX.match?(namespace)
-
- run_command("kubectl delete pvc --namespace=#{namespace} --now --ignore-not-found #{pvc}")
- end
-
def delete_namespaces(namespaces)
return if namespaces.any? { |ns| !K8S_ALLOWED_NAMESPACES_REGEX.match?(ns) }
@@ -58,29 +38,14 @@ module Tooling
run_command(command)
end
- def pvcs_created_before(created_before:)
- resource_created_before(resource_type: 'pvc', created_before: created_before) do |item|
- {
- resource_name: item.dig('metadata', 'name'),
- namespace: item.dig('metadata', 'namespace')
- }
- end
- end
-
def namespaces_created_before(created_before:)
- resource_created_before(resource_type: 'namespace', created_before: created_before) do |item|
- item.dig('metadata', 'name')
- end
- end
-
- def resource_created_before(resource_type:, created_before:)
- response = run_command("kubectl get #{resource_type} --all-namespaces --sort-by='{.metadata.creationTimestamp}' -o json")
+ response = run_command("kubectl get namespace --all-namespaces --sort-by='{.metadata.creationTimestamp}' -o json")
items = JSON.parse(response)['items'] # rubocop:disable Gitlab/Json
items.filter_map do |item|
item_created_at = Time.parse(item.dig('metadata', 'creationTimestamp'))
- yield item if item_created_at < created_before
+ item.dig('metadata', 'name') if item_created_at < created_before
end
rescue ::JSON::ParserError => ex
puts "Ignoring this JSON parsing error: #{ex}\n\nResponse was:\n#{response}"