When an instance cluster already exists migrate disabled

Assume that if an instance level cluster already exists, then the
KubernetesService was not being used, but allow the admin to re-enable
it if required
This commit is contained in:
James Fargher 2019-05-24 09:59:32 +01:00
parent 1a25ad3e57
commit c234e73123
2 changed files with 40 additions and 1 deletions

View File

@ -75,11 +75,13 @@ class MigrateK8sServiceIntegration < ActiveRecord::Migration[5.1]
end
def up
has_instance_cluster = Cluster.instance_type.where(enabled: true).exists?
MigrateK8sServiceIntegration::Service.kubernetes_service_templates.find_each do |service|
next unless service.api_url && service.token
MigrateK8sServiceIntegration::Cluster.create!(
enabled: service.active,
enabled: !has_instance_cluster && service.active,
managed: false,
name: 'KubernetesService',
cluster_type: 'instance_type',

View File

@ -104,6 +104,43 @@ describe MigrateK8sServiceIntegration, :migration do
expect(platform.token).to eq('token-sample')
end
end
context 'when an instance cluster already exists' do
let!(:service) do
MigrateK8sServiceIntegration::Service.create!(
active: true,
template: true,
category: 'deployment',
type: 'KubernetesService',
properties: "{\"namespace\":\"prod\",\"api_url\":\"https://sample.kubernetes.com\",\"ca_pem\":\"ca_pem-sample\",\"token\":\"token-sample\"}"
)
end
let!(:existing_cluster) do
MigrateK8sServiceIntegration::Cluster.create!(
name: 'test-cluster',
cluster_type: :instance_type,
managed: true,
provider_type: :user,
platform_type: :kubernetes
)
end
let(:new_cluster) { MigrateK8sServiceIntegration::Cluster.instance_type.last! }
let(:platform) { new_cluster.platform_kubernetes }
it 'migrates the KubernetesService template to disabled Platform::Kubernetes' do
expect { migrate! }.to change { MigrateK8sServiceIntegration::Cluster.count }.by(1)
expect(new_cluster).not_to be_enabled
expect(new_cluster).to be_user
expect(new_cluster).not_to be_managed
expect(new_cluster.environment_scope).to eq('*')
expect(platform.api_url).to eq('https://sample.kubernetes.com')
expect(platform.ca_cert).to eq('ca_pem-sample')
expect(platform.namespace).to eq('prod')
expect(platform.token).to eq('token-sample')
end
end
end
context 'non-template service' do