Commit 74702f0e authored by Tiger's avatar Tiger

Enable project-level JIT resource creation

Previously this behaviour was only available to group
and instance-level clusters, as some project clusters
relied on Kubernetes credentials being passed through
to the runner instead of having their resources managed
by GitLab (which is not available when using JIT). These
clusters have been migrated to unmanaged, so resources
can be created on demand for the remaining managed clusters.
parent db9ef692
...@@ -47,7 +47,6 @@ module Clusters ...@@ -47,7 +47,6 @@ module Clusters
validate :prevent_modification, on: :update validate :prevent_modification, on: :update
after_save :clear_reactive_cache! after_save :clear_reactive_cache!
after_update :update_kubernetes_namespace
alias_attribute :ca_pem, :ca_cert alias_attribute :ca_pem, :ca_cert
...@@ -223,14 +222,6 @@ module Clusters ...@@ -223,14 +222,6 @@ module Clusters
true true
end end
def update_kubernetes_namespace
return unless saved_change_to_namespace?
run_after_commit do
ClusterConfigureWorker.perform_async(cluster_id)
end
end
end end
end end
end end
...@@ -12,9 +12,6 @@ module Clusters ...@@ -12,9 +12,6 @@ module Clusters
create_gitlab_service_account! create_gitlab_service_account!
configure_kubernetes configure_kubernetes
cluster.save! cluster.save!
ClusterConfigureWorker.perform_async(cluster.id)
rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e rescue Google::Apis::ServerError, Google::Apis::ClientError, Google::Apis::AuthorizationError => e
log_service_error(e.class.name, provider.id, e.message) log_service_error(e.class.name, provider.id, e.message)
provider.make_errored!(s_('ClusterIntegration|Failed to request to Google Cloud Platform: %{message}') % { message: e.message }) provider.make_errored!(s_('ClusterIntegration|Failed to request to Google Cloud Platform: %{message}') % { message: e.message })
......
...@@ -9,8 +9,6 @@ class ClusterProvisionWorker ...@@ -9,8 +9,6 @@ class ClusterProvisionWorker
cluster.provider.try do |provider| cluster.provider.try do |provider|
Clusters::Gcp::ProvisionService.new.execute(provider) if cluster.gcp? Clusters::Gcp::ProvisionService.new.execute(provider) if cluster.gcp?
end end
ClusterConfigureWorker.perform_async(cluster.id) if cluster.user?
end end
end end
end end
---
title: Enable just-in-time Kubernetes resource creation for project-level clusters
merge_request: 29515
author:
type: changed
...@@ -518,9 +518,7 @@ service account of the cluster integration. ...@@ -518,9 +518,7 @@ service account of the cluster integration.
### Troubleshooting failed deployment jobs ### Troubleshooting failed deployment jobs
GitLab will create a namespace and service account specifically for your GitLab will create a namespace and service account specifically for your
deployment jobs. On project level clusters, this happens when the cluster deployment jobs. This happens immediately before the deployment job starts.
is created. On group level clusters, resources are created immediately
before the deployment job starts.
However, sometimes GitLab can not create them. In such instances, your job will fail with the message: However, sometimes GitLab can not create them. In such instances, your job will fail with the message:
......
...@@ -8,7 +8,6 @@ module Gitlab ...@@ -8,7 +8,6 @@ module Gitlab
def unmet? def unmet?
deployment_cluster.present? && deployment_cluster.present? &&
deployment_cluster.managed? && deployment_cluster.managed? &&
!deployment_cluster.project_type? &&
(kubernetes_namespace.new_record? || kubernetes_namespace.service_account_token.blank?) (kubernetes_namespace.new_record? || kubernetes_namespace.service_account_token.blank?)
end end
......
...@@ -340,7 +340,6 @@ describe Projects::ClustersController do ...@@ -340,7 +340,6 @@ describe Projects::ClustersController do
describe 'security' do describe 'security' do
before do before do
allow(ClusterConfigureWorker).to receive(:perform_async)
stub_kubeclient_get_namespace('https://kubernetes.example.com', namespace: 'my-namespace') stub_kubeclient_get_namespace('https://kubernetes.example.com', namespace: 'my-namespace')
end end
...@@ -438,7 +437,6 @@ describe Projects::ClustersController do ...@@ -438,7 +437,6 @@ describe Projects::ClustersController do
end end
before do before do
allow(ClusterConfigureWorker).to receive(:perform_async)
stub_kubeclient_get_namespace('https://kubernetes.example.com', namespace: 'my-namespace') stub_kubeclient_get_namespace('https://kubernetes.example.com', namespace: 'my-namespace')
end end
......
...@@ -122,7 +122,6 @@ describe 'Gcp Cluster', :js do ...@@ -122,7 +122,6 @@ describe 'Gcp Cluster', :js do
context 'when user changes cluster parameters' do context 'when user changes cluster parameters' do
before do before do
allow(ClusterConfigureWorker).to receive(:perform_async)
fill_in 'cluster_platform_kubernetes_attributes_namespace', with: 'my-namespace' fill_in 'cluster_platform_kubernetes_attributes_namespace', with: 'my-namespace'
page.within('#js-cluster-details') { click_button 'Save changes' } page.within('#js-cluster-details') { click_button 'Save changes' }
end end
......
...@@ -45,12 +45,6 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do ...@@ -45,12 +45,6 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
end end
context 'and cluster is project type' do
let(:cluster) { create(:cluster, :project) }
it { is_expected.to be_falsey }
end
end end
context 'and no cluster to deploy to' do context 'and no cluster to deploy to' do
......
...@@ -510,27 +510,4 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching ...@@ -510,27 +510,4 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
it { is_expected.to include(pods: []) } it { is_expected.to include(pods: []) }
end end
end end
describe '#update_kubernetes_namespace' do
let(:cluster) { create(:cluster, :provided_by_gcp) }
let(:platform) { cluster.platform }
context 'when namespace is updated' do
it 'calls ConfigureWorker' do
expect(ClusterConfigureWorker).to receive(:perform_async).with(cluster.id).once
platform.namespace = 'new-namespace'
platform.save
end
end
context 'when namespace is not updated' do
it 'does not call ConfigureWorker' do
expect(ClusterConfigureWorker).not_to receive(:perform_async)
platform.username = "new-username"
platform.save
end
end
end
end end
...@@ -19,10 +19,6 @@ describe Clusters::Gcp::FinalizeCreationService, '#execute' do ...@@ -19,10 +19,6 @@ describe Clusters::Gcp::FinalizeCreationService, '#execute' do
subject { described_class.new.execute(provider) } subject { described_class.new.execute(provider) }
before do
allow(ClusterConfigureWorker).to receive(:perform_async)
end
shared_examples 'success' do shared_examples 'success' do
it 'configures provider and kubernetes' do it 'configures provider and kubernetes' do
subject subject
...@@ -42,12 +38,6 @@ describe Clusters::Gcp::FinalizeCreationService, '#execute' do ...@@ -42,12 +38,6 @@ describe Clusters::Gcp::FinalizeCreationService, '#execute' do
expect(platform.password).to eq(password) expect(platform.password).to eq(password)
expect(platform.token).to eq(token) expect(platform.token).to eq(token)
end end
it 'calls ClusterConfigureWorker in a ascync fashion' do
expect(ClusterConfigureWorker).to receive(:perform_async).with(cluster.id)
subject
end
end end
shared_examples 'error' do shared_examples 'error' do
......
...@@ -39,7 +39,6 @@ describe Clusters::UpdateService do ...@@ -39,7 +39,6 @@ describe Clusters::UpdateService do
end end
before do before do
allow(ClusterConfigureWorker).to receive(:perform_async)
stub_kubeclient_get_namespace('https://kubernetes.example.com', namespace: 'my-namespace') stub_kubeclient_get_namespace('https://kubernetes.example.com', namespace: 'my-namespace')
end end
......
...@@ -23,18 +23,11 @@ describe ClusterProvisionWorker do ...@@ -23,18 +23,11 @@ describe ClusterProvisionWorker do
described_class.new.perform(cluster.id) described_class.new.perform(cluster.id)
end end
it 'configures kubernetes platform' do
expect(ClusterConfigureWorker).to receive(:perform_async).with(cluster.id)
described_class.new.perform(cluster.id)
end
end end
context 'when cluster does not exist' do context 'when cluster does not exist' do
it 'does not provision a cluster' do it 'does not provision a cluster' do
expect_any_instance_of(Clusters::Gcp::ProvisionService).not_to receive(:execute) expect_any_instance_of(Clusters::Gcp::ProvisionService).not_to receive(:execute)
expect(ClusterConfigureWorker).not_to receive(:perform_async)
described_class.new.perform(123) described_class.new.perform(123)
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