Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
5470f02c
Commit
5470f02c
authored
Apr 04, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for tracks
parent
83b6714d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
38 deletions
+112
-38
lib/gitlab/kubernetes/deployment.rb
lib/gitlab/kubernetes/deployment.rb
+3
-3
spec/lib/gitlab/kubernetes/deployment_spec.rb
spec/lib/gitlab/kubernetes/deployment_spec.rb
+58
-17
spec/lib/gitlab/kubernetes/rollout_status_spec.rb
spec/lib/gitlab/kubernetes/rollout_status_spec.rb
+46
-16
spec/support/kubernetes_helpers.rb
spec/support/kubernetes_helpers.rb
+5
-2
No files found.
lib/gitlab/kubernetes/deployment.rb
View file @
5470f02c
...
...
@@ -10,15 +10,15 @@ module Gitlab
end
def
labels
metadata
[
'labels'
]
metadata
.
fetch
(
'labels'
,
{})
end
def
track
labels
.
fetch
(
'track'
,
'stable'
)
labels
.
fetch
(
'track'
)
||
'stable'
end
def
stable?
track
.
nil?
||
track
==
'stable'
track
==
'stable'
end
def
outdated?
...
...
spec/lib/gitlab/kubernetes/deployment_spec.rb
View file @
5470f02c
...
...
@@ -5,60 +5,70 @@ describe Gitlab::Kubernetes::Deployment do
describe
'#name'
do
let
(
:params
)
{
named
(
:selected
)
}
it
{
expect
(
deployment
.
name
).
to
eq
(
:selected
)
}
end
describe
'#labels'
do
let
(
:params
)
{
make
(
'metadata'
,
'labels'
=>
:selected
)
}
it
{
expect
(
deployment
.
labels
).
to
eq
(
:selected
)
}
end
describe
'#outdated?'
do
context
'when outdated'
do
let
(
:params
)
{
generation
(
2
,
1
)
}
it
{
expect
(
deployment
.
outdated?
).
to
be_truthy
}
end
context
'when up to date'
do
let
(
:params
)
{
generation
(
2
,
2
)
}
it
{
expect
(
deployment
.
outdated?
).
to
be_falsy
}
end
context
'when ahead of latest'
do
let
(
:params
)
{
generation
(
1
,
2
)
}
it
{
expect
(
deployment
.
outdated?
).
to
be_falsy
}
end
end
describe
'#wanted_replicas'
do
let
(
:params
)
{
make
(
'spec'
,
'replicas'
=>
:selected
)
}
it
{
expect
(
deployment
.
wanted_replicas
).
to
eq
(
:selected
)
}
end
describe
'#finished_replicas'
do
let
(
:params
)
{
make
(
'status'
,
'availableReplicas'
=>
:selected
)
}
it
{
expect
(
deployment
.
finished_replicas
).
to
eq
(
:selected
)
}
end
describe
'#deploying_replicas'
do
let
(
:params
)
{
make
(
'status'
,
'availableReplicas'
=>
2
,
'updatedReplicas'
=>
4
)
}
it
{
expect
(
deployment
.
deploying_replicas
).
to
eq
(
2
)
}
end
describe
'#waiting_replicas'
do
let
(
:params
)
{
combine
(
make
(
'spec'
,
'replicas'
=>
4
),
make
(
'status'
,
'updatedReplicas'
=>
2
))
}
it
{
expect
(
deployment
.
waiting_replicas
).
to
eq
(
2
)
}
end
describe
'#instances'
do
context
'when unnamed'
do
let
(
:params
)
{
combine
(
generation
(
1
,
1
),
instances
)
}
it
'returns all instances as unknown and waiting'
do
expected
=
[
{
status:
'waiting'
,
tooltip:
'unknown (pod 0) Waiting'
},
{
status:
'waiting'
,
tooltip:
'unknown (pod 1) Waiting'
},
{
status:
'waiting'
,
tooltip:
'unknown (pod 2) Waiting'
},
{
status:
'waiting'
,
tooltip:
'unknown (pod 3) Waiting'
},
{
status:
'waiting'
,
tooltip:
'unknown (pod 0) Waiting'
,
track:
'stable'
,
stable:
true
},
{
status:
'waiting'
,
tooltip:
'unknown (pod 1) Waiting'
,
track:
'stable'
,
stable:
true
},
{
status:
'waiting'
,
tooltip:
'unknown (pod 2) Waiting'
,
track:
'stable'
,
stable:
true
},
{
status:
'waiting'
,
tooltip:
'unknown (pod 3) Waiting'
,
track:
'stable'
,
stable:
true
},
]
expect
(
deployment
.
instances
).
to
eq
(
expected
)
...
...
@@ -67,12 +77,13 @@ describe Gitlab::Kubernetes::Deployment do
context
'when outdated'
do
let
(
:params
)
{
combine
(
named
(
'foo'
),
generation
(
1
,
0
),
instances
)
}
it
'returns all instances as named and waiting'
do
expected
=
[
{
status:
'waiting'
,
tooltip:
'foo (pod 0) Waiting'
},
{
status:
'waiting'
,
tooltip:
'foo (pod 1) Waiting'
},
{
status:
'waiting'
,
tooltip:
'foo (pod 2) Waiting'
},
{
status:
'waiting'
,
tooltip:
'foo (pod 3) Waiting'
},
{
status:
'waiting'
,
tooltip:
'foo (pod 0) Waiting'
,
track:
'stable'
,
stable:
true
},
{
status:
'waiting'
,
tooltip:
'foo (pod 1) Waiting'
,
track:
'stable'
,
stable:
true
},
{
status:
'waiting'
,
tooltip:
'foo (pod 2) Waiting'
,
track:
'stable'
,
stable:
true
},
{
status:
'waiting'
,
tooltip:
'foo (pod 3) Waiting'
,
track:
'stable'
,
stable:
true
},
]
expect
(
deployment
.
instances
).
to
eq
(
expected
)
...
...
@@ -84,15 +95,44 @@ describe Gitlab::Kubernetes::Deployment do
it
'returns all instances'
do
expected
=
[
{
status:
'finished'
,
tooltip:
'foo (pod 0) Finished'
},
{
status:
'deploying'
,
tooltip:
'foo (pod 1) Deploying'
},
{
status:
'waiting'
,
tooltip:
'foo (pod 2) Waiting'
},
{
status:
'waiting'
,
tooltip:
'foo (pod 3) Waiting'
},
{
status:
'finished'
,
tooltip:
'foo (pod 0) Finished'
,
track:
'stable'
,
stable:
true
},
{
status:
'deploying'
,
tooltip:
'foo (pod 1) Deploying'
,
track:
'stable'
,
stable:
true
},
{
status:
'waiting'
,
tooltip:
'foo (pod 2) Waiting'
,
track:
'stable'
,
stable:
true
},
{
status:
'waiting'
,
tooltip:
'foo (pod 3) Waiting'
,
track:
'stable'
,
stable:
true
},
]
expect
(
deployment
.
instances
).
to
eq
(
expected
)
end
end
context
'with track label'
do
let
(
:labels
)
{
{
'track'
=>
track
}
}
let
(
:params
)
{
combine
(
named
(
'foo'
),
generation
(
1
,
0
),
instances
(
1
,
1
,
1
,
labels
))
}
context
'when marked as stable'
do
let
(
:track
)
{
'stable'
}
it
'returns all instances'
do
expected
=
[
{
status:
'waiting'
,
tooltip:
'foo (pod 0) Waiting'
,
track:
'stable'
,
stable:
true
},
]
expect
(
deployment
.
instances
).
to
eq
(
expected
)
end
end
context
'when marked as canary'
do
let
(
:track
)
{
'canary'
}
it
'returns all instances'
do
expected
=
[
{
status:
'waiting'
,
tooltip:
'foo (pod 0) Waiting'
,
track:
'canary'
,
stable:
false
},
]
expect
(
deployment
.
instances
).
to
eq
(
expected
)
end
end
end
end
def
generation
(
expected
,
observed
)
...
...
@@ -102,14 +142,15 @@ describe Gitlab::Kubernetes::Deployment do
)
end
def
named
(
name
=
"foo"
)
make
(
'metadata'
,
'name'
=>
name
)
def
named
(
name
=
"foo"
,
labels
=
{}
)
make
(
'metadata'
,
'name'
=>
name
,
'labels'
=>
labels
)
end
def
instances
def
instances
(
replicas
=
4
,
available
=
1
,
updated
=
2
,
labels
=
{})
combine
(
make
(
'spec'
,
'replicas'
=>
4
),
make
(
'status'
,
'availableReplicas'
=>
1
,
'updatedReplicas'
=>
2
),
named
(
'foo'
,
labels
),
make
(
'spec'
,
'replicas'
=>
replicas
),
make
(
'status'
,
'availableReplicas'
=>
available
,
'updatedReplicas'
=>
updated
),
)
end
...
...
spec/lib/gitlab/kubernetes/rollout_status_spec.rb
View file @
5470f02c
...
...
@@ -2,16 +2,25 @@ require 'spec_helper'
describe
Gitlab
::
Kubernetes
::
RolloutStatus
do
include
KubernetesHelpers
let
(
:specs_all_finished
)
{
[
kube_deployment
(
name:
'one'
),
kube_deployment
(
name:
'two'
)]
}
let
(
:specs_half_finished
)
do
let
(
:track
)
{
nil
}
let
(
:specs
)
{
specs_all_finished
}
let
(
:specs_none
)
{
[]
}
let
(
:specs_all_finished
)
do
[
kube_deployment
(
name:
'one'
),
kube_deployment
(
name:
'two'
).
deep_merge
(
'status'
=>
{
'availableReplicas'
=>
0
}
)
kube_deployment
(
name:
'two'
,
track:
track
)
]
end
let
(
:specs
)
{
specs_all_finished
}
let
(
:specs_none
)
{
[]
}
let
(
:specs_half_finished
)
do
[
kube_deployment
(
name:
'one'
),
kube_deployment
(
name:
'two'
,
track:
track
)
.
deep_merge
(
'status'
=>
{
'availableReplicas'
=>
0
})
]
end
subject
(
:rollout_status
)
{
described_class
.
from_specs
(
*
specs
)
}
...
...
@@ -24,17 +33,36 @@ describe Gitlab::Kubernetes::RolloutStatus do
end
describe
'#instances'
do
it
'stores the union of deployment instances'
do
expected
=
[
{
status:
'finished'
,
tooltip:
'one (pod 0) Finished'
},
{
status:
'finished'
,
tooltip:
'one (pod 1) Finished'
},
{
status:
'finished'
,
tooltip:
'one (pod 2) Finished'
},
{
status:
'finished'
,
tooltip:
'two (pod 0) Finished'
},
{
status:
'finished'
,
tooltip:
'two (pod 1) Finished'
},
{
status:
'finished'
,
tooltip:
'two (pod 2) Finished'
},
]
expect
(
rollout_status
.
instances
).
to
eq
(
expected
)
context
'for stable track'
do
it
'stores the union of deployment instances'
do
expected
=
[
{
status:
'finished'
,
tooltip:
'one (pod 0) Finished'
,
track:
'stable'
,
stable:
true
},
{
status:
'finished'
,
tooltip:
'one (pod 1) Finished'
,
track:
'stable'
,
stable:
true
},
{
status:
'finished'
,
tooltip:
'one (pod 2) Finished'
,
track:
'stable'
,
stable:
true
},
{
status:
'finished'
,
tooltip:
'two (pod 0) Finished'
,
track:
'stable'
,
stable:
true
},
{
status:
'finished'
,
tooltip:
'two (pod 1) Finished'
,
track:
'stable'
,
stable:
true
},
{
status:
'finished'
,
tooltip:
'two (pod 2) Finished'
,
track:
'stable'
,
stable:
true
},
]
expect
(
rollout_status
.
instances
).
to
eq
(
expected
)
end
end
context
'for stable track'
do
let
(
:track
)
{
'canary'
}
it
'stores the union of deployment instances'
do
expected
=
[
{
status:
'finished'
,
tooltip:
'one (pod 0) Finished'
,
track:
'stable'
,
stable:
true
},
{
status:
'finished'
,
tooltip:
'one (pod 1) Finished'
,
track:
'stable'
,
stable:
true
},
{
status:
'finished'
,
tooltip:
'one (pod 2) Finished'
,
track:
'stable'
,
stable:
true
},
{
status:
'finished'
,
tooltip:
'two (pod 0) Finished'
,
track:
'canary'
,
stable:
false
},
{
status:
'finished'
,
tooltip:
'two (pod 1) Finished'
,
track:
'canary'
,
stable:
false
},
{
status:
'finished'
,
tooltip:
'two (pod 2) Finished'
,
track:
'canary'
,
stable:
false
},
]
expect
(
rollout_status
.
instances
).
to
eq
(
expected
)
end
end
end
...
...
@@ -47,6 +75,7 @@ describe Gitlab::Kubernetes::RolloutStatus do
context
'when half of the instances are finished'
do
let
(
:specs
)
{
specs_half_finished
}
it
{
is_expected
.
to
eq
(
50
)
}
end
end
...
...
@@ -60,6 +89,7 @@ describe Gitlab::Kubernetes::RolloutStatus do
context
'when half of the instances are finished'
do
let
(
:specs
)
{
specs_half_finished
}
it
{
is_expected
.
to
be_falsy
}
end
end
...
...
spec/support/kubernetes_helpers.rb
View file @
5470f02c
...
...
@@ -85,12 +85,15 @@ module KubernetesHelpers
}
end
def
kube_deployment
(
name:
"kube-deployment"
,
app:
"valid-deployment-label"
)
def
kube_deployment
(
name:
"kube-deployment"
,
app:
"valid-deployment-label"
,
track:
nil
)
{
"metadata"
=>
{
"name"
=>
name
,
"generation"
=>
4
,
"labels"
=>
{
"app"
=>
app
},
"labels"
=>
{
"app"
=>
app
,
"track"
=>
track
},
},
"spec"
=>
{
"replicas"
=>
3
},
"status"
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment