BigW Consortium Gitlab

Commit 5ced761e by Filipa Lacerda

Merge branch…

Merge branch 'feature/sm/35954-create-kubernetes-cluster-on-gke-from-k8s-service' of https://gitlab.com/gitlab-org/gitlab-ce into feature/sm/35954-create-kubernetes-cluster-on-gke-from-k8s-service * 'feature/sm/35954-create-kubernetes-cluster-on-gke-from-k8s-service' of https://gitlab.com/gitlab-org/gitlab-ce: Use utc for time comparision
parents f71df9f5 638c6162
...@@ -11,7 +11,7 @@ class WaitForClusterCreationWorker ...@@ -11,7 +11,7 @@ class WaitForClusterCreationWorker
Ci::FetchGcpOperationService.new.execute(cluster) do |operation| Ci::FetchGcpOperationService.new.execute(cluster) do |operation|
case operation.status case operation.status
when 'RUNNING' when 'RUNNING'
if TIMEOUT < Time.zone.now - operation.start_time.to_time if TIMEOUT < Time.now.utc - operation.start_time.to_time.utc
return cluster.make_errored!("Cluster creation time exceeds timeout; #{TIMEOUT}") return cluster.make_errored!("Cluster creation time exceeds timeout; #{TIMEOUT}")
end end
......
...@@ -5,6 +5,7 @@ module GoogleApi ...@@ -5,6 +5,7 @@ module GoogleApi
class Client < GoogleApi::Auth class Client < GoogleApi::Auth
DEFAULT_MACHINE_TYPE = 'n1-standard-1'.freeze DEFAULT_MACHINE_TYPE = 'n1-standard-1'.freeze
SCOPE = 'https://www.googleapis.com/auth/cloud-platform'.freeze SCOPE = 'https://www.googleapis.com/auth/cloud-platform'.freeze
LEAST_TOKEN_LIFE_TIME = 10.minutes
class << self class << self
def session_key_for_token def session_key_for_token
...@@ -25,9 +26,7 @@ module GoogleApi ...@@ -25,9 +26,7 @@ module GoogleApi
return false unless expires_at return false unless expires_at
# Making sure that the token will have been still alive during the cluster creation. # Making sure that the token will have been still alive during the cluster creation.
unless DateTime.strptime(expires_at, '%s').to_time > Time.now + 10.minutes return false if token_life_time(expires_at) < LEAST_TOKEN_LIFE_TIME
return false
end
true true
end end
...@@ -68,6 +67,12 @@ module GoogleApi ...@@ -68,6 +67,12 @@ module GoogleApi
m = self_link.match(%r{projects/.*/zones/.*/operations/(.*)}) m = self_link.match(%r{projects/.*/zones/.*/operations/(.*)})
m[1] if m m[1] if m
end end
private
def token_life_time(expires_at)
DateTime.strptime(expires_at, '%s').to_time.utc - Time.now.utc
end
end end
end end
end end
...@@ -7,7 +7,7 @@ describe GoogleApi::CloudPlatform::Client do ...@@ -7,7 +7,7 @@ describe GoogleApi::CloudPlatform::Client do
describe '#validate_token' do describe '#validate_token' do
subject { client.validate_token(expires_at) } subject { client.validate_token(expires_at) }
let(:expires_at) { 1.hour.since.strftime('%s') } let(:expires_at) { 1.hour.since.utc.strftime('%s') }
context 'when token is nil' do context 'when token is nil' do
let(:token) { nil } let(:token) { nil }
...@@ -26,7 +26,7 @@ describe GoogleApi::CloudPlatform::Client do ...@@ -26,7 +26,7 @@ describe GoogleApi::CloudPlatform::Client do
end end
context 'when expires in 10 minutes' do context 'when expires in 10 minutes' do
let(:expires_at) { 5.minutes.since.strftime('%s') } let(:expires_at) { 5.minutes.since.utc.strftime('%s') }
it { is_expected.to be_falsy } it { is_expected.to be_falsy }
end end
......
...@@ -24,7 +24,7 @@ describe WaitForClusterCreationWorker do ...@@ -24,7 +24,7 @@ describe WaitForClusterCreationWorker do
context 'when operation timeout' do context 'when operation timeout' do
before do before do
allow(operation).to receive(:start_time).and_return(30.minutes.ago) allow(operation).to receive(:start_time).and_return(30.minutes.ago.utc)
end end
it 'sets an error message on cluster' do it 'sets an error message on cluster' 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