summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDylan Griffith <dyl.griffith@gmail.com>2018-02-12 14:22:15 +1100
committerDylan Griffith <dyl.griffith@gmail.com>2018-02-15 17:01:11 +1100
commitc1828eaed56159998d1eaafdaa135f1b3480549b (patch)
tree8cd903c910454bfdbc2bfdb1b1e9709eaa5583f1 /spec
parent5ca692b0b04b4f349fb5a08b9dcc7d87c774934e (diff)
downloadgitlab-ce-c1828eaed56159998d1eaafdaa135f1b3480549b.tar.gz
Persist external IP of ingress controller created for GKE (#42643)
Diffstat (limited to 'spec')
-rw-r--r--spec/fixtures/api/schemas/cluster_status.json3
-rw-r--r--spec/models/clusters/applications/ingress_spec.rb14
-rw-r--r--spec/serializers/cluster_application_entity_spec.rb14
-rw-r--r--spec/services/clusters/applications/check_ingress_ip_address_service_spec.rb81
-rw-r--r--spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb20
5 files changed, 131 insertions, 1 deletions
diff --git a/spec/fixtures/api/schemas/cluster_status.json b/spec/fixtures/api/schemas/cluster_status.json
index 489d563be2b..9617157ee37 100644
--- a/spec/fixtures/api/schemas/cluster_status.json
+++ b/spec/fixtures/api/schemas/cluster_status.json
@@ -30,7 +30,8 @@
]
}
},
- "status_reason": { "type": ["string", "null"] }
+ "status_reason": { "type": ["string", "null"] },
+ "external_ip": { "type": ["string", null] }
},
"required" : [ "name", "status" ]
}
diff --git a/spec/models/clusters/applications/ingress_spec.rb b/spec/models/clusters/applications/ingress_spec.rb
index 619c088b0bf..da9535f9d16 100644
--- a/spec/models/clusters/applications/ingress_spec.rb
+++ b/spec/models/clusters/applications/ingress_spec.rb
@@ -5,4 +5,18 @@ describe Clusters::Applications::Ingress do
it { is_expected.to validate_presence_of(:cluster) }
include_examples 'cluster application specs', described_class
+
+ describe '#post_install' do
+ let(:application) { create(:clusters_applications_ingress, :installed) }
+
+ before do
+ allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in)
+ application.post_install
+ end
+
+ it 'schedules a ClusterWaitForIngressIpAddressWorker' do
+ expect(ClusterWaitForIngressIpAddressWorker).to have_received(:perform_in)
+ .with(ClusterWaitForIngressIpAddressWorker::INTERVAL, 'ingress', application.id, 3)
+ end
+ end
end
diff --git a/spec/serializers/cluster_application_entity_spec.rb b/spec/serializers/cluster_application_entity_spec.rb
index b5a55b4ef6e..70b274083b2 100644
--- a/spec/serializers/cluster_application_entity_spec.rb
+++ b/spec/serializers/cluster_application_entity_spec.rb
@@ -26,5 +26,19 @@ describe ClusterApplicationEntity do
expect(subject[:status_reason]).to eq(application.status_reason)
end
end
+
+ context 'for ingress application' do
+ let(:application) do
+ build(
+ :clusters_applications_ingress,
+ :installed,
+ external_ip: '111.222.111.222',
+ )
+ end
+
+ it 'includes external_ip' do
+ expect(subject[:external_ip]).to eq('111.222.111.222')
+ end
+ end
end
end
diff --git a/spec/services/clusters/applications/check_ingress_ip_address_service_spec.rb b/spec/services/clusters/applications/check_ingress_ip_address_service_spec.rb
new file mode 100644
index 00000000000..5d99196fbe6
--- /dev/null
+++ b/spec/services/clusters/applications/check_ingress_ip_address_service_spec.rb
@@ -0,0 +1,81 @@
+require 'spec_helper'
+
+describe Clusters::Applications::CheckIngressIpAddressService do
+ let(:application) { create(:clusters_applications_ingress, :installed) }
+ let(:service) { described_class.new(application) }
+ let(:kube_service) do
+ ::Kubeclient::Resource.new(
+ {
+ status: {
+ loadBalancer: {
+ ingress: ingress
+ }
+ }
+ }
+ )
+ end
+ let(:kubeclient) { double(::Kubeclient::Client, get_service: kube_service) }
+ let(:ingress) { [{ ip: '111.222.111.222' }] }
+
+ before do
+ allow(application.cluster).to receive(:kubeclient).and_return(kubeclient)
+ end
+
+ describe '#execute' do
+ context 'when the ingress ip address is available' do
+ it 'updates the external_ip for the app and does not schedule another worker' do
+ expect(ClusterWaitForIngressIpAddressWorker).not_to receive(:perform_in)
+
+ service.execute(1)
+
+ expect(application.external_ip).to eq('111.222.111.222')
+ end
+ end
+
+ context 'when the ingress ip address is not available' do
+ let(:ingress) { nil }
+
+ it 'it schedules another worker with 1 less retry' do
+ expect(ClusterWaitForIngressIpAddressWorker)
+ .to receive(:perform_in)
+ .with(ClusterWaitForIngressIpAddressWorker::INTERVAL, 'ingress', application.id, 0)
+
+ service.execute(1)
+ end
+
+ context 'when no more retries remaining' do
+ it 'does not schedule another worker' do
+ expect(ClusterWaitForIngressIpAddressWorker).not_to receive(:perform_in)
+
+ service.execute(0)
+ end
+ end
+ end
+
+ context 'when there is already an external_ip' do
+ let(:application) { create(:clusters_applications_ingress, :installed, external_ip: '001.111.002.111') }
+
+ it 'does nothing' do
+ expect(kubeclient).not_to receive(:get_service)
+
+ service.execute(1)
+
+ expect(application.external_ip).to eq('001.111.002.111')
+ end
+ end
+
+ context 'when a kubernetes error occurs' do
+ before do
+ allow(kubeclient).to receive(:get_service).and_raise(KubeException.new(500, 'something blew up', nil))
+ end
+
+ it 'it schedules another worker with 1 less retry' do
+ expect(ClusterWaitForIngressIpAddressWorker)
+ .to receive(:perform_in)
+ .with(ClusterWaitForIngressIpAddressWorker::INTERVAL, 'ingress', application.id, 0)
+
+ service.execute(1)
+ end
+ end
+ end
+end
diff --git a/spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb b/spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb
new file mode 100644
index 00000000000..9f8bf35f604
--- /dev/null
+++ b/spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe ClusterWaitForIngressIpAddressWorker do
+ describe '#perform' do
+ let(:service) { instance_double(Clusters::Applications::CheckIngressIpAddressService) }
+ let(:application) { instance_double(Clusters::Applications::Ingress) }
+ let(:worker) { described_class.new }
+
+ it 'finds the application and calls CheckIngressIpAddressService#execute' do
+ expect(worker).to receive(:find_application).with('ingress', 117).and_yield(application)
+ expect(Clusters::Applications::CheckIngressIpAddressService)
+ .to receive(:new)
+ .with(application)
+ .and_return(service)
+ expect(service).to receive(:execute).with(2)
+
+ worker.perform('ingress', 117, 2)
+ end
+ end
+end