diff options
author | Tiger <twatson@gitlab.com> | 2019-06-06 09:45:00 +0300 |
---|---|---|
committer | Tiger <twatson@gitlab.com> | 2019-06-14 03:05:42 +0300 |
commit | 8a8ddec661eb7a4bca740285622bb3f8419732fd (patch) | |
tree | edf3a8cf0a958641aeeed1850f44de2c1969f32f /spec/migrations | |
parent | c6152f3d28fd609600eeea10fbd38202b33af2d9 (diff) |
Migrate project level clusters with no Kubernetes namespace to unmanaged
These clusters were created before we introduced the
option to manage your own cluster, and not having a
Kubernetes namespace present means that we have tried
and failed to create one - and therefore we cannot manage
your cluster for you.
The 5 minute window should prevent a race condition
where a cluster has only just been created and we
haven't had a chance to create any resources for it
yet.
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/migrate_legacy_managed_clusters_to_unmanaged_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/migrations/migrate_legacy_managed_clusters_to_unmanaged_spec.rb b/spec/migrations/migrate_legacy_managed_clusters_to_unmanaged_spec.rb new file mode 100644 index 00000000000..93426f1f273 --- /dev/null +++ b/spec/migrations/migrate_legacy_managed_clusters_to_unmanaged_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20190606163724_migrate_legacy_managed_clusters_to_unmanaged.rb') + +describe MigrateLegacyManagedClustersToUnmanaged, :migration do + let(:cluster_type) { 'project_type' } + let(:created_at) { 1.hour.ago } + + let!(:cluster) do + table(:clusters).create!( + name: 'cluster', + cluster_type: described_class::Cluster.cluster_types[cluster_type], + managed: true, + created_at: created_at + ) + end + + it 'marks the cluster as unmanaged' do + migrate! + expect(cluster.reload).not_to be_managed + end + + context 'cluster is not project type' do + let(:cluster_type) { 'group_type' } + + it 'does not update the cluster' do + migrate! + expect(cluster.reload).to be_managed + end + end + + context 'cluster has a kubernetes namespace associated' do + before do + table(:clusters_kubernetes_namespaces).create!( + cluster_id: cluster.id, + namespace: 'namespace' + ) + end + + it 'does not update the cluster' do + migrate! + expect(cluster.reload).to be_managed + end + end + + context 'cluster was recently created' do + let(:created_at) { 2.minutes.ago } + + it 'does not update the cluster' do + migrate! + expect(cluster.reload).to be_managed + end + end +end |