Commit c234e731 authored by James Fargher's avatar James Fargher

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
parent 1a25ad3e
...@@ -75,11 +75,13 @@ class MigrateK8sServiceIntegration < ActiveRecord::Migration[5.1] ...@@ -75,11 +75,13 @@ class MigrateK8sServiceIntegration < ActiveRecord::Migration[5.1]
end end
def up def up
has_instance_cluster = Cluster.instance_type.where(enabled: true).exists?
MigrateK8sServiceIntegration::Service.kubernetes_service_templates.find_each do |service| MigrateK8sServiceIntegration::Service.kubernetes_service_templates.find_each do |service|
next unless service.api_url && service.token next unless service.api_url && service.token
MigrateK8sServiceIntegration::Cluster.create!( MigrateK8sServiceIntegration::Cluster.create!(
enabled: service.active, enabled: !has_instance_cluster && service.active,
managed: false, managed: false,
name: 'KubernetesService', name: 'KubernetesService',
cluster_type: 'instance_type', cluster_type: 'instance_type',
......
...@@ -104,6 +104,43 @@ describe MigrateK8sServiceIntegration, :migration do ...@@ -104,6 +104,43 @@ describe MigrateK8sServiceIntegration, :migration do
expect(platform.token).to eq('token-sample') expect(platform.token).to eq('token-sample')
end end
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 end
context 'non-template service' do context 'non-template service' do
......
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