Commit 759dab5b authored by Tiger's avatar Tiger

Add feature flag for build preparing state

The flag is on by default, but allows us to revert back
to the old behaviour if we encounter any problems.
parent 42c6ccd2
......@@ -370,6 +370,8 @@ module Ci
end
def any_unmet_prerequisites?
return false unless Feature.enabled?(:ci_preparing_state, default_enabled: true)
prerequisites.present?
end
......
......@@ -5,6 +5,8 @@ class ClusterConfigureWorker
include ClusterQueue
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::RefreshService.create_or_update_namespaces_for_cluster(cluster)
end
......
......@@ -5,6 +5,8 @@ class ClusterProjectConfigureWorker
include ClusterQueue
def perform(project_id)
return if Feature.enabled?(:ci_preparing_state, default_enabled: true)
project = Project.find(project_id)
::Clusters::RefreshService.create_or_update_namespaces_for_project(project)
......
......@@ -2919,6 +2919,36 @@ describe Ci::Build do
end
end
describe '#any_unmet_prerequisites?' do
let(:build) { create(:ci_build, :created) }
subject { build.any_unmet_prerequisites? }
context 'build has prerequisites' do
before do
allow(build).to receive(:prerequisites).and_return([double])
end
it { is_expected.to be_truthy }
context 'and the ci_preparing_state feature is disabled' do
before do
stub_feature_flags(ci_preparing_state: false)
end
it { is_expected.to be_falsey }
end
end
context 'build does not have prerequisites' do
before do
allow(build).to receive(:prerequisites).and_return([])
end
it { is_expected.to be_falsey }
end
end
describe '#yaml_variables' do
let(:build) { create(:ci_build, pipeline: pipeline, yaml_variables: variables) }
......
......@@ -331,7 +331,6 @@ describe API::ProjectClusters do
it 'should update cluster attributes' do
expect(cluster.platform_kubernetes.namespace).to eq('new-namespace')
expect(cluster.kubernetes_namespace.namespace).to eq('new-namespace')
end
end
......
......@@ -276,6 +276,7 @@ describe Projects::CreateService, '#execute' do
before do
group.add_owner(user)
stub_feature_flags(ci_preparing_state: false)
expect(Clusters::Gcp::Kubernetes::CreateOrUpdateServiceAccountService).to receive(:namespace_creator).and_return(service_account_creator)
expect(Clusters::Gcp::Kubernetes::FetchKubernetesTokenService).to receive(:new).and_return(secrets_fetcher)
end
......
......@@ -83,6 +83,7 @@ describe Projects::TransferService do
subject { transfer_project(project, user, group) }
before do
stub_feature_flags(ci_preparing_state: false)
expect(Clusters::Gcp::Kubernetes::CreateOrUpdateServiceAccountService).to receive(:namespace_creator).and_return(service_account_creator)
expect(Clusters::Gcp::Kubernetes::FetchKubernetesTokenService).to receive(:new).and_return(secrets_fetcher)
end
......
......@@ -4,6 +4,11 @@ require 'spec_helper'
describe ClusterConfigureWorker, '#perform' do
let(:worker) { described_class.new }
let(:ci_preparing_state_enabled) { false }
before do
stub_feature_flags(ci_preparing_state: ci_preparing_state_enabled)
end
context 'when group cluster' do
let(:cluster) { create(:cluster, :group, :provided_by_gcp) }
......@@ -66,4 +71,15 @@ describe ClusterConfigureWorker, '#perform' do
described_class.new.perform(123)
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
# frozen_string_literal: true
require 'spec_helper'
describe ClusterProjectConfigureWorker, '#perform' do
let(:worker) { described_class.new }
context 'ci_preparing_state feature is enabled' do
let(:cluster) { create(:cluster) }
before do
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
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