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
b341c4b0
Commit
b341c4b0
authored
Nov 05, 2021
by
Hordur Freyr Yngvason
Committed by
Mayra Cabrera
Nov 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move kubernetes_variables to scoped_variables
parent
876909a2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
42 deletions
+34
-42
app/models/ci/build.rb
app/models/ci/build.rb
+0
-17
app/models/concerns/ci/contextable.rb
app/models/concerns/ci/contextable.rb
+13
-0
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+21
-25
No files found.
app/models/ci/build.rb
View file @
b341c4b0
...
...
@@ -539,7 +539,6 @@ module Ci
.
concat
(
persisted_variables
)
.
concat
(
dependency_proxy_variables
)
.
concat
(
job_jwt_variables
)
.
concat
(
kubernetes_variables
)
.
concat
(
scoped_variables
)
.
concat
(
job_variables
)
.
concat
(
persisted_environment_variables
)
...
...
@@ -1161,22 +1160,6 @@ module Ci
end
end
def
kubernetes_variables
::
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
collection
|
# A cluster deployemnt may also define a KUBECONFIG variable, so to keep existing
# configurations working we shouldn't overwrite it here.
# This check will be removed when Cluster and Agent configurations are
# merged in https://gitlab.com/gitlab-org/gitlab/-/issues/335089
break
collection
if
deployment
&
.
deployment_cluster
template
=
::
Ci
::
GenerateKubeconfigService
.
new
(
self
).
execute
# rubocop: disable CodeReuse/ServiceClass
if
template
.
valid?
collection
.
append
(
key:
'KUBECONFIG'
,
value:
template
.
to_yaml
,
public:
false
,
file:
true
)
end
end
end
def
conditionally_allow_failure!
(
exit_code
)
return
unless
exit_code
...
...
app/models/concerns/ci/contextable.rb
View file @
b341c4b0
...
...
@@ -17,6 +17,7 @@ module Ci
variables
.
concat
(
project
.
predefined_variables
)
variables
.
concat
(
pipeline
.
predefined_variables
)
variables
.
concat
(
runner
.
predefined_variables
)
if
runnable?
&&
runner
variables
.
concat
(
kubernetes_variables
)
variables
.
concat
(
deployment_variables
(
environment:
environment
))
variables
.
concat
(
yaml_variables
)
variables
.
concat
(
user_variables
)
...
...
@@ -88,6 +89,18 @@ module Ci
end
end
def
kubernetes_variables
::
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
tap
do
|
collection
|
# Should get merged with the cluster kubeconfig in deployment_variables, see
# https://gitlab.com/gitlab-org/gitlab/-/issues/335089
template
=
::
Ci
::
GenerateKubeconfigService
.
new
(
self
).
execute
if
template
.
valid?
collection
.
append
(
key:
'KUBECONFIG'
,
value:
template
.
to_yaml
,
public:
false
,
file:
true
)
end
end
end
def
deployment_variables
(
environment
:)
return
[]
unless
environment
...
...
spec/models/ci/build_spec.rb
View file @
b341c4b0
...
...
@@ -3398,31 +3398,6 @@ RSpec.describe Ci::Build do
it
{
is_expected
.
to
include
(
key:
job_variable
.
key
,
value:
job_variable
.
value
,
public:
false
,
masked:
false
)
}
end
describe
'kubernetes variables'
do
let
(
:service
)
{
double
(
execute:
template
)
}
let
(
:template
)
{
double
(
to_yaml:
'example-kubeconfig'
,
valid?:
template_valid
)
}
let
(
:template_valid
)
{
true
}
before
do
allow
(
Ci
::
GenerateKubeconfigService
).
to
receive
(
:new
).
with
(
build
).
and_return
(
service
)
end
it
{
is_expected
.
to
include
(
key:
'KUBECONFIG'
,
value:
'example-kubeconfig'
,
public:
false
,
file:
true
)
}
context
'job is deploying to a cluster'
do
let
(
:deployment
)
{
create
(
:deployment
,
deployment_cluster:
create
(
:deployment_cluster
))
}
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
deployment:
deployment
)
}
it
{
is_expected
.
not_to
include
(
key:
'KUBECONFIG'
,
value:
'example-kubeconfig'
,
public:
false
,
file:
true
)
}
end
context
'generated config is invalid'
do
let
(
:template_valid
)
{
false
}
it
{
is_expected
.
not_to
include
(
key:
'KUBECONFIG'
,
value:
'example-kubeconfig'
,
public:
false
,
file:
true
)
}
end
end
end
describe
'#scoped_variables'
do
...
...
@@ -3631,6 +3606,27 @@ RSpec.describe Ci::Build do
include_examples
"secret CI variables"
end
describe
'#kubernetes_variables'
do
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:service
)
{
double
(
execute:
template
)
}
let
(
:template
)
{
double
(
to_yaml:
'example-kubeconfig'
,
valid?:
template_valid
)
}
let
(
:template_valid
)
{
true
}
subject
{
build
.
kubernetes_variables
}
before
do
allow
(
Ci
::
GenerateKubeconfigService
).
to
receive
(
:new
).
with
(
build
).
and_return
(
service
)
end
it
{
is_expected
.
to
include
(
key:
'KUBECONFIG'
,
value:
'example-kubeconfig'
,
public:
false
,
file:
true
)
}
context
'generated config is invalid'
do
let
(
:template_valid
)
{
false
}
it
{
is_expected
.
not_to
include
(
key:
'KUBECONFIG'
,
value:
'example-kubeconfig'
,
public:
false
,
file:
true
)
}
end
end
describe
'#deployment_variables'
do
let
(
:build
)
{
create
(
:ci_build
,
environment:
environment
)
}
let
(
:environment
)
{
'production'
}
...
...
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