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 /spec/tooling/lib
parent62798ed33c878f936009da05fdddb707e1c7d58d (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/tooling/lib')
-rw-r--r--spec/tooling/lib/tooling/kubernetes_client_spec.rb177
1 files changed, 2 insertions, 175 deletions
diff --git a/spec/tooling/lib/tooling/kubernetes_client_spec.rb b/spec/tooling/lib/tooling/kubernetes_client_spec.rb
index 20eb78c2f4f..8d127f1345b 100644
--- a/spec/tooling/lib/tooling/kubernetes_client_spec.rb
+++ b/spec/tooling/lib/tooling/kubernetes_client_spec.rb
@@ -14,88 +14,6 @@ RSpec.describe Tooling::KubernetesClient do
allow(instance).to receive(:run_command)
end
- describe '#cleanup_pvcs_by_created_at' do
- let(:pvc_1_created_at) { three_days_ago }
- let(:pvc_2_created_at) { three_days_ago }
- let(:pvc_1_namespace) { 'review-first-review-app' }
- let(:pvc_2_namespace) { 'review-second-review-app' }
- let(:kubectl_pvcs_json) do
- <<~JSON
- {
- "apiVersion": "v1",
- "items": [
- {
- "apiVersion": "v1",
- "kind": "PersistentVolumeClaim",
- "metadata": {
- "creationTimestamp": "#{pvc_1_created_at.utc.iso8601}",
- "name": "pvc1",
- "namespace": "#{pvc_1_namespace}"
- }
- },
- {
- "apiVersion": "v1",
- "kind": "PersistentVolumeClaim",
- "metadata": {
- "creationTimestamp": "#{pvc_2_created_at.utc.iso8601}",
- "name": "pvc2",
- "namespace": "#{pvc_2_namespace}"
- }
- }
- ]
- }
- JSON
- end
-
- subject { instance.cleanup_pvcs_by_created_at(created_before: two_days_ago) }
-
- before do
- allow(instance).to receive(:run_command).with(
- "kubectl get pvc --all-namespaces --sort-by='{.metadata.creationTimestamp}' -o json"
- ).and_return(kubectl_pvcs_json)
- end
-
- context 'when no pvcs are stale' do
- let(:pvc_1_created_at) { one_day_ago }
- let(:pvc_2_created_at) { one_day_ago }
-
- it 'does not delete any PVC' do
- expect(instance).not_to receive(:run_command).with(/kubectl delete pvc/)
-
- subject
- end
- end
-
- context 'when some pvcs are stale' do
- let(:pvc_1_created_at) { three_days_ago }
- let(:pvc_2_created_at) { three_days_ago }
-
- context 'when some pvcs are not in a review app namespaces' do
- let(:pvc_1_namespace) { 'review-my-review-app' }
- let(:pvc_2_namespace) { 'review-apps' } # This is not a review apps namespace, so we should not delete PVCs inside it
-
- it 'deletes the stale pvcs inside of review-apps namespaces only' do
- expect(instance).to receive(:run_command).with("kubectl delete pvc --namespace=#{pvc_1_namespace} --now --ignore-not-found pvc1")
- expect(instance).not_to receive(:run_command).with(/kubectl delete pvc --namespace=#{pvc_2_namespace}/)
-
- subject
- end
- end
-
- context 'when all pvcs are in review-apps namespaces' do
- let(:pvc_1_namespace) { 'review-my-review-app' }
- let(:pvc_2_namespace) { 'review-another-review-app' }
-
- it 'deletes all of the stale pvcs' do
- expect(instance).to receive(:run_command).with("kubectl delete pvc --namespace=#{pvc_1_namespace} --now --ignore-not-found pvc1")
- expect(instance).to receive(:run_command).with("kubectl delete pvc --namespace=#{pvc_2_namespace} --now --ignore-not-found pvc2")
-
- subject
- end
- end
- end
- end
-
describe '#cleanup_namespaces_by_created_at' do
let(:namespace_1_created_at) { three_days_ago }
let(:namespace_2_created_at) { three_days_ago }
@@ -174,32 +92,6 @@ RSpec.describe Tooling::KubernetesClient do
end
end
- describe '#delete_pvc' do
- let(:pvc_name) { 'my-pvc' }
-
- subject { instance.delete_pvc(pvc_name, pvc_namespace) }
-
- context 'when the namespace is not a review app namespace' do
- let(:pvc_namespace) { 'not-a-review-app-namespace' }
-
- it 'does not delete the pvc' do
- expect(instance).not_to receive(:run_command).with(/kubectl delete pvc/)
-
- subject
- end
- end
-
- context 'when the namespace is a review app namespace' do
- let(:pvc_namespace) { 'review-apple-test' }
-
- it 'deletes the pvc' do
- expect(instance).to receive(:run_command).with("kubectl delete pvc --namespace=#{pvc_namespace} --now --ignore-not-found #{pvc_name}")
-
- subject
- end
- end
- end
-
describe '#delete_namespaces' do
subject { instance.delete_namespaces(namespaces) }
@@ -224,70 +116,11 @@ RSpec.describe Tooling::KubernetesClient do
end
end
- describe '#pvcs_created_before' do
- subject { instance.pvcs_created_before(created_before: two_days_ago) }
-
- let(:pvc_1_created_at) { three_days_ago }
- let(:pvc_2_created_at) { three_days_ago }
- let(:pvc_1_namespace) { 'review-first-review-app' }
- let(:pvc_2_namespace) { 'review-second-review-app' }
- let(:kubectl_pvcs_json) do
- <<~JSON
- {
- "apiVersion": "v1",
- "items": [
- {
- "apiVersion": "v1",
- "kind": "PersistentVolumeClaim",
- "metadata": {
- "creationTimestamp": "#{pvc_1_created_at.utc.iso8601}",
- "name": "pvc1",
- "namespace": "#{pvc_1_namespace}"
- }
- },
- {
- "apiVersion": "v1",
- "kind": "PersistentVolumeClaim",
- "metadata": {
- "creationTimestamp": "#{pvc_2_created_at.utc.iso8601}",
- "name": "pvc2",
- "namespace": "#{pvc_2_namespace}"
- }
- }
- ]
- }
- JSON
- end
-
- it 'calls #resource_created_before with the correct parameters' do
- expect(instance).to receive(:resource_created_before).with(resource_type: 'pvc', created_before: two_days_ago)
-
- subject
- end
-
- it 'returns a hash with two keys' do
- allow(instance).to receive(:run_command).with(
- "kubectl get pvc --all-namespaces --sort-by='{.metadata.creationTimestamp}' -o json"
- ).and_return(kubectl_pvcs_json)
-
- expect(subject).to match_array([
- {
- resource_name: 'pvc1',
- namespace: 'review-first-review-app'
- },
- {
- resource_name: 'pvc2',
- namespace: 'review-second-review-app'
- }
- ])
- end
- end
-
describe '#namespaces_created_before' do
subject { instance.namespaces_created_before(created_before: two_days_ago) }
let(:namespace_1_created_at) { three_days_ago }
- let(:namespace_2_created_at) { three_days_ago }
+ let(:namespace_2_created_at) { one_day_ago }
let(:namespace_1_name) { 'review-first-review-app' }
let(:namespace_2_name) { 'review-second-review-app' }
let(:kubectl_namespaces_json) do
@@ -316,18 +149,12 @@ RSpec.describe Tooling::KubernetesClient do
JSON
end
- it 'calls #resource_created_before with the correct parameters' do
- expect(instance).to receive(:resource_created_before).with(resource_type: 'namespace', created_before: two_days_ago)
-
- subject
- end
-
it 'returns an array of namespaces' do
allow(instance).to receive(:run_command).with(
"kubectl get namespace --all-namespaces --sort-by='{.metadata.creationTimestamp}' -o json"
).and_return(kubectl_namespaces_json)
- expect(subject).to match_array(%w[review-first-review-app review-second-review-app])
+ expect(subject).to match_array(%w[review-first-review-app])
end
end