Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3223d9bc
Commit
3223d9bc
authored
Dec 14, 2018
by
Maciej Borsz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
In CreateTestingNS generate name upfront to avoid namespace leakage.
parent
1c04caa0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
3 deletions
+30
-3
util.go
test/e2e/framework/util.go
+30
-3
No files found.
test/e2e/framework/util.go
View file @
3223d9bc
...
@@ -1052,6 +1052,25 @@ func WaitForPersistentVolumeClaimsPhase(phase v1.PersistentVolumeClaimPhase, c c
...
@@ -1052,6 +1052,25 @@ func WaitForPersistentVolumeClaimsPhase(phase v1.PersistentVolumeClaimPhase, c c
return
fmt
.
Errorf
(
"PersistentVolumeClaims %v not all in phase %s within %v"
,
pvcNames
,
phase
,
timeout
)
return
fmt
.
Errorf
(
"PersistentVolumeClaims %v not all in phase %s within %v"
,
pvcNames
,
phase
,
timeout
)
}
}
// findAvailableNamespaceName random namespace name starting with baseName.
func
findAvailableNamespaceName
(
baseName
string
,
c
clientset
.
Interface
)
(
string
,
error
)
{
var
name
string
err
:=
wait
.
PollImmediate
(
Poll
,
30
*
time
.
Second
,
func
()
(
bool
,
error
)
{
name
=
fmt
.
Sprintf
(
"%v-%v"
,
baseName
,
randomSuffix
())
_
,
err
:=
c
.
CoreV1
()
.
Namespaces
()
.
Get
(
name
,
metav1
.
GetOptions
{})
if
err
==
nil
{
// Already taken
return
false
,
nil
}
if
apierrs
.
IsNotFound
(
err
)
{
return
true
,
nil
}
Logf
(
"Unexpected error while getting namespace: %v"
,
err
)
return
false
,
nil
})
return
name
,
err
}
// CreateTestingNS should be used by every test, note that we append a common prefix to the provided test name.
// CreateTestingNS should be used by every test, note that we append a common prefix to the provided test name.
// Please see NewFramework instead of using this directly.
// Please see NewFramework instead of using this directly.
func
CreateTestingNS
(
baseName
string
,
c
clientset
.
Interface
,
labels
map
[
string
]
string
)
(
*
v1
.
Namespace
,
error
)
{
func
CreateTestingNS
(
baseName
string
,
c
clientset
.
Interface
,
labels
map
[
string
]
string
)
(
*
v1
.
Namespace
,
error
)
{
...
@@ -1060,11 +1079,19 @@ func CreateTestingNS(baseName string, c clientset.Interface, labels map[string]s
...
@@ -1060,11 +1079,19 @@ func CreateTestingNS(baseName string, c clientset.Interface, labels map[string]s
}
}
labels
[
"e2e-run"
]
=
string
(
RunId
)
labels
[
"e2e-run"
]
=
string
(
RunId
)
// We don't use ObjectMeta.GenerateName feature, as in case of API call
// failure we don't know whether the namespace was created and what is its
// name.
name
,
err
:=
findAvailableNamespaceName
(
baseName
,
c
)
if
err
!=
nil
{
return
nil
,
err
}
namespaceObj
:=
&
v1
.
Namespace
{
namespaceObj
:=
&
v1
.
Namespace
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
GenerateName
:
fmt
.
Sprintf
(
"e2e-tests-%v-"
,
baseName
)
,
Name
:
name
,
Namespace
:
""
,
Namespace
:
""
,
Labels
:
labels
,
Labels
:
labels
,
},
},
Status
:
v1
.
NamespaceStatus
{},
Status
:
v1
.
NamespaceStatus
{},
}
}
...
...
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