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
cc5a9b2c
Commit
cc5a9b2c
authored
Jul 28, 2021
by
Hordur Freyr Yngvason
Committed by
Stan Hu
Jul 28, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure default k8s namespace is <= 63 chars
parent
1f56f09a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
21 deletions
+26
-21
lib/gitlab/kubernetes/default_namespace.rb
lib/gitlab/kubernetes/default_namespace.rb
+10
-7
spec/lib/gitlab/kubernetes/default_namespace_spec.rb
spec/lib/gitlab/kubernetes/default_namespace_spec.rb
+16
-14
No files found.
lib/gitlab/kubernetes/default_namespace.rb
View file @
cc5a9b2c
...
...
@@ -36,14 +36,17 @@ module Gitlab
end
end
def
default_project_namespace
(
slug
)
namespace_slug
=
"
#{
project
.
path
}
-
#{
project
.
id
}
"
.
downcase
if
cluster
.
namespace_per_environment?
namespace_slug
+=
"-
#{
slug
}
"
def
default_project_namespace
(
environment_
slug
)
maybe_environment_suffix
=
cluster
.
namespace_per_environment?
?
"-
#{
environment_slug
}
"
:
''
suffix
=
"-
#{
project
.
id
}#{
maybe_environment_suffix
}
"
namespace
=
project_path_slug
(
63
-
suffix
.
length
)
+
suffix
Gitlab
::
NamespaceSanitizer
.
sanitize
(
namespace
)
end
Gitlab
::
NamespaceSanitizer
.
sanitize
(
namespace_slug
)
def
project_path_slug
(
max_length
)
Gitlab
::
NamespaceSanitizer
.
sanitize
(
project
.
path
.
downcase
)
.
first
(
max_length
)
end
##
...
...
spec/lib/gitlab/kubernetes/default_namespace_spec.rb
View file @
cc5a9b2c
...
...
@@ -32,6 +32,14 @@ RSpec.describe Gitlab::Kubernetes::DefaultNamespace do
subject
{
generator
.
from_environment_slug
(
environment
.
slug
)
}
shared_examples_for
'handles very long project paths'
do
before
do
allow
(
project
).
to
receive
(
:path
).
and_return
'x'
*
100
end
it
{
is_expected
.
to
satisfy
{
|
s
|
s
.
length
<=
63
}
}
end
context
'namespace per environment is enabled'
do
context
'platform namespace is specified'
do
let
(
:platform_namespace
)
{
'platform-namespace'
}
...
...
@@ -47,15 +55,12 @@ RSpec.describe Gitlab::Kubernetes::DefaultNamespace do
context
'platform namespace is blank'
do
let
(
:platform_namespace
)
{
nil
}
let
(
:mock_namespace
)
{
'mock-namespace'
}
it
'constructs a namespace from the project and environment'
do
expect
(
Gitlab
::
NamespaceSanitizer
).
to
receive
(
:sanitize
)
.
with
(
"
#{
project
.
path
}
-
#{
project
.
id
}
-
#{
environment
.
slug
}
"
.
downcase
)
.
and_return
(
mock_namespace
)
expect
(
subject
).
to
eq
mock_namespace
it
'constructs a namespace from the project and environment slug'
do
expect
(
subject
).
to
eq
"path-with-capitals-
#{
project
.
id
}
-
#{
environment
.
slug
}
"
end
it_behaves_like
'handles very long project paths'
end
end
...
...
@@ -70,15 +75,12 @@ RSpec.describe Gitlab::Kubernetes::DefaultNamespace do
context
'platform namespace is blank'
do
let
(
:platform_namespace
)
{
nil
}
let
(
:mock_namespace
)
{
'mock-namespace'
}
it
'constructs a namespace from the project and environment'
do
expect
(
Gitlab
::
NamespaceSanitizer
).
to
receive
(
:sanitize
)
.
with
(
"
#{
project
.
path
}
-
#{
project
.
id
}
"
.
downcase
)
.
and_return
(
mock_namespace
)
expect
(
subject
).
to
eq
mock_namespace
it
'constructs a namespace from just the project'
do
expect
(
subject
).
to
eq
"path-with-capitals-
#{
project
.
id
}
"
end
it_behaves_like
'handles very long project paths'
end
end
end
...
...
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