Commit f3e541c0 authored by Hordur Freyr Yngvason's avatar Hordur Freyr Yngvason

Reduce noise in cluster cleanup workers

Reduces failures due to unrecoverable, safe to ignore, "user errors".

See https://gitlab.com/gitlab-org/gitlab/-/issues/342923

Changelog: fixed
parent 4debfa65
......@@ -309,7 +309,7 @@ module Clusters
end
def kubeclient
platform_kubernetes.kubeclient if kubernetes?
platform_kubernetes&.kubeclient if kubernetes?
end
def elastic_stack_adapter
......
......@@ -35,9 +35,11 @@ module Clusters
end
def kubeclient_delete_namespace(kubernetes_namespace)
cluster.kubeclient.delete_namespace(kubernetes_namespace.namespace)
cluster.kubeclient&.delete_namespace(kubernetes_namespace.namespace)
rescue Kubeclient::ResourceNotFoundError
# no-op: nothing to delete
# The resources have already been deleted, possibly on a previous attempt that timed out
rescue Gitlab::UrlBlocker::BlockedUrlError
# User gave an invalid cluster from the start, or deleted the endpoint before this job ran
end
end
end
......
......@@ -16,11 +16,14 @@ module Clusters
def delete_gitlab_service_account
log_event(:deleting_gitlab_service_account)
cluster.kubeclient.delete_service_account(
cluster.kubeclient&.delete_service_account(
::Clusters::Kubernetes::GITLAB_SERVICE_ACCOUNT_NAME,
::Clusters::Kubernetes::GITLAB_SERVICE_ACCOUNT_NAMESPACE
)
rescue Kubeclient::ResourceNotFoundError
# The resources have already been deleted, possibly on a previous attempt that timed out
rescue Gitlab::UrlBlocker::BlockedUrlError
# User gave an invalid cluster from the start, or deleted the endpoint before this job ran
end
end
end
......
......@@ -58,6 +58,19 @@ RSpec.describe Clusters::Cleanup::ProjectNamespaceService do
subject
end
context 'when cluster.kubeclient is nil' do
let(:kubeclient_instance_double) { nil }
it 'schedules ::ServiceAccountWorker' do
expect(Clusters::Cleanup::ServiceAccountWorker).to receive(:perform_async).with(cluster.id)
subject
end
it 'deletes namespaces from database' do
expect { subject }.to change { cluster.kubernetes_namespaces.exists? }.from(true).to(false)
end
end
end
context 'when cluster has no namespaces' do
......
......@@ -44,5 +44,13 @@ RSpec.describe Clusters::Cleanup::ServiceAccountService do
it 'deletes cluster' do
expect { subject }.to change { Clusters::Cluster.where(id: cluster.id).exists? }.from(true).to(false)
end
context 'when cluster.kubeclient is nil' do
let(:kubeclient_instance_double) { nil }
it 'deletes cluster' do
expect { subject }.to change { Clusters::Cluster.where(id: cluster.id).exists? }.from(true).to(false)
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