Commit a6a1afe0 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch...

Merge branch '60500-disable-jit-kubernetes-resource-creation-for-project-level-clusters' into 'master'

Disable JIT Kubernetes resource creation for project level clusters

Closes #60500

See merge request gitlab-org/gitlab-ce!27352
parents 52375ed7 e33ecfde
...@@ -21,7 +21,11 @@ module Clusters ...@@ -21,7 +21,11 @@ module Clusters
private_class_method :projects_with_missing_kubernetes_namespaces_for_cluster private_class_method :projects_with_missing_kubernetes_namespaces_for_cluster
def self.clusters_with_missing_kubernetes_namespaces_for_project(project) def self.clusters_with_missing_kubernetes_namespaces_for_project(project)
project.all_clusters.missing_kubernetes_namespace(project.kubernetes_namespaces) if Feature.enabled?(:ci_preparing_state, default_enabled: true)
project.clusters.missing_kubernetes_namespace(project.kubernetes_namespaces)
else
project.all_clusters.missing_kubernetes_namespace(project.kubernetes_namespaces)
end
end end
private_class_method :clusters_with_missing_kubernetes_namespaces_for_project private_class_method :clusters_with_missing_kubernetes_namespaces_for_project
......
...@@ -5,10 +5,10 @@ class ClusterConfigureWorker ...@@ -5,10 +5,10 @@ class ClusterConfigureWorker
include ClusterQueue include ClusterQueue
def perform(cluster_id) def perform(cluster_id)
return if Feature.enabled?(:ci_preparing_state, default_enabled: true)
Clusters::Cluster.find_by_id(cluster_id).try do |cluster| Clusters::Cluster.find_by_id(cluster_id).try do |cluster|
Clusters::RefreshService.create_or_update_namespaces_for_cluster(cluster) if cluster.project_type? || Feature.disabled?(:ci_preparing_state, default_enabled: true)
Clusters::RefreshService.create_or_update_namespaces_for_cluster(cluster)
end
end end
end end
end end
...@@ -5,8 +5,6 @@ class ClusterProjectConfigureWorker ...@@ -5,8 +5,6 @@ class ClusterProjectConfigureWorker
include ClusterQueue include ClusterQueue
def perform(project_id) def perform(project_id)
return if Feature.enabled?(:ci_preparing_state, default_enabled: true)
project = Project.find(project_id) project = Project.find(project_id)
::Clusters::RefreshService.create_or_update_namespaces_for_project(project) ::Clusters::RefreshService.create_or_update_namespaces_for_project(project)
......
---
title: Disable just-in-time Kubernetes resource creation for project level clusters
merge_request: 27352
author:
type: changed
...@@ -565,7 +565,9 @@ service account of the cluster integration. ...@@ -565,7 +565,9 @@ 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, immediately before the jobs starts. deployment jobs. On project level clusters, this happens when the cluster
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:
......
...@@ -6,7 +6,9 @@ module Gitlab ...@@ -6,7 +6,9 @@ module Gitlab
module Prerequisite module Prerequisite
class KubernetesNamespace < Base class KubernetesNamespace < Base
def unmet? def unmet?
deployment_cluster.present? && kubernetes_namespace.new_record? deployment_cluster.present? &&
!deployment_cluster.project_type? &&
kubernetes_namespace.new_record?
end end
def complete! def complete!
......
...@@ -20,7 +20,7 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do ...@@ -20,7 +20,7 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
let!(:deployment) { create(:deployment, deployable: build) } let!(:deployment) { create(:deployment, deployable: build) }
context 'and a cluster to deploy to' do context 'and a cluster to deploy to' do
let(:cluster) { create(:cluster, projects: [build.project]) } let(:cluster) { create(:cluster, :group) }
before do before do
allow(build.deployment).to receive(:cluster).and_return(cluster) allow(build.deployment).to receive(:cluster).and_return(cluster)
...@@ -33,6 +33,12 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do ...@@ -33,6 +33,12 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
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
...@@ -52,7 +58,7 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do ...@@ -52,7 +58,7 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
subject { described_class.new(build).complete! } subject { described_class.new(build).complete! }
context 'completion is required' do context 'completion is required' do
let(:cluster) { create(:cluster, projects: [build.project]) } let(:cluster) { create(:cluster, :group) }
before do before do
allow(build.deployment).to receive(:cluster).and_return(cluster) allow(build.deployment).to receive(:cluster).and_return(cluster)
......
...@@ -93,14 +93,32 @@ describe Clusters::RefreshService do ...@@ -93,14 +93,32 @@ describe Clusters::RefreshService do
let(:group) { cluster.group } let(:group) { cluster.group }
let(:project) { create(:project, group: group) } let(:project) { create(:project, group: group) }
include_examples 'creates a kubernetes namespace' context 'when ci_preparing_state feature flag is enabled' do
include_examples 'does not create a kubernetes namespace'
context 'when project already has kubernetes namespace' do context 'when project already has kubernetes namespace' do
before do
create(:cluster_kubernetes_namespace, project: project, cluster: cluster)
end
include_examples 'does not create a kubernetes namespace'
end
end
context 'when ci_preparing_state feature flag is disabled' do
before do before do
create(:cluster_kubernetes_namespace, project: project, cluster: cluster) stub_feature_flags(ci_preparing_state: false)
end end
include_examples 'does not create a kubernetes namespace' include_examples 'creates a kubernetes namespace'
context 'when project already has kubernetes namespace' do
before do
create(:cluster_kubernetes_namespace, project: project, cluster: cluster)
end
include_examples 'does not create a kubernetes namespace'
end
end end
end end
end end
......
...@@ -10,25 +10,35 @@ describe ClusterConfigureWorker, '#perform' do ...@@ -10,25 +10,35 @@ describe ClusterConfigureWorker, '#perform' do
stub_feature_flags(ci_preparing_state: ci_preparing_state_enabled) stub_feature_flags(ci_preparing_state: ci_preparing_state_enabled)
end end
context 'when group cluster' do shared_examples 'configured cluster' do
let(:cluster) { create(:cluster, :group, :provided_by_gcp) } it 'creates a namespace' do
let(:group) { cluster.group } expect(Clusters::RefreshService).to receive(:create_or_update_namespaces_for_cluster).with(cluster).once
context 'when group has no projects' do worker.perform(cluster.id)
it 'does not create a namespace' do end
expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).not_to receive(:execute) end
worker.perform(cluster.id) shared_examples 'unconfigured cluster' do
end it 'does not create a namespace' do
expect(Clusters::RefreshService).not_to receive(:create_or_update_namespaces_for_cluster)
worker.perform(cluster.id)
end end
end
context 'group cluster' do
let(:cluster) { create(:cluster, :group, :provided_by_gcp) }
let(:group) { cluster.group }
context 'when group has a project' do context 'when group has a project' do
let!(:project) { create(:project, group: group) } let!(:project) { create(:project, group: group) }
it 'creates a namespace for the project' do it_behaves_like 'configured cluster'
expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute).once
context 'ci_preparing_state feature is enabled' do
let(:ci_preparing_state_enabled) { true }
worker.perform(cluster.id) it_behaves_like 'unconfigured cluster'
end end
end end
...@@ -36,32 +46,26 @@ describe ClusterConfigureWorker, '#perform' do ...@@ -36,32 +46,26 @@ describe ClusterConfigureWorker, '#perform' do
let!(:subgroup) { create(:group, parent: group) } let!(:subgroup) { create(:group, parent: group) }
let!(:project) { create(:project, group: subgroup) } let!(:project) { create(:project, group: subgroup) }
it 'creates a namespace for the project' do it_behaves_like 'configured cluster'
expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute).once
worker.perform(cluster.id) context 'ci_preparing_state feature is enabled' do
let(:ci_preparing_state_enabled) { true }
it_behaves_like 'unconfigured cluster'
end end
end end
end end
context 'when provider type is gcp' do context 'when provider type is gcp' do
let(:cluster) { create(:cluster, :project, :provided_by_gcp) } let!(:cluster) { create(:cluster, :project, :provided_by_gcp) }
it 'configures kubernetes platform' do
expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute)
described_class.new.perform(cluster.id) it_behaves_like 'configured cluster'
end
end end
context 'when provider type is user' do context 'when provider type is user' do
let(:cluster) { create(:cluster, :project, :provided_by_user) } let!(:cluster) { create(:cluster, :project, :provided_by_user) }
it 'configures kubernetes platform' do it_behaves_like 'configured cluster'
expect_any_instance_of(Clusters::Gcp::Kubernetes::CreateOrUpdateNamespaceService).to receive(:execute)
described_class.new.perform(cluster.id)
end
end end
context 'when cluster does not exist' do context 'when cluster does not exist' do
...@@ -71,15 +75,4 @@ describe ClusterConfigureWorker, '#perform' do ...@@ -71,15 +75,4 @@ describe ClusterConfigureWorker, '#perform' do
described_class.new.perform(123) described_class.new.perform(123)
end end
end end
context 'ci_preparing_state feature is enabled' do
let(:cluster) { create(:cluster) }
let(:ci_preparing_state_enabled) { true }
it 'does not configure the cluster' do
expect(Clusters::RefreshService).not_to receive(:create_or_update_namespaces_for_cluster)
described_class.new.perform(cluster.id)
end
end
end end
...@@ -4,18 +4,11 @@ require 'spec_helper' ...@@ -4,18 +4,11 @@ require 'spec_helper'
describe ClusterProjectConfigureWorker, '#perform' do describe ClusterProjectConfigureWorker, '#perform' do
let(:worker) { described_class.new } let(:worker) { described_class.new }
let(:cluster) { create(:cluster, :project) }
context 'ci_preparing_state feature is enabled' do it 'configures the cluster' do
let(:cluster) { create(:cluster) } expect(Clusters::RefreshService).to receive(:create_or_update_namespaces_for_project)
before do described_class.new.perform(cluster.projects.first.id)
stub_feature_flags(ci_preparing_state: true)
end
it 'does not configure the cluster' do
expect(Clusters::RefreshService).not_to receive(:create_or_update_namespaces_for_project)
described_class.new.perform(cluster.id)
end
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