1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20190517153211_migrate_k8s_service_integration.rb')
describe MigrateK8sServiceIntegration do
context 'template service' do
context 'with namespace' 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(:cluster) { MigrateK8sServiceIntegration::Cluster.instance_type.last! }
let(:platform) { cluster.platform_kubernetes }
it 'migrates the KubernetesService template to Platform::Kubernetes' do
expect { migrate! }.to change { MigrateK8sServiceIntegration::Cluster.count }.by(1)
expect(cluster).to be_enabled
expect(cluster).to be_user
expect(cluster).not_to be_managed
expect(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
context 'without namespace' do
let!(:service) do
MigrateK8sServiceIntegration::Service.create!(
active: true,
template: true,
category: 'deployment',
type: 'KubernetesService',
properties: "{\"namespace\":\"\",\"api_url\":\"https://sample.kubernetes.com\",\"ca_pem\":\"ca_pem-sample\",\"token\":\"token-sample\"}"
)
end
let(:cluster) { MigrateK8sServiceIntegration::Cluster.instance_type.last! }
let(:platform) { cluster.platform_kubernetes }
it 'migrates the KubernetesService template to Platform::Kubernetes' do
expect { migrate! }.to change { MigrateK8sServiceIntegration::Cluster.count }.by(1)
expect(cluster).to be_enabled
expect(cluster).to be_user
expect(cluster).not_to be_managed
expect(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 be_nil
expect(platform.token).to eq('token-sample')
end
end
context 'with nullified parameters' do
let!(:service) do
MigrateK8sServiceIntegration::Service.create!(
active: true,
template: true,
category: 'deployment',
type: 'KubernetesService',
properties: "{}"
)
end
it 'does not migrate the KubernetesService' do
expect { migrate! }.not_to change { MigrateK8sServiceIntegration::Cluster.count }
end
end
context 'when disabled' do
let!(:service) do
MigrateK8sServiceIntegration::Service.create!(
active: false,
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(:cluster) { MigrateK8sServiceIntegration::Cluster.instance_type.last! }
let(:platform) { cluster.platform_kubernetes }
it 'migrates the KubernetesService template to Platform::Kubernetes' do
expect { migrate! }.to change { MigrateK8sServiceIntegration::Cluster.count }.by(1)
expect(cluster).not_to be_enabled
expect(cluster).to be_user
expect(cluster).not_to be_managed
expect(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
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
let!(:service) do
MigrateK8sServiceIntegration::Service.create!(
active: true,
template: false,
category: 'deployment',
type: 'KubernetesService',
properties: "{\"namespace\":\"prod\",\"api_url\":\"https://sample.kubernetes.com\",\"ca_pem\":\"ca_pem-sample\",\"token\":\"token-sample\"}"
)
end
it 'does not migrate the KubernetesService' do
expect { migrate! }.not_to change { MigrateK8sServiceIntegration::Cluster.count }
end
end
end
|