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
7ea612db
Commit
7ea612db
authored
May 17, 2018
by
xuzhonghu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove request context.WithUID
parent
e59ae29f
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
7 additions
and
66 deletions
+7
-66
context.go
...ing/src/k8s.io/apiserver/pkg/endpoints/request/context.go
+0
-27
context_test.go
...rc/k8s.io/apiserver/pkg/endpoints/request/context_test.go
+0
-18
create.go
staging/src/k8s.io/apiserver/pkg/registry/rest/create.go
+1
-1
meta.go
staging/src/k8s.io/apiserver/pkg/registry/rest/meta.go
+2
-8
meta_test.go
staging/src/k8s.io/apiserver/pkg/registry/rest/meta_test.go
+4
-12
No files found.
staging/src/k8s.io/apiserver/pkg/endpoints/request/context.go
View file @
7ea612db
...
@@ -20,7 +20,6 @@ import (
...
@@ -20,7 +20,6 @@ import (
"context"
"context"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apiserver/pkg/apis/audit"
"k8s.io/apiserver/pkg/apis/audit"
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/authentication/user"
)
)
...
@@ -35,12 +34,6 @@ const (
...
@@ -35,12 +34,6 @@ const (
// userKey is the context key for the request user.
// userKey is the context key for the request user.
userKey
userKey
// uidKey is the context key for the uid to assign to an object on create.
uidKey
// userAgentKey is the context key for the request user agent.
userAgentKey
// auditKey is the context key for the audit event.
// auditKey is the context key for the audit event.
auditKey
auditKey
)
)
...
@@ -77,15 +70,6 @@ func NamespaceValue(ctx context.Context) string {
...
@@ -77,15 +70,6 @@ func NamespaceValue(ctx context.Context) string {
return
namespace
return
namespace
}
}
// WithNamespaceDefaultIfNone returns a context whose namespace is the default if and only if the parent context has no namespace value
func
WithNamespaceDefaultIfNone
(
parent
context
.
Context
)
context
.
Context
{
namespace
,
ok
:=
NamespaceFrom
(
parent
)
if
!
ok
||
len
(
namespace
)
==
0
{
return
WithNamespace
(
parent
,
metav1
.
NamespaceDefault
)
}
return
parent
}
// WithUser returns a copy of parent in which the user value is set
// WithUser returns a copy of parent in which the user value is set
func
WithUser
(
parent
context
.
Context
,
user
user
.
Info
)
context
.
Context
{
func
WithUser
(
parent
context
.
Context
,
user
user
.
Info
)
context
.
Context
{
return
WithValue
(
parent
,
userKey
,
user
)
return
WithValue
(
parent
,
userKey
,
user
)
...
@@ -97,17 +81,6 @@ func UserFrom(ctx context.Context) (user.Info, bool) {
...
@@ -97,17 +81,6 @@ func UserFrom(ctx context.Context) (user.Info, bool) {
return
user
,
ok
return
user
,
ok
}
}
// WithUID returns a copy of parent in which the uid value is set
func
WithUID
(
parent
context
.
Context
,
uid
types
.
UID
)
context
.
Context
{
return
WithValue
(
parent
,
uidKey
,
uid
)
}
// UIDFrom returns the value of the uid key on the ctx
func
UIDFrom
(
ctx
context
.
Context
)
(
types
.
UID
,
bool
)
{
uid
,
ok
:=
ctx
.
Value
(
uidKey
)
.
(
types
.
UID
)
return
uid
,
ok
}
// WithAuditEvent returns set audit event struct.
// WithAuditEvent returns set audit event struct.
func
WithAuditEvent
(
parent
context
.
Context
,
ev
*
audit
.
Event
)
context
.
Context
{
func
WithAuditEvent
(
parent
context
.
Context
,
ev
*
audit
.
Event
)
context
.
Context
{
return
WithValue
(
parent
,
auditKey
,
ev
)
return
WithValue
(
parent
,
auditKey
,
ev
)
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/request/context_test.go
View file @
7ea612db
...
@@ -20,7 +20,6 @@ import (
...
@@ -20,7 +20,6 @@ import (
"testing"
"testing"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/authentication/user"
)
)
...
@@ -92,20 +91,3 @@ func TestUserContext(t *testing.T) {
...
@@ -92,20 +91,3 @@ func TestUserContext(t *testing.T) {
}
}
}
}
//TestUIDContext validates that a UID can be get/set on a context object
func
TestUIDContext
(
t
*
testing
.
T
)
{
ctx
:=
NewContext
()
_
,
ok
:=
UIDFrom
(
ctx
)
if
ok
{
t
.
Fatalf
(
"Should not be ok because there is no UID on the context"
)
}
ctx
=
WithUID
(
ctx
,
types
.
UID
(
"testUID"
),
)
_
,
ok
=
UIDFrom
(
ctx
)
if
!
ok
{
t
.
Fatalf
(
"Error getting UID"
)
}
}
staging/src/k8s.io/apiserver/pkg/registry/rest/create.go
View file @
7ea612db
...
@@ -87,7 +87,7 @@ func BeforeCreate(strategy RESTCreateStrategy, ctx context.Context, obj runtime.
...
@@ -87,7 +87,7 @@ func BeforeCreate(strategy RESTCreateStrategy, ctx context.Context, obj runtime.
objectMeta
.
SetDeletionTimestamp
(
nil
)
objectMeta
.
SetDeletionTimestamp
(
nil
)
objectMeta
.
SetDeletionGracePeriodSeconds
(
nil
)
objectMeta
.
SetDeletionGracePeriodSeconds
(
nil
)
strategy
.
PrepareForCreate
(
ctx
,
obj
)
strategy
.
PrepareForCreate
(
ctx
,
obj
)
FillObjectMetaSystemFields
(
ctx
,
objectMeta
)
FillObjectMetaSystemFields
(
objectMeta
)
if
len
(
objectMeta
.
GetGenerateName
())
>
0
&&
len
(
objectMeta
.
GetName
())
==
0
{
if
len
(
objectMeta
.
GetGenerateName
())
>
0
&&
len
(
objectMeta
.
GetName
())
==
0
{
objectMeta
.
SetName
(
strategy
.
GenerateName
(
objectMeta
.
GetGenerateName
()))
objectMeta
.
SetName
(
strategy
.
GenerateName
(
objectMeta
.
GetGenerateName
()))
}
}
...
...
staging/src/k8s.io/apiserver/pkg/registry/rest/meta.go
View file @
7ea612db
...
@@ -25,15 +25,9 @@ import (
...
@@ -25,15 +25,9 @@ import (
)
)
// FillObjectMetaSystemFields populates fields that are managed by the system on ObjectMeta.
// FillObjectMetaSystemFields populates fields that are managed by the system on ObjectMeta.
func
FillObjectMetaSystemFields
(
ctx
context
.
Context
,
meta
metav1
.
Object
)
{
func
FillObjectMetaSystemFields
(
meta
metav1
.
Object
)
{
meta
.
SetCreationTimestamp
(
metav1
.
Now
())
meta
.
SetCreationTimestamp
(
metav1
.
Now
())
// allows admission controllers to assign a UID earlier in the request processing
meta
.
SetUID
(
uuid
.
NewUUID
())
// to support tracking resources pending creation.
uid
,
found
:=
genericapirequest
.
UIDFrom
(
ctx
)
if
!
found
{
uid
=
uuid
.
NewUUID
()
}
meta
.
SetUID
(
uid
)
meta
.
SetSelfLink
(
""
)
meta
.
SetSelfLink
(
""
)
}
}
...
...
staging/src/k8s.io/apiserver/pkg/registry/rest/meta_test.go
View file @
7ea612db
...
@@ -21,34 +21,26 @@ import (
...
@@ -21,34 +21,26 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apiserver/pkg/apis/example"
"k8s.io/apiserver/pkg/apis/example"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
)
)
// TestFillObjectMetaSystemFields validates that system populated fields are set on an object
// TestFillObjectMetaSystemFields validates that system populated fields are set on an object
func
TestFillObjectMetaSystemFields
(
t
*
testing
.
T
)
{
func
TestFillObjectMetaSystemFields
(
t
*
testing
.
T
)
{
ctx
:=
genericapirequest
.
NewDefaultContext
()
resource
:=
metav1
.
ObjectMeta
{}
resource
:=
metav1
.
ObjectMeta
{}
FillObjectMetaSystemFields
(
ctx
,
&
resource
)
FillObjectMetaSystemFields
(
&
resource
)
if
resource
.
CreationTimestamp
.
Time
.
IsZero
()
{
if
resource
.
CreationTimestamp
.
Time
.
IsZero
()
{
t
.
Errorf
(
"resource.CreationTimestamp is zero"
)
t
.
Errorf
(
"resource.CreationTimestamp is zero"
)
}
else
if
len
(
resource
.
UID
)
==
0
{
}
else
if
len
(
resource
.
UID
)
==
0
{
t
.
Errorf
(
"resource.UID missing"
)
t
.
Errorf
(
"resource.UID missing"
)
}
}
// verify we can inject a UID
if
len
(
resource
.
UID
)
==
0
{
uid
:=
uuid
.
NewUUID
()
t
.
Errorf
(
"resource.UID missing"
)
ctx
=
genericapirequest
.
WithUID
(
ctx
,
uid
)
resource
=
metav1
.
ObjectMeta
{}
FillObjectMetaSystemFields
(
ctx
,
&
resource
)
if
resource
.
UID
!=
uid
{
t
.
Errorf
(
"resource.UID expected: %v, actual: %v"
,
uid
,
resource
.
UID
)
}
}
}
}
// TestHasObjectMetaSystemFieldValues validates that true is returned if and only if all fields are populated
// TestHasObjectMetaSystemFieldValues validates that true is returned if and only if all fields are populated
func
TestHasObjectMetaSystemFieldValues
(
t
*
testing
.
T
)
{
func
TestHasObjectMetaSystemFieldValues
(
t
*
testing
.
T
)
{
ctx
:=
genericapirequest
.
NewDefaultContext
()
resource
:=
metav1
.
ObjectMeta
{}
resource
:=
metav1
.
ObjectMeta
{}
objMeta
,
err
:=
meta
.
Accessor
(
&
resource
)
objMeta
,
err
:=
meta
.
Accessor
(
&
resource
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -57,7 +49,7 @@ func TestHasObjectMetaSystemFieldValues(t *testing.T) {
...
@@ -57,7 +49,7 @@ func TestHasObjectMetaSystemFieldValues(t *testing.T) {
if
metav1
.
HasObjectMetaSystemFieldValues
(
objMeta
)
{
if
metav1
.
HasObjectMetaSystemFieldValues
(
objMeta
)
{
t
.
Errorf
(
"the resource does not have all fields yet populated, but incorrectly reports it does"
)
t
.
Errorf
(
"the resource does not have all fields yet populated, but incorrectly reports it does"
)
}
}
FillObjectMetaSystemFields
(
ctx
,
&
resource
)
FillObjectMetaSystemFields
(
&
resource
)
if
!
metav1
.
HasObjectMetaSystemFieldValues
(
objMeta
)
{
if
!
metav1
.
HasObjectMetaSystemFieldValues
(
objMeta
)
{
t
.
Errorf
(
"the resource does have all fields populated, but incorrectly reports it does not"
)
t
.
Errorf
(
"the resource does have all fields populated, but incorrectly reports it does not"
)
}
}
...
...
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