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
54fd2aae
Commit
54fd2aae
authored
Apr 24, 2018
by
Mike Danese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace request.Context with context.Context
parent
a0f94123
Show whitespace changes
Inline
Side-by-side
Showing
206 changed files
with
944 additions
and
945 deletions
+944
-945
BUILD
pkg/printers/storage/BUILD
+0
-1
storage.go
pkg/printers/storage/storage.go
+3
-2
BUILD
...stry/admissionregistration/initializerconfiguration/BUILD
+0
-1
strategy.go
...dmissionregistration/initializerconfiguration/strategy.go
+5
-5
BUILD
.../admissionregistration/mutatingwebhookconfiguration/BUILD
+0
-1
strategy.go
...sionregistration/mutatingwebhookconfiguration/strategy.go
+5
-5
BUILD
...dmissionregistration/validatingwebhookconfiguration/BUILD
+0
-1
strategy.go
...onregistration/validatingwebhookconfiguration/strategy.go
+5
-5
BUILD
pkg/registry/apps/controllerrevision/BUILD
+0
-1
strategy.go
pkg/registry/apps/controllerrevision/strategy.go
+6
-5
BUILD
pkg/registry/apps/daemonset/storage/BUILD
+0
-1
storage.go
pkg/registry/apps/daemonset/storage/storage.go
+4
-3
strategy.go
pkg/registry/apps/daemonset/strategy.go
+9
-7
registry.go
pkg/registry/apps/deployment/registry.go
+11
-11
BUILD
pkg/registry/apps/deployment/storage/BUILD
+0
-1
storage.go
pkg/registry/apps/deployment/storage/storage.go
+8
-8
strategy.go
pkg/registry/apps/deployment/strategy.go
+9
-7
registry.go
pkg/registry/apps/replicaset/registry.go
+13
-13
BUILD
pkg/registry/apps/replicaset/storage/BUILD
+0
-1
storage.go
pkg/registry/apps/replicaset/storage/storage.go
+5
-5
strategy.go
pkg/registry/apps/replicaset/strategy.go
+8
-7
registry.go
pkg/registry/apps/statefulset/registry.go
+13
-13
BUILD
pkg/registry/apps/statefulset/storage/BUILD
+0
-1
storage.go
pkg/registry/apps/statefulset/storage/storage.go
+5
-5
strategy.go
pkg/registry/apps/statefulset/strategy.go
+9
-7
storage.go
pkg/registry/authentication/tokenreview/storage.go
+2
-1
rest.go
pkg/registry/authorization/localsubjectaccessreview/rest.go
+2
-1
rest.go
pkg/registry/authorization/selfsubjectaccessreview/rest.go
+2
-1
rest.go
pkg/registry/authorization/selfsubjectrulesreview/rest.go
+2
-1
BUILD
pkg/registry/authorization/subjectaccessreview/BUILD
+0
-1
rest.go
pkg/registry/authorization/subjectaccessreview/rest.go
+2
-2
BUILD
pkg/registry/autoscaling/horizontalpodautoscaler/BUILD
+0
-1
BUILD
...egistry/autoscaling/horizontalpodautoscaler/storage/BUILD
+0
-1
storage.go
...ry/autoscaling/horizontalpodautoscaler/storage/storage.go
+4
-3
strategy.go
pkg/registry/autoscaling/horizontalpodautoscaler/strategy.go
+8
-7
BUILD
pkg/registry/batch/cronjob/BUILD
+0
-1
BUILD
pkg/registry/batch/cronjob/storage/BUILD
+0
-1
storage.go
pkg/registry/batch/cronjob/storage/storage.go
+4
-3
strategy.go
pkg/registry/batch/cronjob/strategy.go
+9
-8
BUILD
pkg/registry/batch/job/BUILD
+0
-1
BUILD
pkg/registry/batch/job/storage/BUILD
+0
-1
storage.go
pkg/registry/batch/job/storage/storage.go
+4
-3
strategy.go
pkg/registry/batch/job/strategy.go
+8
-8
registry.go
pkg/registry/certificates/certificates/registry.go
+14
-13
BUILD
pkg/registry/certificates/certificates/storage/BUILD
+0
-1
storage.go
pkg/registry/certificates/certificates/storage/storage.go
+4
-3
strategy.go
pkg/registry/certificates/certificates/strategy.go
+10
-9
strategy_test.go
pkg/registry/certificates/certificates/strategy_test.go
+2
-1
BUILD
pkg/registry/core/componentstatus/BUILD
+0
-1
rest.go
pkg/registry/core/componentstatus/rest.go
+3
-3
BUILD
pkg/registry/core/configmap/BUILD
+0
-1
registry.go
pkg/registry/core/configmap/registry.go
+14
-13
strategy.go
pkg/registry/core/configmap/strategy.go
+6
-5
BUILD
pkg/registry/core/endpoint/BUILD
+0
-1
registry.go
pkg/registry/core/endpoint/registry.go
+12
-11
strategy.go
pkg/registry/core/endpoint/strategy.go
+6
-5
BUILD
pkg/registry/core/event/BUILD
+0
-1
strategy.go
pkg/registry/core/event/strategy.go
+6
-6
BUILD
pkg/registry/core/limitrange/BUILD
+0
-1
strategy.go
pkg/registry/core/limitrange/strategy.go
+7
-6
BUILD
pkg/registry/core/namespace/BUILD
+0
-1
registry.go
pkg/registry/core/namespace/registry.go
+14
-13
BUILD
pkg/registry/core/namespace/storage/BUILD
+0
-1
storage.go
pkg/registry/core/namespace/storage/storage.go
+12
-12
strategy.go
pkg/registry/core/namespace/strategy.go
+9
-9
BUILD
pkg/registry/core/node/BUILD
+0
-1
registry.go
pkg/registry/core/node/registry.go
+14
-13
BUILD
pkg/registry/core/node/rest/BUILD
+0
-1
proxy.go
pkg/registry/core/node/rest/proxy.go
+2
-2
storage.go
pkg/registry/core/node/storage/storage.go
+4
-3
strategy.go
pkg/registry/core/node/strategy.go
+11
-11
BUILD
pkg/registry/core/persistentvolume/BUILD
+0
-1
BUILD
pkg/registry/core/persistentvolume/storage/BUILD
+0
-1
storage.go
pkg/registry/core/persistentvolume/storage/storage.go
+4
-3
strategy.go
pkg/registry/core/persistentvolume/strategy.go
+7
-7
BUILD
pkg/registry/core/persistentvolumeclaim/BUILD
+0
-1
BUILD
pkg/registry/core/persistentvolumeclaim/storage/BUILD
+0
-1
storage.go
pkg/registry/core/persistentvolumeclaim/storage/storage.go
+4
-3
strategy.go
pkg/registry/core/persistentvolumeclaim/strategy.go
+7
-7
BUILD
pkg/registry/core/pod/BUILD
+0
-1
BUILD
pkg/registry/core/pod/rest/BUILD
+0
-1
log.go
pkg/registry/core/pod/rest/log.go
+2
-2
subresources.go
pkg/registry/core/pod/rest/subresources.go
+5
-5
BUILD
pkg/registry/core/pod/storage/BUILD
+0
-1
eviction.go
pkg/registry/core/pod/storage/eviction.go
+3
-3
storage.go
pkg/registry/core/pod/storage/storage.go
+7
-7
strategy.go
pkg/registry/core/pod/strategy.go
+17
-17
strategy_test.go
pkg/registry/core/pod/strategy_test.go
+2
-1
BUILD
pkg/registry/core/podtemplate/BUILD
+0
-1
strategy.go
pkg/registry/core/podtemplate/strategy.go
+7
-6
BUILD
pkg/registry/core/replicationcontroller/BUILD
+0
-1
registry.go
pkg/registry/core/replicationcontroller/registry.go
+13
-13
BUILD
pkg/registry/core/replicationcontroller/storage/BUILD
+0
-1
storage.go
pkg/registry/core/replicationcontroller/storage/storage.go
+5
-5
strategy.go
pkg/registry/core/replicationcontroller/strategy.go
+8
-8
BUILD
pkg/registry/core/resourcequota/BUILD
+0
-1
BUILD
pkg/registry/core/resourcequota/storage/BUILD
+0
-1
storage.go
pkg/registry/core/resourcequota/storage/storage.go
+4
-3
strategy.go
pkg/registry/core/resourcequota/strategy.go
+8
-7
BUILD
pkg/registry/core/secret/BUILD
+0
-1
strategy.go
pkg/registry/core/secret/strategy.go
+6
-6
BUILD
pkg/registry/core/service/BUILD
+0
-1
proxy.go
pkg/registry/core/service/proxy.go
+2
-2
registry.go
pkg/registry/core/service/registry.go
+15
-15
rest.go
pkg/registry/core/service/storage/rest.go
+11
-10
rest_test.go
pkg/registry/core/service/storage/rest_test.go
+12
-11
storage.go
pkg/registry/core/service/storage/storage.go
+4
-3
strategy.go
pkg/registry/core/service/strategy.go
+8
-8
BUILD
pkg/registry/core/serviceaccount/BUILD
+0
-1
token.go
pkg/registry/core/serviceaccount/storage/token.go
+4
-3
strategy.go
pkg/registry/core/serviceaccount/strategy.go
+6
-5
BUILD
pkg/registry/events/event/BUILD
+0
-1
strategy.go
pkg/registry/events/event/strategy.go
+5
-5
BUILD
pkg/registry/extensions/controller/storage/BUILD
+0
-1
storage.go
pkg/registry/extensions/controller/storage/storage.go
+3
-3
BUILD
pkg/registry/extensions/ingress/BUILD
+0
-1
BUILD
pkg/registry/extensions/ingress/storage/BUILD
+0
-1
storage.go
pkg/registry/extensions/ingress/storage/storage.go
+4
-3
strategy.go
pkg/registry/extensions/ingress/strategy.go
+8
-7
BUILD
pkg/registry/networking/networkpolicy/BUILD
+0
-1
registry.go
pkg/registry/networking/networkpolicy/registry.go
+14
-13
strategy.go
pkg/registry/networking/networkpolicy/strategy.go
+5
-5
BUILD
pkg/registry/policy/poddisruptionbudget/BUILD
+0
-1
BUILD
pkg/registry/policy/poddisruptionbudget/storage/BUILD
+0
-1
storage.go
pkg/registry/policy/poddisruptionbudget/storage/storage.go
+4
-3
strategy.go
pkg/registry/policy/poddisruptionbudget/strategy.go
+8
-7
BUILD
pkg/registry/policy/podsecuritypolicy/BUILD
+0
-1
strategy.go
pkg/registry/policy/podsecuritypolicy/strategy.go
+6
-5
BUILD
pkg/registry/rbac/clusterrole/policybased/BUILD
+0
-1
storage.go
pkg/registry/rbac/clusterrole/policybased/storage.go
+4
-4
registry.go
pkg/registry/rbac/clusterrole/registry.go
+14
-12
strategy.go
pkg/registry/rbac/clusterrole/strategy.go
+6
-5
BUILD
pkg/registry/rbac/clusterrolebinding/policybased/BUILD
+0
-1
storage.go
pkg/registry/rbac/clusterrolebinding/policybased/storage.go
+5
-4
registry.go
pkg/registry/rbac/clusterrolebinding/registry.go
+14
-12
strategy.go
pkg/registry/rbac/clusterrolebinding/strategy.go
+6
-5
escalation_check.go
pkg/registry/rbac/escalation_check.go
+3
-2
BUILD
pkg/registry/rbac/role/policybased/BUILD
+0
-1
storage.go
pkg/registry/rbac/role/policybased/storage.go
+5
-4
registry.go
pkg/registry/rbac/role/registry.go
+14
-12
strategy.go
pkg/registry/rbac/role/strategy.go
+6
-5
storage.go
pkg/registry/rbac/rolebinding/policybased/storage.go
+5
-3
registry.go
pkg/registry/rbac/rolebinding/registry.go
+14
-12
strategy.go
pkg/registry/rbac/rolebinding/strategy.go
+6
-5
rule.go
pkg/registry/rbac/validation/rule.go
+2
-1
endpoint.go
pkg/registry/registrytest/endpoint.go
+6
-6
node.go
pkg/registry/registrytest/node.go
+7
-7
service.go
pkg/registry/registrytest/service.go
+8
-7
BUILD
pkg/registry/scheduling/priorityclass/BUILD
+0
-1
registry.go
pkg/registry/scheduling/priorityclass/registry.go
+14
-13
BUILD
pkg/registry/scheduling/priorityclass/storage/BUILD
+0
-1
storage.go
pkg/registry/scheduling/priorityclass/storage/storage.go
+2
-2
strategy.go
pkg/registry/scheduling/priorityclass/strategy.go
+6
-5
BUILD
pkg/registry/settings/podpreset/BUILD
+0
-1
registry.go
pkg/registry/settings/podpreset/registry.go
+14
-13
strategy.go
pkg/registry/settings/podpreset/strategy.go
+6
-5
BUILD
pkg/registry/storage/storageclass/BUILD
+0
-1
strategy.go
pkg/registry/storage/storageclass/strategy.go
+6
-5
BUILD
pkg/registry/storage/volumeattachment/BUILD
+0
-1
strategy.go
pkg/registry/storage/volumeattachment/strategy.go
+6
-5
BUILD
...apiextensions-apiserver/pkg/registry/customresource/BUILD
+0
-1
etcd.go
...iextensions-apiserver/pkg/registry/customresource/etcd.go
+5
-5
registry.go
...ensions-apiserver/pkg/registry/customresource/registry.go
+13
-13
status_strategy.go
...-apiserver/pkg/registry/customresource/status_strategy.go
+4
-3
strategy.go
...ensions-apiserver/pkg/registry/customresource/strategy.go
+6
-5
BUILD
...piserver/pkg/registry/customresource/tableconvertor/BUILD
+0
-1
tableconvertor.go
.../registry/customresource/tableconvertor/tableconvertor.go
+2
-2
validator.go
...nsions-apiserver/pkg/registry/customresource/validator.go
+4
-4
BUILD
...ons-apiserver/pkg/registry/customresourcedefinition/BUILD
+0
-1
etcd.go
...s-apiserver/pkg/registry/customresourcedefinition/etcd.go
+3
-3
strategy.go
...iserver/pkg/registry/customresourcedefinition/strategy.go
+7
-7
apiserver_test.go
staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go
+18
-17
authorization.go
...c/k8s.io/apiserver/pkg/endpoints/filters/authorization.go
+2
-1
impersonation_test.go
....io/apiserver/pkg/endpoints/filters/impersonation_test.go
+2
-1
create.go
...ing/src/k8s.io/apiserver/pkg/endpoints/handlers/create.go
+2
-1
get.go
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/get.go
+4
-3
patch.go
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/patch.go
+4
-3
response.go
...g/src/k8s.io/apiserver/pkg/endpoints/handlers/response.go
+2
-2
errors.go
...piserver/pkg/endpoints/handlers/responsewriters/errors.go
+2
-2
rest.go
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/rest.go
+2
-1
rest_test.go
.../src/k8s.io/apiserver/pkg/endpoints/handlers/rest_test.go
+3
-2
update.go
...ing/src/k8s.io/apiserver/pkg/endpoints/handlers/update.go
+2
-1
context.go
...ing/src/k8s.io/apiserver/pkg/endpoints/request/context.go
+14
-42
requestinfo.go
...src/k8s.io/apiserver/pkg/endpoints/request/requestinfo.go
+3
-2
store.go
...c/k8s.io/apiserver/pkg/registry/generic/registry/store.go
+31
-30
store_test.go
....io/apiserver/pkg/registry/generic/registry/store_test.go
+14
-13
BUILD
...g/src/k8s.io/apiserver/pkg/registry/generic/testing/BUILD
+0
-1
tester.go
...c/k8s.io/apiserver/pkg/registry/generic/testing/tester.go
+3
-3
create.go
staging/src/k8s.io/apiserver/pkg/registry/rest/create.go
+5
-4
delete.go
staging/src/k8s.io/apiserver/pkg/registry/rest/delete.go
+4
-4
export.go
staging/src/k8s.io/apiserver/pkg/registry/rest/export.go
+3
-2
meta.go
staging/src/k8s.io/apiserver/pkg/registry/rest/meta.go
+4
-2
rest.go
staging/src/k8s.io/apiserver/pkg/registry/rest/rest.go
+16
-16
resttest.go
...c/k8s.io/apiserver/pkg/registry/rest/resttest/resttest.go
+7
-6
table.go
staging/src/k8s.io/apiserver/pkg/registry/rest/table.go
+2
-2
update.go
staging/src/k8s.io/apiserver/pkg/registry/rest/update.go
+7
-7
BUILD
staging/src/k8s.io/apiserver/pkg/server/BUILD
+0
-1
genericapiserver_test.go
.../src/k8s.io/apiserver/pkg/server/genericapiserver_test.go
+2
-2
BUILD
.../src/k8s.io/kube-aggregator/pkg/registry/apiservice/BUILD
+0
-1
BUILD
...k8s.io/kube-aggregator/pkg/registry/apiservice/etcd/BUILD
+0
-1
etcd.go
...s.io/kube-aggregator/pkg/registry/apiservice/etcd/etcd.go
+3
-2
strategy.go
...8s.io/kube-aggregator/pkg/registry/apiservice/strategy.go
+7
-7
BUILD
...k8s.io/sample-apiserver/pkg/registry/wardle/fischer/BUILD
+0
-1
strategy.go
.../sample-apiserver/pkg/registry/wardle/fischer/strategy.go
+5
-5
BUILD
...k8s.io/sample-apiserver/pkg/registry/wardle/flunder/BUILD
+0
-1
strategy.go
.../sample-apiserver/pkg/registry/wardle/flunder/strategy.go
+5
-5
No files found.
pkg/printers/storage/BUILD
View file @
54fd2aae
...
...
@@ -13,7 +13,6 @@ go_library(
"//pkg/printers:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1beta1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
],
)
...
...
pkg/printers/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
storage
import
(
"context"
metav1beta1
"k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/kubernetes/pkg/printers"
)
...
...
@@ -27,6 +28,6 @@ type TableConvertor struct {
printers
.
TablePrinter
}
func
(
c
TableConvertor
)
ConvertToTable
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
func
(
c
TableConvertor
)
ConvertToTable
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
return
c
.
TablePrinter
.
PrintTable
(
obj
,
printers
.
PrintOptions
{
Wide
:
true
})
}
pkg/registry/admissionregistration/initializerconfiguration/BUILD
View file @
54fd2aae
...
...
@@ -18,7 +18,6 @@ go_library(
"//pkg/apis/admissionregistration/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
)
...
...
pkg/registry/admissionregistration/initializerconfiguration/strategy.go
View file @
54fd2aae
...
...
@@ -17,11 +17,11 @@ limitations under the License.
package
initializerconfiguration
import
(
"context"
"reflect"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/admissionregistration"
...
...
@@ -43,13 +43,13 @@ func (initializerConfigurationStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of an InitializerConfiguration before creation.
func
(
initializerConfigurationStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
initializerConfigurationStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
ic
:=
obj
.
(
*
admissionregistration
.
InitializerConfiguration
)
ic
.
Generation
=
1
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
initializerConfigurationStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
initializerConfigurationStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newIC
:=
obj
.
(
*
admissionregistration
.
InitializerConfiguration
)
oldIC
:=
old
.
(
*
admissionregistration
.
InitializerConfiguration
)
...
...
@@ -62,7 +62,7 @@ func (initializerConfigurationStrategy) PrepareForUpdate(ctx genericapirequest.C
}
// Validate validates a new InitializerConfiguration.
func
(
initializerConfigurationStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
initializerConfigurationStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
ic
:=
obj
.
(
*
admissionregistration
.
InitializerConfiguration
)
return
validation
.
ValidateInitializerConfiguration
(
ic
)
}
...
...
@@ -77,7 +77,7 @@ func (initializerConfigurationStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
initializerConfigurationStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
initializerConfigurationStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
validationErrorList
:=
validation
.
ValidateInitializerConfiguration
(
obj
.
(
*
admissionregistration
.
InitializerConfiguration
))
updateErrorList
:=
validation
.
ValidateInitializerConfigurationUpdate
(
obj
.
(
*
admissionregistration
.
InitializerConfiguration
),
old
.
(
*
admissionregistration
.
InitializerConfiguration
))
return
append
(
validationErrorList
,
updateErrorList
...
)
...
...
pkg/registry/admissionregistration/mutatingwebhookconfiguration/BUILD
View file @
54fd2aae
...
...
@@ -18,7 +18,6 @@ go_library(
"//pkg/apis/admissionregistration/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
)
...
...
pkg/registry/admissionregistration/mutatingwebhookconfiguration/strategy.go
View file @
54fd2aae
...
...
@@ -17,11 +17,11 @@ limitations under the License.
package
mutatingwebhookconfiguration
import
(
"context"
"reflect"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/admissionregistration"
...
...
@@ -43,13 +43,13 @@ func (mutatingWebhookConfigurationStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of an mutatingWebhookConfiguration before creation.
func
(
mutatingWebhookConfigurationStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
mutatingWebhookConfigurationStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
ic
:=
obj
.
(
*
admissionregistration
.
MutatingWebhookConfiguration
)
ic
.
Generation
=
1
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
mutatingWebhookConfigurationStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
mutatingWebhookConfigurationStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newIC
:=
obj
.
(
*
admissionregistration
.
MutatingWebhookConfiguration
)
oldIC
:=
old
.
(
*
admissionregistration
.
MutatingWebhookConfiguration
)
...
...
@@ -62,7 +62,7 @@ func (mutatingWebhookConfigurationStrategy) PrepareForUpdate(ctx genericapireque
}
// Validate validates a new mutatingWebhookConfiguration.
func
(
mutatingWebhookConfigurationStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
mutatingWebhookConfigurationStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
ic
:=
obj
.
(
*
admissionregistration
.
MutatingWebhookConfiguration
)
return
validation
.
ValidateMutatingWebhookConfiguration
(
ic
)
}
...
...
@@ -77,7 +77,7 @@ func (mutatingWebhookConfigurationStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
mutatingWebhookConfigurationStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
mutatingWebhookConfigurationStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
validationErrorList
:=
validation
.
ValidateMutatingWebhookConfiguration
(
obj
.
(
*
admissionregistration
.
MutatingWebhookConfiguration
))
updateErrorList
:=
validation
.
ValidateMutatingWebhookConfigurationUpdate
(
obj
.
(
*
admissionregistration
.
MutatingWebhookConfiguration
),
old
.
(
*
admissionregistration
.
MutatingWebhookConfiguration
))
return
append
(
validationErrorList
,
updateErrorList
...
)
...
...
pkg/registry/admissionregistration/validatingwebhookconfiguration/BUILD
View file @
54fd2aae
...
...
@@ -18,7 +18,6 @@ go_library(
"//pkg/apis/admissionregistration/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
)
...
...
pkg/registry/admissionregistration/validatingwebhookconfiguration/strategy.go
View file @
54fd2aae
...
...
@@ -17,11 +17,11 @@ limitations under the License.
package
validatingwebhookconfiguration
import
(
"context"
"reflect"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/admissionregistration"
...
...
@@ -43,13 +43,13 @@ func (validatingWebhookConfigurationStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of an validatingWebhookConfiguration before creation.
func
(
validatingWebhookConfigurationStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
validatingWebhookConfigurationStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
ic
:=
obj
.
(
*
admissionregistration
.
ValidatingWebhookConfiguration
)
ic
.
Generation
=
1
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
validatingWebhookConfigurationStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
validatingWebhookConfigurationStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newIC
:=
obj
.
(
*
admissionregistration
.
ValidatingWebhookConfiguration
)
oldIC
:=
old
.
(
*
admissionregistration
.
ValidatingWebhookConfiguration
)
...
...
@@ -62,7 +62,7 @@ func (validatingWebhookConfigurationStrategy) PrepareForUpdate(ctx genericapireq
}
// Validate validates a new validatingWebhookConfiguration.
func
(
validatingWebhookConfigurationStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
validatingWebhookConfigurationStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
ic
:=
obj
.
(
*
admissionregistration
.
ValidatingWebhookConfiguration
)
return
validation
.
ValidateValidatingWebhookConfiguration
(
ic
)
}
...
...
@@ -77,7 +77,7 @@ func (validatingWebhookConfigurationStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
validatingWebhookConfigurationStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
validatingWebhookConfigurationStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
validationErrorList
:=
validation
.
ValidateValidatingWebhookConfiguration
(
obj
.
(
*
admissionregistration
.
ValidatingWebhookConfiguration
))
updateErrorList
:=
validation
.
ValidateValidatingWebhookConfigurationUpdate
(
obj
.
(
*
admissionregistration
.
ValidatingWebhookConfiguration
),
old
.
(
*
admissionregistration
.
ValidatingWebhookConfiguration
))
return
append
(
validationErrorList
,
updateErrorList
...
)
...
...
pkg/registry/apps/controllerrevision/BUILD
View file @
54fd2aae
...
...
@@ -32,7 +32,6 @@ go_library(
"//pkg/apis/apps/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
...
...
pkg/registry/apps/controllerrevision/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
controllerrevision
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
...
...
@@ -54,17 +55,17 @@ func (strategy) AllowCreateOnUpdate() bool {
return
false
}
func
(
strategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
strategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
_
=
obj
.
(
*
apps
.
ControllerRevision
)
}
func
(
strategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
revision
:=
obj
.
(
*
apps
.
ControllerRevision
)
return
validation
.
ValidateControllerRevision
(
revision
)
}
func
(
strategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
newObj
,
oldObj
runtime
.
Object
)
{
func
(
strategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
newObj
,
oldObj
runtime
.
Object
)
{
_
=
oldObj
.
(
*
apps
.
ControllerRevision
)
_
=
newObj
.
(
*
apps
.
ControllerRevision
)
}
...
...
@@ -73,7 +74,7 @@ func (strategy) AllowUnconditionalUpdate() bool {
return
true
}
func
(
strategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
newObj
,
oldObj
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
newObj
,
oldObj
runtime
.
Object
)
field
.
ErrorList
{
oldRevision
,
newRevision
:=
oldObj
.
(
*
apps
.
ControllerRevision
),
newObj
.
(
*
apps
.
ControllerRevision
)
return
validation
.
ValidateControllerRevisionUpdate
(
newRevision
,
oldRevision
)
}
pkg/registry/apps/daemonset/storage/BUILD
View file @
54fd2aae
...
...
@@ -36,7 +36,6 @@ go_library(
"//pkg/registry/apps/daemonset:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/apps/daemonset/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
storage
import
(
"context"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -90,11 +91,11 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
pkg/registry/apps/daemonset/strategy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
daemonset
import
(
"context"
appsv1beta2
"k8s.io/api/apps/v1beta2"
extensionsv1beta1
"k8s.io/api/extensions/v1beta1"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
...
...
@@ -43,7 +45,7 @@ type daemonSetStrategy struct {
var
Strategy
=
daemonSetStrategy
{
legacyscheme
.
Scheme
,
names
.
SimpleNameGenerator
}
// DefaultGarbageCollectionPolicy returns OrphanDependents by default. For apps/v1, returns DeleteDependents.
func
(
daemonSetStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
genericapireques
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
func
(
daemonSetStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
contex
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
if
requestInfo
,
found
:=
genericapirequest
.
RequestInfoFrom
(
ctx
);
found
{
groupVersion
:=
schema
.
GroupVersion
{
Group
:
requestInfo
.
APIGroup
,
Version
:
requestInfo
.
APIVersion
}
switch
groupVersion
{
...
...
@@ -63,7 +65,7 @@ func (daemonSetStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of a daemon set before creation.
func
(
daemonSetStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
daemonSetStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
daemonSet
:=
obj
.
(
*
extensions
.
DaemonSet
)
daemonSet
.
Status
=
extensions
.
DaemonSetStatus
{}
...
...
@@ -76,7 +78,7 @@ func (daemonSetStrategy) PrepareForCreate(ctx genericapirequest.Context, obj run
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
daemonSetStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
daemonSetStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newDaemonSet
:=
obj
.
(
*
extensions
.
DaemonSet
)
oldDaemonSet
:=
old
.
(
*
extensions
.
DaemonSet
)
...
...
@@ -111,7 +113,7 @@ func (daemonSetStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, ol
}
// Validate validates a new daemon set.
func
(
daemonSetStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
daemonSetStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
daemonSet
:=
obj
.
(
*
extensions
.
DaemonSet
)
return
validation
.
ValidateDaemonSet
(
daemonSet
)
}
...
...
@@ -127,7 +129,7 @@ func (daemonSetStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
daemonSetStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
daemonSetStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
newDaemonSet
:=
obj
.
(
*
extensions
.
DaemonSet
)
oldDaemonSet
:=
old
.
(
*
extensions
.
DaemonSet
)
allErrs
:=
validation
.
ValidateDaemonSet
(
obj
.
(
*
extensions
.
DaemonSet
))
...
...
@@ -162,12 +164,12 @@ type daemonSetStatusStrategy struct {
var
StatusStrategy
=
daemonSetStatusStrategy
{
Strategy
}
func
(
daemonSetStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
daemonSetStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newDaemonSet
:=
obj
.
(
*
extensions
.
DaemonSet
)
oldDaemonSet
:=
old
.
(
*
extensions
.
DaemonSet
)
newDaemonSet
.
Spec
=
oldDaemonSet
.
Spec
}
func
(
daemonSetStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
daemonSetStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateDaemonSetStatusUpdate
(
obj
.
(
*
extensions
.
DaemonSet
),
old
.
(
*
extensions
.
DaemonSet
))
}
pkg/registry/apps/deployment/registry.go
View file @
54fd2aae
...
...
@@ -17,22 +17,22 @@ limitations under the License.
package
deployment
import
(
"context"
"fmt"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/extensions"
)
// Registry is an interface for things that know how to store Deployments.
type
Registry
interface
{
ListDeployments
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
extensions
.
DeploymentList
,
error
)
GetDeployment
(
ctx
genericapireques
t
.
Context
,
deploymentID
string
,
options
*
metav1
.
GetOptions
)
(
*
extensions
.
Deployment
,
error
)
CreateDeployment
(
ctx
genericapireques
t
.
Context
,
deployment
*
extensions
.
Deployment
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
extensions
.
Deployment
,
error
)
UpdateDeployment
(
ctx
genericapireques
t
.
Context
,
deployment
*
extensions
.
Deployment
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
extensions
.
Deployment
,
error
)
DeleteDeployment
(
ctx
genericapireques
t
.
Context
,
deploymentID
string
)
error
ListDeployments
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
extensions
.
DeploymentList
,
error
)
GetDeployment
(
ctx
contex
t
.
Context
,
deploymentID
string
,
options
*
metav1
.
GetOptions
)
(
*
extensions
.
Deployment
,
error
)
CreateDeployment
(
ctx
contex
t
.
Context
,
deployment
*
extensions
.
Deployment
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
extensions
.
Deployment
,
error
)
UpdateDeployment
(
ctx
contex
t
.
Context
,
deployment
*
extensions
.
Deployment
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
extensions
.
Deployment
,
error
)
DeleteDeployment
(
ctx
contex
t
.
Context
,
deploymentID
string
)
error
}
// storage puts strong typing around storage calls
...
...
@@ -45,7 +45,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListDeployments
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
extensions
.
DeploymentList
,
error
)
{
func
(
s
*
storage
)
ListDeployments
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
extensions
.
DeploymentList
,
error
)
{
if
options
!=
nil
&&
options
.
FieldSelector
!=
nil
&&
!
options
.
FieldSelector
.
Empty
()
{
return
nil
,
fmt
.
Errorf
(
"field selector not supported yet"
)
}
...
...
@@ -56,7 +56,7 @@ func (s *storage) ListDeployments(ctx genericapirequest.Context, options *metain
return
obj
.
(
*
extensions
.
DeploymentList
),
err
}
func
(
s
*
storage
)
GetDeployment
(
ctx
genericapireques
t
.
Context
,
deploymentID
string
,
options
*
metav1
.
GetOptions
)
(
*
extensions
.
Deployment
,
error
)
{
func
(
s
*
storage
)
GetDeployment
(
ctx
contex
t
.
Context
,
deploymentID
string
,
options
*
metav1
.
GetOptions
)
(
*
extensions
.
Deployment
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
deploymentID
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -64,7 +64,7 @@ func (s *storage) GetDeployment(ctx genericapirequest.Context, deploymentID stri
return
obj
.
(
*
extensions
.
Deployment
),
nil
}
func
(
s
*
storage
)
CreateDeployment
(
ctx
genericapireques
t
.
Context
,
deployment
*
extensions
.
Deployment
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
extensions
.
Deployment
,
error
)
{
func
(
s
*
storage
)
CreateDeployment
(
ctx
contex
t
.
Context
,
deployment
*
extensions
.
Deployment
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
extensions
.
Deployment
,
error
)
{
obj
,
err
:=
s
.
Create
(
ctx
,
deployment
,
createValidation
,
false
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -72,7 +72,7 @@ func (s *storage) CreateDeployment(ctx genericapirequest.Context, deployment *ex
return
obj
.
(
*
extensions
.
Deployment
),
nil
}
func
(
s
*
storage
)
UpdateDeployment
(
ctx
genericapireques
t
.
Context
,
deployment
*
extensions
.
Deployment
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
extensions
.
Deployment
,
error
)
{
func
(
s
*
storage
)
UpdateDeployment
(
ctx
contex
t
.
Context
,
deployment
*
extensions
.
Deployment
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
extensions
.
Deployment
,
error
)
{
obj
,
_
,
err
:=
s
.
Update
(
ctx
,
deployment
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
deployment
),
createValidation
,
updateValidation
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -80,7 +80,7 @@ func (s *storage) UpdateDeployment(ctx genericapirequest.Context, deployment *ex
return
obj
.
(
*
extensions
.
Deployment
),
nil
}
func
(
s
*
storage
)
DeleteDeployment
(
ctx
genericapireques
t
.
Context
,
deploymentID
string
)
error
{
func
(
s
*
storage
)
DeleteDeployment
(
ctx
contex
t
.
Context
,
deploymentID
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
deploymentID
,
nil
)
return
err
}
pkg/registry/apps/deployment/storage/BUILD
View file @
54fd2aae
...
...
@@ -53,7 +53,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/apps/deployment/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
storage
import
(
"context"
"fmt"
"net/http"
...
...
@@ -24,7 +25,6 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -123,12 +123,12 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
...
...
@@ -144,7 +144,7 @@ func (r *RollbackREST) New() runtime.Object {
var
_
=
rest
.
Creater
(
&
RollbackREST
{})
func
(
r
*
RollbackREST
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
RollbackREST
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
rollback
,
ok
:=
obj
.
(
*
extensions
.
DeploymentRollback
)
if
!
ok
{
return
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"not a DeploymentRollback: %#v"
,
obj
))
...
...
@@ -166,7 +166,7 @@ func (r *RollbackREST) Create(ctx genericapirequest.Context, obj runtime.Object,
},
nil
}
func
(
r
*
RollbackREST
)
rollbackDeployment
(
ctx
genericapireques
t
.
Context
,
deploymentID
string
,
config
*
extensions
.
RollbackConfig
,
annotations
map
[
string
]
string
)
error
{
func
(
r
*
RollbackREST
)
rollbackDeployment
(
ctx
contex
t
.
Context
,
deploymentID
string
,
config
*
extensions
.
RollbackConfig
,
annotations
map
[
string
]
string
)
error
{
if
_
,
err
:=
r
.
setDeploymentRollback
(
ctx
,
deploymentID
,
config
,
annotations
);
err
!=
nil
{
err
=
storeerr
.
InterpretGetError
(
err
,
extensions
.
Resource
(
"deployments"
),
deploymentID
)
err
=
storeerr
.
InterpretUpdateError
(
err
,
extensions
.
Resource
(
"deployments"
),
deploymentID
)
...
...
@@ -178,7 +178,7 @@ func (r *RollbackREST) rollbackDeployment(ctx genericapirequest.Context, deploym
return
nil
}
func
(
r
*
RollbackREST
)
setDeploymentRollback
(
ctx
genericapireques
t
.
Context
,
deploymentID
string
,
config
*
extensions
.
RollbackConfig
,
annotations
map
[
string
]
string
)
(
*
extensions
.
Deployment
,
error
)
{
func
(
r
*
RollbackREST
)
setDeploymentRollback
(
ctx
contex
t
.
Context
,
deploymentID
string
,
config
*
extensions
.
RollbackConfig
,
annotations
map
[
string
]
string
)
(
*
extensions
.
Deployment
,
error
)
{
dKey
,
err
:=
r
.
store
.
KeyFunc
(
ctx
,
deploymentID
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -228,7 +228,7 @@ func (r *ScaleREST) New() runtime.Object {
return
&
autoscaling
.
Scale
{}
}
func
(
r
*
ScaleREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
ScaleREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
deployment
,
err
:=
r
.
registry
.
GetDeployment
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
errors
.
NewNotFound
(
extensions
.
Resource
(
"deployments/scale"
),
name
)
...
...
@@ -240,7 +240,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met
return
scale
,
nil
}
func
(
r
*
ScaleREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
ScaleREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
deployment
,
err
:=
r
.
registry
.
GetDeployment
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
false
,
errors
.
NewNotFound
(
extensions
.
Resource
(
"deployments/scale"
),
name
)
...
...
pkg/registry/apps/deployment/strategy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
deployment
import
(
"context"
appsv1beta1
"k8s.io/api/apps/v1beta1"
appsv1beta2
"k8s.io/api/apps/v1beta2"
extensionsv1beta1
"k8s.io/api/extensions/v1beta1"
...
...
@@ -45,7 +47,7 @@ type deploymentStrategy struct {
var
Strategy
=
deploymentStrategy
{
legacyscheme
.
Scheme
,
names
.
SimpleNameGenerator
}
// DefaultGarbageCollectionPolicy returns OrphanDependents by default. For apps/v1, returns DeleteDependents.
func
(
deploymentStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
genericapireques
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
func
(
deploymentStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
contex
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
if
requestInfo
,
found
:=
genericapirequest
.
RequestInfoFrom
(
ctx
);
found
{
groupVersion
:=
schema
.
GroupVersion
{
Group
:
requestInfo
.
APIGroup
,
Version
:
requestInfo
.
APIVersion
}
switch
groupVersion
{
...
...
@@ -65,7 +67,7 @@ func (deploymentStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func
(
deploymentStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
deploymentStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
deployment
:=
obj
.
(
*
extensions
.
Deployment
)
deployment
.
Status
=
extensions
.
DeploymentStatus
{}
deployment
.
Generation
=
1
...
...
@@ -74,7 +76,7 @@ func (deploymentStrategy) PrepareForCreate(ctx genericapirequest.Context, obj ru
}
// Validate validates a new deployment.
func
(
deploymentStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
deploymentStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
deployment
:=
obj
.
(
*
extensions
.
Deployment
)
return
validation
.
ValidateDeployment
(
deployment
)
}
...
...
@@ -89,7 +91,7 @@ func (deploymentStrategy) AllowCreateOnUpdate() bool {
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
deploymentStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
deploymentStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newDeployment
:=
obj
.
(
*
extensions
.
Deployment
)
oldDeployment
:=
old
.
(
*
extensions
.
Deployment
)
newDeployment
.
Status
=
oldDeployment
.
Status
...
...
@@ -107,7 +109,7 @@ func (deploymentStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, o
}
// ValidateUpdate is the default update validation for an end user.
func
(
deploymentStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
deploymentStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
newDeployment
:=
obj
.
(
*
extensions
.
Deployment
)
oldDeployment
:=
old
.
(
*
extensions
.
Deployment
)
allErrs
:=
validation
.
ValidateDeploymentUpdate
(
newDeployment
,
oldDeployment
)
...
...
@@ -142,7 +144,7 @@ type deploymentStatusStrategy struct {
var
StatusStrategy
=
deploymentStatusStrategy
{
Strategy
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update of status
func
(
deploymentStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
deploymentStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newDeployment
:=
obj
.
(
*
extensions
.
Deployment
)
oldDeployment
:=
old
.
(
*
extensions
.
Deployment
)
newDeployment
.
Spec
=
oldDeployment
.
Spec
...
...
@@ -150,6 +152,6 @@ func (deploymentStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context,
}
// ValidateUpdate is the default update validation for an end user updating status
func
(
deploymentStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
deploymentStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateDeploymentStatusUpdate
(
obj
.
(
*
extensions
.
Deployment
),
old
.
(
*
extensions
.
Deployment
))
}
pkg/registry/apps/replicaset/registry.go
View file @
54fd2aae
...
...
@@ -19,24 +19,24 @@ limitations under the License.
package
replicaset
import
(
"context"
"fmt"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/extensions"
)
// Registry is an interface for things that know how to store ReplicaSets.
type
Registry
interface
{
ListReplicaSets
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
extensions
.
ReplicaSetList
,
error
)
WatchReplicaSets
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
GetReplicaSet
(
ctx
genericapireques
t
.
Context
,
replicaSetID
string
,
options
*
metav1
.
GetOptions
)
(
*
extensions
.
ReplicaSet
,
error
)
CreateReplicaSet
(
ctx
genericapireques
t
.
Context
,
replicaSet
*
extensions
.
ReplicaSet
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
extensions
.
ReplicaSet
,
error
)
UpdateReplicaSet
(
ctx
genericapireques
t
.
Context
,
replicaSet
*
extensions
.
ReplicaSet
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
extensions
.
ReplicaSet
,
error
)
DeleteReplicaSet
(
ctx
genericapireques
t
.
Context
,
replicaSetID
string
)
error
ListReplicaSets
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
extensions
.
ReplicaSetList
,
error
)
WatchReplicaSets
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
GetReplicaSet
(
ctx
contex
t
.
Context
,
replicaSetID
string
,
options
*
metav1
.
GetOptions
)
(
*
extensions
.
ReplicaSet
,
error
)
CreateReplicaSet
(
ctx
contex
t
.
Context
,
replicaSet
*
extensions
.
ReplicaSet
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
extensions
.
ReplicaSet
,
error
)
UpdateReplicaSet
(
ctx
contex
t
.
Context
,
replicaSet
*
extensions
.
ReplicaSet
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
extensions
.
ReplicaSet
,
error
)
DeleteReplicaSet
(
ctx
contex
t
.
Context
,
replicaSetID
string
)
error
}
// storage puts strong typing around storage calls
...
...
@@ -50,7 +50,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListReplicaSets
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
extensions
.
ReplicaSetList
,
error
)
{
func
(
s
*
storage
)
ListReplicaSets
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
extensions
.
ReplicaSetList
,
error
)
{
if
options
!=
nil
&&
options
.
FieldSelector
!=
nil
&&
!
options
.
FieldSelector
.
Empty
()
{
return
nil
,
fmt
.
Errorf
(
"field selector not supported yet"
)
}
...
...
@@ -61,11 +61,11 @@ func (s *storage) ListReplicaSets(ctx genericapirequest.Context, options *metain
return
obj
.
(
*
extensions
.
ReplicaSetList
),
err
}
func
(
s
*
storage
)
WatchReplicaSets
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchReplicaSets
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetReplicaSet
(
ctx
genericapireques
t
.
Context
,
replicaSetID
string
,
options
*
metav1
.
GetOptions
)
(
*
extensions
.
ReplicaSet
,
error
)
{
func
(
s
*
storage
)
GetReplicaSet
(
ctx
contex
t
.
Context
,
replicaSetID
string
,
options
*
metav1
.
GetOptions
)
(
*
extensions
.
ReplicaSet
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
replicaSetID
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -73,7 +73,7 @@ func (s *storage) GetReplicaSet(ctx genericapirequest.Context, replicaSetID stri
return
obj
.
(
*
extensions
.
ReplicaSet
),
nil
}
func
(
s
*
storage
)
CreateReplicaSet
(
ctx
genericapireques
t
.
Context
,
replicaSet
*
extensions
.
ReplicaSet
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
extensions
.
ReplicaSet
,
error
)
{
func
(
s
*
storage
)
CreateReplicaSet
(
ctx
contex
t
.
Context
,
replicaSet
*
extensions
.
ReplicaSet
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
extensions
.
ReplicaSet
,
error
)
{
obj
,
err
:=
s
.
Create
(
ctx
,
replicaSet
,
createValidation
,
false
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -81,7 +81,7 @@ func (s *storage) CreateReplicaSet(ctx genericapirequest.Context, replicaSet *ex
return
obj
.
(
*
extensions
.
ReplicaSet
),
nil
}
func
(
s
*
storage
)
UpdateReplicaSet
(
ctx
genericapireques
t
.
Context
,
replicaSet
*
extensions
.
ReplicaSet
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
extensions
.
ReplicaSet
,
error
)
{
func
(
s
*
storage
)
UpdateReplicaSet
(
ctx
contex
t
.
Context
,
replicaSet
*
extensions
.
ReplicaSet
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
extensions
.
ReplicaSet
,
error
)
{
obj
,
_
,
err
:=
s
.
Update
(
ctx
,
replicaSet
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
replicaSet
),
createValidation
,
updateValidation
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -89,7 +89,7 @@ func (s *storage) UpdateReplicaSet(ctx genericapirequest.Context, replicaSet *ex
return
obj
.
(
*
extensions
.
ReplicaSet
),
nil
}
func
(
s
*
storage
)
DeleteReplicaSet
(
ctx
genericapireques
t
.
Context
,
replicaSetID
string
)
error
{
func
(
s
*
storage
)
DeleteReplicaSet
(
ctx
contex
t
.
Context
,
replicaSetID
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
replicaSetID
,
nil
)
return
err
}
pkg/registry/apps/replicaset/storage/BUILD
View file @
54fd2aae
...
...
@@ -50,7 +50,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/apps/replicaset/storage/storage.go
View file @
54fd2aae
...
...
@@ -19,13 +19,13 @@ limitations under the License.
package
storage
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -121,12 +121,12 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
...
...
@@ -156,7 +156,7 @@ func (r *ScaleREST) New() runtime.Object {
return
&
autoscaling
.
Scale
{}
}
func
(
r
*
ScaleREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
ScaleREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
rs
,
err
:=
r
.
registry
.
GetReplicaSet
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
errors
.
NewNotFound
(
extensions
.
Resource
(
"replicasets/scale"
),
name
)
...
...
@@ -168,7 +168,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met
return
scale
,
err
}
func
(
r
*
ScaleREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
ScaleREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
rs
,
err
:=
r
.
registry
.
GetReplicaSet
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
false
,
errors
.
NewNotFound
(
extensions
.
Resource
(
"replicasets/scale"
),
name
)
...
...
pkg/registry/apps/replicaset/strategy.go
View file @
54fd2aae
...
...
@@ -19,6 +19,7 @@ limitations under the License.
package
replicaset
import
(
"context"
"fmt"
"strconv"
...
...
@@ -52,7 +53,7 @@ type rsStrategy struct {
var
Strategy
=
rsStrategy
{
legacyscheme
.
Scheme
,
names
.
SimpleNameGenerator
}
// DefaultGarbageCollectionPolicy returns OrphanDependents by default. For apps/v1, returns DeleteDependents.
func
(
rsStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
genericapireques
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
func
(
rsStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
contex
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
if
requestInfo
,
found
:=
genericapirequest
.
RequestInfoFrom
(
ctx
);
found
{
groupVersion
:=
schema
.
GroupVersion
{
Group
:
requestInfo
.
APIGroup
,
Version
:
requestInfo
.
APIVersion
}
switch
groupVersion
{
...
...
@@ -72,7 +73,7 @@ func (rsStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of a ReplicaSet before creation.
func
(
rsStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
rsStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
rs
:=
obj
.
(
*
extensions
.
ReplicaSet
)
rs
.
Status
=
extensions
.
ReplicaSetStatus
{}
...
...
@@ -82,7 +83,7 @@ func (rsStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Ob
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
rsStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
rsStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newRS
:=
obj
.
(
*
extensions
.
ReplicaSet
)
oldRS
:=
old
.
(
*
extensions
.
ReplicaSet
)
// update is not allowed to set status
...
...
@@ -105,7 +106,7 @@ func (rsStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runti
}
// Validate validates a new ReplicaSet.
func
(
rsStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
rsStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
rs
:=
obj
.
(
*
extensions
.
ReplicaSet
)
return
validation
.
ValidateReplicaSet
(
rs
)
}
...
...
@@ -121,7 +122,7 @@ func (rsStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
rsStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
rsStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
newReplicaSet
:=
obj
.
(
*
extensions
.
ReplicaSet
)
oldReplicaSet
:=
old
.
(
*
extensions
.
ReplicaSet
)
allErrs
:=
validation
.
ValidateReplicaSet
(
obj
.
(
*
extensions
.
ReplicaSet
))
...
...
@@ -184,13 +185,13 @@ type rsStatusStrategy struct {
var
StatusStrategy
=
rsStatusStrategy
{
Strategy
}
func
(
rsStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
rsStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newRS
:=
obj
.
(
*
extensions
.
ReplicaSet
)
oldRS
:=
old
.
(
*
extensions
.
ReplicaSet
)
// update is not allowed to set spec
newRS
.
Spec
=
oldRS
.
Spec
}
func
(
rsStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
rsStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateReplicaSetStatusUpdate
(
obj
.
(
*
extensions
.
ReplicaSet
),
old
.
(
*
extensions
.
ReplicaSet
))
}
pkg/registry/apps/statefulset/registry.go
View file @
54fd2aae
...
...
@@ -17,25 +17,25 @@ limitations under the License.
package
statefulset
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/api/errors"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/apps"
)
// Registry is an interface for things that know how to store StatefulSets.
type
Registry
interface
{
ListStatefulSets
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
apps
.
StatefulSetList
,
error
)
WatchStatefulSets
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
GetStatefulSet
(
ctx
genericapireques
t
.
Context
,
statefulSetID
string
,
options
*
metav1
.
GetOptions
)
(
*
apps
.
StatefulSet
,
error
)
CreateStatefulSet
(
ctx
genericapireques
t
.
Context
,
statefulSet
*
apps
.
StatefulSet
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
apps
.
StatefulSet
,
error
)
UpdateStatefulSet
(
ctx
genericapireques
t
.
Context
,
statefulSet
*
apps
.
StatefulSet
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
apps
.
StatefulSet
,
error
)
DeleteStatefulSet
(
ctx
genericapireques
t
.
Context
,
statefulSetID
string
)
error
ListStatefulSets
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
apps
.
StatefulSetList
,
error
)
WatchStatefulSets
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
GetStatefulSet
(
ctx
contex
t
.
Context
,
statefulSetID
string
,
options
*
metav1
.
GetOptions
)
(
*
apps
.
StatefulSet
,
error
)
CreateStatefulSet
(
ctx
contex
t
.
Context
,
statefulSet
*
apps
.
StatefulSet
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
apps
.
StatefulSet
,
error
)
UpdateStatefulSet
(
ctx
contex
t
.
Context
,
statefulSet
*
apps
.
StatefulSet
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
apps
.
StatefulSet
,
error
)
DeleteStatefulSet
(
ctx
contex
t
.
Context
,
statefulSetID
string
)
error
}
// storage puts strong typing around storage calls
...
...
@@ -49,7 +49,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListStatefulSets
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
apps
.
StatefulSetList
,
error
)
{
func
(
s
*
storage
)
ListStatefulSets
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
apps
.
StatefulSetList
,
error
)
{
if
options
!=
nil
&&
options
.
FieldSelector
!=
nil
&&
!
options
.
FieldSelector
.
Empty
()
{
return
nil
,
fmt
.
Errorf
(
"field selector not supported yet"
)
}
...
...
@@ -60,11 +60,11 @@ func (s *storage) ListStatefulSets(ctx genericapirequest.Context, options *metai
return
obj
.
(
*
apps
.
StatefulSetList
),
err
}
func
(
s
*
storage
)
WatchStatefulSets
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchStatefulSets
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetStatefulSet
(
ctx
genericapireques
t
.
Context
,
statefulSetID
string
,
options
*
metav1
.
GetOptions
)
(
*
apps
.
StatefulSet
,
error
)
{
func
(
s
*
storage
)
GetStatefulSet
(
ctx
contex
t
.
Context
,
statefulSetID
string
,
options
*
metav1
.
GetOptions
)
(
*
apps
.
StatefulSet
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
statefulSetID
,
options
)
if
err
!=
nil
{
return
nil
,
errors
.
NewNotFound
(
apps
.
Resource
(
"statefulsets/scale"
),
statefulSetID
)
...
...
@@ -72,7 +72,7 @@ func (s *storage) GetStatefulSet(ctx genericapirequest.Context, statefulSetID st
return
obj
.
(
*
apps
.
StatefulSet
),
nil
}
func
(
s
*
storage
)
CreateStatefulSet
(
ctx
genericapireques
t
.
Context
,
statefulSet
*
apps
.
StatefulSet
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
apps
.
StatefulSet
,
error
)
{
func
(
s
*
storage
)
CreateStatefulSet
(
ctx
contex
t
.
Context
,
statefulSet
*
apps
.
StatefulSet
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
apps
.
StatefulSet
,
error
)
{
obj
,
err
:=
s
.
Create
(
ctx
,
statefulSet
,
rest
.
ValidateAllObjectFunc
,
false
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -80,7 +80,7 @@ func (s *storage) CreateStatefulSet(ctx genericapirequest.Context, statefulSet *
return
obj
.
(
*
apps
.
StatefulSet
),
nil
}
func
(
s
*
storage
)
UpdateStatefulSet
(
ctx
genericapireques
t
.
Context
,
statefulSet
*
apps
.
StatefulSet
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
apps
.
StatefulSet
,
error
)
{
func
(
s
*
storage
)
UpdateStatefulSet
(
ctx
contex
t
.
Context
,
statefulSet
*
apps
.
StatefulSet
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
apps
.
StatefulSet
,
error
)
{
obj
,
_
,
err
:=
s
.
Update
(
ctx
,
statefulSet
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
statefulSet
),
createValidation
,
updateValidation
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -88,7 +88,7 @@ func (s *storage) UpdateStatefulSet(ctx genericapirequest.Context, statefulSet *
return
obj
.
(
*
apps
.
StatefulSet
),
nil
}
func
(
s
*
storage
)
DeleteStatefulSet
(
ctx
genericapireques
t
.
Context
,
statefulSetID
string
)
error
{
func
(
s
*
storage
)
DeleteStatefulSet
(
ctx
contex
t
.
Context
,
statefulSetID
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
statefulSetID
,
nil
)
return
err
}
pkg/registry/apps/statefulset/storage/BUILD
View file @
54fd2aae
...
...
@@ -49,7 +49,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/apps/statefulset/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,13 +17,13 @@ limitations under the License.
package
storage
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -104,12 +104,12 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
...
...
@@ -145,7 +145,7 @@ func (r *ScaleREST) New() runtime.Object {
return
&
autoscaling
.
Scale
{}
}
func
(
r
*
ScaleREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
ScaleREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
ss
,
err
:=
r
.
registry
.
GetStatefulSet
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -157,7 +157,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met
return
scale
,
err
}
func
(
r
*
ScaleREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
ScaleREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
ss
,
err
:=
r
.
registry
.
GetStatefulSet
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
false
,
err
...
...
pkg/registry/apps/statefulset/strategy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
statefulset
import
(
"context"
appsv1beta1
"k8s.io/api/apps/v1beta1"
appsv1beta2
"k8s.io/api/apps/v1beta2"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
...
...
@@ -42,7 +44,7 @@ type statefulSetStrategy struct {
var
Strategy
=
statefulSetStrategy
{
legacyscheme
.
Scheme
,
names
.
SimpleNameGenerator
}
// DefaultGarbageCollectionPolicy returns OrphanDependents by default. For apps/v1, returns DeleteDependents.
func
(
statefulSetStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
genericapireques
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
func
(
statefulSetStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
contex
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
if
requestInfo
,
found
:=
genericapirequest
.
RequestInfoFrom
(
ctx
);
found
{
groupVersion
:=
schema
.
GroupVersion
{
Group
:
requestInfo
.
APIGroup
,
Version
:
requestInfo
.
APIVersion
}
switch
groupVersion
{
...
...
@@ -62,7 +64,7 @@ func (statefulSetStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of an StatefulSet before creation.
func
(
statefulSetStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
statefulSetStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
statefulSet
:=
obj
.
(
*
apps
.
StatefulSet
)
// create cannot set status
statefulSet
.
Status
=
apps
.
StatefulSetStatus
{}
...
...
@@ -73,7 +75,7 @@ func (statefulSetStrategy) PrepareForCreate(ctx genericapirequest.Context, obj r
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
statefulSetStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
statefulSetStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newStatefulSet
:=
obj
.
(
*
apps
.
StatefulSet
)
oldStatefulSet
:=
old
.
(
*
apps
.
StatefulSet
)
// Update is not allowed to set status
...
...
@@ -92,7 +94,7 @@ func (statefulSetStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj,
}
// Validate validates a new StatefulSet.
func
(
statefulSetStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
statefulSetStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
statefulSet
:=
obj
.
(
*
apps
.
StatefulSet
)
return
validation
.
ValidateStatefulSet
(
statefulSet
)
}
...
...
@@ -107,7 +109,7 @@ func (statefulSetStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
statefulSetStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
statefulSetStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
validationErrorList
:=
validation
.
ValidateStatefulSet
(
obj
.
(
*
apps
.
StatefulSet
))
updateErrorList
:=
validation
.
ValidateStatefulSetUpdate
(
obj
.
(
*
apps
.
StatefulSet
),
old
.
(
*
apps
.
StatefulSet
))
return
append
(
validationErrorList
,
updateErrorList
...
)
...
...
@@ -125,7 +127,7 @@ type statefulSetStatusStrategy struct {
var
StatusStrategy
=
statefulSetStatusStrategy
{
Strategy
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update of status
func
(
statefulSetStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
statefulSetStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newStatefulSet
:=
obj
.
(
*
apps
.
StatefulSet
)
oldStatefulSet
:=
old
.
(
*
apps
.
StatefulSet
)
// status changes are not allowed to update spec
...
...
@@ -133,7 +135,7 @@ func (statefulSetStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context,
}
// ValidateUpdate is the default update validation for an end user updating status
func
(
statefulSetStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
statefulSetStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
// TODO: Validate status updates.
return
validation
.
ValidateStatefulSetStatusUpdate
(
obj
.
(
*
apps
.
StatefulSet
),
old
.
(
*
apps
.
StatefulSet
))
}
pkg/registry/authentication/tokenreview/storage.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
tokenreview
import
(
"context"
"fmt"
"net/http"
...
...
@@ -40,7 +41,7 @@ func (r *REST) New() runtime.Object {
return
&
authentication
.
TokenReview
{}
}
func
(
r
*
REST
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
REST
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
tokenReview
,
ok
:=
obj
.
(
*
authentication
.
TokenReview
)
if
!
ok
{
return
nil
,
apierrors
.
NewBadRequest
(
fmt
.
Sprintf
(
"not a TokenReview: %#v"
,
obj
))
...
...
pkg/registry/authorization/localsubjectaccessreview/rest.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
localsubjectaccessreview
import
(
"context"
"fmt"
kapierrors
"k8s.io/apimachinery/pkg/api/errors"
...
...
@@ -41,7 +42,7 @@ func (r *REST) New() runtime.Object {
return
&
authorizationapi
.
LocalSubjectAccessReview
{}
}
func
(
r
*
REST
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
REST
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
localSubjectAccessReview
,
ok
:=
obj
.
(
*
authorizationapi
.
LocalSubjectAccessReview
)
if
!
ok
{
return
nil
,
kapierrors
.
NewBadRequest
(
fmt
.
Sprintf
(
"not a LocaLocalSubjectAccessReview: %#v"
,
obj
))
...
...
pkg/registry/authorization/selfsubjectaccessreview/rest.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
selfsubjectaccessreview
import
(
"context"
"fmt"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
...
...
@@ -41,7 +42,7 @@ func (r *REST) New() runtime.Object {
return
&
authorizationapi
.
SelfSubjectAccessReview
{}
}
func
(
r
*
REST
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
REST
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
selfSAR
,
ok
:=
obj
.
(
*
authorizationapi
.
SelfSubjectAccessReview
)
if
!
ok
{
return
nil
,
apierrors
.
NewBadRequest
(
fmt
.
Sprintf
(
"not a SelfSubjectAccessReview: %#v"
,
obj
))
...
...
pkg/registry/authorization/selfsubjectrulesreview/rest.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
selfsubjectrulesreview
import
(
"context"
"fmt"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
...
...
@@ -43,7 +44,7 @@ func (r *REST) New() runtime.Object {
}
// Create attempts to get self subject rules in specific namespace.
func
(
r
*
REST
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
REST
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
selfSRR
,
ok
:=
obj
.
(
*
authorizationapi
.
SelfSubjectRulesReview
)
if
!
ok
{
return
nil
,
apierrors
.
NewBadRequest
(
fmt
.
Sprintf
(
"not a SelfSubjectRulesReview: %#v"
,
obj
))
...
...
pkg/registry/authorization/subjectaccessreview/BUILD
View file @
54fd2aae
...
...
@@ -17,7 +17,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/authorization/authorizer:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
],
)
...
...
pkg/registry/authorization/subjectaccessreview/rest.go
View file @
54fd2aae
...
...
@@ -17,12 +17,12 @@ limitations under the License.
package
subjectaccessreview
import
(
"context"
"fmt"
kapierrors
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/authorization/authorizer"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
authorizationapi
"k8s.io/kubernetes/pkg/apis/authorization"
authorizationvalidation
"k8s.io/kubernetes/pkg/apis/authorization/validation"
...
...
@@ -41,7 +41,7 @@ func (r *REST) New() runtime.Object {
return
&
authorizationapi
.
SubjectAccessReview
{}
}
func
(
r
*
REST
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
REST
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
subjectAccessReview
,
ok
:=
obj
.
(
*
authorizationapi
.
SubjectAccessReview
)
if
!
ok
{
return
nil
,
kapierrors
.
NewBadRequest
(
fmt
.
Sprintf
(
"not a SubjectAccessReview: %#v"
,
obj
))
...
...
pkg/registry/autoscaling/horizontalpodautoscaler/BUILD
View file @
54fd2aae
...
...
@@ -18,7 +18,6 @@ go_library(
"//pkg/apis/autoscaling/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
)
...
...
pkg/registry/autoscaling/horizontalpodautoscaler/storage/BUILD
View file @
54fd2aae
...
...
@@ -41,7 +41,6 @@ go_library(
"//pkg/registry/autoscaling/horizontalpodautoscaler:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/autoscaling/horizontalpodautoscaler/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
storage
import
(
"context"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -83,11 +84,11 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
pkg/registry/autoscaling/horizontalpodautoscaler/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
horizontalpodautoscaler
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/autoscaling"
...
...
@@ -42,7 +43,7 @@ func (autoscalerStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func
(
autoscalerStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
autoscalerStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
newHPA
:=
obj
.
(
*
autoscaling
.
HorizontalPodAutoscaler
)
// create cannot set status
...
...
@@ -50,7 +51,7 @@ func (autoscalerStrategy) PrepareForCreate(ctx genericapirequest.Context, obj ru
}
// Validate validates a new autoscaler.
func
(
autoscalerStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
autoscalerStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
autoscaler
:=
obj
.
(
*
autoscaling
.
HorizontalPodAutoscaler
)
return
validation
.
ValidateHorizontalPodAutoscaler
(
autoscaler
)
}
...
...
@@ -65,7 +66,7 @@ func (autoscalerStrategy) AllowCreateOnUpdate() bool {
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
autoscalerStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
autoscalerStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newHPA
:=
obj
.
(
*
autoscaling
.
HorizontalPodAutoscaler
)
oldHPA
:=
old
.
(
*
autoscaling
.
HorizontalPodAutoscaler
)
// Update is not allowed to set status
...
...
@@ -73,7 +74,7 @@ func (autoscalerStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, o
}
// ValidateUpdate is the default update validation for an end user.
func
(
autoscalerStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
autoscalerStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateHorizontalPodAutoscalerUpdate
(
obj
.
(
*
autoscaling
.
HorizontalPodAutoscaler
),
old
.
(
*
autoscaling
.
HorizontalPodAutoscaler
))
}
...
...
@@ -87,13 +88,13 @@ type autoscalerStatusStrategy struct {
var
StatusStrategy
=
autoscalerStatusStrategy
{
Strategy
}
func
(
autoscalerStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
autoscalerStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newAutoscaler
:=
obj
.
(
*
autoscaling
.
HorizontalPodAutoscaler
)
oldAutoscaler
:=
old
.
(
*
autoscaling
.
HorizontalPodAutoscaler
)
// status changes are not allowed to update spec
newAutoscaler
.
Spec
=
oldAutoscaler
.
Spec
}
func
(
autoscalerStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
autoscalerStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateHorizontalPodAutoscalerStatusUpdate
(
obj
.
(
*
autoscaling
.
HorizontalPodAutoscaler
),
old
.
(
*
autoscaling
.
HorizontalPodAutoscaler
))
}
pkg/registry/batch/cronjob/BUILD
View file @
54fd2aae
...
...
@@ -20,7 +20,6 @@ go_library(
"//pkg/apis/batch/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
...
...
pkg/registry/batch/cronjob/storage/BUILD
View file @
54fd2aae
...
...
@@ -38,7 +38,6 @@ go_library(
"//pkg/registry/batch/cronjob:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/batch/cronjob/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
storage
import
(
"context"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -82,11 +83,11 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
pkg/registry/batch/cronjob/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
cronjob
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
...
...
@@ -39,7 +40,7 @@ var Strategy = cronJobStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
// DefaultGarbageCollectionPolicy returns Orphan because that was the default
// behavior before the server-side garbage collection was implemented.
func
(
cronJobStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
genericapireques
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
func
(
cronJobStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
contex
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
return
rest
.
OrphanDependents
}
...
...
@@ -49,7 +50,7 @@ func (cronJobStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of a scheduled job before creation.
func
(
cronJobStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
cronJobStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
cronJob
:=
obj
.
(
*
batch
.
CronJob
)
cronJob
.
Status
=
batch
.
CronJobStatus
{}
...
...
@@ -57,7 +58,7 @@ func (cronJobStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runti
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
cronJobStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
cronJobStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newCronJob
:=
obj
.
(
*
batch
.
CronJob
)
oldCronJob
:=
old
.
(
*
batch
.
CronJob
)
newCronJob
.
Status
=
oldCronJob
.
Status
...
...
@@ -67,7 +68,7 @@ func (cronJobStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old
}
// Validate validates a new scheduled job.
func
(
cronJobStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
cronJobStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
cronJob
:=
obj
.
(
*
batch
.
CronJob
)
return
validation
.
ValidateCronJob
(
cronJob
)
}
...
...
@@ -86,7 +87,7 @@ func (cronJobStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
cronJobStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
cronJobStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateCronJobUpdate
(
obj
.
(
*
batch
.
CronJob
),
old
.
(
*
batch
.
CronJob
))
}
...
...
@@ -96,12 +97,12 @@ type cronJobStatusStrategy struct {
var
StatusStrategy
=
cronJobStatusStrategy
{
Strategy
}
func
(
cronJobStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
cronJobStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newJob
:=
obj
.
(
*
batch
.
CronJob
)
oldJob
:=
old
.
(
*
batch
.
CronJob
)
newJob
.
Spec
=
oldJob
.
Spec
}
func
(
cronJobStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
cronJobStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
field
.
ErrorList
{}
}
pkg/registry/batch/job/BUILD
View file @
54fd2aae
...
...
@@ -23,7 +23,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
...
...
pkg/registry/batch/job/storage/BUILD
View file @
54fd2aae
...
...
@@ -36,7 +36,6 @@ go_library(
"//pkg/registry/batch/job:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/batch/job/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
storage
import
(
"context"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -93,11 +94,11 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
pkg/registry/batch/job/strategy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
job
import
(
"context"
"fmt"
"strconv"
...
...
@@ -25,7 +26,6 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage"
...
...
@@ -47,7 +47,7 @@ var Strategy = jobStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
// DefaultGarbageCollectionPolicy returns Orphan because that was the default
// behavior before the server-side garbage collection was implemented.
func
(
jobStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
genericapireques
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
func
(
jobStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
contex
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
return
rest
.
OrphanDependents
}
...
...
@@ -57,7 +57,7 @@ func (jobStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of a job before creation.
func
(
jobStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
jobStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
job
:=
obj
.
(
*
batch
.
Job
)
job
.
Status
=
batch
.
JobStatus
{}
...
...
@@ -65,7 +65,7 @@ func (jobStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.O
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
jobStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
jobStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newJob
:=
obj
.
(
*
batch
.
Job
)
oldJob
:=
old
.
(
*
batch
.
Job
)
newJob
.
Status
=
oldJob
.
Status
...
...
@@ -75,7 +75,7 @@ func (jobStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runt
}
// Validate validates a new job.
func
(
jobStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
jobStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
job
:=
obj
.
(
*
batch
.
Job
)
// TODO: move UID generation earlier and do this in defaulting logic?
if
job
.
Spec
.
ManualSelector
==
nil
||
*
job
.
Spec
.
ManualSelector
==
false
{
...
...
@@ -148,7 +148,7 @@ func (jobStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
jobStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
jobStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
validationErrorList
:=
validation
.
ValidateJob
(
obj
.
(
*
batch
.
Job
))
updateErrorList
:=
validation
.
ValidateJobUpdate
(
obj
.
(
*
batch
.
Job
),
old
.
(
*
batch
.
Job
))
return
append
(
validationErrorList
,
updateErrorList
...
)
...
...
@@ -160,13 +160,13 @@ type jobStatusStrategy struct {
var
StatusStrategy
=
jobStatusStrategy
{
Strategy
}
func
(
jobStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
jobStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newJob
:=
obj
.
(
*
batch
.
Job
)
oldJob
:=
old
.
(
*
batch
.
Job
)
newJob
.
Spec
=
oldJob
.
Spec
}
func
(
jobStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
jobStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateJobUpdateStatus
(
obj
.
(
*
batch
.
Job
),
old
.
(
*
batch
.
Job
))
}
...
...
pkg/registry/certificates/certificates/registry.go
View file @
54fd2aae
...
...
@@ -17,22 +17,23 @@ limitations under the License.
package
certificates
import
(
"context"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/certificates"
)
// Registry is an interface for things that know how to store CSRs.
type
Registry
interface
{
ListCSRs
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
certificates
.
CertificateSigningRequestList
,
error
)
CreateCSR
(
ctx
genericapireques
t
.
Context
,
csr
*
certificates
.
CertificateSigningRequest
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateCSR
(
ctx
genericapireques
t
.
Context
,
csr
*
certificates
.
CertificateSigningRequest
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetCSR
(
ctx
genericapireques
t
.
Context
,
csrID
string
,
options
*
metav1
.
GetOptions
)
(
*
certificates
.
CertificateSigningRequest
,
error
)
DeleteCSR
(
ctx
genericapireques
t
.
Context
,
csrID
string
)
error
WatchCSRs
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
ListCSRs
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
certificates
.
CertificateSigningRequestList
,
error
)
CreateCSR
(
ctx
contex
t
.
Context
,
csr
*
certificates
.
CertificateSigningRequest
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateCSR
(
ctx
contex
t
.
Context
,
csr
*
certificates
.
CertificateSigningRequest
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetCSR
(
ctx
contex
t
.
Context
,
csrID
string
,
options
*
metav1
.
GetOptions
)
(
*
certificates
.
CertificateSigningRequest
,
error
)
DeleteCSR
(
ctx
contex
t
.
Context
,
csrID
string
)
error
WatchCSRs
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
}
// storage puts strong typing around storage calls
...
...
@@ -46,7 +47,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListCSRs
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
certificates
.
CertificateSigningRequestList
,
error
)
{
func
(
s
*
storage
)
ListCSRs
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
certificates
.
CertificateSigningRequestList
,
error
)
{
obj
,
err
:=
s
.
List
(
ctx
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -55,21 +56,21 @@ func (s *storage) ListCSRs(ctx genericapirequest.Context, options *metainternalv
return
obj
.
(
*
certificates
.
CertificateSigningRequestList
),
nil
}
func
(
s
*
storage
)
CreateCSR
(
ctx
genericapireques
t
.
Context
,
csr
*
certificates
.
CertificateSigningRequest
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
func
(
s
*
storage
)
CreateCSR
(
ctx
contex
t
.
Context
,
csr
*
certificates
.
CertificateSigningRequest
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
_
,
err
:=
s
.
Create
(
ctx
,
csr
,
createValidation
,
false
)
return
err
}
func
(
s
*
storage
)
UpdateCSR
(
ctx
genericapireques
t
.
Context
,
csr
*
certificates
.
CertificateSigningRequest
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
func
(
s
*
storage
)
UpdateCSR
(
ctx
contex
t
.
Context
,
csr
*
certificates
.
CertificateSigningRequest
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
_
,
_
,
err
:=
s
.
Update
(
ctx
,
csr
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
csr
),
createValidation
,
updateValidation
)
return
err
}
func
(
s
*
storage
)
WatchCSRs
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchCSRs
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetCSR
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
certificates
.
CertificateSigningRequest
,
error
)
{
func
(
s
*
storage
)
GetCSR
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
certificates
.
CertificateSigningRequest
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -77,7 +78,7 @@ func (s *storage) GetCSR(ctx genericapirequest.Context, name string, options *me
return
obj
.
(
*
certificates
.
CertificateSigningRequest
),
nil
}
func
(
s
*
storage
)
DeleteCSR
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
{
func
(
s
*
storage
)
DeleteCSR
(
ctx
contex
t
.
Context
,
name
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
name
,
nil
)
return
err
}
pkg/registry/certificates/certificates/storage/BUILD
View file @
54fd2aae
...
...
@@ -16,7 +16,6 @@ go_library(
"//pkg/printers/storage:go_default_library",
"//pkg/registry/certificates/certificates:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/certificates/certificates/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,8 +17,9 @@ limitations under the License.
package
storage
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -83,7 +84,7 @@ func (r *StatusREST) New() runtime.Object {
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
...
...
@@ -97,6 +98,6 @@ func (r *ApprovalREST) New() runtime.Object {
}
// Update alters the approval subset of an object.
func
(
r
*
ApprovalREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
ApprovalREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
pkg/registry/certificates/certificates/strategy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
certificates
import
(
"context"
"fmt"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
...
...
@@ -51,7 +52,7 @@ func (csrStrategy) AllowCreateOnUpdate() bool {
// PrepareForCreate clears fields that are not allowed to be set by end users
// on creation.
func
(
csrStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
csrStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
csr
:=
obj
.
(
*
certificates
.
CertificateSigningRequest
)
// Clear any user-specified info
...
...
@@ -79,7 +80,7 @@ func (csrStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.O
// PrepareForUpdate clears fields that are not allowed to be set by end users
// on update. Certificate requests are immutable after creation except via subresources.
func
(
csrStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
csrStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newCSR
:=
obj
.
(
*
certificates
.
CertificateSigningRequest
)
oldCSR
:=
old
.
(
*
certificates
.
CertificateSigningRequest
)
...
...
@@ -88,7 +89,7 @@ func (csrStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runt
}
// Validate validates a new CSR. Validation must check for a correct signature.
func
(
csrStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
csrStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
csr
:=
obj
.
(
*
certificates
.
CertificateSigningRequest
)
return
validation
.
ValidateCertificateSigningRequest
(
csr
)
}
...
...
@@ -97,7 +98,7 @@ func (csrStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) f
func
(
csrStrategy
)
Canonicalize
(
obj
runtime
.
Object
)
{}
// ValidateUpdate is the default update validation for an end user.
func
(
csrStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
csrStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
oldCSR
:=
old
.
(
*
certificates
.
CertificateSigningRequest
)
newCSR
:=
obj
.
(
*
certificates
.
CertificateSigningRequest
)
return
validation
.
ValidateCertificateSigningRequestUpdate
(
newCSR
,
oldCSR
)
...
...
@@ -112,7 +113,7 @@ func (csrStrategy) AllowUnconditionalUpdate() bool {
return
true
}
func
(
s
csrStrategy
)
Export
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
{
func
(
s
csrStrategy
)
Export
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
{
csr
,
ok
:=
obj
.
(
*
certificates
.
CertificateSigningRequest
)
if
!
ok
{
// unexpected programmer error
...
...
@@ -134,7 +135,7 @@ type csrStatusStrategy struct {
var
StatusStrategy
=
csrStatusStrategy
{
Strategy
}
func
(
csrStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
csrStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newCSR
:=
obj
.
(
*
certificates
.
CertificateSigningRequest
)
oldCSR
:=
old
.
(
*
certificates
.
CertificateSigningRequest
)
...
...
@@ -150,7 +151,7 @@ func (csrStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, ol
}
}
func
(
csrStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
csrStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateCertificateSigningRequestUpdate
(
obj
.
(
*
certificates
.
CertificateSigningRequest
),
old
.
(
*
certificates
.
CertificateSigningRequest
))
}
...
...
@@ -168,7 +169,7 @@ var ApprovalStrategy = csrApprovalStrategy{Strategy}
// PrepareForUpdate prepares the new certificate signing request by limiting
// the data that is updated to only the conditions. Also, if there is no
// existing LastUpdateTime on a condition, the current date/time will be set.
func
(
csrApprovalStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
csrApprovalStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newCSR
:=
obj
.
(
*
certificates
.
CertificateSigningRequest
)
oldCSR
:=
old
.
(
*
certificates
.
CertificateSigningRequest
)
...
...
@@ -186,6 +187,6 @@ func (csrApprovalStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj,
newCSR
.
Status
=
oldCSR
.
Status
}
func
(
csrApprovalStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
csrApprovalStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateCertificateSigningRequestUpdate
(
obj
.
(
*
certificates
.
CertificateSigningRequest
),
old
.
(
*
certificates
.
CertificateSigningRequest
))
}
pkg/registry/certificates/certificates/strategy_test.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
certificates
import
(
"context"
"reflect"
"testing"
...
...
@@ -29,7 +30,7 @@ import (
func
TestStrategyCreate
(
t
*
testing
.
T
)
{
tests
:=
map
[
string
]
struct
{
ctx
genericapireques
t
.
Context
ctx
contex
t
.
Context
obj
runtime
.
Object
expectedObj
runtime
.
Object
}{
...
...
pkg/registry/core/componentstatus/BUILD
View file @
54fd2aae
...
...
@@ -22,7 +22,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
],
)
...
...
pkg/registry/core/componentstatus/rest.go
View file @
54fd2aae
...
...
@@ -17,13 +17,13 @@ limitations under the License.
package
componentstatus
import
(
"context"
"fmt"
"sync"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/probe"
...
...
@@ -50,7 +50,7 @@ func (rs *REST) NewList() runtime.Object {
// Returns the list of component status. Note that the label and field are both ignored.
// Note that this call doesn't support labels or selectors.
func
(
rs
*
REST
)
List
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
func
(
rs
*
REST
)
List
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
servers
:=
rs
.
GetServersToValidate
()
wait
:=
sync
.
WaitGroup
{}
...
...
@@ -73,7 +73,7 @@ func (rs *REST) List(ctx genericapirequest.Context, options *metainternalversion
return
&
api
.
ComponentStatusList
{
Items
:
reply
},
nil
}
func
(
rs
*
REST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
rs
*
REST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
servers
:=
rs
.
GetServersToValidate
()
if
server
,
ok
:=
servers
[
name
];
!
ok
{
...
...
pkg/registry/core/configmap/BUILD
View file @
54fd2aae
...
...
@@ -23,7 +23,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
...
...
pkg/registry/core/configmap/registry.go
View file @
54fd2aae
...
...
@@ -17,22 +17,23 @@ limitations under the License.
package
configmap
import
(
"context"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
api
"k8s.io/kubernetes/pkg/apis/core"
)
// Registry is an interface for things that know how to store ConfigMaps.
type
Registry
interface
{
ListConfigMaps
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ConfigMapList
,
error
)
WatchConfigMaps
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
GetConfigMap
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
ConfigMap
,
error
)
CreateConfigMap
(
ctx
genericapireques
t
.
Context
,
cfg
*
api
.
ConfigMap
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
ConfigMap
,
error
)
UpdateConfigMap
(
ctx
genericapireques
t
.
Context
,
cfg
*
api
.
ConfigMap
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
ConfigMap
,
error
)
DeleteConfigMap
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
ListConfigMaps
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ConfigMapList
,
error
)
WatchConfigMaps
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
GetConfigMap
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
ConfigMap
,
error
)
CreateConfigMap
(
ctx
contex
t
.
Context
,
cfg
*
api
.
ConfigMap
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
ConfigMap
,
error
)
UpdateConfigMap
(
ctx
contex
t
.
Context
,
cfg
*
api
.
ConfigMap
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
ConfigMap
,
error
)
DeleteConfigMap
(
ctx
contex
t
.
Context
,
name
string
)
error
}
// storage puts strong typing around storage calls
...
...
@@ -46,7 +47,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListConfigMaps
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ConfigMapList
,
error
)
{
func
(
s
*
storage
)
ListConfigMaps
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ConfigMapList
,
error
)
{
obj
,
err
:=
s
.
List
(
ctx
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -55,11 +56,11 @@ func (s *storage) ListConfigMaps(ctx genericapirequest.Context, options *metaint
return
obj
.
(
*
api
.
ConfigMapList
),
err
}
func
(
s
*
storage
)
WatchConfigMaps
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchConfigMaps
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetConfigMap
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
ConfigMap
,
error
)
{
func
(
s
*
storage
)
GetConfigMap
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
ConfigMap
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -68,7 +69,7 @@ func (s *storage) GetConfigMap(ctx genericapirequest.Context, name string, optio
return
obj
.
(
*
api
.
ConfigMap
),
nil
}
func
(
s
*
storage
)
CreateConfigMap
(
ctx
genericapireques
t
.
Context
,
cfg
*
api
.
ConfigMap
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
ConfigMap
,
error
)
{
func
(
s
*
storage
)
CreateConfigMap
(
ctx
contex
t
.
Context
,
cfg
*
api
.
ConfigMap
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
ConfigMap
,
error
)
{
obj
,
err
:=
s
.
Create
(
ctx
,
cfg
,
createValidation
,
false
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -77,7 +78,7 @@ func (s *storage) CreateConfigMap(ctx genericapirequest.Context, cfg *api.Config
return
obj
.
(
*
api
.
ConfigMap
),
nil
}
func
(
s
*
storage
)
UpdateConfigMap
(
ctx
genericapireques
t
.
Context
,
cfg
*
api
.
ConfigMap
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
ConfigMap
,
error
)
{
func
(
s
*
storage
)
UpdateConfigMap
(
ctx
contex
t
.
Context
,
cfg
*
api
.
ConfigMap
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
ConfigMap
,
error
)
{
obj
,
_
,
err
:=
s
.
Update
(
ctx
,
cfg
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
cfg
),
createValidation
,
updateValidation
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -86,7 +87,7 @@ func (s *storage) UpdateConfigMap(ctx genericapirequest.Context, cfg *api.Config
return
obj
.
(
*
api
.
ConfigMap
),
nil
}
func
(
s
*
storage
)
DeleteConfigMap
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
{
func
(
s
*
storage
)
DeleteConfigMap
(
ctx
contex
t
.
Context
,
name
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
name
,
nil
)
return
err
}
pkg/registry/core/configmap/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
configmap
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
...
...
@@ -47,11 +48,11 @@ func (strategy) NamespaceScoped() bool {
return
true
}
func
(
strategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
strategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
_
=
obj
.
(
*
api
.
ConfigMap
)
}
func
(
strategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
cfg
:=
obj
.
(
*
api
.
ConfigMap
)
return
validation
.
ValidateConfigMap
(
cfg
)
...
...
@@ -65,7 +66,7 @@ func (strategy) AllowCreateOnUpdate() bool {
return
false
}
func
(
strategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
newObj
,
oldObj
runtime
.
Object
)
{
func
(
strategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
newObj
,
oldObj
runtime
.
Object
)
{
_
=
oldObj
.
(
*
api
.
ConfigMap
)
_
=
newObj
.
(
*
api
.
ConfigMap
)
}
...
...
@@ -74,7 +75,7 @@ func (strategy) AllowUnconditionalUpdate() bool {
return
true
}
func
(
strategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
newObj
,
oldObj
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
newObj
,
oldObj
runtime
.
Object
)
field
.
ErrorList
{
oldCfg
,
newCfg
:=
oldObj
.
(
*
api
.
ConfigMap
),
newObj
.
(
*
api
.
ConfigMap
)
return
validation
.
ValidateConfigMapUpdate
(
newCfg
,
oldCfg
)
...
...
pkg/registry/core/endpoint/BUILD
View file @
54fd2aae
...
...
@@ -23,7 +23,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
...
...
pkg/registry/core/endpoint/registry.go
View file @
54fd2aae
...
...
@@ -17,21 +17,22 @@ limitations under the License.
package
endpoint
import
(
"context"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
api
"k8s.io/kubernetes/pkg/apis/core"
)
// Registry is an interface for things that know how to store endpoints.
type
Registry
interface
{
ListEndpoints
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
EndpointsList
,
error
)
GetEndpoints
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Endpoints
,
error
)
WatchEndpoints
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
UpdateEndpoints
(
ctx
genericapireques
t
.
Context
,
e
*
api
.
Endpoints
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
DeleteEndpoints
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
ListEndpoints
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
EndpointsList
,
error
)
GetEndpoints
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Endpoints
,
error
)
WatchEndpoints
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
UpdateEndpoints
(
ctx
contex
t
.
Context
,
e
*
api
.
Endpoints
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
DeleteEndpoints
(
ctx
contex
t
.
Context
,
name
string
)
error
}
// storage puts strong typing around storage calls
...
...
@@ -45,7 +46,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListEndpoints
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
EndpointsList
,
error
)
{
func
(
s
*
storage
)
ListEndpoints
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
EndpointsList
,
error
)
{
obj
,
err
:=
s
.
List
(
ctx
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -53,11 +54,11 @@ func (s *storage) ListEndpoints(ctx genericapirequest.Context, options *metainte
return
obj
.
(
*
api
.
EndpointsList
),
nil
}
func
(
s
*
storage
)
WatchEndpoints
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchEndpoints
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetEndpoints
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Endpoints
,
error
)
{
func
(
s
*
storage
)
GetEndpoints
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Endpoints
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -65,12 +66,12 @@ func (s *storage) GetEndpoints(ctx genericapirequest.Context, name string, optio
return
obj
.
(
*
api
.
Endpoints
),
nil
}
func
(
s
*
storage
)
UpdateEndpoints
(
ctx
genericapireques
t
.
Context
,
endpoints
*
api
.
Endpoints
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
func
(
s
*
storage
)
UpdateEndpoints
(
ctx
contex
t
.
Context
,
endpoints
*
api
.
Endpoints
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
_
,
_
,
err
:=
s
.
Update
(
ctx
,
endpoints
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
endpoints
),
createValidation
,
updateValidation
)
return
err
}
func
(
s
*
storage
)
DeleteEndpoints
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
{
func
(
s
*
storage
)
DeleteEndpoints
(
ctx
contex
t
.
Context
,
name
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
name
,
nil
)
return
err
}
pkg/registry/core/endpoint/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
endpoint
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
endptspkg
"k8s.io/kubernetes/pkg/api/endpoints"
"k8s.io/kubernetes/pkg/api/legacyscheme"
...
...
@@ -43,15 +44,15 @@ func (endpointsStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func
(
endpointsStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
endpointsStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
endpointsStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
endpointsStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
}
// Validate validates a new endpoints.
func
(
endpointsStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
endpointsStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateEndpoints
(
obj
.
(
*
api
.
Endpoints
))
}
...
...
@@ -67,7 +68,7 @@ func (endpointsStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
endpointsStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
endpointsStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
errorList
:=
validation
.
ValidateEndpoints
(
obj
.
(
*
api
.
Endpoints
))
return
append
(
errorList
,
validation
.
ValidateEndpointsUpdate
(
obj
.
(
*
api
.
Endpoints
),
old
.
(
*
api
.
Endpoints
))
...
)
}
...
...
pkg/registry/core/event/BUILD
View file @
54fd2aae
...
...
@@ -21,7 +21,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
...
...
pkg/registry/core/event/strategy.go
View file @
54fd2aae
...
...
@@ -17,13 +17,13 @@ limitations under the License.
package
event
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage"
...
...
@@ -42,7 +42,7 @@ type eventStrategy struct {
// Event objects via the REST API.
var
Strategy
=
eventStrategy
{
legacyscheme
.
Scheme
,
names
.
SimpleNameGenerator
}
func
(
eventStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
genericapireques
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
func
(
eventStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
contex
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
return
rest
.
Unsupported
}
...
...
@@ -50,13 +50,13 @@ func (eventStrategy) NamespaceScoped() bool {
return
true
}
func
(
eventStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
eventStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
}
func
(
eventStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
eventStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
}
func
(
eventStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
eventStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
event
:=
obj
.
(
*
api
.
Event
)
return
validation
.
ValidateEvent
(
event
)
}
...
...
@@ -69,7 +69,7 @@ func (eventStrategy) AllowCreateOnUpdate() bool {
return
true
}
func
(
eventStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
eventStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
event
:=
obj
.
(
*
api
.
Event
)
return
validation
.
ValidateEvent
(
event
)
}
...
...
pkg/registry/core/limitrange/BUILD
View file @
54fd2aae
...
...
@@ -19,7 +19,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
)
...
...
pkg/registry/core/limitrange/strategy.go
View file @
54fd2aae
...
...
@@ -17,10 +17,11 @@ limitations under the License.
package
limitrange
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
api
"k8s.io/kubernetes/pkg/apis/core"
...
...
@@ -40,17 +41,17 @@ func (limitrangeStrategy) NamespaceScoped() bool {
return
true
}
func
(
limitrangeStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
limitrangeStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
limitRange
:=
obj
.
(
*
api
.
LimitRange
)
if
len
(
limitRange
.
Name
)
==
0
{
limitRange
.
Name
=
string
(
uuid
.
NewUUID
())
}
}
func
(
limitrangeStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
limitrangeStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
}
func
(
limitrangeStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
limitrangeStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
limitRange
:=
obj
.
(
*
api
.
LimitRange
)
return
validation
.
ValidateLimitRange
(
limitRange
)
}
...
...
@@ -63,7 +64,7 @@ func (limitrangeStrategy) AllowCreateOnUpdate() bool {
return
true
}
func
(
limitrangeStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
limitrangeStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
limitRange
:=
obj
.
(
*
api
.
LimitRange
)
return
validation
.
ValidateLimitRange
(
limitRange
)
}
...
...
@@ -72,7 +73,7 @@ func (limitrangeStrategy) AllowUnconditionalUpdate() bool {
return
true
}
func
(
limitrangeStrategy
)
Export
(
genericapireques
t
.
Context
,
runtime
.
Object
,
bool
)
error
{
func
(
limitrangeStrategy
)
Export
(
contex
t
.
Context
,
runtime
.
Object
,
bool
)
error
{
// Copied from OpenShift exporter
// TODO: this needs to be fixed
// limitrange.Strategy.PrepareForCreate(ctx, obj)
...
...
pkg/registry/core/namespace/BUILD
View file @
54fd2aae
...
...
@@ -25,7 +25,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
...
...
pkg/registry/core/namespace/registry.go
View file @
54fd2aae
...
...
@@ -17,22 +17,23 @@ limitations under the License.
package
namespace
import
(
"context"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
api
"k8s.io/kubernetes/pkg/apis/core"
)
// Registry is an interface implemented by things that know how to store Namespace objects.
type
Registry
interface
{
ListNamespaces
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
NamespaceList
,
error
)
WatchNamespaces
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
GetNamespace
(
ctx
genericapireques
t
.
Context
,
namespaceID
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Namespace
,
error
)
CreateNamespace
(
ctx
genericapireques
t
.
Context
,
namespace
*
api
.
Namespace
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateNamespace
(
ctx
genericapireques
t
.
Context
,
namespace
*
api
.
Namespace
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
DeleteNamespace
(
ctx
genericapireques
t
.
Context
,
namespaceID
string
)
error
ListNamespaces
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
NamespaceList
,
error
)
WatchNamespaces
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
GetNamespace
(
ctx
contex
t
.
Context
,
namespaceID
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Namespace
,
error
)
CreateNamespace
(
ctx
contex
t
.
Context
,
namespace
*
api
.
Namespace
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateNamespace
(
ctx
contex
t
.
Context
,
namespace
*
api
.
Namespace
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
DeleteNamespace
(
ctx
contex
t
.
Context
,
namespaceID
string
)
error
}
// storage puts strong typing around storage calls
...
...
@@ -46,7 +47,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListNamespaces
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
NamespaceList
,
error
)
{
func
(
s
*
storage
)
ListNamespaces
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
NamespaceList
,
error
)
{
obj
,
err
:=
s
.
List
(
ctx
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -54,11 +55,11 @@ func (s *storage) ListNamespaces(ctx genericapirequest.Context, options *metaint
return
obj
.
(
*
api
.
NamespaceList
),
nil
}
func
(
s
*
storage
)
WatchNamespaces
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchNamespaces
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetNamespace
(
ctx
genericapireques
t
.
Context
,
namespaceName
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Namespace
,
error
)
{
func
(
s
*
storage
)
GetNamespace
(
ctx
contex
t
.
Context
,
namespaceName
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Namespace
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
namespaceName
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -66,17 +67,17 @@ func (s *storage) GetNamespace(ctx genericapirequest.Context, namespaceName stri
return
obj
.
(
*
api
.
Namespace
),
nil
}
func
(
s
*
storage
)
CreateNamespace
(
ctx
genericapireques
t
.
Context
,
namespace
*
api
.
Namespace
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
func
(
s
*
storage
)
CreateNamespace
(
ctx
contex
t
.
Context
,
namespace
*
api
.
Namespace
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
_
,
err
:=
s
.
Create
(
ctx
,
namespace
,
createValidation
,
false
)
return
err
}
func
(
s
*
storage
)
UpdateNamespace
(
ctx
genericapireques
t
.
Context
,
namespace
*
api
.
Namespace
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
func
(
s
*
storage
)
UpdateNamespace
(
ctx
contex
t
.
Context
,
namespace
*
api
.
Namespace
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
_
,
_
,
err
:=
s
.
Update
(
ctx
,
namespace
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
namespace
),
createValidation
,
updateValidation
)
return
err
}
func
(
s
*
storage
)
DeleteNamespace
(
ctx
genericapireques
t
.
Context
,
namespaceID
string
)
error
{
func
(
s
*
storage
)
DeleteNamespace
(
ctx
contex
t
.
Context
,
namespaceID
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
namespaceID
,
nil
)
return
err
}
pkg/registry/core/namespace/storage/BUILD
View file @
54fd2aae
...
...
@@ -40,7 +40,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1beta1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/core/namespace/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
storage
import
(
"context"
"fmt"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
...
...
@@ -25,7 +26,6 @@ import (
metav1beta1
"k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -92,32 +92,32 @@ func (r *REST) NewList() runtime.Object {
return
r
.
store
.
NewList
()
}
func
(
r
*
REST
)
List
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
REST
)
List
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
List
(
ctx
,
options
)
}
func
(
r
*
REST
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
REST
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Create
(
ctx
,
obj
,
createValidation
,
includeUninitialized
)
}
func
(
r
*
REST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
REST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
func
(
r
*
REST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
REST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
func
(
r
*
REST
)
Watch
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
r
*
REST
)
Watch
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
r
.
store
.
Watch
(
ctx
,
options
)
}
func
(
r
*
REST
)
Export
(
ctx
genericapireques
t
.
Context
,
name
string
,
opts
metav1
.
ExportOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
REST
)
Export
(
ctx
contex
t
.
Context
,
name
string
,
opts
metav1
.
ExportOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Export
(
ctx
,
name
,
opts
)
}
// Delete enforces life-cycle rules for namespace termination
func
(
r
*
REST
)
Delete
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
REST
)
Delete
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
nsObj
,
err
:=
r
.
Get
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
false
,
err
...
...
@@ -208,7 +208,7 @@ func (r *REST) Delete(ctx genericapirequest.Context, name string, options *metav
return
r
.
store
.
Delete
(
ctx
,
name
,
options
)
}
func
(
e
*
REST
)
ConvertToTable
(
ctx
genericapireques
t
.
Context
,
object
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
func
(
e
*
REST
)
ConvertToTable
(
ctx
contex
t
.
Context
,
object
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
return
e
.
store
.
ConvertToTable
(
ctx
,
object
,
tableOptions
)
}
...
...
@@ -225,12 +225,12 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
...
...
@@ -239,6 +239,6 @@ func (r *FinalizeREST) New() runtime.Object {
}
// Update alters the status finalizers subset of an object.
func
(
r
*
FinalizeREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
FinalizeREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
pkg/registry/core/namespace/strategy.go
View file @
54fd2aae
...
...
@@ -17,13 +17,13 @@ limitations under the License.
package
namespace
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
apistorage
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage/names"
...
...
@@ -48,7 +48,7 @@ func (namespaceStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func
(
namespaceStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
namespaceStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
// on create, status is active
namespace
:=
obj
.
(
*
api
.
Namespace
)
namespace
.
Status
=
api
.
NamespaceStatus
{
...
...
@@ -73,7 +73,7 @@ func (namespaceStrategy) PrepareForCreate(ctx genericapirequest.Context, obj run
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
namespaceStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
namespaceStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newNamespace
:=
obj
.
(
*
api
.
Namespace
)
oldNamespace
:=
old
.
(
*
api
.
Namespace
)
newNamespace
.
Spec
.
Finalizers
=
oldNamespace
.
Spec
.
Finalizers
...
...
@@ -81,7 +81,7 @@ func (namespaceStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, ol
}
// Validate validates a new namespace.
func
(
namespaceStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
namespaceStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
namespace
:=
obj
.
(
*
api
.
Namespace
)
return
validation
.
ValidateNamespace
(
namespace
)
}
...
...
@@ -96,7 +96,7 @@ func (namespaceStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
namespaceStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
namespaceStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
errorList
:=
validation
.
ValidateNamespace
(
obj
.
(
*
api
.
Namespace
))
return
append
(
errorList
,
validation
.
ValidateNamespaceUpdate
(
obj
.
(
*
api
.
Namespace
),
old
.
(
*
api
.
Namespace
))
...
)
}
...
...
@@ -111,13 +111,13 @@ type namespaceStatusStrategy struct {
var
StatusStrategy
=
namespaceStatusStrategy
{
Strategy
}
func
(
namespaceStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
namespaceStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newNamespace
:=
obj
.
(
*
api
.
Namespace
)
oldNamespace
:=
old
.
(
*
api
.
Namespace
)
newNamespace
.
Spec
=
oldNamespace
.
Spec
}
func
(
namespaceStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
namespaceStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateNamespaceStatusUpdate
(
obj
.
(
*
api
.
Namespace
),
old
.
(
*
api
.
Namespace
))
}
...
...
@@ -127,12 +127,12 @@ type namespaceFinalizeStrategy struct {
var
FinalizeStrategy
=
namespaceFinalizeStrategy
{
Strategy
}
func
(
namespaceFinalizeStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
namespaceFinalizeStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateNamespaceFinalizeUpdate
(
obj
.
(
*
api
.
Namespace
),
old
.
(
*
api
.
Namespace
))
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
namespaceFinalizeStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
namespaceFinalizeStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newNamespace
:=
obj
.
(
*
api
.
Namespace
)
oldNamespace
:=
old
.
(
*
api
.
Namespace
)
newNamespace
.
Status
=
oldNamespace
.
Status
...
...
pkg/registry/core/node/BUILD
View file @
54fd2aae
...
...
@@ -30,7 +30,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
...
...
pkg/registry/core/node/registry.go
View file @
54fd2aae
...
...
@@ -17,22 +17,23 @@ limitations under the License.
package
node
import
(
"context"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
api
"k8s.io/kubernetes/pkg/apis/core"
)
// Registry is an interface for things that know how to store node.
type
Registry
interface
{
ListNodes
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
NodeList
,
error
)
CreateNode
(
ctx
genericapireques
t
.
Context
,
node
*
api
.
Node
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateNode
(
ctx
genericapireques
t
.
Context
,
node
*
api
.
Node
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetNode
(
ctx
genericapireques
t
.
Context
,
nodeID
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Node
,
error
)
DeleteNode
(
ctx
genericapireques
t
.
Context
,
nodeID
string
)
error
WatchNodes
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
ListNodes
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
NodeList
,
error
)
CreateNode
(
ctx
contex
t
.
Context
,
node
*
api
.
Node
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateNode
(
ctx
contex
t
.
Context
,
node
*
api
.
Node
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetNode
(
ctx
contex
t
.
Context
,
nodeID
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Node
,
error
)
DeleteNode
(
ctx
contex
t
.
Context
,
nodeID
string
)
error
WatchNodes
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
}
// storage puts strong typing around storage calls
...
...
@@ -46,7 +47,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListNodes
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
NodeList
,
error
)
{
func
(
s
*
storage
)
ListNodes
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
NodeList
,
error
)
{
obj
,
err
:=
s
.
List
(
ctx
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -55,21 +56,21 @@ func (s *storage) ListNodes(ctx genericapirequest.Context, options *metainternal
return
obj
.
(
*
api
.
NodeList
),
nil
}
func
(
s
*
storage
)
CreateNode
(
ctx
genericapireques
t
.
Context
,
node
*
api
.
Node
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
func
(
s
*
storage
)
CreateNode
(
ctx
contex
t
.
Context
,
node
*
api
.
Node
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
_
,
err
:=
s
.
Create
(
ctx
,
node
,
createValidation
,
false
)
return
err
}
func
(
s
*
storage
)
UpdateNode
(
ctx
genericapireques
t
.
Context
,
node
*
api
.
Node
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
func
(
s
*
storage
)
UpdateNode
(
ctx
contex
t
.
Context
,
node
*
api
.
Node
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
_
,
_
,
err
:=
s
.
Update
(
ctx
,
node
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
node
),
createValidation
,
updateValidation
)
return
err
}
func
(
s
*
storage
)
WatchNodes
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchNodes
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetNode
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Node
,
error
)
{
func
(
s
*
storage
)
GetNode
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Node
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -77,7 +78,7 @@ func (s *storage) GetNode(ctx genericapirequest.Context, name string, options *m
return
obj
.
(
*
api
.
Node
),
nil
}
func
(
s
*
storage
)
DeleteNode
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
{
func
(
s
*
storage
)
DeleteNode
(
ctx
contex
t
.
Context
,
name
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
name
,
nil
)
return
err
}
pkg/registry/core/node/rest/BUILD
View file @
54fd2aae
...
...
@@ -17,7 +17,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/proxy:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
],
...
...
pkg/registry/core/node/rest/proxy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
node
import
(
"context"
"fmt"
"net/http"
"net/url"
...
...
@@ -24,7 +25,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/proxy"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
api
"k8s.io/kubernetes/pkg/apis/core"
...
...
@@ -61,7 +61,7 @@ func (r *ProxyREST) NewConnectOptions() (runtime.Object, bool, string) {
}
// Connect returns a handler for the node proxy
func
(
r
*
ProxyREST
)
Connect
(
ctx
genericapireques
t
.
Context
,
id
string
,
opts
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
func
(
r
*
ProxyREST
)
Connect
(
ctx
contex
t
.
Context
,
id
string
,
opts
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
proxyOpts
,
ok
:=
opts
.
(
*
api
.
NodeProxyOptions
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"Invalid options object: %#v"
,
opts
)
...
...
pkg/registry/core/node/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
storage
import
(
"context"
"fmt"
"net/http"
"net/url"
...
...
@@ -63,12 +64,12 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
...
...
@@ -137,7 +138,7 @@ func NewStorage(optsGetter generic.RESTOptionsGetter, kubeletClientConfig client
var
_
=
rest
.
Redirector
(
&
REST
{})
// ResourceLocation returns a URL to which one can send traffic for the specified node.
func
(
r
*
REST
)
ResourceLocation
(
ctx
genericapireques
t
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
func
(
r
*
REST
)
ResourceLocation
(
ctx
contex
t
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
return
node
.
ResourceLocation
(
r
,
r
.
connection
,
r
.
proxyTransport
,
ctx
,
id
)
}
...
...
pkg/registry/core/node/strategy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
node
import
(
"context"
"fmt"
"net"
"net/http"
...
...
@@ -30,7 +31,6 @@ import (
"k8s.io/apimachinery/pkg/types"
utilnet
"k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
pkgstorage
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage/names"
...
...
@@ -63,7 +63,7 @@ func (nodeStrategy) AllowCreateOnUpdate() bool {
}
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func
(
nodeStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
nodeStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
node
:=
obj
.
(
*
api
.
Node
)
// Nodes allow *all* fields, including status, to be set on create.
...
...
@@ -73,7 +73,7 @@ func (nodeStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
nodeStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
nodeStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newNode
:=
obj
.
(
*
api
.
Node
)
oldNode
:=
old
.
(
*
api
.
Node
)
newNode
.
Status
=
oldNode
.
Status
...
...
@@ -85,7 +85,7 @@ func (nodeStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old run
}
// Validate validates a new node.
func
(
nodeStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
nodeStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
node
:=
obj
.
(
*
api
.
Node
)
return
validation
.
ValidateNode
(
node
)
}
...
...
@@ -95,7 +95,7 @@ func (nodeStrategy) Canonicalize(obj runtime.Object) {
}
// ValidateUpdate is the default update validation for an end user.
func
(
nodeStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
nodeStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
errorList
:=
validation
.
ValidateNode
(
obj
.
(
*
api
.
Node
))
return
append
(
errorList
,
validation
.
ValidateNodeUpdate
(
obj
.
(
*
api
.
Node
),
old
.
(
*
api
.
Node
))
...
)
}
...
...
@@ -104,7 +104,7 @@ func (nodeStrategy) AllowUnconditionalUpdate() bool {
return
true
}
func
(
ns
nodeStrategy
)
Export
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
{
func
(
ns
nodeStrategy
)
Export
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
{
n
,
ok
:=
obj
.
(
*
api
.
Node
)
if
!
ok
{
// unexpected programmer error
...
...
@@ -126,18 +126,18 @@ type nodeStatusStrategy struct {
var
StatusStrategy
=
nodeStatusStrategy
{
Strategy
}
func
(
nodeStatusStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
nodeStatusStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
_
=
obj
.
(
*
api
.
Node
)
// Nodes allow *all* fields, including status, to be set on create.
}
func
(
nodeStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
nodeStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newNode
:=
obj
.
(
*
api
.
Node
)
oldNode
:=
old
.
(
*
api
.
Node
)
newNode
.
Spec
=
oldNode
.
Spec
}
func
(
nodeStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
nodeStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateNodeUpdate
(
obj
.
(
*
api
.
Node
),
old
.
(
*
api
.
Node
))
}
...
...
@@ -147,7 +147,7 @@ func (nodeStatusStrategy) Canonicalize(obj runtime.Object) {
// ResourceGetter is an interface for retrieving resources by ResourceLocation.
type
ResourceGetter
interface
{
Get
(
genericapireques
t
.
Context
,
string
,
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
Get
(
contex
t
.
Context
,
string
,
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
}
// NodeToSelectableFields returns a field set that represents the object.
...
...
@@ -185,7 +185,7 @@ func NodeNameTriggerFunc(obj runtime.Object) []pkgstorage.MatchValue {
}
// ResourceLocation returns a URL and transport which one can use to send traffic for the specified node.
func
ResourceLocation
(
getter
ResourceGetter
,
connection
client
.
ConnectionInfoGetter
,
proxyTransport
http
.
RoundTripper
,
ctx
genericapireques
t
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
func
ResourceLocation
(
getter
ResourceGetter
,
connection
client
.
ConnectionInfoGetter
,
proxyTransport
http
.
RoundTripper
,
ctx
contex
t
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
schemeReq
,
name
,
portReq
,
valid
:=
utilnet
.
SplitSchemeNamePort
(
id
)
if
!
valid
{
return
nil
,
nil
,
errors
.
NewBadRequest
(
fmt
.
Sprintf
(
"invalid node request %q"
,
id
))
...
...
pkg/registry/core/persistentvolume/BUILD
View file @
54fd2aae
...
...
@@ -23,7 +23,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
...
...
pkg/registry/core/persistentvolume/storage/BUILD
View file @
54fd2aae
...
...
@@ -40,7 +40,6 @@ go_library(
"//pkg/registry/core/persistentvolume:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/core/persistentvolume/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
storage
import
(
"context"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -78,11 +79,11 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
pkg/registry/core/persistentvolume/strategy.go
View file @
54fd2aae
...
...
@@ -17,13 +17,13 @@ limitations under the License.
package
persistentvolume
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage/names"
...
...
@@ -49,14 +49,14 @@ func (persistentvolumeStrategy) NamespaceScoped() bool {
}
// ResetBeforeCreate clears the Status field which is not allowed to be set by end users on creation.
func
(
persistentvolumeStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
persistentvolumeStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
pv
:=
obj
.
(
*
api
.
PersistentVolume
)
pv
.
Status
=
api
.
PersistentVolumeStatus
{}
pvutil
.
DropDisabledAlphaFields
(
&
pv
.
Spec
)
}
func
(
persistentvolumeStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
persistentvolumeStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
persistentvolume
:=
obj
.
(
*
api
.
PersistentVolume
)
errorList
:=
validation
.
ValidatePersistentVolume
(
persistentvolume
)
return
append
(
errorList
,
volumevalidation
.
ValidatePersistentVolume
(
persistentvolume
)
...
)
...
...
@@ -71,7 +71,7 @@ func (persistentvolumeStrategy) AllowCreateOnUpdate() bool {
}
// PrepareForUpdate sets the Status fields which is not allowed to be set by an end user updating a PV
func
(
persistentvolumeStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
persistentvolumeStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newPv
:=
obj
.
(
*
api
.
PersistentVolume
)
oldPv
:=
old
.
(
*
api
.
PersistentVolume
)
newPv
.
Status
=
oldPv
.
Status
...
...
@@ -80,7 +80,7 @@ func (persistentvolumeStrategy) PrepareForUpdate(ctx genericapirequest.Context,
pvutil
.
DropDisabledAlphaFields
(
&
oldPv
.
Spec
)
}
func
(
persistentvolumeStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
persistentvolumeStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
newPv
:=
obj
.
(
*
api
.
PersistentVolume
)
errorList
:=
validation
.
ValidatePersistentVolume
(
newPv
)
errorList
=
append
(
errorList
,
volumevalidation
.
ValidatePersistentVolume
(
newPv
)
...
)
...
...
@@ -98,13 +98,13 @@ type persistentvolumeStatusStrategy struct {
var
StatusStrategy
=
persistentvolumeStatusStrategy
{
Strategy
}
// PrepareForUpdate sets the Spec field which is not allowed to be changed when updating a PV's Status
func
(
persistentvolumeStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
persistentvolumeStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newPv
:=
obj
.
(
*
api
.
PersistentVolume
)
oldPv
:=
old
.
(
*
api
.
PersistentVolume
)
newPv
.
Spec
=
oldPv
.
Spec
}
func
(
persistentvolumeStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
persistentvolumeStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidatePersistentVolumeStatusUpdate
(
obj
.
(
*
api
.
PersistentVolume
),
old
.
(
*
api
.
PersistentVolume
))
}
...
...
pkg/registry/core/persistentvolumeclaim/BUILD
View file @
54fd2aae
...
...
@@ -22,7 +22,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
...
...
pkg/registry/core/persistentvolumeclaim/storage/BUILD
View file @
54fd2aae
...
...
@@ -40,7 +40,6 @@ go_library(
"//pkg/registry/core/persistentvolumeclaim:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/core/persistentvolumeclaim/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
storage
import
(
"context"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -78,11 +79,11 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
pkg/registry/core/persistentvolumeclaim/strategy.go
View file @
54fd2aae
...
...
@@ -17,13 +17,13 @@ limitations under the License.
package
persistentvolumeclaim
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage/names"
...
...
@@ -48,14 +48,14 @@ func (persistentvolumeclaimStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the Status field which is not allowed to be set by end users on creation.
func
(
persistentvolumeclaimStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
persistentvolumeclaimStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
pvc
:=
obj
.
(
*
api
.
PersistentVolumeClaim
)
pvc
.
Status
=
api
.
PersistentVolumeClaimStatus
{}
pvcutil
.
DropDisabledAlphaFields
(
&
pvc
.
Spec
)
}
func
(
persistentvolumeclaimStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
persistentvolumeclaimStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
pvc
:=
obj
.
(
*
api
.
PersistentVolumeClaim
)
return
validation
.
ValidatePersistentVolumeClaim
(
pvc
)
}
...
...
@@ -69,7 +69,7 @@ func (persistentvolumeclaimStrategy) AllowCreateOnUpdate() bool {
}
// PrepareForUpdate sets the Status field which is not allowed to be set by end users on update
func
(
persistentvolumeclaimStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
persistentvolumeclaimStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newPvc
:=
obj
.
(
*
api
.
PersistentVolumeClaim
)
oldPvc
:=
old
.
(
*
api
.
PersistentVolumeClaim
)
newPvc
.
Status
=
oldPvc
.
Status
...
...
@@ -78,7 +78,7 @@ func (persistentvolumeclaimStrategy) PrepareForUpdate(ctx genericapirequest.Cont
pvcutil
.
DropDisabledAlphaFields
(
&
oldPvc
.
Spec
)
}
func
(
persistentvolumeclaimStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
persistentvolumeclaimStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
errorList
:=
validation
.
ValidatePersistentVolumeClaim
(
obj
.
(
*
api
.
PersistentVolumeClaim
))
return
append
(
errorList
,
validation
.
ValidatePersistentVolumeClaimUpdate
(
obj
.
(
*
api
.
PersistentVolumeClaim
),
old
.
(
*
api
.
PersistentVolumeClaim
))
...
)
}
...
...
@@ -94,13 +94,13 @@ type persistentvolumeclaimStatusStrategy struct {
var
StatusStrategy
=
persistentvolumeclaimStatusStrategy
{
Strategy
}
// PrepareForUpdate sets the Spec field which is not allowed to be changed when updating a PV's Status
func
(
persistentvolumeclaimStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
persistentvolumeclaimStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newPv
:=
obj
.
(
*
api
.
PersistentVolumeClaim
)
oldPv
:=
old
.
(
*
api
.
PersistentVolumeClaim
)
newPv
.
Spec
=
oldPv
.
Spec
}
func
(
persistentvolumeclaimStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
persistentvolumeclaimStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidatePersistentVolumeClaimStatusUpdate
(
obj
.
(
*
api
.
PersistentVolumeClaim
),
old
.
(
*
api
.
PersistentVolumeClaim
))
}
...
...
pkg/registry/core/pod/BUILD
View file @
54fd2aae
...
...
@@ -30,7 +30,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/features:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
...
...
pkg/registry/core/pod/rest/BUILD
View file @
54fd2aae
...
...
@@ -23,7 +23,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/proxy:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/features:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/rest:go_default_library",
...
...
pkg/registry/core/pod/rest/log.go
View file @
54fd2aae
...
...
@@ -17,11 +17,11 @@ limitations under the License.
package
rest
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
genericrest
"k8s.io/apiserver/pkg/registry/generic/rest"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -62,7 +62,7 @@ func (r *LogREST) ProducesObject(verb string) interface{} {
}
// Get retrieves a runtime.Object that will stream the contents of the pod log
func
(
r
*
LogREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
opts
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
LogREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
opts
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
logOpts
,
ok
:=
opts
.
(
*
api
.
PodLogOptions
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid options object: %#v"
,
opts
)
...
...
pkg/registry/core/pod/rest/subresources.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
rest
import
(
"context"
"fmt"
"net/http"
"net/url"
...
...
@@ -24,7 +25,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/proxy"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
genericfeatures
"k8s.io/apiserver/pkg/features"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -62,7 +62,7 @@ func (r *ProxyREST) NewConnectOptions() (runtime.Object, bool, string) {
}
// Connect returns a handler for the pod proxy
func
(
r
*
ProxyREST
)
Connect
(
ctx
genericapireques
t
.
Context
,
id
string
,
opts
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
func
(
r
*
ProxyREST
)
Connect
(
ctx
contex
t
.
Context
,
id
string
,
opts
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
proxyOpts
,
ok
:=
opts
.
(
*
api
.
PodProxyOptions
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"Invalid options object: %#v"
,
opts
)
...
...
@@ -94,7 +94,7 @@ func (r *AttachREST) New() runtime.Object {
}
// Connect returns a handler for the pod exec proxy
func
(
r
*
AttachREST
)
Connect
(
ctx
genericapireques
t
.
Context
,
name
string
,
opts
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
func
(
r
*
AttachREST
)
Connect
(
ctx
contex
t
.
Context
,
name
string
,
opts
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
attachOpts
,
ok
:=
opts
.
(
*
api
.
PodAttachOptions
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"Invalid options object: %#v"
,
opts
)
...
...
@@ -131,7 +131,7 @@ func (r *ExecREST) New() runtime.Object {
}
// Connect returns a handler for the pod exec proxy
func
(
r
*
ExecREST
)
Connect
(
ctx
genericapireques
t
.
Context
,
name
string
,
opts
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
func
(
r
*
ExecREST
)
Connect
(
ctx
contex
t
.
Context
,
name
string
,
opts
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
execOpts
,
ok
:=
opts
.
(
*
api
.
PodExecOptions
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid options object: %#v"
,
opts
)
...
...
@@ -179,7 +179,7 @@ func (r *PortForwardREST) ConnectMethods() []string {
}
// Connect returns a handler for the pod portforward proxy
func
(
r
*
PortForwardREST
)
Connect
(
ctx
genericapireques
t
.
Context
,
name
string
,
opts
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
func
(
r
*
PortForwardREST
)
Connect
(
ctx
contex
t
.
Context
,
name
string
,
opts
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
portForwardOpts
,
ok
:=
opts
.
(
*
api
.
PodPortForwardOptions
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid options object: %#v"
,
opts
)
...
...
pkg/registry/core/pod/storage/BUILD
View file @
54fd2aae
...
...
@@ -61,7 +61,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/core/pod/storage/eviction.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
storage
import
(
"context"
"fmt"
"time"
...
...
@@ -26,7 +27,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/wait"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/client-go/util/retry"
...
...
@@ -78,7 +78,7 @@ func (r *EvictionREST) New() runtime.Object {
}
// Create attempts to create a new eviction. That is, it tries to evict a pod.
func
(
r
*
EvictionREST
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
EvictionREST
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
eviction
:=
obj
.
(
*
policy
.
Eviction
)
obj
,
err
:=
r
.
store
.
Get
(
ctx
,
eviction
.
Name
,
&
metav1
.
GetOptions
{})
...
...
@@ -177,7 +177,7 @@ func (r *EvictionREST) checkAndDecrement(namespace string, podName string, pdb p
}
// getPodDisruptionBudgets returns any PDBs that match the pod or err if there's an error.
func
(
r
*
EvictionREST
)
getPodDisruptionBudgets
(
ctx
genericapireques
t
.
Context
,
pod
*
api
.
Pod
)
([]
policy
.
PodDisruptionBudget
,
error
)
{
func
(
r
*
EvictionREST
)
getPodDisruptionBudgets
(
ctx
contex
t
.
Context
,
pod
*
api
.
Pod
)
([]
policy
.
PodDisruptionBudget
,
error
)
{
if
len
(
pod
.
Labels
)
==
0
{
return
nil
,
nil
}
...
...
pkg/registry/core/pod/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
storage
import
(
"context"
"fmt"
"net/http"
"net/url"
...
...
@@ -24,7 +25,6 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -102,7 +102,7 @@ func NewStorage(optsGetter generic.RESTOptionsGetter, k client.ConnectionInfoGet
var
_
=
rest
.
Redirector
(
&
REST
{})
// ResourceLocation returns a pods location from its HostIP
func
(
r
*
REST
)
ResourceLocation
(
ctx
genericapireques
t
.
Context
,
name
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
func
(
r
*
REST
)
ResourceLocation
(
ctx
contex
t
.
Context
,
name
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
return
pod
.
ResourceLocation
(
r
,
r
.
proxyTransport
,
ctx
,
name
)
}
...
...
@@ -135,7 +135,7 @@ func (r *BindingREST) New() runtime.Object {
var
_
=
rest
.
Creater
(
&
BindingREST
{})
// Create ensures a pod is bound to a specific host.
func
(
r
*
BindingREST
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
out
runtime
.
Object
,
err
error
)
{
func
(
r
*
BindingREST
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
out
runtime
.
Object
,
err
error
)
{
binding
:=
obj
.
(
*
api
.
Binding
)
// TODO: move me to a binding strategy
...
...
@@ -151,7 +151,7 @@ func (r *BindingREST) Create(ctx genericapirequest.Context, obj runtime.Object,
// setPodHostAndAnnotations sets the given pod's host to 'machine' if and only if it was
// previously 'oldMachine' and merges the provided annotations with those of the pod.
// Returns the current state of the pod, or an error.
func
(
r
*
BindingREST
)
setPodHostAndAnnotations
(
ctx
genericapireques
t
.
Context
,
podID
,
oldMachine
,
machine
string
,
annotations
map
[
string
]
string
)
(
finalPod
*
api
.
Pod
,
err
error
)
{
func
(
r
*
BindingREST
)
setPodHostAndAnnotations
(
ctx
contex
t
.
Context
,
podID
,
oldMachine
,
machine
string
,
annotations
map
[
string
]
string
)
(
finalPod
*
api
.
Pod
,
err
error
)
{
podKey
,
err
:=
r
.
store
.
KeyFunc
(
ctx
,
podID
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -185,7 +185,7 @@ func (r *BindingREST) setPodHostAndAnnotations(ctx genericapirequest.Context, po
}
// assignPod assigns the given pod to the given machine.
func
(
r
*
BindingREST
)
assignPod
(
ctx
genericapireques
t
.
Context
,
podID
string
,
machine
string
,
annotations
map
[
string
]
string
)
(
err
error
)
{
func
(
r
*
BindingREST
)
assignPod
(
ctx
contex
t
.
Context
,
podID
string
,
machine
string
,
annotations
map
[
string
]
string
)
(
err
error
)
{
if
_
,
err
=
r
.
setPodHostAndAnnotations
(
ctx
,
podID
,
""
,
machine
,
annotations
);
err
!=
nil
{
err
=
storeerr
.
InterpretGetError
(
err
,
api
.
Resource
(
"pods"
),
podID
)
err
=
storeerr
.
InterpretUpdateError
(
err
,
api
.
Resource
(
"pods"
),
podID
)
...
...
@@ -207,11 +207,11 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
pkg/registry/core/pod/strategy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
pod
import
(
"context"
"fmt"
"net"
"net/http"
...
...
@@ -35,7 +36,6 @@ import (
"k8s.io/apimachinery/pkg/types"
utilnet
"k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/features"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/storage"
...
...
@@ -65,7 +65,7 @@ func (podStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func
(
podStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
podStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
pod
:=
obj
.
(
*
api
.
Pod
)
pod
.
Status
=
api
.
PodStatus
{
Phase
:
api
.
PodPending
,
...
...
@@ -76,7 +76,7 @@ func (podStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.O
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
podStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
podStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newPod
:=
obj
.
(
*
api
.
Pod
)
oldPod
:=
old
.
(
*
api
.
Pod
)
newPod
.
Status
=
oldPod
.
Status
...
...
@@ -86,7 +86,7 @@ func (podStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runt
}
// Validate validates a new pod.
func
(
podStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
podStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
pod
:=
obj
.
(
*
api
.
Pod
)
return
validation
.
ValidatePod
(
pod
)
}
...
...
@@ -116,7 +116,7 @@ func isUpdatingUninitializedPod(old runtime.Object) (bool, error) {
}
// ValidateUpdate is the default update validation for an end user.
func
(
podStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
podStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
errorList
:=
validation
.
ValidatePod
(
obj
.
(
*
api
.
Pod
))
uninitializedUpdate
,
err
:=
isUpdatingUninitializedPod
(
old
)
if
err
!=
nil
{
...
...
@@ -135,7 +135,7 @@ func (podStrategy) AllowUnconditionalUpdate() bool {
// CheckGracefulDelete allows a pod to be gracefully deleted. It updates the DeleteOptions to
// reflect the desired grace value.
func
(
podStrategy
)
CheckGracefulDelete
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
options
*
metav1
.
DeleteOptions
)
bool
{
func
(
podStrategy
)
CheckGracefulDelete
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
options
*
metav1
.
DeleteOptions
)
bool
{
if
options
==
nil
{
return
false
}
...
...
@@ -168,7 +168,7 @@ type podStrategyWithoutGraceful struct {
}
// CheckGracefulDelete prohibits graceful deletion.
func
(
podStrategyWithoutGraceful
)
CheckGracefulDelete
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
options
*
metav1
.
DeleteOptions
)
bool
{
func
(
podStrategyWithoutGraceful
)
CheckGracefulDelete
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
options
*
metav1
.
DeleteOptions
)
bool
{
return
false
}
...
...
@@ -181,7 +181,7 @@ type podStatusStrategy struct {
var
StatusStrategy
=
podStatusStrategy
{
Strategy
}
func
(
podStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
podStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newPod
:=
obj
.
(
*
api
.
Pod
)
oldPod
:=
old
.
(
*
api
.
Pod
)
newPod
.
Spec
=
oldPod
.
Spec
...
...
@@ -192,7 +192,7 @@ func (podStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, ol
newPod
.
OwnerReferences
=
oldPod
.
OwnerReferences
}
func
(
podStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
podStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
var
errorList
field
.
ErrorList
uninitializedUpdate
,
err
:=
isUpdatingUninitializedPod
(
old
)
if
err
!=
nil
{
...
...
@@ -249,10 +249,10 @@ func PodToSelectableFields(pod *api.Pod) fields.Set {
// ResourceGetter is an interface for retrieving resources by ResourceLocation.
type
ResourceGetter
interface
{
Get
(
genericapireques
t
.
Context
,
string
,
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
Get
(
contex
t
.
Context
,
string
,
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
}
func
getPod
(
getter
ResourceGetter
,
ctx
genericapireques
t
.
Context
,
name
string
)
(
*
api
.
Pod
,
error
)
{
func
getPod
(
getter
ResourceGetter
,
ctx
contex
t
.
Context
,
name
string
)
(
*
api
.
Pod
,
error
)
{
obj
,
err
:=
getter
.
Get
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -265,7 +265,7 @@ func getPod(getter ResourceGetter, ctx genericapirequest.Context, name string) (
}
// ResourceLocation returns a URL to which one can send traffic for the specified pod.
func
ResourceLocation
(
getter
ResourceGetter
,
rt
http
.
RoundTripper
,
ctx
genericapireques
t
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
func
ResourceLocation
(
getter
ResourceGetter
,
rt
http
.
RoundTripper
,
ctx
contex
t
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
// Allow ID as "podname" or "podname:port" or "scheme:podname:port".
// If port is not specified, try to use the first defined port on the pod.
scheme
,
name
,
port
,
valid
:=
utilnet
.
SplitSchemeNamePort
(
id
)
...
...
@@ -314,7 +314,7 @@ func getContainerNames(containers []api.Container) string {
func
LogLocation
(
getter
ResourceGetter
,
connInfo
client
.
ConnectionInfoGetter
,
ctx
genericapireques
t
.
Context
,
ctx
contex
t
.
Context
,
name
string
,
opts
*
api
.
PodLogOptions
,
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
...
...
@@ -450,7 +450,7 @@ func streamParams(params url.Values, opts runtime.Object) error {
func
AttachLocation
(
getter
ResourceGetter
,
connInfo
client
.
ConnectionInfoGetter
,
ctx
genericapireques
t
.
Context
,
ctx
contex
t
.
Context
,
name
string
,
opts
*
api
.
PodAttachOptions
,
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
...
...
@@ -462,7 +462,7 @@ func AttachLocation(
func
ExecLocation
(
getter
ResourceGetter
,
connInfo
client
.
ConnectionInfoGetter
,
ctx
genericapireques
t
.
Context
,
ctx
contex
t
.
Context
,
name
string
,
opts
*
api
.
PodExecOptions
,
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
...
...
@@ -472,7 +472,7 @@ func ExecLocation(
func
streamLocation
(
getter
ResourceGetter
,
connInfo
client
.
ConnectionInfoGetter
,
ctx
genericapireques
t
.
Context
,
ctx
contex
t
.
Context
,
name
string
,
opts
runtime
.
Object
,
container
,
...
...
@@ -531,7 +531,7 @@ func streamLocation(
func
PortForwardLocation
(
getter
ResourceGetter
,
connInfo
client
.
ConnectionInfoGetter
,
ctx
genericapireques
t
.
Context
,
ctx
contex
t
.
Context
,
name
string
,
opts
*
api
.
PodPortForwardOptions
,
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
...
...
pkg/registry/core/pod/strategy_test.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
pod
import
(
"context"
"net/url"
"reflect"
"testing"
...
...
@@ -268,7 +269,7 @@ type mockPodGetter struct {
pod
*
api
.
Pod
}
func
(
g
mockPodGetter
)
Get
(
genericapireques
t
.
Context
,
string
,
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
g
mockPodGetter
)
Get
(
contex
t
.
Context
,
string
,
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
g
.
pod
,
nil
}
...
...
pkg/registry/core/podtemplate/BUILD
View file @
54fd2aae
...
...
@@ -19,7 +19,6 @@ go_library(
"//pkg/apis/core/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
)
...
...
pkg/registry/core/podtemplate/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
podtemplate
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/pod"
...
...
@@ -43,14 +44,14 @@ func (podTemplateStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func
(
podTemplateStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
podTemplateStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
template
:=
obj
.
(
*
api
.
PodTemplate
)
pod
.
DropDisabledAlphaFields
(
&
template
.
Template
.
Spec
)
}
// Validate validates a new pod template.
func
(
podTemplateStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
podTemplateStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
pod
:=
obj
.
(
*
api
.
PodTemplate
)
return
validation
.
ValidatePodTemplate
(
pod
)
}
...
...
@@ -65,7 +66,7 @@ func (podTemplateStrategy) AllowCreateOnUpdate() bool {
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
podTemplateStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
podTemplateStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newTemplate
:=
obj
.
(
*
api
.
PodTemplate
)
oldTemplate
:=
old
.
(
*
api
.
PodTemplate
)
...
...
@@ -74,7 +75,7 @@ func (podTemplateStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj,
}
// ValidateUpdate is the default update validation for an end user.
func
(
podTemplateStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
podTemplateStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidatePodTemplateUpdate
(
obj
.
(
*
api
.
PodTemplate
),
old
.
(
*
api
.
PodTemplate
))
}
...
...
@@ -82,7 +83,7 @@ func (podTemplateStrategy) AllowUnconditionalUpdate() bool {
return
true
}
func
(
podTemplateStrategy
)
Export
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
{
func
(
podTemplateStrategy
)
Export
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
{
// Do nothing
return
nil
}
pkg/registry/core/replicationcontroller/BUILD
View file @
54fd2aae
...
...
@@ -28,7 +28,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
...
...
pkg/registry/core/replicationcontroller/registry.go
View file @
54fd2aae
...
...
@@ -19,24 +19,24 @@ limitations under the License.
package
replicationcontroller
import
(
"context"
"fmt"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
api
"k8s.io/kubernetes/pkg/apis/core"
)
// Registry is an interface for things that know how to store ReplicationControllers.
type
Registry
interface
{
ListControllers
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ReplicationControllerList
,
error
)
WatchControllers
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
GetController
(
ctx
genericapireques
t
.
Context
,
controllerID
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
ReplicationController
,
error
)
CreateController
(
ctx
genericapireques
t
.
Context
,
controller
*
api
.
ReplicationController
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
ReplicationController
,
error
)
UpdateController
(
ctx
genericapireques
t
.
Context
,
controller
*
api
.
ReplicationController
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
ReplicationController
,
error
)
DeleteController
(
ctx
genericapireques
t
.
Context
,
controllerID
string
)
error
ListControllers
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ReplicationControllerList
,
error
)
WatchControllers
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
GetController
(
ctx
contex
t
.
Context
,
controllerID
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
ReplicationController
,
error
)
CreateController
(
ctx
contex
t
.
Context
,
controller
*
api
.
ReplicationController
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
ReplicationController
,
error
)
UpdateController
(
ctx
contex
t
.
Context
,
controller
*
api
.
ReplicationController
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
ReplicationController
,
error
)
DeleteController
(
ctx
contex
t
.
Context
,
controllerID
string
)
error
}
// storage puts strong typing around storage calls
...
...
@@ -50,7 +50,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListControllers
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ReplicationControllerList
,
error
)
{
func
(
s
*
storage
)
ListControllers
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ReplicationControllerList
,
error
)
{
if
options
!=
nil
&&
options
.
FieldSelector
!=
nil
&&
!
options
.
FieldSelector
.
Empty
()
{
return
nil
,
fmt
.
Errorf
(
"field selector not supported yet"
)
}
...
...
@@ -61,11 +61,11 @@ func (s *storage) ListControllers(ctx genericapirequest.Context, options *metain
return
obj
.
(
*
api
.
ReplicationControllerList
),
err
}
func
(
s
*
storage
)
WatchControllers
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchControllers
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetController
(
ctx
genericapireques
t
.
Context
,
controllerID
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
ReplicationController
,
error
)
{
func
(
s
*
storage
)
GetController
(
ctx
contex
t
.
Context
,
controllerID
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
ReplicationController
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
controllerID
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -73,7 +73,7 @@ func (s *storage) GetController(ctx genericapirequest.Context, controllerID stri
return
obj
.
(
*
api
.
ReplicationController
),
nil
}
func
(
s
*
storage
)
CreateController
(
ctx
genericapireques
t
.
Context
,
controller
*
api
.
ReplicationController
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
ReplicationController
,
error
)
{
func
(
s
*
storage
)
CreateController
(
ctx
contex
t
.
Context
,
controller
*
api
.
ReplicationController
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
ReplicationController
,
error
)
{
obj
,
err
:=
s
.
Create
(
ctx
,
controller
,
createValidation
,
false
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -81,7 +81,7 @@ func (s *storage) CreateController(ctx genericapirequest.Context, controller *ap
return
obj
.
(
*
api
.
ReplicationController
),
nil
}
func
(
s
*
storage
)
UpdateController
(
ctx
genericapireques
t
.
Context
,
controller
*
api
.
ReplicationController
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
ReplicationController
,
error
)
{
func
(
s
*
storage
)
UpdateController
(
ctx
contex
t
.
Context
,
controller
*
api
.
ReplicationController
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
ReplicationController
,
error
)
{
obj
,
_
,
err
:=
s
.
Update
(
ctx
,
controller
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
controller
),
createValidation
,
updateValidation
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -89,7 +89,7 @@ func (s *storage) UpdateController(ctx genericapirequest.Context, controller *ap
return
obj
.
(
*
api
.
ReplicationController
),
nil
}
func
(
s
*
storage
)
DeleteController
(
ctx
genericapireques
t
.
Context
,
controllerID
string
)
error
{
func
(
s
*
storage
)
DeleteController
(
ctx
contex
t
.
Context
,
controllerID
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
controllerID
,
nil
)
return
err
}
pkg/registry/core/replicationcontroller/storage/BUILD
View file @
54fd2aae
...
...
@@ -48,7 +48,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/core/replicationcontroller/storage/storage.go
View file @
54fd2aae
...
...
@@ -19,6 +19,7 @@ limitations under the License.
package
storage
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/api/errors"
...
...
@@ -26,7 +27,6 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -114,12 +114,12 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
...
...
@@ -145,7 +145,7 @@ func (r *ScaleREST) New() runtime.Object {
return
&
autoscaling
.
Scale
{}
}
func
(
r
*
ScaleREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
ScaleREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
rc
,
err
:=
r
.
registry
.
GetController
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
errors
.
NewNotFound
(
autoscaling
.
Resource
(
"replicationcontrollers/scale"
),
name
)
...
...
@@ -153,7 +153,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met
return
scaleFromRC
(
rc
),
nil
}
func
(
r
*
ScaleREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
ScaleREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
rc
,
err
:=
r
.
registry
.
GetController
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
false
,
errors
.
NewNotFound
(
autoscaling
.
Resource
(
"replicationcontrollers/scale"
),
name
)
...
...
pkg/registry/core/replicationcontroller/strategy.go
View file @
54fd2aae
...
...
@@ -19,6 +19,7 @@ limitations under the License.
package
replicationcontroller
import
(
"context"
"fmt"
"strconv"
"strings"
...
...
@@ -28,7 +29,6 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/rest"
apistorage
"k8s.io/apiserver/pkg/storage"
...
...
@@ -51,7 +51,7 @@ var Strategy = rcStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
// DefaultGarbageCollectionPolicy returns Orphan because that was the default
// behavior before the server-side garbage collection was implemented.
func
(
rcStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
genericapireques
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
func
(
rcStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
contex
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
return
rest
.
OrphanDependents
}
...
...
@@ -61,7 +61,7 @@ func (rcStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of a replication controller before creation.
func
(
rcStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
rcStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
controller
:=
obj
.
(
*
api
.
ReplicationController
)
controller
.
Status
=
api
.
ReplicationControllerStatus
{}
...
...
@@ -73,7 +73,7 @@ func (rcStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Ob
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
rcStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
rcStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newController
:=
obj
.
(
*
api
.
ReplicationController
)
oldController
:=
old
.
(
*
api
.
ReplicationController
)
// update is not allowed to set status
...
...
@@ -100,7 +100,7 @@ func (rcStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runti
}
// Validate validates a new replication controller.
func
(
rcStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
rcStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
controller
:=
obj
.
(
*
api
.
ReplicationController
)
return
validation
.
ValidateReplicationController
(
controller
)
}
...
...
@@ -116,7 +116,7 @@ func (rcStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
rcStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
rcStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
oldRc
:=
old
.
(
*
api
.
ReplicationController
)
newRc
:=
obj
.
(
*
api
.
ReplicationController
)
...
...
@@ -183,13 +183,13 @@ type rcStatusStrategy struct {
var
StatusStrategy
=
rcStatusStrategy
{
Strategy
}
func
(
rcStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
rcStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newRc
:=
obj
.
(
*
api
.
ReplicationController
)
oldRc
:=
old
.
(
*
api
.
ReplicationController
)
// update is not allowed to set spec
newRc
.
Spec
=
oldRc
.
Spec
}
func
(
rcStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
rcStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateReplicationControllerStatusUpdate
(
obj
.
(
*
api
.
ReplicationController
),
old
.
(
*
api
.
ReplicationController
))
}
pkg/registry/core/resourcequota/BUILD
View file @
54fd2aae
...
...
@@ -19,7 +19,6 @@ go_library(
"//pkg/apis/core/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
)
...
...
pkg/registry/core/resourcequota/storage/BUILD
View file @
54fd2aae
...
...
@@ -36,7 +36,6 @@ go_library(
"//pkg/registry/core/resourcequota:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/core/resourcequota/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
storage
import
(
"context"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -72,11 +73,11 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
pkg/registry/core/resourcequota/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
resourcequota
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
api
"k8s.io/kubernetes/pkg/apis/core"
...
...
@@ -42,20 +43,20 @@ func (resourcequotaStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func
(
resourcequotaStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
resourcequotaStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
resourcequota
:=
obj
.
(
*
api
.
ResourceQuota
)
resourcequota
.
Status
=
api
.
ResourceQuotaStatus
{}
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
resourcequotaStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
resourcequotaStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newResourcequota
:=
obj
.
(
*
api
.
ResourceQuota
)
oldResourcequota
:=
old
.
(
*
api
.
ResourceQuota
)
newResourcequota
.
Status
=
oldResourcequota
.
Status
}
// Validate validates a new resourcequota.
func
(
resourcequotaStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
resourcequotaStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
resourcequota
:=
obj
.
(
*
api
.
ResourceQuota
)
return
validation
.
ValidateResourceQuota
(
resourcequota
)
}
...
...
@@ -70,7 +71,7 @@ func (resourcequotaStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
resourcequotaStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
resourcequotaStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
errorList
:=
validation
.
ValidateResourceQuota
(
obj
.
(
*
api
.
ResourceQuota
))
return
append
(
errorList
,
validation
.
ValidateResourceQuotaUpdate
(
obj
.
(
*
api
.
ResourceQuota
),
old
.
(
*
api
.
ResourceQuota
))
...
)
}
...
...
@@ -85,12 +86,12 @@ type resourcequotaStatusStrategy struct {
var
StatusStrategy
=
resourcequotaStatusStrategy
{
Strategy
}
func
(
resourcequotaStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
resourcequotaStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newResourcequota
:=
obj
.
(
*
api
.
ResourceQuota
)
oldResourcequota
:=
old
.
(
*
api
.
ResourceQuota
)
newResourcequota
.
Spec
=
oldResourcequota
.
Spec
}
func
(
resourcequotaStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
resourcequotaStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateResourceQuotaStatusUpdate
(
obj
.
(
*
api
.
ResourceQuota
),
old
.
(
*
api
.
ResourceQuota
))
}
pkg/registry/core/secret/BUILD
View file @
54fd2aae
...
...
@@ -22,7 +22,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
...
...
pkg/registry/core/secret/strategy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
secret
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/api/errors"
...
...
@@ -24,7 +25,6 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/rest"
apistorage
"k8s.io/apiserver/pkg/storage"
...
...
@@ -52,10 +52,10 @@ func (strategy) NamespaceScoped() bool {
return
true
}
func
(
strategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
strategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
}
func
(
strategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateSecret
(
obj
.
(
*
api
.
Secret
))
}
...
...
@@ -66,10 +66,10 @@ func (strategy) AllowCreateOnUpdate() bool {
return
false
}
func
(
strategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
strategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
}
func
(
strategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateSecretUpdate
(
obj
.
(
*
api
.
Secret
),
old
.
(
*
api
.
Secret
))
}
...
...
@@ -77,7 +77,7 @@ func (strategy) AllowUnconditionalUpdate() bool {
return
true
}
func
(
s
strategy
)
Export
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
{
func
(
s
strategy
)
Export
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
{
t
,
ok
:=
obj
.
(
*
api
.
Secret
)
if
!
ok
{
// unexpected programmer error
...
...
pkg/registry/core/service/BUILD
View file @
54fd2aae
...
...
@@ -27,7 +27,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/util/proxy:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
...
...
pkg/registry/core/service/proxy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
service
import
(
"context"
"fmt"
"net/http"
"net/url"
...
...
@@ -24,7 +25,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/proxy"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
api
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/capabilities"
...
...
@@ -57,7 +57,7 @@ func (r *ProxyREST) NewConnectOptions() (runtime.Object, bool, string) {
}
// Connect returns a handler for the service proxy
func
(
r
*
ProxyREST
)
Connect
(
ctx
genericapireques
t
.
Context
,
id
string
,
opts
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
func
(
r
*
ProxyREST
)
Connect
(
ctx
contex
t
.
Context
,
id
string
,
opts
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
proxyOpts
,
ok
:=
opts
.
(
*
api
.
ServiceProxyOptions
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"Invalid options object: %#v"
,
opts
)
...
...
pkg/registry/core/service/registry.go
View file @
54fd2aae
...
...
@@ -17,25 +17,25 @@ limitations under the License.
package
service
import
(
"context"
"fmt"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
api
"k8s.io/kubernetes/pkg/apis/core"
)
// Registry is an interface for things that know how to store services.
type
Registry
interface
{
ListServices
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ServiceList
,
error
)
CreateService
(
ctx
genericapireques
t
.
Context
,
svc
*
api
.
Service
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
Service
,
error
)
GetService
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Service
,
error
)
DeleteService
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
UpdateService
(
ctx
genericapireques
t
.
Context
,
svc
*
api
.
Service
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
Service
,
error
)
WatchServices
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
ExportService
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
metav1
.
ExportOptions
)
(
*
api
.
Service
,
error
)
ListServices
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ServiceList
,
error
)
CreateService
(
ctx
contex
t
.
Context
,
svc
*
api
.
Service
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
Service
,
error
)
GetService
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Service
,
error
)
DeleteService
(
ctx
contex
t
.
Context
,
name
string
)
error
UpdateService
(
ctx
contex
t
.
Context
,
svc
*
api
.
Service
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
Service
,
error
)
WatchServices
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
ExportService
(
ctx
contex
t
.
Context
,
name
string
,
options
metav1
.
ExportOptions
)
(
*
api
.
Service
,
error
)
}
// storage puts strong typing around storage calls
...
...
@@ -49,7 +49,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListServices
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ServiceList
,
error
)
{
func
(
s
*
storage
)
ListServices
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ServiceList
,
error
)
{
obj
,
err
:=
s
.
List
(
ctx
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -57,7 +57,7 @@ func (s *storage) ListServices(ctx genericapirequest.Context, options *metainter
return
obj
.
(
*
api
.
ServiceList
),
nil
}
func
(
s
*
storage
)
CreateService
(
ctx
genericapireques
t
.
Context
,
svc
*
api
.
Service
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
Service
,
error
)
{
func
(
s
*
storage
)
CreateService
(
ctx
contex
t
.
Context
,
svc
*
api
.
Service
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
Service
,
error
)
{
obj
,
err
:=
s
.
Create
(
ctx
,
svc
,
createValidation
,
false
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -65,7 +65,7 @@ func (s *storage) CreateService(ctx genericapirequest.Context, svc *api.Service,
return
obj
.
(
*
api
.
Service
),
nil
}
func
(
s
*
storage
)
GetService
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Service
,
error
)
{
func
(
s
*
storage
)
GetService
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Service
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -73,12 +73,12 @@ func (s *storage) GetService(ctx genericapirequest.Context, name string, options
return
obj
.
(
*
api
.
Service
),
nil
}
func
(
s
*
storage
)
DeleteService
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
{
func
(
s
*
storage
)
DeleteService
(
ctx
contex
t
.
Context
,
name
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
name
,
nil
)
return
err
}
func
(
s
*
storage
)
UpdateService
(
ctx
genericapireques
t
.
Context
,
svc
*
api
.
Service
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
Service
,
error
)
{
func
(
s
*
storage
)
UpdateService
(
ctx
contex
t
.
Context
,
svc
*
api
.
Service
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
Service
,
error
)
{
obj
,
_
,
err
:=
s
.
Update
(
ctx
,
svc
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
svc
),
createValidation
,
updateValidation
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -86,13 +86,13 @@ func (s *storage) UpdateService(ctx genericapirequest.Context, svc *api.Service,
return
obj
.
(
*
api
.
Service
),
nil
}
func
(
s
*
storage
)
WatchServices
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchServices
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
// If StandardStorage implements rest.Exporter, returns exported service.
// Otherwise export is not supported.
func
(
s
*
storage
)
ExportService
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
metav1
.
ExportOptions
)
(
*
api
.
Service
,
error
)
{
func
(
s
*
storage
)
ExportService
(
ctx
contex
t
.
Context
,
name
string
,
options
metav1
.
ExportOptions
)
(
*
api
.
Service
,
error
)
{
exporter
,
isExporter
:=
s
.
StandardStorage
.
(
rest
.
Exporter
)
if
!
isExporter
{
return
nil
,
fmt
.
Errorf
(
"export is not supported"
)
...
...
pkg/registry/core/service/storage/rest.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
storage
import
(
"context"
"fmt"
"math/rand"
"net"
...
...
@@ -130,23 +131,23 @@ func (rs *REST) NewList() runtime.Object {
return
rs
.
services
.
NewList
()
}
func
(
rs
*
REST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
rs
*
REST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
rs
.
services
.
Get
(
ctx
,
name
,
options
)
}
func
(
rs
*
REST
)
List
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
func
(
rs
*
REST
)
List
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
return
rs
.
services
.
List
(
ctx
,
options
)
}
func
(
rs
*
REST
)
Watch
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
rs
*
REST
)
Watch
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
rs
.
services
.
Watch
(
ctx
,
options
)
}
func
(
rs
*
REST
)
Export
(
ctx
genericapireques
t
.
Context
,
name
string
,
opts
metav1
.
ExportOptions
)
(
runtime
.
Object
,
error
)
{
func
(
rs
*
REST
)
Export
(
ctx
contex
t
.
Context
,
name
string
,
opts
metav1
.
ExportOptions
)
(
runtime
.
Object
,
error
)
{
return
rs
.
services
.
Export
(
ctx
,
name
,
opts
)
}
func
(
rs
*
REST
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
rs
*
REST
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
service
:=
obj
.
(
*
api
.
Service
)
if
err
:=
rest
.
BeforeCreate
(
registry
.
Strategy
,
ctx
,
obj
);
err
!=
nil
{
...
...
@@ -207,7 +208,7 @@ func (rs *REST) Create(ctx genericapirequest.Context, obj runtime.Object, create
return
out
,
err
}
func
(
rs
*
REST
)
Delete
(
ctx
genericapireques
t
.
Context
,
id
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
rs
*
REST
)
Delete
(
ctx
contex
t
.
Context
,
id
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
// TODO: handle graceful
obj
,
_
,
err
:=
rs
.
services
.
Delete
(
ctx
,
id
,
options
)
if
err
!=
nil
{
...
...
@@ -320,7 +321,7 @@ func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service, node
return
true
,
nil
}
func
(
rs
*
REST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
rs
*
REST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
oldObj
,
err
:=
rs
.
services
.
Get
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
false
,
err
...
...
@@ -413,7 +414,7 @@ func (rs *REST) Update(ctx genericapirequest.Context, name string, objInfo rest.
var
_
=
rest
.
Redirector
(
&
REST
{})
// ResourceLocation returns a URL to which one can send traffic for the specified service.
func
(
rs
*
REST
)
ResourceLocation
(
ctx
genericapireques
t
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
func
(
rs
*
REST
)
ResourceLocation
(
ctx
contex
t
.
Context
,
id
string
)
(
*
url
.
URL
,
http
.
RoundTripper
,
error
)
{
// Allow ID as "svcname", "svcname:port", or "scheme:svcname:port".
svcScheme
,
svcName
,
portStr
,
valid
:=
utilnet
.
SplitSchemeNamePort
(
id
)
if
!
valid
{
...
...
@@ -486,11 +487,11 @@ func (rs *REST) ResourceLocation(ctx genericapirequest.Context, id string) (*url
return
nil
,
nil
,
errors
.
NewServiceUnavailable
(
fmt
.
Sprintf
(
"no endpoints available for service %q"
,
id
))
}
func
(
r
*
REST
)
ConvertToTable
(
ctx
genericapireques
t
.
Context
,
object
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
func
(
r
*
REST
)
ConvertToTable
(
ctx
contex
t
.
Context
,
object
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
return
r
.
services
.
ConvertToTable
(
ctx
,
object
,
tableOptions
)
}
func
isValidAddress
(
ctx
genericapireques
t
.
Context
,
addr
*
api
.
EndpointAddress
,
pods
rest
.
Getter
)
error
{
func
isValidAddress
(
ctx
contex
t
.
Context
,
addr
*
api
.
EndpointAddress
,
pods
rest
.
Getter
)
error
{
if
addr
.
TargetRef
==
nil
{
return
fmt
.
Errorf
(
"Address has no target ref, skipping: %v"
,
addr
)
}
...
...
pkg/registry/core/service/storage/rest_test.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
storage
import
(
"context"
"net"
"reflect"
"strings"
...
...
@@ -64,12 +65,12 @@ type serviceStorage struct {
Err
error
}
func
(
s
*
serviceStorage
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
s
*
serviceStorage
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
s
.
GottenID
=
name
return
s
.
Service
,
s
.
Err
}
func
(
s
*
serviceStorage
)
GetService
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Service
,
error
)
{
func
(
s
*
serviceStorage
)
GetService
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Service
,
error
)
{
return
s
.
Service
,
s
.
Err
}
...
...
@@ -77,7 +78,7 @@ func (s *serviceStorage) NewList() runtime.Object {
panic
(
"not implemented"
)
}
func
(
s
*
serviceStorage
)
List
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
func
(
s
*
serviceStorage
)
List
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
ns
,
_
:=
genericapirequest
.
NamespaceFrom
(
ctx
)
// Copy metadata from internal list into result
...
...
@@ -102,7 +103,7 @@ func (s *serviceStorage) New() runtime.Object {
panic
(
"not implemented"
)
}
func
(
s
*
serviceStorage
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
s
*
serviceStorage
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
svc
:=
obj
.
(
*
api
.
Service
)
s
.
CreatedID
=
obj
.
(
metav1
.
Object
)
.
GetName
()
s
.
Service
=
svc
.
DeepCopy
()
...
...
@@ -115,7 +116,7 @@ func (s *serviceStorage) Create(ctx genericapirequest.Context, obj runtime.Objec
return
svc
,
s
.
Err
}
func
(
s
*
serviceStorage
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
s
*
serviceStorage
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
s
.
UpdatedID
=
name
obj
,
err
:=
objInfo
.
UpdatedObject
(
ctx
,
s
.
OldService
)
if
err
!=
nil
{
...
...
@@ -125,24 +126,24 @@ func (s *serviceStorage) Update(ctx genericapirequest.Context, name string, objI
return
s
.
Service
,
s
.
Created
,
s
.
Err
}
func
(
s
*
serviceStorage
)
Delete
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
s
*
serviceStorage
)
Delete
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
s
.
DeletedID
=
name
return
s
.
Service
,
s
.
DeletedImmediately
,
s
.
Err
}
func
(
s
*
serviceStorage
)
DeleteCollection
(
ctx
genericapireques
t
.
Context
,
options
*
metav1
.
DeleteOptions
,
listOptions
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
func
(
s
*
serviceStorage
)
DeleteCollection
(
ctx
contex
t
.
Context
,
options
*
metav1
.
DeleteOptions
,
listOptions
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
panic
(
"not implemented"
)
}
func
(
s
*
serviceStorage
)
Watch
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
serviceStorage
)
Watch
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
panic
(
"not implemented"
)
}
func
(
s
*
serviceStorage
)
ConvertToTable
(
ctx
genericapireques
t
.
Context
,
object
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
func
(
s
*
serviceStorage
)
ConvertToTable
(
ctx
contex
t
.
Context
,
object
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
panic
(
"not implemented"
)
}
func
(
s
*
serviceStorage
)
Export
(
ctx
genericapireques
t
.
Context
,
name
string
,
opts
metav1
.
ExportOptions
)
(
runtime
.
Object
,
error
)
{
func
(
s
*
serviceStorage
)
Export
(
ctx
contex
t
.
Context
,
name
string
,
opts
metav1
.
ExportOptions
)
(
runtime
.
Object
,
error
)
{
panic
(
"not implemented"
)
}
...
...
@@ -207,7 +208,7 @@ func makeIPNet(t *testing.T) *net.IPNet {
return
net
}
func
releaseServiceNodePorts
(
t
*
testing
.
T
,
ctx
genericapireques
t
.
Context
,
svcName
string
,
rest
*
REST
,
registry
ServiceStorage
)
{
func
releaseServiceNodePorts
(
t
*
testing
.
T
,
ctx
contex
t
.
Context
,
svcName
string
,
rest
*
REST
,
registry
ServiceStorage
)
{
obj
,
err
:=
registry
.
Get
(
ctx
,
svcName
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
...
...
pkg/registry/core/service/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
storage
import
(
"context"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -84,11 +85,11 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
pkg/registry/core/service/strategy.go
View file @
54fd2aae
...
...
@@ -17,11 +17,11 @@ limitations under the License.
package
service
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
api
"k8s.io/kubernetes/pkg/apis/core"
...
...
@@ -44,20 +44,20 @@ func (svcStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears fields that are not allowed to be set by end users on creation.
func
(
svcStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
svcStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
service
:=
obj
.
(
*
api
.
Service
)
service
.
Status
=
api
.
ServiceStatus
{}
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
svcStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
svcStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newService
:=
obj
.
(
*
api
.
Service
)
oldService
:=
old
.
(
*
api
.
Service
)
newService
.
Status
=
oldService
.
Status
}
// Validate validates a new service.
func
(
svcStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
svcStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
service
:=
obj
.
(
*
api
.
Service
)
return
validation
.
ValidateService
(
service
)
}
...
...
@@ -70,7 +70,7 @@ func (svcStrategy) AllowCreateOnUpdate() bool {
return
true
}
func
(
svcStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
svcStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateServiceUpdate
(
obj
.
(
*
api
.
Service
),
old
.
(
*
api
.
Service
))
}
...
...
@@ -78,7 +78,7 @@ func (svcStrategy) AllowUnconditionalUpdate() bool {
return
true
}
func
(
svcStrategy
)
Export
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
{
func
(
svcStrategy
)
Export
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
{
t
,
ok
:=
obj
.
(
*
api
.
Service
)
if
!
ok
{
// unexpected programmer error
...
...
@@ -108,7 +108,7 @@ type serviceStatusStrategy struct {
var
StatusStrategy
=
serviceStatusStrategy
{
Strategy
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update of status
func
(
serviceStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
serviceStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newService
:=
obj
.
(
*
api
.
Service
)
oldService
:=
old
.
(
*
api
.
Service
)
// status changes are not allowed to update spec
...
...
@@ -116,6 +116,6 @@ func (serviceStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj
}
// ValidateUpdate is the default update validation for an end user updating status
func
(
serviceStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
serviceStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateServiceStatusUpdate
(
obj
.
(
*
api
.
Service
),
old
.
(
*
api
.
Service
))
}
pkg/registry/core/serviceaccount/BUILD
View file @
54fd2aae
...
...
@@ -18,7 +18,6 @@ go_library(
"//pkg/apis/core/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
)
...
...
pkg/registry/core/serviceaccount/storage/token.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
storage
import
(
"context"
"fmt"
authenticationapiv1
"k8s.io/api/authentication/v1"
...
...
@@ -46,7 +47,7 @@ type TokenREST struct {
var
_
=
rest
.
NamedCreater
(
&
TokenREST
{})
func
(
r
*
TokenREST
)
Create
(
ctx
genericapireques
t
.
Context
,
name
string
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
TokenREST
)
Create
(
ctx
contex
t
.
Context
,
name
string
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
if
err
:=
createValidation
(
obj
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -120,11 +121,11 @@ func (r *TokenREST) GroupVersionKind(containingGV schema.GroupVersion) schema.Gr
}
type
getter
interface
{
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
}
// newContext return a copy of ctx in which new RequestInfo is set
func
newContext
(
ctx
genericapirequest
.
Context
,
resource
,
name
string
,
gvk
schema
.
GroupVersionKind
)
genericapireques
t
.
Context
{
func
newContext
(
ctx
context
.
Context
,
resource
,
name
string
,
gvk
schema
.
GroupVersionKind
)
contex
t
.
Context
{
oldInfo
,
found
:=
genericapirequest
.
RequestInfoFrom
(
ctx
)
if
!
found
{
return
ctx
...
...
pkg/registry/core/serviceaccount/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
serviceaccount
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
api
"k8s.io/kubernetes/pkg/apis/core"
...
...
@@ -40,11 +41,11 @@ func (strategy) NamespaceScoped() bool {
return
true
}
func
(
strategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
strategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
cleanSecretReferences
(
obj
.
(
*
api
.
ServiceAccount
))
}
func
(
strategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateServiceAccount
(
obj
.
(
*
api
.
ServiceAccount
))
}
...
...
@@ -56,7 +57,7 @@ func (strategy) AllowCreateOnUpdate() bool {
return
false
}
func
(
strategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
strategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
cleanSecretReferences
(
obj
.
(
*
api
.
ServiceAccount
))
}
...
...
@@ -66,7 +67,7 @@ func cleanSecretReferences(serviceAccount *api.ServiceAccount) {
}
}
func
(
strategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateServiceAccountUpdate
(
obj
.
(
*
api
.
ServiceAccount
),
old
.
(
*
api
.
ServiceAccount
))
}
...
...
pkg/registry/events/event/BUILD
View file @
54fd2aae
...
...
@@ -16,7 +16,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
...
...
pkg/registry/events/event/strategy.go
View file @
54fd2aae
...
...
@@ -17,13 +17,13 @@ limitations under the License.
package
event
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
apistorage
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage/names"
...
...
@@ -47,15 +47,15 @@ func (eventStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of a Pod Preset before creation.
func
(
eventStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
eventStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
eventStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
eventStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
}
// Validate validates a new Event.
func
(
eventStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
eventStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
event
:=
obj
.
(
*
api
.
Event
)
return
validation
.
ValidateEvent
(
event
)
}
...
...
@@ -69,7 +69,7 @@ func (eventStrategy) AllowCreateOnUpdate() bool {
func
(
eventStrategy
)
Canonicalize
(
obj
runtime
.
Object
)
{}
// ValidateUpdate is the default update validation for an end user.
func
(
eventStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
eventStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
event
:=
obj
.
(
*
api
.
Event
)
return
validation
.
ValidateEvent
(
event
)
}
...
...
pkg/registry/extensions/controller/storage/BUILD
View file @
54fd2aae
...
...
@@ -39,7 +39,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
],
...
...
pkg/registry/extensions/controller/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,13 +17,13 @@ limitations under the License.
package
storage
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/autoscaling"
...
...
@@ -63,7 +63,7 @@ func (r *ScaleREST) New() runtime.Object {
return
&
autoscaling
.
Scale
{}
}
func
(
r
*
ScaleREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
ScaleREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
rc
,
err
:=
(
*
r
.
registry
)
.
GetController
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
errors
.
NewNotFound
(
extensions
.
Resource
(
"replicationcontrollers/scale"
),
name
)
...
...
@@ -71,7 +71,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met
return
scaleFromRC
(
rc
),
nil
}
func
(
r
*
ScaleREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
ScaleREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
rc
,
err
:=
(
*
r
.
registry
)
.
GetController
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
false
,
errors
.
NewNotFound
(
extensions
.
Resource
(
"replicationcontrollers/scale"
),
name
)
...
...
pkg/registry/extensions/ingress/BUILD
View file @
54fd2aae
...
...
@@ -20,7 +20,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
)
...
...
pkg/registry/extensions/ingress/storage/BUILD
View file @
54fd2aae
...
...
@@ -37,7 +37,6 @@ go_library(
"//pkg/registry/extensions/ingress:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/extensions/ingress/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
storage
import
(
"context"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -76,11 +77,11 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
pkg/registry/extensions/ingress/strategy.go
View file @
54fd2aae
...
...
@@ -17,10 +17,11 @@ limitations under the License.
package
ingress
import
(
"context"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/extensions"
...
...
@@ -42,7 +43,7 @@ func (ingressStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of an Ingress before creation.
func
(
ingressStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
ingressStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
ingress
:=
obj
.
(
*
extensions
.
Ingress
)
// create cannot set status
ingress
.
Status
=
extensions
.
IngressStatus
{}
...
...
@@ -51,7 +52,7 @@ func (ingressStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runti
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
ingressStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
ingressStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newIngress
:=
obj
.
(
*
extensions
.
Ingress
)
oldIngress
:=
old
.
(
*
extensions
.
Ingress
)
// Update is not allowed to set status
...
...
@@ -67,7 +68,7 @@ func (ingressStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old
}
// Validate validates a new Ingress.
func
(
ingressStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
ingressStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
ingress
:=
obj
.
(
*
extensions
.
Ingress
)
err
:=
validation
.
ValidateIngress
(
ingress
)
return
err
...
...
@@ -83,7 +84,7 @@ func (ingressStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
ingressStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
ingressStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
validationErrorList
:=
validation
.
ValidateIngress
(
obj
.
(
*
extensions
.
Ingress
))
updateErrorList
:=
validation
.
ValidateIngressUpdate
(
obj
.
(
*
extensions
.
Ingress
),
old
.
(
*
extensions
.
Ingress
))
return
append
(
validationErrorList
,
updateErrorList
...
)
...
...
@@ -101,7 +102,7 @@ type ingressStatusStrategy struct {
var
StatusStrategy
=
ingressStatusStrategy
{
Strategy
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update of status
func
(
ingressStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
ingressStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newIngress
:=
obj
.
(
*
extensions
.
Ingress
)
oldIngress
:=
old
.
(
*
extensions
.
Ingress
)
// status changes are not allowed to update spec
...
...
@@ -109,6 +110,6 @@ func (ingressStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj
}
// ValidateUpdate is the default update validation for an end user updating status
func
(
ingressStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
ingressStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateIngressStatusUpdate
(
obj
.
(
*
extensions
.
Ingress
),
old
.
(
*
extensions
.
Ingress
))
}
pkg/registry/networking/networkpolicy/BUILD
View file @
54fd2aae
...
...
@@ -22,7 +22,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
...
...
pkg/registry/networking/networkpolicy/registry.go
View file @
54fd2aae
...
...
@@ -17,22 +17,23 @@ limitations under the License.
package
networkpolicy
import
(
"context"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/networking"
)
// Registry is an interface for things that know how to store NetworkPolicies.
type
Registry
interface
{
ListNetworkPolicies
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
networking
.
NetworkPolicyList
,
error
)
CreateNetworkPolicy
(
ctx
genericapireques
t
.
Context
,
np
*
networking
.
NetworkPolicy
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateNetworkPolicy
(
ctx
genericapireques
t
.
Context
,
np
*
networking
.
NetworkPolicy
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetNetworkPolicy
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
networking
.
NetworkPolicy
,
error
)
DeleteNetworkPolicy
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
WatchNetworkPolicies
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
ListNetworkPolicies
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
networking
.
NetworkPolicyList
,
error
)
CreateNetworkPolicy
(
ctx
contex
t
.
Context
,
np
*
networking
.
NetworkPolicy
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateNetworkPolicy
(
ctx
contex
t
.
Context
,
np
*
networking
.
NetworkPolicy
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetNetworkPolicy
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
networking
.
NetworkPolicy
,
error
)
DeleteNetworkPolicy
(
ctx
contex
t
.
Context
,
name
string
)
error
WatchNetworkPolicies
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
}
// storage puts strong typing around storage calls
...
...
@@ -46,7 +47,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListNetworkPolicies
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
networking
.
NetworkPolicyList
,
error
)
{
func
(
s
*
storage
)
ListNetworkPolicies
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
networking
.
NetworkPolicyList
,
error
)
{
obj
,
err
:=
s
.
List
(
ctx
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -55,21 +56,21 @@ func (s *storage) ListNetworkPolicies(ctx genericapirequest.Context, options *me
return
obj
.
(
*
networking
.
NetworkPolicyList
),
nil
}
func
(
s
*
storage
)
CreateNetworkPolicy
(
ctx
genericapireques
t
.
Context
,
np
*
networking
.
NetworkPolicy
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
func
(
s
*
storage
)
CreateNetworkPolicy
(
ctx
contex
t
.
Context
,
np
*
networking
.
NetworkPolicy
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
_
,
err
:=
s
.
Create
(
ctx
,
np
,
createValidation
,
false
)
return
err
}
func
(
s
*
storage
)
UpdateNetworkPolicy
(
ctx
genericapireques
t
.
Context
,
np
*
networking
.
NetworkPolicy
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
func
(
s
*
storage
)
UpdateNetworkPolicy
(
ctx
contex
t
.
Context
,
np
*
networking
.
NetworkPolicy
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
_
,
_
,
err
:=
s
.
Update
(
ctx
,
np
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
np
),
createValidation
,
updateValidation
)
return
err
}
func
(
s
*
storage
)
WatchNetworkPolicies
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchNetworkPolicies
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetNetworkPolicy
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
networking
.
NetworkPolicy
,
error
)
{
func
(
s
*
storage
)
GetNetworkPolicy
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
networking
.
NetworkPolicy
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -77,7 +78,7 @@ func (s *storage) GetNetworkPolicy(ctx genericapirequest.Context, name string, o
return
obj
.
(
*
networking
.
NetworkPolicy
),
nil
}
func
(
s
*
storage
)
DeleteNetworkPolicy
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
{
func
(
s
*
storage
)
DeleteNetworkPolicy
(
ctx
contex
t
.
Context
,
name
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
name
,
nil
)
return
err
}
pkg/registry/networking/networkpolicy/strategy.go
View file @
54fd2aae
...
...
@@ -17,11 +17,11 @@ limitations under the License.
package
networkpolicy
import
(
"context"
"reflect"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/networking"
...
...
@@ -43,13 +43,13 @@ func (networkPolicyStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of a NetworkPolicy before creation.
func
(
networkPolicyStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
networkPolicyStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
networkPolicy
:=
obj
.
(
*
networking
.
NetworkPolicy
)
networkPolicy
.
Generation
=
1
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
networkPolicyStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
networkPolicyStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newNetworkPolicy
:=
obj
.
(
*
networking
.
NetworkPolicy
)
oldNetworkPolicy
:=
old
.
(
*
networking
.
NetworkPolicy
)
...
...
@@ -62,7 +62,7 @@ func (networkPolicyStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj
}
// Validate validates a new NetworkPolicy.
func
(
networkPolicyStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
networkPolicyStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
networkPolicy
:=
obj
.
(
*
networking
.
NetworkPolicy
)
return
validation
.
ValidateNetworkPolicy
(
networkPolicy
)
}
...
...
@@ -76,7 +76,7 @@ func (networkPolicyStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
networkPolicyStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
networkPolicyStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
validationErrorList
:=
validation
.
ValidateNetworkPolicy
(
obj
.
(
*
networking
.
NetworkPolicy
))
updateErrorList
:=
validation
.
ValidateNetworkPolicyUpdate
(
obj
.
(
*
networking
.
NetworkPolicy
),
old
.
(
*
networking
.
NetworkPolicy
))
return
append
(
validationErrorList
,
updateErrorList
...
)
...
...
pkg/registry/policy/poddisruptionbudget/BUILD
View file @
54fd2aae
...
...
@@ -20,7 +20,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
)
...
...
pkg/registry/policy/poddisruptionbudget/storage/BUILD
View file @
54fd2aae
...
...
@@ -37,7 +37,6 @@ go_library(
"//pkg/registry/policy/poddisruptionbudget:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/policy/poddisruptionbudget/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
storage
import
(
"context"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -73,11 +74,11 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
pkg/registry/policy/poddisruptionbudget/strategy.go
View file @
54fd2aae
...
...
@@ -17,10 +17,11 @@ limitations under the License.
package
poddisruptionbudget
import
(
"context"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/policy"
...
...
@@ -42,7 +43,7 @@ func (podDisruptionBudgetStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of an PodDisruptionBudget before creation.
func
(
podDisruptionBudgetStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
podDisruptionBudgetStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
podDisruptionBudget
:=
obj
.
(
*
policy
.
PodDisruptionBudget
)
// create cannot set status
podDisruptionBudget
.
Status
=
policy
.
PodDisruptionBudgetStatus
{}
...
...
@@ -51,7 +52,7 @@ func (podDisruptionBudgetStrategy) PrepareForCreate(ctx genericapirequest.Contex
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
podDisruptionBudgetStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
podDisruptionBudgetStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newPodDisruptionBudget
:=
obj
.
(
*
policy
.
PodDisruptionBudget
)
oldPodDisruptionBudget
:=
old
.
(
*
policy
.
PodDisruptionBudget
)
// Update is not allowed to set status
...
...
@@ -66,7 +67,7 @@ func (podDisruptionBudgetStrategy) PrepareForUpdate(ctx genericapirequest.Contex
}
// Validate validates a new PodDisruptionBudget.
func
(
podDisruptionBudgetStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
podDisruptionBudgetStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
podDisruptionBudget
:=
obj
.
(
*
policy
.
PodDisruptionBudget
)
return
validation
.
ValidatePodDisruptionBudget
(
podDisruptionBudget
)
}
...
...
@@ -81,7 +82,7 @@ func (podDisruptionBudgetStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
podDisruptionBudgetStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
podDisruptionBudgetStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
validationErrorList
:=
validation
.
ValidatePodDisruptionBudget
(
obj
.
(
*
policy
.
PodDisruptionBudget
))
updateErrorList
:=
validation
.
ValidatePodDisruptionBudgetUpdate
(
obj
.
(
*
policy
.
PodDisruptionBudget
),
old
.
(
*
policy
.
PodDisruptionBudget
))
return
append
(
validationErrorList
,
updateErrorList
...
)
...
...
@@ -100,7 +101,7 @@ type podDisruptionBudgetStatusStrategy struct {
var
StatusStrategy
=
podDisruptionBudgetStatusStrategy
{
Strategy
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update of status
func
(
podDisruptionBudgetStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
podDisruptionBudgetStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newPodDisruptionBudget
:=
obj
.
(
*
policy
.
PodDisruptionBudget
)
oldPodDisruptionBudget
:=
old
.
(
*
policy
.
PodDisruptionBudget
)
// status changes are not allowed to update spec
...
...
@@ -108,7 +109,7 @@ func (podDisruptionBudgetStatusStrategy) PrepareForUpdate(ctx genericapirequest.
}
// ValidateUpdate is the default update validation for an end user updating status
func
(
podDisruptionBudgetStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
podDisruptionBudgetStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
// TODO: Validate status updates.
return
field
.
ErrorList
{}
// return validation.ValidatePodDisruptionBudgetStatusUpdate(obj.(*policy.PodDisruptionBudget), old.(*policy.PodDisruptionBudget))
...
...
pkg/registry/policy/podsecuritypolicy/BUILD
View file @
54fd2aae
...
...
@@ -18,7 +18,6 @@ go_library(
"//pkg/apis/policy/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
...
...
pkg/registry/policy/podsecuritypolicy/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
podsecuritypolicy
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
...
...
@@ -53,19 +54,19 @@ func (strategy) AllowUnconditionalUpdate() bool {
return
true
}
func
(
strategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
strategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
}
func
(
strategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
strategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
}
func
(
strategy
)
Canonicalize
(
obj
runtime
.
Object
)
{
}
func
(
strategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidatePodSecurityPolicy
(
obj
.
(
*
policy
.
PodSecurityPolicy
))
}
func
(
strategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidatePodSecurityPolicyUpdate
(
old
.
(
*
policy
.
PodSecurityPolicy
),
obj
.
(
*
policy
.
PodSecurityPolicy
))
}
pkg/registry/rbac/clusterrole/policybased/BUILD
View file @
54fd2aae
...
...
@@ -16,7 +16,6 @@ go_library(
"//pkg/registry/rbac/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
],
)
...
...
pkg/registry/rbac/clusterrole/policybased/storage.go
View file @
54fd2aae
...
...
@@ -18,11 +18,11 @@ limitations under the License.
package
policybased
import
(
"context"
"errors"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
kapihelper
"k8s.io/kubernetes/pkg/apis/core/helper"
"k8s.io/kubernetes/pkg/apis/rbac"
...
...
@@ -47,7 +47,7 @@ var fullAuthority = []rbac.PolicyRule{
rbac
.
NewRule
(
"*"
)
.
URLs
(
"*"
)
.
RuleOrDie
(),
}
func
(
s
*
Storage
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidatingAdmission
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
s
*
Storage
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidatingAdmission
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
if
rbacregistry
.
EscalationAllowed
(
ctx
)
{
return
s
.
StandardStorage
.
Create
(
ctx
,
obj
,
createValidatingAdmission
,
includeUninitialized
)
}
...
...
@@ -67,12 +67,12 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, crea
return
s
.
StandardStorage
.
Create
(
ctx
,
obj
,
createValidatingAdmission
,
includeUninitialized
)
}
func
(
s
*
Storage
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
obj
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
s
*
Storage
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
obj
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
if
rbacregistry
.
EscalationAllowed
(
ctx
)
{
return
s
.
StandardStorage
.
Update
(
ctx
,
name
,
obj
,
createValidation
,
updateValidation
)
}
nonEscalatingInfo
:=
rest
.
WrapUpdatedObjectInfo
(
obj
,
func
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
nonEscalatingInfo
:=
rest
.
WrapUpdatedObjectInfo
(
obj
,
func
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
clusterRole
:=
obj
.
(
*
rbac
.
ClusterRole
)
oldClusterRole
:=
oldObj
.
(
*
rbac
.
ClusterRole
)
...
...
pkg/registry/rbac/clusterrole/registry.go
View file @
54fd2aae
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
clusterrole
import
(
"context"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
...
...
@@ -27,12 +29,12 @@ import (
// Registry is an interface for things that know how to store ClusterRoles.
type
Registry
interface
{
ListClusterRoles
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
ClusterRoleList
,
error
)
CreateClusterRole
(
ctx
genericapireques
t
.
Context
,
clusterRole
*
rbac
.
ClusterRole
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateClusterRole
(
ctx
genericapireques
t
.
Context
,
clusterRole
*
rbac
.
ClusterRole
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetClusterRole
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
ClusterRole
,
error
)
DeleteClusterRole
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
WatchClusterRoles
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
ListClusterRoles
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
ClusterRoleList
,
error
)
CreateClusterRole
(
ctx
contex
t
.
Context
,
clusterRole
*
rbac
.
ClusterRole
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateClusterRole
(
ctx
contex
t
.
Context
,
clusterRole
*
rbac
.
ClusterRole
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetClusterRole
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
ClusterRole
,
error
)
DeleteClusterRole
(
ctx
contex
t
.
Context
,
name
string
)
error
WatchClusterRoles
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
}
// storage puts strong typing around storage calls
...
...
@@ -46,7 +48,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListClusterRoles
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
ClusterRoleList
,
error
)
{
func
(
s
*
storage
)
ListClusterRoles
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
ClusterRoleList
,
error
)
{
obj
,
err
:=
s
.
List
(
ctx
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -55,21 +57,21 @@ func (s *storage) ListClusterRoles(ctx genericapirequest.Context, options *metai
return
obj
.
(
*
rbac
.
ClusterRoleList
),
nil
}
func
(
s
*
storage
)
CreateClusterRole
(
ctx
genericapireques
t
.
Context
,
clusterRole
*
rbac
.
ClusterRole
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
func
(
s
*
storage
)
CreateClusterRole
(
ctx
contex
t
.
Context
,
clusterRole
*
rbac
.
ClusterRole
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
_
,
err
:=
s
.
Create
(
ctx
,
clusterRole
,
createValidation
,
false
)
return
err
}
func
(
s
*
storage
)
UpdateClusterRole
(
ctx
genericapireques
t
.
Context
,
clusterRole
*
rbac
.
ClusterRole
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
func
(
s
*
storage
)
UpdateClusterRole
(
ctx
contex
t
.
Context
,
clusterRole
*
rbac
.
ClusterRole
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
_
,
_
,
err
:=
s
.
Update
(
ctx
,
clusterRole
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
clusterRole
),
createValidation
,
updateValidation
)
return
err
}
func
(
s
*
storage
)
WatchClusterRoles
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchClusterRoles
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetClusterRole
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
ClusterRole
,
error
)
{
func
(
s
*
storage
)
GetClusterRole
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
ClusterRole
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -77,7 +79,7 @@ func (s *storage) GetClusterRole(ctx genericapirequest.Context, name string, opt
return
obj
.
(
*
rbac
.
ClusterRole
),
nil
}
func
(
s
*
storage
)
DeleteClusterRole
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
{
func
(
s
*
storage
)
DeleteClusterRole
(
ctx
contex
t
.
Context
,
name
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
name
,
nil
)
return
err
}
...
...
pkg/registry/rbac/clusterrole/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
clusterrole
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
...
...
@@ -55,12 +56,12 @@ func (strategy) AllowCreateOnUpdate() bool {
// PrepareForCreate clears fields that are not allowed to be set by end users
// on creation.
func
(
strategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
strategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
_
=
obj
.
(
*
rbac
.
ClusterRole
)
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
strategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
strategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newClusterRole
:=
obj
.
(
*
rbac
.
ClusterRole
)
oldClusterRole
:=
old
.
(
*
rbac
.
ClusterRole
)
...
...
@@ -68,7 +69,7 @@ func (strategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime
}
// Validate validates a new ClusterRole. Validation must check for a correct signature.
func
(
strategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
clusterRole
:=
obj
.
(
*
rbac
.
ClusterRole
)
return
validation
.
ValidateClusterRole
(
clusterRole
)
}
...
...
@@ -79,7 +80,7 @@ func (strategy) Canonicalize(obj runtime.Object) {
}
// ValidateUpdate is the default update validation for an end user.
func
(
strategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
newObj
:=
obj
.
(
*
rbac
.
ClusterRole
)
errorList
:=
validation
.
ValidateClusterRole
(
newObj
)
return
append
(
errorList
,
validation
.
ValidateClusterRoleUpdate
(
newObj
,
old
.
(
*
rbac
.
ClusterRole
))
...
)
...
...
pkg/registry/rbac/clusterrolebinding/policybased/BUILD
View file @
54fd2aae
...
...
@@ -18,7 +18,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/authorization/authorizer:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
],
)
...
...
pkg/registry/rbac/clusterrolebinding/policybased/storage.go
View file @
54fd2aae
...
...
@@ -18,11 +18,12 @@ limitations under the License.
package
policybased
import
(
"context"
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/authorization/authorizer"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
kapihelper
"k8s.io/kubernetes/pkg/apis/core/helper"
"k8s.io/kubernetes/pkg/apis/rbac"
...
...
@@ -44,7 +45,7 @@ func NewStorage(s rest.StandardStorage, authorizer authorizer.Authorizer, ruleRe
return
&
Storage
{
s
,
authorizer
,
ruleResolver
}
}
func
(
s
*
Storage
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
s
*
Storage
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
if
rbacregistry
.
EscalationAllowed
(
ctx
)
{
return
s
.
StandardStorage
.
Create
(
ctx
,
obj
,
createValidation
,
includeUninitialized
)
}
...
...
@@ -64,12 +65,12 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, crea
return
s
.
StandardStorage
.
Create
(
ctx
,
obj
,
createValidation
,
includeUninitialized
)
}
func
(
s
*
Storage
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
obj
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
s
*
Storage
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
obj
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
if
rbacregistry
.
EscalationAllowed
(
ctx
)
{
return
s
.
StandardStorage
.
Update
(
ctx
,
name
,
obj
,
createValidation
,
updateValidation
)
}
nonEscalatingInfo
:=
rest
.
WrapUpdatedObjectInfo
(
obj
,
func
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
nonEscalatingInfo
:=
rest
.
WrapUpdatedObjectInfo
(
obj
,
func
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
clusterRoleBinding
:=
obj
.
(
*
rbac
.
ClusterRoleBinding
)
// if we're only mutating fields needed for the GC to eventually delete this obj, return
...
...
pkg/registry/rbac/clusterrolebinding/registry.go
View file @
54fd2aae
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
clusterrolebinding
import
(
"context"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
...
...
@@ -27,12 +29,12 @@ import (
// Registry is an interface for things that know how to store ClusterRoleBindings.
type
Registry
interface
{
ListClusterRoleBindings
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
ClusterRoleBindingList
,
error
)
CreateClusterRoleBinding
(
ctx
genericapireques
t
.
Context
,
clusterRoleBinding
*
rbac
.
ClusterRoleBinding
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateClusterRoleBinding
(
ctx
genericapireques
t
.
Context
,
clusterRoleBinding
*
rbac
.
ClusterRoleBinding
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetClusterRoleBinding
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
ClusterRoleBinding
,
error
)
DeleteClusterRoleBinding
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
WatchClusterRoleBindings
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
ListClusterRoleBindings
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
ClusterRoleBindingList
,
error
)
CreateClusterRoleBinding
(
ctx
contex
t
.
Context
,
clusterRoleBinding
*
rbac
.
ClusterRoleBinding
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateClusterRoleBinding
(
ctx
contex
t
.
Context
,
clusterRoleBinding
*
rbac
.
ClusterRoleBinding
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetClusterRoleBinding
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
ClusterRoleBinding
,
error
)
DeleteClusterRoleBinding
(
ctx
contex
t
.
Context
,
name
string
)
error
WatchClusterRoleBindings
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
}
// storage puts strong typing around storage calls
...
...
@@ -46,7 +48,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListClusterRoleBindings
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
ClusterRoleBindingList
,
error
)
{
func
(
s
*
storage
)
ListClusterRoleBindings
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
ClusterRoleBindingList
,
error
)
{
obj
,
err
:=
s
.
List
(
ctx
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -55,21 +57,21 @@ func (s *storage) ListClusterRoleBindings(ctx genericapirequest.Context, options
return
obj
.
(
*
rbac
.
ClusterRoleBindingList
),
nil
}
func
(
s
*
storage
)
CreateClusterRoleBinding
(
ctx
genericapireques
t
.
Context
,
clusterRoleBinding
*
rbac
.
ClusterRoleBinding
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
func
(
s
*
storage
)
CreateClusterRoleBinding
(
ctx
contex
t
.
Context
,
clusterRoleBinding
*
rbac
.
ClusterRoleBinding
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
_
,
err
:=
s
.
Create
(
ctx
,
clusterRoleBinding
,
createValidation
,
false
)
return
err
}
func
(
s
*
storage
)
UpdateClusterRoleBinding
(
ctx
genericapireques
t
.
Context
,
clusterRoleBinding
*
rbac
.
ClusterRoleBinding
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
func
(
s
*
storage
)
UpdateClusterRoleBinding
(
ctx
contex
t
.
Context
,
clusterRoleBinding
*
rbac
.
ClusterRoleBinding
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
_
,
_
,
err
:=
s
.
Update
(
ctx
,
clusterRoleBinding
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
clusterRoleBinding
),
createValidation
,
updateValidation
)
return
err
}
func
(
s
*
storage
)
WatchClusterRoleBindings
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchClusterRoleBindings
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetClusterRoleBinding
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
ClusterRoleBinding
,
error
)
{
func
(
s
*
storage
)
GetClusterRoleBinding
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
ClusterRoleBinding
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -77,7 +79,7 @@ func (s *storage) GetClusterRoleBinding(ctx genericapirequest.Context, name stri
return
obj
.
(
*
rbac
.
ClusterRoleBinding
),
nil
}
func
(
s
*
storage
)
DeleteClusterRoleBinding
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
{
func
(
s
*
storage
)
DeleteClusterRoleBinding
(
ctx
contex
t
.
Context
,
name
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
name
,
nil
)
return
err
}
...
...
pkg/registry/rbac/clusterrolebinding/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
clusterrolebinding
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
...
...
@@ -55,12 +56,12 @@ func (strategy) AllowCreateOnUpdate() bool {
// PrepareForCreate clears fields that are not allowed to be set by end users
// on creation.
func
(
strategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
strategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
_
=
obj
.
(
*
rbac
.
ClusterRoleBinding
)
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
strategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
strategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newClusterRoleBinding
:=
obj
.
(
*
rbac
.
ClusterRoleBinding
)
oldClusterRoleBinding
:=
old
.
(
*
rbac
.
ClusterRoleBinding
)
...
...
@@ -68,7 +69,7 @@ func (strategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime
}
// Validate validates a new ClusterRoleBinding. Validation must check for a correct signature.
func
(
strategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
clusterRoleBinding
:=
obj
.
(
*
rbac
.
ClusterRoleBinding
)
return
validation
.
ValidateClusterRoleBinding
(
clusterRoleBinding
)
}
...
...
@@ -79,7 +80,7 @@ func (strategy) Canonicalize(obj runtime.Object) {
}
// ValidateUpdate is the default update validation for an end user.
func
(
strategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
newObj
:=
obj
.
(
*
rbac
.
ClusterRoleBinding
)
errorList
:=
validation
.
ValidateClusterRoleBinding
(
newObj
)
return
append
(
errorList
,
validation
.
ValidateClusterRoleBindingUpdate
(
newObj
,
old
.
(
*
rbac
.
ClusterRoleBinding
))
...
)
...
...
pkg/registry/rbac/escalation_check.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
rbac
import
(
"context"
"fmt"
utilruntime
"k8s.io/apimachinery/pkg/util/runtime"
...
...
@@ -26,7 +27,7 @@ import (
"k8s.io/kubernetes/pkg/apis/rbac"
)
func
EscalationAllowed
(
ctx
genericapireques
t
.
Context
)
bool
{
func
EscalationAllowed
(
ctx
contex
t
.
Context
)
bool
{
u
,
ok
:=
genericapirequest
.
UserFrom
(
ctx
)
if
!
ok
{
return
false
...
...
@@ -44,7 +45,7 @@ func EscalationAllowed(ctx genericapirequest.Context) bool {
}
// BindingAuthorized returns true if the user associated with the context is explicitly authorized to bind the specified roleRef
func
BindingAuthorized
(
ctx
genericapireques
t
.
Context
,
roleRef
rbac
.
RoleRef
,
bindingNamespace
string
,
a
authorizer
.
Authorizer
)
bool
{
func
BindingAuthorized
(
ctx
contex
t
.
Context
,
roleRef
rbac
.
RoleRef
,
bindingNamespace
string
,
a
authorizer
.
Authorizer
)
bool
{
if
a
==
nil
{
return
false
}
...
...
pkg/registry/rbac/role/policybased/BUILD
View file @
54fd2aae
...
...
@@ -16,7 +16,6 @@ go_library(
"//pkg/registry/rbac/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
],
)
...
...
pkg/registry/rbac/role/policybased/storage.go
View file @
54fd2aae
...
...
@@ -18,9 +18,10 @@ limitations under the License.
package
policybased
import
(
"context"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
kapihelper
"k8s.io/kubernetes/pkg/apis/core/helper"
"k8s.io/kubernetes/pkg/apis/rbac"
...
...
@@ -40,7 +41,7 @@ func NewStorage(s rest.StandardStorage, ruleResolver rbacregistryvalidation.Auth
return
&
Storage
{
s
,
ruleResolver
}
}
func
(
s
*
Storage
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
s
*
Storage
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
if
rbacregistry
.
EscalationAllowed
(
ctx
)
{
return
s
.
StandardStorage
.
Create
(
ctx
,
obj
,
createValidation
,
includeUninitialized
)
}
...
...
@@ -53,12 +54,12 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, crea
return
s
.
StandardStorage
.
Create
(
ctx
,
obj
,
createValidation
,
includeUninitialized
)
}
func
(
s
*
Storage
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
obj
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
s
*
Storage
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
obj
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
if
rbacregistry
.
EscalationAllowed
(
ctx
)
{
return
s
.
StandardStorage
.
Update
(
ctx
,
name
,
obj
,
createValidation
,
updateValidation
)
}
nonEscalatingInfo
:=
rest
.
WrapUpdatedObjectInfo
(
obj
,
func
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
nonEscalatingInfo
:=
rest
.
WrapUpdatedObjectInfo
(
obj
,
func
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
role
:=
obj
.
(
*
rbac
.
Role
)
// if we're only mutating fields needed for the GC to eventually delete this obj, return
...
...
pkg/registry/rbac/role/registry.go
View file @
54fd2aae
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
role
import
(
"context"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
...
...
@@ -27,12 +29,12 @@ import (
// Registry is an interface for things that know how to store Roles.
type
Registry
interface
{
ListRoles
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
RoleList
,
error
)
CreateRole
(
ctx
genericapireques
t
.
Context
,
role
*
rbac
.
Role
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateRole
(
ctx
genericapireques
t
.
Context
,
role
*
rbac
.
Role
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetRole
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
Role
,
error
)
DeleteRole
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
WatchRoles
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
ListRoles
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
RoleList
,
error
)
CreateRole
(
ctx
contex
t
.
Context
,
role
*
rbac
.
Role
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateRole
(
ctx
contex
t
.
Context
,
role
*
rbac
.
Role
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetRole
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
Role
,
error
)
DeleteRole
(
ctx
contex
t
.
Context
,
name
string
)
error
WatchRoles
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
}
// storage puts strong typing around storage calls
...
...
@@ -46,7 +48,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListRoles
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
RoleList
,
error
)
{
func
(
s
*
storage
)
ListRoles
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
RoleList
,
error
)
{
obj
,
err
:=
s
.
List
(
ctx
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -55,22 +57,22 @@ func (s *storage) ListRoles(ctx genericapirequest.Context, options *metainternal
return
obj
.
(
*
rbac
.
RoleList
),
nil
}
func
(
s
*
storage
)
CreateRole
(
ctx
genericapireques
t
.
Context
,
role
*
rbac
.
Role
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
func
(
s
*
storage
)
CreateRole
(
ctx
contex
t
.
Context
,
role
*
rbac
.
Role
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
_
,
err
:=
s
.
Create
(
ctx
,
role
,
createValidation
,
false
)
return
err
}
func
(
s
*
storage
)
UpdateRole
(
ctx
genericapireques
t
.
Context
,
role
*
rbac
.
Role
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
func
(
s
*
storage
)
UpdateRole
(
ctx
contex
t
.
Context
,
role
*
rbac
.
Role
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
// TODO: any admission?
_
,
_
,
err
:=
s
.
Update
(
ctx
,
role
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
role
),
createValidation
,
updateValidation
)
return
err
}
func
(
s
*
storage
)
WatchRoles
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchRoles
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetRole
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
Role
,
error
)
{
func
(
s
*
storage
)
GetRole
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
Role
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -78,7 +80,7 @@ func (s *storage) GetRole(ctx genericapirequest.Context, name string, options *m
return
obj
.
(
*
rbac
.
Role
),
nil
}
func
(
s
*
storage
)
DeleteRole
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
{
func
(
s
*
storage
)
DeleteRole
(
ctx
contex
t
.
Context
,
name
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
name
,
nil
)
return
err
}
...
...
pkg/registry/rbac/role/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
role
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
...
...
@@ -55,12 +56,12 @@ func (strategy) AllowCreateOnUpdate() bool {
// PrepareForCreate clears fields that are not allowed to be set by end users
// on creation.
func
(
strategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
strategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
_
=
obj
.
(
*
rbac
.
Role
)
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
strategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
strategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newRole
:=
obj
.
(
*
rbac
.
Role
)
oldRole
:=
old
.
(
*
rbac
.
Role
)
...
...
@@ -68,7 +69,7 @@ func (strategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime
}
// Validate validates a new Role. Validation must check for a correct signature.
func
(
strategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
role
:=
obj
.
(
*
rbac
.
Role
)
return
validation
.
ValidateRole
(
role
)
}
...
...
@@ -79,7 +80,7 @@ func (strategy) Canonicalize(obj runtime.Object) {
}
// ValidateUpdate is the default update validation for an end user.
func
(
strategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
newObj
:=
obj
.
(
*
rbac
.
Role
)
errorList
:=
validation
.
ValidateRole
(
newObj
)
return
append
(
errorList
,
validation
.
ValidateRoleUpdate
(
newObj
,
old
.
(
*
rbac
.
Role
))
...
)
...
...
pkg/registry/rbac/rolebinding/policybased/storage.go
View file @
54fd2aae
...
...
@@ -18,6 +18,8 @@ limitations under the License.
package
policybased
import
(
"context"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/authorization/authorizer"
...
...
@@ -43,7 +45,7 @@ func NewStorage(s rest.StandardStorage, authorizer authorizer.Authorizer, ruleRe
return
&
Storage
{
s
,
authorizer
,
ruleResolver
}
}
func
(
s
*
Storage
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
s
*
Storage
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
if
rbacregistry
.
EscalationAllowed
(
ctx
)
{
return
s
.
StandardStorage
.
Create
(
ctx
,
obj
,
createValidation
,
includeUninitialized
)
}
...
...
@@ -70,12 +72,12 @@ func (s *Storage) Create(ctx genericapirequest.Context, obj runtime.Object, crea
return
s
.
StandardStorage
.
Create
(
ctx
,
obj
,
createValidation
,
includeUninitialized
)
}
func
(
s
*
Storage
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
obj
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
s
*
Storage
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
obj
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
if
rbacregistry
.
EscalationAllowed
(
ctx
)
{
return
s
.
StandardStorage
.
Update
(
ctx
,
name
,
obj
,
createValidation
,
updateValidation
)
}
nonEscalatingInfo
:=
rest
.
WrapUpdatedObjectInfo
(
obj
,
func
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
nonEscalatingInfo
:=
rest
.
WrapUpdatedObjectInfo
(
obj
,
func
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
// Get the namespace from the context (populated from the URL).
// The namespace in the object can be empty until StandardStorage.Update()->BeforeUpdate() populates it from the context.
namespace
,
ok
:=
genericapirequest
.
NamespaceFrom
(
ctx
)
...
...
pkg/registry/rbac/rolebinding/registry.go
View file @
54fd2aae
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
rolebinding
import
(
"context"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
...
...
@@ -27,12 +29,12 @@ import (
// Registry is an interface for things that know how to store RoleBindings.
type
Registry
interface
{
ListRoleBindings
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
RoleBindingList
,
error
)
CreateRoleBinding
(
ctx
genericapireques
t
.
Context
,
roleBinding
*
rbac
.
RoleBinding
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateRoleBinding
(
ctx
genericapireques
t
.
Context
,
roleBinding
*
rbac
.
RoleBinding
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetRoleBinding
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
RoleBinding
,
error
)
DeleteRoleBinding
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
WatchRoleBindings
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
ListRoleBindings
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
RoleBindingList
,
error
)
CreateRoleBinding
(
ctx
contex
t
.
Context
,
roleBinding
*
rbac
.
RoleBinding
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdateRoleBinding
(
ctx
contex
t
.
Context
,
roleBinding
*
rbac
.
RoleBinding
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetRoleBinding
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
RoleBinding
,
error
)
DeleteRoleBinding
(
ctx
contex
t
.
Context
,
name
string
)
error
WatchRoleBindings
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
}
// storage puts strong typing around storage calls
...
...
@@ -46,7 +48,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListRoleBindings
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
RoleBindingList
,
error
)
{
func
(
s
*
storage
)
ListRoleBindings
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
rbac
.
RoleBindingList
,
error
)
{
obj
,
err
:=
s
.
List
(
ctx
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -55,22 +57,22 @@ func (s *storage) ListRoleBindings(ctx genericapirequest.Context, options *metai
return
obj
.
(
*
rbac
.
RoleBindingList
),
nil
}
func
(
s
*
storage
)
CreateRoleBinding
(
ctx
genericapireques
t
.
Context
,
roleBinding
*
rbac
.
RoleBinding
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
func
(
s
*
storage
)
CreateRoleBinding
(
ctx
contex
t
.
Context
,
roleBinding
*
rbac
.
RoleBinding
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
// TODO(ericchiang): add additional validation
_
,
err
:=
s
.
Create
(
ctx
,
roleBinding
,
createValidation
,
false
)
return
err
}
func
(
s
*
storage
)
UpdateRoleBinding
(
ctx
genericapireques
t
.
Context
,
roleBinding
*
rbac
.
RoleBinding
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
func
(
s
*
storage
)
UpdateRoleBinding
(
ctx
contex
t
.
Context
,
roleBinding
*
rbac
.
RoleBinding
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
_
,
_
,
err
:=
s
.
Update
(
ctx
,
roleBinding
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
roleBinding
),
createValidation
,
updateValidation
)
return
err
}
func
(
s
*
storage
)
WatchRoleBindings
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchRoleBindings
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetRoleBinding
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
RoleBinding
,
error
)
{
func
(
s
*
storage
)
GetRoleBinding
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
rbac
.
RoleBinding
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -78,7 +80,7 @@ func (s *storage) GetRoleBinding(ctx genericapirequest.Context, name string, opt
return
obj
.
(
*
rbac
.
RoleBinding
),
nil
}
func
(
s
*
storage
)
DeleteRoleBinding
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
{
func
(
s
*
storage
)
DeleteRoleBinding
(
ctx
contex
t
.
Context
,
name
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
name
,
nil
)
return
err
}
...
...
pkg/registry/rbac/rolebinding/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
rolebinding
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
...
...
@@ -55,12 +56,12 @@ func (strategy) AllowCreateOnUpdate() bool {
// PrepareForCreate clears fields that are not allowed to be set by end users
// on creation.
func
(
strategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
strategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
_
=
obj
.
(
*
rbac
.
RoleBinding
)
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
strategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
strategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newRoleBinding
:=
obj
.
(
*
rbac
.
RoleBinding
)
oldRoleBinding
:=
old
.
(
*
rbac
.
RoleBinding
)
...
...
@@ -68,7 +69,7 @@ func (strategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime
}
// Validate validates a new RoleBinding. Validation must check for a correct signature.
func
(
strategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
roleBinding
:=
obj
.
(
*
rbac
.
RoleBinding
)
return
validation
.
ValidateRoleBinding
(
roleBinding
)
}
...
...
@@ -79,7 +80,7 @@ func (strategy) Canonicalize(obj runtime.Object) {
}
// ValidateUpdate is the default update validation for an end user.
func
(
strategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
newObj
:=
obj
.
(
*
rbac
.
RoleBinding
)
errorList
:=
validation
.
ValidateRoleBinding
(
newObj
)
return
append
(
errorList
,
validation
.
ValidateRoleBindingUpdate
(
newObj
,
old
.
(
*
rbac
.
RoleBinding
))
...
)
...
...
pkg/registry/rbac/validation/rule.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
validation
import
(
"context"
"errors"
"fmt"
...
...
@@ -46,7 +47,7 @@ type AuthorizationRuleResolver interface {
}
// ConfirmNoEscalation determines if the roles for a given user in a given namespace encompass the provided role.
func
ConfirmNoEscalation
(
ctx
genericapireques
t
.
Context
,
ruleResolver
AuthorizationRuleResolver
,
rules
[]
rbac
.
PolicyRule
)
error
{
func
ConfirmNoEscalation
(
ctx
contex
t
.
Context
,
ruleResolver
AuthorizationRuleResolver
,
rules
[]
rbac
.
PolicyRule
)
error
{
ruleResolutionErrors
:=
[]
error
{}
user
,
ok
:=
genericapirequest
.
UserFrom
(
ctx
)
...
...
pkg/registry/registrytest/endpoint.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
registrytest
import
(
"context"
"fmt"
"sync"
...
...
@@ -24,7 +25,6 @@ import (
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
api
"k8s.io/kubernetes/pkg/apis/core"
)
...
...
@@ -38,7 +38,7 @@ type EndpointRegistry struct {
lock
sync
.
Mutex
}
func
(
e
*
EndpointRegistry
)
ListEndpoints
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
EndpointsList
,
error
)
{
func
(
e
*
EndpointRegistry
)
ListEndpoints
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
EndpointsList
,
error
)
{
// TODO: support namespaces in this mock
e
.
lock
.
Lock
()
defer
e
.
lock
.
Unlock
()
...
...
@@ -46,7 +46,7 @@ func (e *EndpointRegistry) ListEndpoints(ctx genericapirequest.Context, options
return
e
.
Endpoints
,
e
.
Err
}
func
(
e
*
EndpointRegistry
)
GetEndpoints
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Endpoints
,
error
)
{
func
(
e
*
EndpointRegistry
)
GetEndpoints
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Endpoints
,
error
)
{
// TODO: support namespaces in this mock
e
.
lock
.
Lock
()
defer
e
.
lock
.
Unlock
()
...
...
@@ -63,11 +63,11 @@ func (e *EndpointRegistry) GetEndpoints(ctx genericapirequest.Context, name stri
return
nil
,
errors
.
NewNotFound
(
api
.
Resource
(
"endpoints"
),
name
)
}
func
(
e
*
EndpointRegistry
)
WatchEndpoints
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
e
*
EndpointRegistry
)
WatchEndpoints
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
nil
,
fmt
.
Errorf
(
"unimplemented!"
)
}
func
(
e
*
EndpointRegistry
)
UpdateEndpoints
(
ctx
genericapireques
t
.
Context
,
endpoints
*
api
.
Endpoints
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
func
(
e
*
EndpointRegistry
)
UpdateEndpoints
(
ctx
contex
t
.
Context
,
endpoints
*
api
.
Endpoints
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
// TODO: support namespaces in this mock
e
.
lock
.
Lock
()
defer
e
.
lock
.
Unlock
()
...
...
@@ -94,7 +94,7 @@ func (e *EndpointRegistry) UpdateEndpoints(ctx genericapirequest.Context, endpoi
return
nil
}
func
(
e
*
EndpointRegistry
)
DeleteEndpoints
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
{
func
(
e
*
EndpointRegistry
)
DeleteEndpoints
(
ctx
contex
t
.
Context
,
name
string
)
error
{
// TODO: support namespaces in this mock
e
.
lock
.
Lock
()
defer
e
.
lock
.
Unlock
()
...
...
pkg/registry/registrytest/node.go
View file @
54fd2aae
...
...
@@ -17,13 +17,13 @@ limitations under the License.
package
registrytest
import
(
"context"
"sync"
"k8s.io/apimachinery/pkg/api/errors"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
api
"k8s.io/kubernetes/pkg/apis/core"
)
...
...
@@ -60,13 +60,13 @@ func (r *NodeRegistry) SetError(err error) {
r
.
Err
=
err
}
func
(
r
*
NodeRegistry
)
ListNodes
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
NodeList
,
error
)
{
func
(
r
*
NodeRegistry
)
ListNodes
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
NodeList
,
error
)
{
r
.
Lock
()
defer
r
.
Unlock
()
return
&
r
.
Nodes
,
r
.
Err
}
func
(
r
*
NodeRegistry
)
CreateNode
(
ctx
genericapireques
t
.
Context
,
node
*
api
.
Node
)
error
{
func
(
r
*
NodeRegistry
)
CreateNode
(
ctx
contex
t
.
Context
,
node
*
api
.
Node
)
error
{
r
.
Lock
()
defer
r
.
Unlock
()
r
.
Node
=
node
.
Name
...
...
@@ -74,7 +74,7 @@ func (r *NodeRegistry) CreateNode(ctx genericapirequest.Context, node *api.Node)
return
r
.
Err
}
func
(
r
*
NodeRegistry
)
UpdateNode
(
ctx
genericapireques
t
.
Context
,
node
*
api
.
Node
)
error
{
func
(
r
*
NodeRegistry
)
UpdateNode
(
ctx
contex
t
.
Context
,
node
*
api
.
Node
)
error
{
r
.
Lock
()
defer
r
.
Unlock
()
for
i
,
item
:=
range
r
.
Nodes
.
Items
{
...
...
@@ -86,7 +86,7 @@ func (r *NodeRegistry) UpdateNode(ctx genericapirequest.Context, node *api.Node)
return
r
.
Err
}
func
(
r
*
NodeRegistry
)
GetNode
(
ctx
genericapireques
t
.
Context
,
nodeID
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Node
,
error
)
{
func
(
r
*
NodeRegistry
)
GetNode
(
ctx
contex
t
.
Context
,
nodeID
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Node
,
error
)
{
r
.
Lock
()
defer
r
.
Unlock
()
if
r
.
Err
!=
nil
{
...
...
@@ -100,7 +100,7 @@ func (r *NodeRegistry) GetNode(ctx genericapirequest.Context, nodeID string, opt
return
nil
,
errors
.
NewNotFound
(
api
.
Resource
(
"nodes"
),
nodeID
)
}
func
(
r
*
NodeRegistry
)
DeleteNode
(
ctx
genericapireques
t
.
Context
,
nodeID
string
)
error
{
func
(
r
*
NodeRegistry
)
DeleteNode
(
ctx
contex
t
.
Context
,
nodeID
string
)
error
{
r
.
Lock
()
defer
r
.
Unlock
()
var
newList
[]
api
.
Node
...
...
@@ -113,6 +113,6 @@ func (r *NodeRegistry) DeleteNode(ctx genericapirequest.Context, nodeID string)
return
r
.
Err
}
func
(
r
*
NodeRegistry
)
WatchNodes
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
r
*
NodeRegistry
)
WatchNodes
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
nil
,
r
.
Err
}
pkg/registry/registrytest/service.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
registrytest
import
(
"context"
"sync"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
...
...
@@ -49,7 +50,7 @@ func (r *ServiceRegistry) SetError(err error) {
r
.
Err
=
err
}
func
(
r
*
ServiceRegistry
)
ListServices
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ServiceList
,
error
)
{
func
(
r
*
ServiceRegistry
)
ListServices
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
api
.
ServiceList
,
error
)
{
r
.
mu
.
Lock
()
defer
r
.
mu
.
Unlock
()
...
...
@@ -73,7 +74,7 @@ func (r *ServiceRegistry) ListServices(ctx genericapirequest.Context, options *m
return
res
,
r
.
Err
}
func
(
r
*
ServiceRegistry
)
CreateService
(
ctx
genericapireques
t
.
Context
,
svc
*
api
.
Service
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
Service
,
error
)
{
func
(
r
*
ServiceRegistry
)
CreateService
(
ctx
contex
t
.
Context
,
svc
*
api
.
Service
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
api
.
Service
,
error
)
{
r
.
mu
.
Lock
()
defer
r
.
mu
.
Unlock
()
...
...
@@ -83,7 +84,7 @@ func (r *ServiceRegistry) CreateService(ctx genericapirequest.Context, svc *api.
return
svc
,
r
.
Err
}
func
(
r
*
ServiceRegistry
)
GetService
(
ctx
genericapireques
t
.
Context
,
id
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Service
,
error
)
{
func
(
r
*
ServiceRegistry
)
GetService
(
ctx
contex
t
.
Context
,
id
string
,
options
*
metav1
.
GetOptions
)
(
*
api
.
Service
,
error
)
{
r
.
mu
.
Lock
()
defer
r
.
mu
.
Unlock
()
...
...
@@ -91,7 +92,7 @@ func (r *ServiceRegistry) GetService(ctx genericapirequest.Context, id string, o
return
r
.
Service
,
r
.
Err
}
func
(
r
*
ServiceRegistry
)
DeleteService
(
ctx
genericapireques
t
.
Context
,
id
string
)
error
{
func
(
r
*
ServiceRegistry
)
DeleteService
(
ctx
contex
t
.
Context
,
id
string
)
error
{
r
.
mu
.
Lock
()
defer
r
.
mu
.
Unlock
()
...
...
@@ -100,7 +101,7 @@ func (r *ServiceRegistry) DeleteService(ctx genericapirequest.Context, id string
return
r
.
Err
}
func
(
r
*
ServiceRegistry
)
UpdateService
(
ctx
genericapireques
t
.
Context
,
svc
*
api
.
Service
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
Service
,
error
)
{
func
(
r
*
ServiceRegistry
)
UpdateService
(
ctx
contex
t
.
Context
,
svc
*
api
.
Service
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
api
.
Service
,
error
)
{
r
.
mu
.
Lock
()
defer
r
.
mu
.
Unlock
()
...
...
@@ -110,14 +111,14 @@ func (r *ServiceRegistry) UpdateService(ctx genericapirequest.Context, svc *api.
return
svc
,
r
.
Err
}
func
(
r
*
ServiceRegistry
)
WatchServices
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
r
*
ServiceRegistry
)
WatchServices
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
r
.
mu
.
Lock
()
defer
r
.
mu
.
Unlock
()
return
nil
,
r
.
Err
}
func
(
r
*
ServiceRegistry
)
ExportService
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
metav1
.
ExportOptions
)
(
*
api
.
Service
,
error
)
{
func
(
r
*
ServiceRegistry
)
ExportService
(
ctx
contex
t
.
Context
,
name
string
,
options
metav1
.
ExportOptions
)
(
*
api
.
Service
,
error
)
{
r
.
mu
.
Lock
()
defer
r
.
mu
.
Unlock
()
...
...
pkg/registry/scheduling/priorityclass/BUILD
View file @
54fd2aae
...
...
@@ -34,7 +34,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
...
...
pkg/registry/scheduling/priorityclass/registry.go
View file @
54fd2aae
...
...
@@ -17,22 +17,23 @@ limitations under the License.
package
priorityclass
import
(
"context"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/scheduling"
)
// Registry is an interface for things that know how to store PriorityClass.
type
Registry
interface
{
ListPriorityClasses
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
scheduling
.
PriorityClassList
,
error
)
CreatePriorityClass
(
ctx
genericapireques
t
.
Context
,
pc
*
scheduling
.
PriorityClass
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdatePriorityClass
(
ctx
genericapireques
t
.
Context
,
pc
*
scheduling
.
PriorityClass
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetPriorityClass
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
scheduling
.
PriorityClass
,
error
)
DeletePriorityClass
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
WatchPriorityClasses
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
ListPriorityClasses
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
scheduling
.
PriorityClassList
,
error
)
CreatePriorityClass
(
ctx
contex
t
.
Context
,
pc
*
scheduling
.
PriorityClass
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdatePriorityClass
(
ctx
contex
t
.
Context
,
pc
*
scheduling
.
PriorityClass
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetPriorityClass
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
scheduling
.
PriorityClass
,
error
)
DeletePriorityClass
(
ctx
contex
t
.
Context
,
name
string
)
error
WatchPriorityClasses
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
}
// storage puts strong typing around storage calls
...
...
@@ -46,7 +47,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListPriorityClasses
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
scheduling
.
PriorityClassList
,
error
)
{
func
(
s
*
storage
)
ListPriorityClasses
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
scheduling
.
PriorityClassList
,
error
)
{
obj
,
err
:=
s
.
List
(
ctx
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -55,21 +56,21 @@ func (s *storage) ListPriorityClasses(ctx genericapirequest.Context, options *me
return
obj
.
(
*
scheduling
.
PriorityClassList
),
nil
}
func
(
s
*
storage
)
CreatePriorityClass
(
ctx
genericapireques
t
.
Context
,
pc
*
scheduling
.
PriorityClass
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
func
(
s
*
storage
)
CreatePriorityClass
(
ctx
contex
t
.
Context
,
pc
*
scheduling
.
PriorityClass
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
_
,
err
:=
s
.
Create
(
ctx
,
pc
,
createValidation
,
false
)
return
err
}
func
(
s
*
storage
)
UpdatePriorityClass
(
ctx
genericapireques
t
.
Context
,
pc
*
scheduling
.
PriorityClass
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
func
(
s
*
storage
)
UpdatePriorityClass
(
ctx
contex
t
.
Context
,
pc
*
scheduling
.
PriorityClass
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
_
,
_
,
err
:=
s
.
Update
(
ctx
,
pc
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
pc
),
createValidation
,
updateValidation
)
return
err
}
func
(
s
*
storage
)
WatchPriorityClasses
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchPriorityClasses
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetPriorityClass
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
scheduling
.
PriorityClass
,
error
)
{
func
(
s
*
storage
)
GetPriorityClass
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
scheduling
.
PriorityClass
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -77,7 +78,7 @@ func (s *storage) GetPriorityClass(ctx genericapirequest.Context, name string, o
return
obj
.
(
*
scheduling
.
PriorityClass
),
nil
}
func
(
s
*
storage
)
DeletePriorityClass
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
{
func
(
s
*
storage
)
DeletePriorityClass
(
ctx
contex
t
.
Context
,
name
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
name
,
nil
)
return
err
}
pkg/registry/scheduling/priorityclass/storage/BUILD
View file @
54fd2aae
...
...
@@ -34,7 +34,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
pkg/registry/scheduling/priorityclass/storage/storage.go
View file @
54fd2aae
...
...
@@ -17,12 +17,12 @@ limitations under the License.
package
storage
import
(
"context"
"errors"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -63,7 +63,7 @@ func (r *REST) ShortNames() []string {
}
// Delete ensures that system priority classes are not deleted.
func
(
r
*
REST
)
Delete
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
REST
)
Delete
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
for
_
,
spc
:=
range
scheduling
.
SystemPriorityClasses
()
{
if
name
==
spc
.
Name
{
return
nil
,
false
,
apierrors
.
NewForbidden
(
scheduling
.
Resource
(
"priorityclasses"
),
spc
.
Name
,
errors
.
New
(
"this is a system priority class and cannot be deleted"
))
...
...
pkg/registry/scheduling/priorityclass/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
priorityclass
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/scheduling"
...
...
@@ -41,19 +42,19 @@ func (priorityClassStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of a PriorityClass before creation.
func
(
priorityClassStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
priorityClassStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
pc
:=
obj
.
(
*
scheduling
.
PriorityClass
)
pc
.
Generation
=
1
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
priorityClassStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
priorityClassStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
_
=
obj
.
(
*
scheduling
.
PriorityClass
)
_
=
old
.
(
*
scheduling
.
PriorityClass
)
}
// Validate validates a new PriorityClass.
func
(
priorityClassStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
priorityClassStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
pc
:=
obj
.
(
*
scheduling
.
PriorityClass
)
return
validation
.
ValidatePriorityClass
(
pc
)
}
...
...
@@ -67,7 +68,7 @@ func (priorityClassStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
priorityClassStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
priorityClassStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidatePriorityClassUpdate
(
obj
.
(
*
scheduling
.
PriorityClass
),
old
.
(
*
scheduling
.
PriorityClass
))
}
...
...
pkg/registry/settings/podpreset/BUILD
View file @
54fd2aae
...
...
@@ -23,7 +23,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
...
...
pkg/registry/settings/podpreset/registry.go
View file @
54fd2aae
...
...
@@ -17,22 +17,23 @@ limitations under the License.
package
podpreset
import
(
"context"
metainternalversion
"k8s.io/apimachinery/pkg/apis/meta/internalversion"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/kubernetes/pkg/apis/settings"
)
// Registry is an interface for things that know how to store PodPresets.
type
Registry
interface
{
ListPodPresets
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
settings
.
PodPresetList
,
error
)
CreatePodPreset
(
ctx
genericapireques
t
.
Context
,
pp
*
settings
.
PodPreset
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdatePodPreset
(
ctx
genericapireques
t
.
Context
,
pp
*
settings
.
PodPreset
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetPodPreset
(
ctx
genericapireques
t
.
Context
,
ppID
string
,
options
*
metav1
.
GetOptions
)
(
*
settings
.
PodPreset
,
error
)
DeletePodPreset
(
ctx
genericapireques
t
.
Context
,
ppID
string
)
error
WatchPodPresets
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
ListPodPresets
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
settings
.
PodPresetList
,
error
)
CreatePodPreset
(
ctx
contex
t
.
Context
,
pp
*
settings
.
PodPreset
,
createValidation
rest
.
ValidateObjectFunc
)
error
UpdatePodPreset
(
ctx
contex
t
.
Context
,
pp
*
settings
.
PodPreset
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
GetPodPreset
(
ctx
contex
t
.
Context
,
ppID
string
,
options
*
metav1
.
GetOptions
)
(
*
settings
.
PodPreset
,
error
)
DeletePodPreset
(
ctx
contex
t
.
Context
,
ppID
string
)
error
WatchPodPresets
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
}
// storage puts strong typing around storage calls
...
...
@@ -46,7 +47,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListPodPresets
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
settings
.
PodPresetList
,
error
)
{
func
(
s
*
storage
)
ListPodPresets
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
settings
.
PodPresetList
,
error
)
{
obj
,
err
:=
s
.
List
(
ctx
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -55,21 +56,21 @@ func (s *storage) ListPodPresets(ctx genericapirequest.Context, options *metaint
return
obj
.
(
*
settings
.
PodPresetList
),
nil
}
func
(
s
*
storage
)
CreatePodPreset
(
ctx
genericapireques
t
.
Context
,
pp
*
settings
.
PodPreset
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
func
(
s
*
storage
)
CreatePodPreset
(
ctx
contex
t
.
Context
,
pp
*
settings
.
PodPreset
,
createValidation
rest
.
ValidateObjectFunc
)
error
{
_
,
err
:=
s
.
Create
(
ctx
,
pp
,
createValidation
,
false
)
return
err
}
func
(
s
*
storage
)
UpdatePodPreset
(
ctx
genericapireques
t
.
Context
,
pp
*
settings
.
PodPreset
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
func
(
s
*
storage
)
UpdatePodPreset
(
ctx
contex
t
.
Context
,
pp
*
settings
.
PodPreset
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
error
{
_
,
_
,
err
:=
s
.
Update
(
ctx
,
pp
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
pp
),
createValidation
,
updateValidation
)
return
err
}
func
(
s
*
storage
)
WatchPodPresets
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchPodPresets
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetPodPreset
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
settings
.
PodPreset
,
error
)
{
func
(
s
*
storage
)
GetPodPreset
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
*
settings
.
PodPreset
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -77,7 +78,7 @@ func (s *storage) GetPodPreset(ctx genericapirequest.Context, name string, optio
return
obj
.
(
*
settings
.
PodPreset
),
nil
}
func
(
s
*
storage
)
DeletePodPreset
(
ctx
genericapireques
t
.
Context
,
name
string
)
error
{
func
(
s
*
storage
)
DeletePodPreset
(
ctx
contex
t
.
Context
,
name
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
name
,
nil
)
return
err
}
pkg/registry/settings/podpreset/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
podpreset
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/pod"
...
...
@@ -42,7 +43,7 @@ func (podPresetStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of a Pod Preset before creation.
func
(
podPresetStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
podPresetStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
pip
:=
obj
.
(
*
settings
.
PodPreset
)
pip
.
Generation
=
1
...
...
@@ -50,7 +51,7 @@ func (podPresetStrategy) PrepareForCreate(ctx genericapirequest.Context, obj run
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
podPresetStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
podPresetStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newPodPreset
:=
obj
.
(
*
settings
.
PodPreset
)
oldPodPreset
:=
old
.
(
*
settings
.
PodPreset
)
...
...
@@ -62,7 +63,7 @@ func (podPresetStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, ol
}
// Validate validates a new PodPreset.
func
(
podPresetStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
podPresetStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
pip
:=
obj
.
(
*
settings
.
PodPreset
)
return
validation
.
ValidatePodPreset
(
pip
)
}
...
...
@@ -76,7 +77,7 @@ func (podPresetStrategy) AllowCreateOnUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user.
func
(
podPresetStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
podPresetStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
validationErrorList
:=
validation
.
ValidatePodPreset
(
obj
.
(
*
settings
.
PodPreset
))
updateErrorList
:=
validation
.
ValidatePodPresetUpdate
(
obj
.
(
*
settings
.
PodPreset
),
old
.
(
*
settings
.
PodPreset
))
return
append
(
validationErrorList
,
updateErrorList
...
)
...
...
pkg/registry/storage/storageclass/BUILD
View file @
54fd2aae
...
...
@@ -21,7 +21,6 @@ go_library(
"//pkg/features:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
],
...
...
pkg/registry/storage/storageclass/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
storageclass
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/api/legacyscheme"
...
...
@@ -44,7 +45,7 @@ func (storageClassStrategy) NamespaceScoped() bool {
}
// ResetBeforeCreate clears the Status field which is not allowed to be set by end users on creation.
func
(
storageClassStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
storageClassStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
class
:=
obj
.
(
*
storage
.
StorageClass
)
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
ExpandPersistentVolumes
)
{
...
...
@@ -54,7 +55,7 @@ func (storageClassStrategy) PrepareForCreate(ctx genericapirequest.Context, obj
storageutil
.
DropDisabledAlphaFields
(
class
)
}
func
(
storageClassStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
storageClassStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
storageClass
:=
obj
.
(
*
storage
.
StorageClass
)
return
validation
.
ValidateStorageClass
(
storageClass
)
}
...
...
@@ -68,7 +69,7 @@ func (storageClassStrategy) AllowCreateOnUpdate() bool {
}
// PrepareForUpdate sets the Status fields which is not allowed to be set by an end user updating a PV
func
(
storageClassStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
storageClassStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newClass
:=
obj
.
(
*
storage
.
StorageClass
)
oldClass
:=
old
.
(
*
storage
.
StorageClass
)
...
...
@@ -80,7 +81,7 @@ func (storageClassStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj,
storageutil
.
DropDisabledAlphaFields
(
newClass
)
}
func
(
storageClassStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
storageClassStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
errorList
:=
validation
.
ValidateStorageClass
(
obj
.
(
*
storage
.
StorageClass
))
return
append
(
errorList
,
validation
.
ValidateStorageClassUpdate
(
obj
.
(
*
storage
.
StorageClass
),
old
.
(
*
storage
.
StorageClass
))
...
)
}
...
...
pkg/registry/storage/volumeattachment/BUILD
View file @
54fd2aae
...
...
@@ -14,7 +14,6 @@ go_library(
"//pkg/apis/storage/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
],
)
...
...
pkg/registry/storage/volumeattachment/strategy.go
View file @
54fd2aae
...
...
@@ -17,9 +17,10 @@ limitations under the License.
package
volumeattachment
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/storage"
...
...
@@ -41,10 +42,10 @@ func (volumeAttachmentStrategy) NamespaceScoped() bool {
}
// ResetBeforeCreate clears the Status field which is not allowed to be set by end users on creation.
func
(
volumeAttachmentStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
volumeAttachmentStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
}
func
(
volumeAttachmentStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
volumeAttachmentStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
volumeAttachment
:=
obj
.
(
*
storage
.
VolumeAttachment
)
return
validation
.
ValidateVolumeAttachment
(
volumeAttachment
)
}
...
...
@@ -58,10 +59,10 @@ func (volumeAttachmentStrategy) AllowCreateOnUpdate() bool {
}
// PrepareForUpdate sets the Status fields which is not allowed to be set by an end user updating a PV
func
(
volumeAttachmentStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
volumeAttachmentStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
}
func
(
volumeAttachmentStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
volumeAttachmentStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
newVolumeAttachmentObj
:=
obj
.
(
*
storage
.
VolumeAttachment
)
oldVolumeAttachmentObj
:=
old
.
(
*
storage
.
VolumeAttachment
)
errorList
:=
validation
.
ValidateVolumeAttachment
(
newVolumeAttachmentObj
)
...
...
staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/BUILD
View file @
54fd2aae
...
...
@@ -35,7 +35,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/etcd.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
customresource
import
(
"context"
"fmt"
"strings"
...
...
@@ -26,7 +27,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -121,12 +121,12 @@ func (r *StatusREST) New() runtime.Object {
}
// Get retrieves the object from the storage. It is required to support Patch.
func
(
r
*
StatusREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
StatusREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
r
.
store
.
Get
(
ctx
,
name
,
options
)
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
...
...
@@ -150,7 +150,7 @@ func (r *ScaleREST) New() runtime.Object {
return
&
autoscalingv1
.
Scale
{}
}
func
(
r
*
ScaleREST
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
ScaleREST
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
cr
,
err
:=
r
.
registry
.
GetCustomResource
(
ctx
,
name
,
options
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -166,7 +166,7 @@ func (r *ScaleREST) Get(ctx genericapirequest.Context, name string, options *met
return
scaleObject
,
err
}
func
(
r
*
ScaleREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
ScaleREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
cr
,
err
:=
r
.
registry
.
GetCustomResource
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
false
,
err
...
...
staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/registry.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
customresource
import
(
"context"
"fmt"
"strings"
...
...
@@ -26,18 +27,17 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
)
// Registry is an interface for things that know how to store CustomResources.
type
Registry
interface
{
ListCustomResources
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
unstructured
.
UnstructuredList
,
error
)
WatchCustomResources
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
GetCustomResource
(
ctx
genericapireques
t
.
Context
,
customResourceID
string
,
options
*
metav1
.
GetOptions
)
(
*
unstructured
.
Unstructured
,
error
)
CreateCustomResource
(
ctx
genericapireques
t
.
Context
,
customResource
*
unstructured
.
Unstructured
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
unstructured
.
Unstructured
,
error
)
UpdateCustomResource
(
ctx
genericapireques
t
.
Context
,
customResource
*
unstructured
.
Unstructured
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
unstructured
.
Unstructured
,
error
)
DeleteCustomResource
(
ctx
genericapireques
t
.
Context
,
customResourceID
string
)
error
ListCustomResources
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
unstructured
.
UnstructuredList
,
error
)
WatchCustomResources
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
GetCustomResource
(
ctx
contex
t
.
Context
,
customResourceID
string
,
options
*
metav1
.
GetOptions
)
(
*
unstructured
.
Unstructured
,
error
)
CreateCustomResource
(
ctx
contex
t
.
Context
,
customResource
*
unstructured
.
Unstructured
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
unstructured
.
Unstructured
,
error
)
UpdateCustomResource
(
ctx
contex
t
.
Context
,
customResource
*
unstructured
.
Unstructured
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
unstructured
.
Unstructured
,
error
)
DeleteCustomResource
(
ctx
contex
t
.
Context
,
customResourceID
string
)
error
}
// storage puts strong typing around storage calls
...
...
@@ -51,7 +51,7 @@ func NewRegistry(s rest.StandardStorage) Registry {
return
&
storage
{
s
}
}
func
(
s
*
storage
)
ListCustomResources
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
unstructured
.
UnstructuredList
,
error
)
{
func
(
s
*
storage
)
ListCustomResources
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
*
unstructured
.
UnstructuredList
,
error
)
{
if
options
!=
nil
&&
options
.
FieldSelector
!=
nil
&&
!
options
.
FieldSelector
.
Empty
()
{
return
nil
,
fmt
.
Errorf
(
"field selector not supported yet"
)
}
...
...
@@ -62,11 +62,11 @@ func (s *storage) ListCustomResources(ctx genericapirequest.Context, options *me
return
obj
.
(
*
unstructured
.
UnstructuredList
),
err
}
func
(
s
*
storage
)
WatchCustomResources
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
s
*
storage
)
WatchCustomResources
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
return
s
.
Watch
(
ctx
,
options
)
}
func
(
s
*
storage
)
GetCustomResource
(
ctx
genericapireques
t
.
Context
,
customResourceID
string
,
options
*
metav1
.
GetOptions
)
(
*
unstructured
.
Unstructured
,
error
)
{
func
(
s
*
storage
)
GetCustomResource
(
ctx
contex
t
.
Context
,
customResourceID
string
,
options
*
metav1
.
GetOptions
)
(
*
unstructured
.
Unstructured
,
error
)
{
obj
,
err
:=
s
.
Get
(
ctx
,
customResourceID
,
options
)
customResource
,
ok
:=
obj
.
(
*
unstructured
.
Unstructured
)
if
!
ok
{
...
...
@@ -82,7 +82,7 @@ func (s *storage) GetCustomResource(ctx genericapirequest.Context, customResourc
return
customResource
,
nil
}
func
(
s
*
storage
)
CreateCustomResource
(
ctx
genericapireques
t
.
Context
,
customResource
*
unstructured
.
Unstructured
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
unstructured
.
Unstructured
,
error
)
{
func
(
s
*
storage
)
CreateCustomResource
(
ctx
contex
t
.
Context
,
customResource
*
unstructured
.
Unstructured
,
createValidation
rest
.
ValidateObjectFunc
)
(
*
unstructured
.
Unstructured
,
error
)
{
obj
,
err
:=
s
.
Create
(
ctx
,
customResource
,
rest
.
ValidateAllObjectFunc
,
false
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -90,7 +90,7 @@ func (s *storage) CreateCustomResource(ctx genericapirequest.Context, customReso
return
obj
.
(
*
unstructured
.
Unstructured
),
nil
}
func
(
s
*
storage
)
UpdateCustomResource
(
ctx
genericapireques
t
.
Context
,
customResource
*
unstructured
.
Unstructured
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
unstructured
.
Unstructured
,
error
)
{
func
(
s
*
storage
)
UpdateCustomResource
(
ctx
contex
t
.
Context
,
customResource
*
unstructured
.
Unstructured
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
*
unstructured
.
Unstructured
,
error
)
{
obj
,
_
,
err
:=
s
.
Update
(
ctx
,
customResource
.
GetName
(),
rest
.
DefaultUpdatedObjectInfo
(
customResource
),
createValidation
,
updateValidation
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -98,7 +98,7 @@ func (s *storage) UpdateCustomResource(ctx genericapirequest.Context, customReso
return
obj
.
(
*
unstructured
.
Unstructured
),
nil
}
func
(
s
*
storage
)
DeleteCustomResource
(
ctx
genericapireques
t
.
Context
,
customResourceID
string
)
error
{
func
(
s
*
storage
)
DeleteCustomResource
(
ctx
contex
t
.
Context
,
customResourceID
string
)
error
{
_
,
_
,
err
:=
s
.
Delete
(
ctx
,
customResourceID
,
nil
)
return
err
}
staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/status_strategy.go
View file @
54fd2aae
...
...
@@ -17,10 +17,11 @@ limitations under the License.
package
customresource
import
(
"context"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
)
type
statusStrategy
struct
{
...
...
@@ -31,7 +32,7 @@ func NewStatusStrategy(strategy customResourceStrategy) statusStrategy {
return
statusStrategy
{
strategy
}
}
func
(
a
statusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
a
statusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newCustomResourceObject
:=
obj
.
(
*
unstructured
.
Unstructured
)
oldCustomResourceObject
:=
old
.
(
*
unstructured
.
Unstructured
)
...
...
@@ -57,6 +58,6 @@ func (a statusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old
}
// ValidateUpdate is the default update validation for an end user updating status.
func
(
a
statusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
a
statusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
a
.
customResourceStrategy
.
validator
.
ValidateStatusUpdate
(
ctx
,
obj
,
old
,
a
.
scale
)
}
staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/strategy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
customresource
import
(
"context"
"github.com/go-openapi/validate"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
...
...
@@ -28,7 +30,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
apiserverstorage
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage/names"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
...
...
@@ -69,7 +70,7 @@ func (a customResourceStrategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of a CustomResource before creation.
func
(
a
customResourceStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
a
customResourceStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
apiextensionsfeatures
.
CustomResourceSubresources
)
&&
a
.
status
!=
nil
{
customResourceObject
:=
obj
.
(
*
unstructured
.
Unstructured
)
customResource
:=
customResourceObject
.
UnstructuredContent
()
...
...
@@ -85,7 +86,7 @@ func (a customResourceStrategy) PrepareForCreate(ctx genericapirequest.Context,
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
a
customResourceStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
a
customResourceStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
if
!
utilfeature
.
DefaultFeatureGate
.
Enabled
(
apiextensionsfeatures
.
CustomResourceSubresources
)
||
a
.
status
==
nil
{
return
}
...
...
@@ -126,7 +127,7 @@ func (a customResourceStrategy) PrepareForUpdate(ctx genericapirequest.Context,
}
// Validate validates a new CustomResource.
func
(
a
customResourceStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
a
customResourceStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
return
a
.
validator
.
Validate
(
ctx
,
obj
,
a
.
scale
)
}
...
...
@@ -146,7 +147,7 @@ func (customResourceStrategy) AllowUnconditionalUpdate() bool {
}
// ValidateUpdate is the default update validation for an end user updating status.
func
(
a
customResourceStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
a
customResourceStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
a
.
validator
.
ValidateUpdate
(
ctx
,
obj
,
old
,
a
.
scale
)
}
...
...
staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/tableconvertor/BUILD
View file @
54fd2aae
...
...
@@ -12,7 +12,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1beta1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/client-go/util/jsonpath:go_default_library",
],
...
...
staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/tableconvertor/tableconvertor.go
View file @
54fd2aae
...
...
@@ -18,6 +18,7 @@ package tableconvertor
import
(
"bytes"
"context"
"fmt"
"strings"
...
...
@@ -28,7 +29,6 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1beta1
"k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/client-go/util/jsonpath"
)
...
...
@@ -85,7 +85,7 @@ type convertor struct {
columns
[]
*
jsonpath
.
JSONPath
}
func
(
c
*
convertor
)
ConvertToTable
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
func
(
c
*
convertor
)
ConvertToTable
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
table
:=
&
metav1beta1
.
Table
{
ColumnDefinitions
:
c
.
headers
,
}
...
...
staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/validator.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
customresource
import
(
"context"
"fmt"
"math"
"strings"
...
...
@@ -29,7 +30,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
apiservervalidation
"k8s.io/apiextensions-apiserver/pkg/apiserver/validation"
...
...
@@ -42,7 +42,7 @@ type customResourceValidator struct {
statusSchemaValidator
*
validate
.
SchemaValidator
}
func
(
a
customResourceValidator
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
scale
*
apiextensions
.
CustomResourceSubresourceScale
)
field
.
ErrorList
{
func
(
a
customResourceValidator
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
scale
*
apiextensions
.
CustomResourceSubresourceScale
)
field
.
ErrorList
{
accessor
,
err
:=
meta
.
Accessor
(
obj
)
if
err
!=
nil
{
return
field
.
ErrorList
{
field
.
Invalid
(
field
.
NewPath
(
"metadata"
),
nil
,
err
.
Error
())}
...
...
@@ -109,7 +109,7 @@ func (a customResourceValidator) Validate(ctx genericapirequest.Context, obj run
return
validation
.
ValidateObjectMetaAccessor
(
accessor
,
a
.
namespaceScoped
,
validation
.
NameIsDNSSubdomain
,
field
.
NewPath
(
"metadata"
))
}
func
(
a
customResourceValidator
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
,
scale
*
apiextensions
.
CustomResourceSubresourceScale
)
field
.
ErrorList
{
func
(
a
customResourceValidator
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
,
scale
*
apiextensions
.
CustomResourceSubresourceScale
)
field
.
ErrorList
{
objAccessor
,
err
:=
meta
.
Accessor
(
obj
)
if
err
!=
nil
{
return
field
.
ErrorList
{
field
.
Invalid
(
field
.
NewPath
(
"metadata"
),
nil
,
err
.
Error
())}
...
...
@@ -180,7 +180,7 @@ func (a customResourceValidator) ValidateUpdate(ctx genericapirequest.Context, o
return
validation
.
ValidateObjectMetaAccessorUpdate
(
objAccessor
,
oldAccessor
,
field
.
NewPath
(
"metadata"
))
}
func
(
a
customResourceValidator
)
ValidateStatusUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
,
scale
*
apiextensions
.
CustomResourceSubresourceScale
)
field
.
ErrorList
{
func
(
a
customResourceValidator
)
ValidateStatusUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
,
scale
*
apiextensions
.
CustomResourceSubresourceScale
)
field
.
ErrorList
{
objAccessor
,
err
:=
meta
.
Accessor
(
obj
)
if
err
!=
nil
{
return
field
.
ErrorList
{
field
.
Invalid
(
field
.
NewPath
(
"metadata"
),
nil
,
err
.
Error
())}
...
...
staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresourcedefinition/BUILD
View file @
54fd2aae
...
...
@@ -23,7 +23,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresourcedefinition/etcd.go
View file @
54fd2aae
...
...
@@ -17,13 +17,13 @@ limitations under the License.
package
customresourcedefinition
import
(
"context"
"fmt"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
apierrors
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -66,7 +66,7 @@ func (r *REST) ShortNames() []string {
}
// Delete adds the CRD finalizer to the list
func
(
r
*
REST
)
Delete
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
REST
)
Delete
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
obj
,
err
:=
r
.
Get
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
false
,
err
...
...
@@ -167,6 +167,6 @@ func (r *StatusREST) New() runtime.Object {
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresourcedefinition/strategy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
customresourcedefinition
import
(
"context"
"fmt"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
...
...
@@ -24,7 +25,6 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage/names"
...
...
@@ -50,7 +50,7 @@ func (strategy) NamespaceScoped() bool {
}
// PrepareForCreate clears the status of a CustomResourceDefinition before creation.
func
(
strategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
strategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
crd
:=
obj
.
(
*
apiextensions
.
CustomResourceDefinition
)
crd
.
Status
=
apiextensions
.
CustomResourceDefinitionStatus
{}
crd
.
Generation
=
1
...
...
@@ -65,7 +65,7 @@ func (strategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Obje
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func
(
strategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
strategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newCRD
:=
obj
.
(
*
apiextensions
.
CustomResourceDefinition
)
oldCRD
:=
old
.
(
*
apiextensions
.
CustomResourceDefinition
)
newCRD
.
Status
=
oldCRD
.
Status
...
...
@@ -93,7 +93,7 @@ func (strategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime
}
// Validate validates a new CustomResourceDefinition.
func
(
strategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateCustomResourceDefinition
(
obj
.
(
*
apiextensions
.
CustomResourceDefinition
))
}
...
...
@@ -113,7 +113,7 @@ func (strategy) Canonicalize(obj runtime.Object) {
}
// ValidateUpdate is the default update validation for an end user updating status.
func
(
strategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
strategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateCustomResourceDefinitionUpdate
(
obj
.
(
*
apiextensions
.
CustomResourceDefinition
),
old
.
(
*
apiextensions
.
CustomResourceDefinition
))
}
...
...
@@ -130,7 +130,7 @@ func (statusStrategy) NamespaceScoped() bool {
return
false
}
func
(
statusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
statusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newObj
:=
obj
.
(
*
apiextensions
.
CustomResourceDefinition
)
oldObj
:=
old
.
(
*
apiextensions
.
CustomResourceDefinition
)
newObj
.
Spec
=
oldObj
.
Spec
...
...
@@ -155,7 +155,7 @@ func (statusStrategy) AllowUnconditionalUpdate() bool {
func
(
statusStrategy
)
Canonicalize
(
obj
runtime
.
Object
)
{
}
func
(
statusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
statusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateUpdateCustomResourceDefinitionStatus
(
obj
.
(
*
apiextensions
.
CustomResourceDefinition
),
old
.
(
*
apiextensions
.
CustomResourceDefinition
))
}
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/apiserver_test.go
View file @
54fd2aae
...
...
@@ -19,6 +19,7 @@ package endpoints
import
(
"bytes"
"compress/gzip"
"context"
"encoding/json"
"errors"
"fmt"
...
...
@@ -414,7 +415,7 @@ type SimpleRESTStorage struct {
injectedFunction
func
(
obj
runtime
.
Object
)
(
returnObj
runtime
.
Object
,
err
error
)
}
func
(
storage
*
SimpleRESTStorage
)
Export
(
ctx
reques
t
.
Context
,
name
string
,
opts
metav1
.
ExportOptions
)
(
runtime
.
Object
,
error
)
{
func
(
storage
*
SimpleRESTStorage
)
Export
(
ctx
contex
t
.
Context
,
name
string
,
opts
metav1
.
ExportOptions
)
(
runtime
.
Object
,
error
)
{
obj
,
err
:=
storage
.
Get
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -429,11 +430,11 @@ func (storage *SimpleRESTStorage) Export(ctx request.Context, name string, opts
return
obj
,
storage
.
errors
[
"export"
]
}
func
(
storage
*
SimpleRESTStorage
)
ConvertToTable
(
ctx
reques
t
.
Context
,
obj
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
func
(
storage
*
SimpleRESTStorage
)
ConvertToTable
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
return
rest
.
NewDefaultTableConvertor
(
schema
.
GroupResource
{
Resource
:
"simple"
})
.
ConvertToTable
(
ctx
,
obj
,
tableOptions
)
}
func
(
storage
*
SimpleRESTStorage
)
List
(
ctx
reques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
func
(
storage
*
SimpleRESTStorage
)
List
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
storage
.
checkContext
(
ctx
)
result
:=
&
genericapitesting
.
SimpleList
{
ListMeta
:
metav1
.
ListMeta
{
...
...
@@ -488,7 +489,7 @@ func (h *OutputConnect) ServeHTTP(w http.ResponseWriter, req *http.Request) {
w
.
Write
([]
byte
(
h
.
response
))
}
func
(
storage
*
SimpleRESTStorage
)
Get
(
ctx
reques
t
.
Context
,
id
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
storage
*
SimpleRESTStorage
)
Get
(
ctx
contex
t
.
Context
,
id
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
storage
.
checkContext
(
ctx
)
if
id
==
"binary"
{
return
storage
.
stream
,
storage
.
errors
[
"get"
]
...
...
@@ -496,11 +497,11 @@ func (storage *SimpleRESTStorage) Get(ctx request.Context, id string, options *m
return
storage
.
item
.
DeepCopy
(),
storage
.
errors
[
"get"
]
}
func
(
storage
*
SimpleRESTStorage
)
checkContext
(
ctx
reques
t
.
Context
)
{
func
(
storage
*
SimpleRESTStorage
)
checkContext
(
ctx
contex
t
.
Context
)
{
storage
.
actualNamespace
,
storage
.
namespacePresent
=
request
.
NamespaceFrom
(
ctx
)
}
func
(
storage
*
SimpleRESTStorage
)
Delete
(
ctx
reques
t
.
Context
,
id
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
storage
*
SimpleRESTStorage
)
Delete
(
ctx
contex
t
.
Context
,
id
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
storage
.
checkContext
(
ctx
)
storage
.
deleted
=
id
storage
.
deleteOptions
=
options
...
...
@@ -523,7 +524,7 @@ func (storage *SimpleRESTStorage) NewList() runtime.Object {
return
&
genericapitesting
.
SimpleList
{}
}
func
(
storage
*
SimpleRESTStorage
)
Create
(
ctx
reques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
storage
*
SimpleRESTStorage
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
storage
.
checkContext
(
ctx
)
storage
.
created
=
obj
.
(
*
genericapitesting
.
Simple
)
if
err
:=
storage
.
errors
[
"create"
];
err
!=
nil
{
...
...
@@ -539,7 +540,7 @@ func (storage *SimpleRESTStorage) Create(ctx request.Context, obj runtime.Object
return
obj
,
err
}
func
(
storage
*
SimpleRESTStorage
)
Update
(
ctx
reques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
storage
*
SimpleRESTStorage
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
storage
.
checkContext
(
ctx
)
obj
,
err
:=
objInfo
.
UpdatedObject
(
ctx
,
&
storage
.
item
)
if
err
!=
nil
{
...
...
@@ -559,7 +560,7 @@ func (storage *SimpleRESTStorage) Update(ctx request.Context, name string, objIn
}
// Implement ResourceWatcher.
func
(
storage
*
SimpleRESTStorage
)
Watch
(
ctx
reques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
storage
*
SimpleRESTStorage
)
Watch
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
storage
.
lock
.
Lock
()
defer
storage
.
lock
.
Unlock
()
storage
.
checkContext
(
ctx
)
...
...
@@ -608,7 +609,7 @@ func (s *ConnecterRESTStorage) New() runtime.Object {
return
&
genericapitesting
.
Simple
{}
}
func
(
s
*
ConnecterRESTStorage
)
Connect
(
ctx
reques
t
.
Context
,
id
string
,
options
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
func
(
s
*
ConnecterRESTStorage
)
Connect
(
ctx
contex
t
.
Context
,
id
string
,
options
runtime
.
Object
,
responder
rest
.
Responder
)
(
http
.
Handler
,
error
)
{
s
.
receivedConnectOptions
=
options
s
.
receivedID
=
id
s
.
receivedResponder
=
responder
...
...
@@ -633,7 +634,7 @@ type LegacyRESTStorage struct {
*
SimpleRESTStorage
}
func
(
storage
LegacyRESTStorage
)
Delete
(
ctx
reques
t
.
Context
,
id
string
)
(
runtime
.
Object
,
error
)
{
func
(
storage
LegacyRESTStorage
)
Delete
(
ctx
contex
t
.
Context
,
id
string
)
(
runtime
.
Object
,
error
)
{
obj
,
_
,
err
:=
storage
.
SimpleRESTStorage
.
Delete
(
ctx
,
id
,
nil
)
return
obj
,
err
}
...
...
@@ -659,7 +660,7 @@ type GetWithOptionsRESTStorage struct {
takesPath
string
}
func
(
r
*
GetWithOptionsRESTStorage
)
Get
(
ctx
reques
t
.
Context
,
name
string
,
options
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
GetWithOptionsRESTStorage
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
if
_
,
ok
:=
options
.
(
*
genericapitesting
.
SimpleGetOptions
);
!
ok
{
return
nil
,
fmt
.
Errorf
(
"Unexpected options object: %#v"
,
options
)
}
...
...
@@ -682,7 +683,7 @@ type GetWithOptionsRootRESTStorage struct {
takesPath
string
}
func
(
r
*
GetWithOptionsRootRESTStorage
)
Get
(
ctx
reques
t
.
Context
,
name
string
,
options
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
func
(
r
*
GetWithOptionsRootRESTStorage
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
if
_
,
ok
:=
options
.
(
*
genericapitesting
.
SimpleGetOptions
);
!
ok
{
return
nil
,
fmt
.
Errorf
(
"Unexpected options object: %#v"
,
options
)
}
...
...
@@ -704,7 +705,7 @@ type NamedCreaterRESTStorage struct {
createdName
string
}
func
(
storage
*
NamedCreaterRESTStorage
)
Create
(
ctx
reques
t
.
Context
,
name
string
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
storage
*
NamedCreaterRESTStorage
)
Create
(
ctx
contex
t
.
Context
,
name
string
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
storage
.
checkContext
(
ctx
)
storage
.
created
=
obj
.
(
*
genericapitesting
.
Simple
)
storage
.
createdName
=
name
...
...
@@ -734,12 +735,12 @@ func (storage *SimpleTypedStorage) New() runtime.Object {
return
storage
.
baseType
}
func
(
storage
*
SimpleTypedStorage
)
Get
(
ctx
reques
t
.
Context
,
id
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
storage
*
SimpleTypedStorage
)
Get
(
ctx
contex
t
.
Context
,
id
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
storage
.
checkContext
(
ctx
)
return
storage
.
item
.
DeepCopyObject
(),
storage
.
errors
[
"get"
]
}
func
(
storage
*
SimpleTypedStorage
)
checkContext
(
ctx
reques
t
.
Context
)
{
func
(
storage
*
SimpleTypedStorage
)
checkContext
(
ctx
contex
t
.
Context
)
{
storage
.
actualNamespace
,
storage
.
namespacePresent
=
request
.
NamespaceFrom
(
ctx
)
}
...
...
@@ -3831,7 +3832,7 @@ func (storage *SimpleXGSubresourceRESTStorage) New() runtime.Object {
return
&
genericapitesting
.
SimpleXGSubresource
{}
}
func
(
storage
*
SimpleXGSubresourceRESTStorage
)
Get
(
ctx
reques
t
.
Context
,
id
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
storage
*
SimpleXGSubresourceRESTStorage
)
Get
(
ctx
contex
t
.
Context
,
id
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
storage
.
item
.
DeepCopyObject
(),
nil
}
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/filters/authorization.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
filters
import
(
"context"
"errors"
"net/http"
...
...
@@ -76,7 +77,7 @@ func WithAuthorization(handler http.Handler, a authorizer.Authorizer, s runtime.
})
}
func
GetAuthorizerAttributes
(
ctx
reques
t
.
Context
)
(
authorizer
.
Attributes
,
error
)
{
func
GetAuthorizerAttributes
(
ctx
contex
t
.
Context
)
(
authorizer
.
Attributes
,
error
)
{
attribs
:=
authorizer
.
AttributesRecord
{}
user
,
ok
:=
request
.
UserFrom
(
ctx
)
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/filters/impersonation_test.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
filters
import
(
"context"
"fmt"
"net/http"
"net/http/httptest"
...
...
@@ -308,7 +309,7 @@ func TestImpersonationFilter(t *testing.T) {
},
}
var
ctx
reques
t
.
Context
var
ctx
contex
t
.
Context
var
actualUser
user
.
Info
var
lock
sync
.
Mutex
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/create.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
handlers
import
(
"context"
"fmt"
"net/http"
"time"
...
...
@@ -163,6 +164,6 @@ type namedCreaterAdapter struct {
rest
.
Creater
}
func
(
c
*
namedCreaterAdapter
)
Create
(
ctx
reques
t
.
Context
,
name
string
,
obj
runtime
.
Object
,
createValidatingAdmission
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
c
*
namedCreaterAdapter
)
Create
(
ctx
contex
t
.
Context
,
name
string
,
obj
runtime
.
Object
,
createValidatingAdmission
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
return
c
.
Creater
.
Create
(
ctx
,
obj
,
createValidatingAdmission
,
includeUninitialized
)
}
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/get.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
handlers
import
(
"context"
"fmt"
"math/rand"
"net/http"
...
...
@@ -40,7 +41,7 @@ import (
// getterFunc performs a get request with the given context and object name. The request
// may be used to deserialize an options object to pass to the getter.
type
getterFunc
func
(
ctx
reques
t
.
Context
,
name
string
,
req
*
http
.
Request
,
trace
*
utiltrace
.
Trace
)
(
runtime
.
Object
,
error
)
type
getterFunc
func
(
ctx
contex
t
.
Context
,
name
string
,
req
*
http
.
Request
,
trace
*
utiltrace
.
Trace
)
(
runtime
.
Object
,
error
)
// getResourceHandler is an HTTP handler function for get requests. It delegates to the
// passed-in getterFunc to perform the actual get.
...
...
@@ -80,7 +81,7 @@ func getResourceHandler(scope RequestScope, getter getterFunc) http.HandlerFunc
// GetResource returns a function that handles retrieving a single resource from a rest.Storage object.
func
GetResource
(
r
rest
.
Getter
,
e
rest
.
Exporter
,
scope
RequestScope
)
http
.
HandlerFunc
{
return
getResourceHandler
(
scope
,
func
(
ctx
reques
t
.
Context
,
name
string
,
req
*
http
.
Request
,
trace
*
utiltrace
.
Trace
)
(
runtime
.
Object
,
error
)
{
func
(
ctx
contex
t
.
Context
,
name
string
,
req
*
http
.
Request
,
trace
*
utiltrace
.
Trace
)
(
runtime
.
Object
,
error
)
{
// check for export
options
:=
metav1
.
GetOptions
{}
if
values
:=
req
.
URL
.
Query
();
len
(
values
)
>
0
{
...
...
@@ -110,7 +111,7 @@ func GetResource(r rest.Getter, e rest.Exporter, scope RequestScope) http.Handle
// GetResourceWithOptions returns a function that handles retrieving a single resource from a rest.Storage object.
func
GetResourceWithOptions
(
r
rest
.
GetterWithOptions
,
scope
RequestScope
,
isSubresource
bool
)
http
.
HandlerFunc
{
return
getResourceHandler
(
scope
,
func
(
ctx
reques
t
.
Context
,
name
string
,
req
*
http
.
Request
,
trace
*
utiltrace
.
Trace
)
(
runtime
.
Object
,
error
)
{
func
(
ctx
contex
t
.
Context
,
name
string
,
req
*
http
.
Request
,
trace
*
utiltrace
.
Trace
)
(
runtime
.
Object
,
error
)
{
opts
,
subpath
,
subpathKey
:=
r
.
NewGetOptions
()
trace
.
Step
(
"About to process Get options"
)
if
err
:=
getRequestOptions
(
req
,
scope
,
opts
,
subpath
,
subpathKey
,
isSubresource
);
err
!=
nil
{
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/patch.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
handlers
import
(
"context"
"fmt"
"net/http"
"strings"
...
...
@@ -151,7 +152,7 @@ type mutateObjectUpdateFunc func(obj, old runtime.Object) error
// patchResource divides PatchResource for easier unit testing
func
patchResource
(
ctx
reques
t
.
Context
,
ctx
contex
t
.
Context
,
updateMutation
mutateObjectUpdateFunc
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
,
...
...
@@ -184,7 +185,7 @@ func patchResource(
// applyPatch is called every time GuaranteedUpdate asks for the updated object,
// and is given the currently persisted object as input.
applyPatch
:=
func
(
_
reques
t
.
Context
,
_
,
currentObject
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
applyPatch
:=
func
(
_
contex
t
.
Context
,
_
,
currentObject
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
// Make sure we actually have a persisted currentObject
trace
.
Step
(
"About to apply patch"
)
if
hasUID
,
err
:=
hasUID
(
currentObject
);
err
!=
nil
{
...
...
@@ -373,7 +374,7 @@ func patchResource(
// applyAdmission is called every time GuaranteedUpdate asks for the updated object,
// and is given the currently persisted object and the patched object as input.
applyAdmission
:=
func
(
ctx
reques
t
.
Context
,
patchedObject
runtime
.
Object
,
currentObject
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
applyAdmission
:=
func
(
ctx
contex
t
.
Context
,
patchedObject
runtime
.
Object
,
currentObject
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
trace
.
Step
(
"About to check admission control"
)
return
patchedObject
,
updateMutation
(
patchedObject
,
currentObject
)
}
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/response.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
handlers
import
(
"context"
"fmt"
"net/http"
...
...
@@ -28,12 +29,11 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/endpoints/handlers/negotiation"
"k8s.io/apiserver/pkg/endpoints/handlers/responsewriters"
"k8s.io/apiserver/pkg/endpoints/request"
)
// transformResponseObject takes an object loaded from storage and performs any necessary transformations.
// Will write the complete response object.
func
transformResponseObject
(
ctx
reques
t
.
Context
,
scope
RequestScope
,
req
*
http
.
Request
,
w
http
.
ResponseWriter
,
statusCode
int
,
result
runtime
.
Object
)
{
func
transformResponseObject
(
ctx
contex
t
.
Context
,
scope
RequestScope
,
req
*
http
.
Request
,
w
http
.
ResponseWriter
,
statusCode
int
,
result
runtime
.
Object
)
{
// TODO: fetch the media type much earlier in request processing and pass it into this method.
mediaType
,
_
,
err
:=
negotiation
.
NegotiateOutputMediaType
(
req
,
scope
.
Serializer
,
&
scope
)
if
err
!=
nil
{
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/errors.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
responsewriters
import
(
"context"
"fmt"
"net/http"
"strings"
...
...
@@ -26,7 +27,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
utilruntime
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apiserver/pkg/authorization/authorizer"
"k8s.io/apiserver/pkg/endpoints/request"
)
// Avoid emitting errors that look like valid HTML. Quotes are okay.
...
...
@@ -41,7 +41,7 @@ func BadGatewayError(w http.ResponseWriter, req *http.Request) {
}
// Forbidden renders a simple forbidden error
func
Forbidden
(
ctx
reques
t
.
Context
,
attributes
authorizer
.
Attributes
,
w
http
.
ResponseWriter
,
req
*
http
.
Request
,
reason
string
,
s
runtime
.
NegotiatedSerializer
)
{
func
Forbidden
(
ctx
contex
t
.
Context
,
attributes
authorizer
.
Attributes
,
w
http
.
ResponseWriter
,
req
*
http
.
Request
,
reason
string
,
s
runtime
.
NegotiatedSerializer
)
{
msg
:=
sanitizer
.
Replace
(
forbiddenMessage
(
attributes
))
w
.
Header
()
.
Set
(
"X-Content-Type-Options"
,
"nosniff"
)
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/rest.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
handlers
import
(
"context"
"encoding/hex"
"fmt"
"io/ioutil"
...
...
@@ -263,7 +264,7 @@ func checkName(obj runtime.Object, name, namespace string, namer ScopeNamer) err
// setListSelfLink sets the self link of a list to the base URL, then sets the self links
// on all child objects returned. Returns the number of items in the list.
func
setListSelfLink
(
obj
runtime
.
Object
,
ctx
reques
t
.
Context
,
req
*
http
.
Request
,
namer
ScopeNamer
)
(
int
,
error
)
{
func
setListSelfLink
(
obj
runtime
.
Object
,
ctx
contex
t
.
Context
,
req
*
http
.
Request
,
namer
ScopeNamer
)
(
int
,
error
)
{
if
!
meta
.
IsListType
(
obj
)
{
return
0
,
nil
}
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/rest_test.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
handlers
import
(
"context"
"errors"
"fmt"
"net/http"
...
...
@@ -171,7 +172,7 @@ func (p *testPatcher) New() runtime.Object {
return
&
example
.
Pod
{}
}
func
(
p
*
testPatcher
)
Update
(
ctx
reques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
p
*
testPatcher
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
currentPod
:=
p
.
startingPod
if
p
.
numUpdates
>
0
{
currentPod
=
p
.
updatePod
...
...
@@ -200,7 +201,7 @@ func (p *testPatcher) Update(ctx request.Context, name string, objInfo rest.Upda
return
inPod
,
false
,
nil
}
func
(
p
*
testPatcher
)
Get
(
ctx
reques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
p
*
testPatcher
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
p
.
t
.
Fatal
(
"Unexpected call to testPatcher.Get"
)
return
nil
,
errors
.
New
(
"Unexpected call to testPatcher.Get"
)
}
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/update.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
handlers
import
(
"context"
"fmt"
"net/http"
"time"
...
...
@@ -90,7 +91,7 @@ func UpdateResource(r rest.Updater, scope RequestScope, typer runtime.ObjectType
staticAdmissionAttributes
:=
admission
.
NewAttributesRecord
(
nil
,
nil
,
scope
.
Kind
,
namespace
,
name
,
scope
.
Resource
,
scope
.
Subresource
,
admission
.
Update
,
userInfo
)
var
transformers
[]
rest
.
TransformFunc
if
mutatingAdmission
,
ok
:=
admit
.
(
admission
.
MutationInterface
);
ok
&&
mutatingAdmission
.
Handles
(
admission
.
Update
)
{
transformers
=
append
(
transformers
,
func
(
ctx
reques
t
.
Context
,
newObj
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
transformers
=
append
(
transformers
,
func
(
ctx
contex
t
.
Context
,
newObj
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
newObj
,
mutatingAdmission
.
Admit
(
admission
.
NewAttributesRecord
(
newObj
,
oldObj
,
scope
.
Kind
,
namespace
,
name
,
scope
.
Resource
,
scope
.
Subresource
,
admission
.
Update
,
userInfo
))
})
}
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/request/context.go
View file @
54fd2aae
...
...
@@ -18,8 +18,6 @@ package request
import
(
"context"
"errors"
"time"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
...
...
@@ -27,28 +25,6 @@ import (
"k8s.io/apiserver/pkg/authentication/user"
)
// Context carries values across API boundaries.
// This context matches the context.Context interface
// (https://blog.golang.org/context), for the purposes
// of passing the api.Context through to the storage tier.
// TODO: Determine the extent that this abstraction+interface
// is used by the api, and whether we can remove.
type
Context
interface
{
// Value returns the value associated with key or nil if none.
Value
(
key
interface
{})
interface
{}
// Deadline returns the time when this Context will be canceled, if any.
Deadline
()
(
deadline
time
.
Time
,
ok
bool
)
// Done returns a channel that is closed when this Context is canceled
// or times out.
Done
()
<-
chan
struct
{}
// Err indicates why this context was canceled, after the Done channel
// is closed.
Err
()
error
}
// The key type is unexported to prevent collisions
type
key
int
...
...
@@ -70,43 +46,39 @@ const (
)
// NewContext instantiates a base context object for request flows.
func
NewContext
()
Context
{
func
NewContext
()
context
.
Context
{
return
context
.
TODO
()
}
// NewDefaultContext instantiates a base context object for request flows in the default namespace
func
NewDefaultContext
()
Context
{
func
NewDefaultContext
()
context
.
Context
{
return
WithNamespace
(
NewContext
(),
metav1
.
NamespaceDefault
)
}
// WithValue returns a copy of parent in which the value associated with key is val.
func
WithValue
(
parent
Context
,
key
interface
{},
val
interface
{})
Context
{
internalCtx
,
ok
:=
parent
.
(
context
.
Context
)
if
!
ok
{
panic
(
errors
.
New
(
"Invalid context type"
))
}
return
context
.
WithValue
(
internalCtx
,
key
,
val
)
func
WithValue
(
parent
context
.
Context
,
key
interface
{},
val
interface
{})
context
.
Context
{
return
context
.
WithValue
(
parent
,
key
,
val
)
}
// WithNamespace returns a copy of parent in which the namespace value is set
func
WithNamespace
(
parent
Context
,
namespace
string
)
Context
{
func
WithNamespace
(
parent
context
.
Context
,
namespace
string
)
context
.
Context
{
return
WithValue
(
parent
,
namespaceKey
,
namespace
)
}
// NamespaceFrom returns the value of the namespace key on the ctx
func
NamespaceFrom
(
ctx
Context
)
(
string
,
bool
)
{
func
NamespaceFrom
(
ctx
context
.
Context
)
(
string
,
bool
)
{
namespace
,
ok
:=
ctx
.
Value
(
namespaceKey
)
.
(
string
)
return
namespace
,
ok
}
// NamespaceValue returns the value of the namespace key on the ctx, or the empty string if none
func
NamespaceValue
(
ctx
Context
)
string
{
func
NamespaceValue
(
ctx
context
.
Context
)
string
{
namespace
,
_
:=
NamespaceFrom
(
ctx
)
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
{
func
WithNamespaceDefaultIfNone
(
parent
context
.
Context
)
context
.
Context
{
namespace
,
ok
:=
NamespaceFrom
(
parent
)
if
!
ok
||
len
(
namespace
)
==
0
{
return
WithNamespace
(
parent
,
metav1
.
NamespaceDefault
)
...
...
@@ -115,34 +87,34 @@ func WithNamespaceDefaultIfNone(parent Context) Context {
}
// WithUser returns a copy of parent in which the user value is set
func
WithUser
(
parent
Context
,
user
user
.
Info
)
Context
{
func
WithUser
(
parent
context
.
Context
,
user
user
.
Info
)
context
.
Context
{
return
WithValue
(
parent
,
userKey
,
user
)
}
// UserFrom returns the value of the user key on the ctx
func
UserFrom
(
ctx
Context
)
(
user
.
Info
,
bool
)
{
func
UserFrom
(
ctx
context
.
Context
)
(
user
.
Info
,
bool
)
{
user
,
ok
:=
ctx
.
Value
(
userKey
)
.
(
user
.
Info
)
return
user
,
ok
}
// WithUID returns a copy of parent in which the uid value is set
func
WithUID
(
parent
Context
,
uid
types
.
UID
)
Context
{
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
)
(
types
.
UID
,
bool
)
{
func
UIDFrom
(
ctx
context
.
Context
)
(
types
.
UID
,
bool
)
{
uid
,
ok
:=
ctx
.
Value
(
uidKey
)
.
(
types
.
UID
)
return
uid
,
ok
}
// WithAuditEvent returns set audit event struct.
func
WithAuditEvent
(
parent
Context
,
ev
*
audit
.
Event
)
Context
{
func
WithAuditEvent
(
parent
context
.
Context
,
ev
*
audit
.
Event
)
context
.
Context
{
return
WithValue
(
parent
,
auditKey
,
ev
)
}
// AuditEventFrom returns the audit event struct on the ctx
func
AuditEventFrom
(
ctx
Context
)
*
audit
.
Event
{
func
AuditEventFrom
(
ctx
context
.
Context
)
*
audit
.
Event
{
ev
,
_
:=
ctx
.
Value
(
auditKey
)
.
(
*
audit
.
Event
)
return
ev
}
staging/src/k8s.io/apiserver/pkg/endpoints/request/requestinfo.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
request
import
(
"context"
"fmt"
"net/http"
"strings"
...
...
@@ -232,12 +233,12 @@ type requestInfoKeyType int
const
requestInfoKey
requestInfoKeyType
=
iota
// WithRequestInfo returns a copy of parent in which the request info value is set
func
WithRequestInfo
(
parent
Context
,
info
*
RequestInfo
)
Context
{
func
WithRequestInfo
(
parent
context
.
Context
,
info
*
RequestInfo
)
context
.
Context
{
return
WithValue
(
parent
,
requestInfoKey
,
info
)
}
// RequestInfoFrom returns the value of the RequestInfo key on the ctx
func
RequestInfoFrom
(
ctx
Context
)
(
*
RequestInfo
,
bool
)
{
func
RequestInfoFrom
(
ctx
context
.
Context
)
(
*
RequestInfo
,
bool
)
{
info
,
ok
:=
ctx
.
Value
(
requestInfoKey
)
.
(
*
RequestInfo
)
return
info
,
ok
}
...
...
staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
registry
import
(
"context"
"fmt"
"reflect"
"strings"
...
...
@@ -99,14 +100,14 @@ type Store struct {
// entire collection (listing and watching).
//
// KeyRootFunc and KeyFunc must be supplied together or not at all.
KeyRootFunc
func
(
ctx
genericapireques
t
.
Context
)
string
KeyRootFunc
func
(
ctx
contex
t
.
Context
)
string
// KeyFunc returns the key for a specific object in the collection.
// KeyFunc is called for Create/Update/Get/Delete. Note that 'namespace'
// can be gotten from ctx.
//
// KeyFunc and KeyRootFunc must be supplied together or not at all.
KeyFunc
func
(
ctx
genericapireques
t
.
Context
,
name
string
)
(
string
,
error
)
KeyFunc
func
(
ctx
contex
t
.
Context
,
name
string
)
(
string
,
error
)
// ObjectNameFunc returns the name of an object or an error.
ObjectNameFunc
func
(
obj
runtime
.
Object
)
(
string
,
error
)
...
...
@@ -190,7 +191,7 @@ const (
// NamespaceKeyRootFunc is the default function for constructing storage paths
// to resource directories enforcing namespace rules.
func
NamespaceKeyRootFunc
(
ctx
genericapireques
t
.
Context
,
prefix
string
)
string
{
func
NamespaceKeyRootFunc
(
ctx
contex
t
.
Context
,
prefix
string
)
string
{
key
:=
prefix
ns
,
ok
:=
genericapirequest
.
NamespaceFrom
(
ctx
)
if
ok
&&
len
(
ns
)
>
0
{
...
...
@@ -202,7 +203,7 @@ func NamespaceKeyRootFunc(ctx genericapirequest.Context, prefix string) string {
// NamespaceKeyFunc is the default function for constructing storage paths to
// a resource relative to the given prefix enforcing namespace rules. If the
// context does not contain a namespace, it errors.
func
NamespaceKeyFunc
(
ctx
genericapireques
t
.
Context
,
prefix
string
,
name
string
)
(
string
,
error
)
{
func
NamespaceKeyFunc
(
ctx
contex
t
.
Context
,
prefix
string
,
name
string
)
(
string
,
error
)
{
key
:=
NamespaceKeyRootFunc
(
ctx
,
prefix
)
ns
,
ok
:=
genericapirequest
.
NamespaceFrom
(
ctx
)
if
!
ok
||
len
(
ns
)
==
0
{
...
...
@@ -220,7 +221,7 @@ func NamespaceKeyFunc(ctx genericapirequest.Context, prefix string, name string)
// NoNamespaceKeyFunc is the default function for constructing storage paths
// to a resource relative to the given prefix without a namespace.
func
NoNamespaceKeyFunc
(
ctx
genericapireques
t
.
Context
,
prefix
string
,
name
string
)
(
string
,
error
)
{
func
NoNamespaceKeyFunc
(
ctx
contex
t
.
Context
,
prefix
string
,
name
string
)
(
string
,
error
)
{
if
len
(
name
)
==
0
{
return
""
,
kubeerr
.
NewBadRequest
(
"Name parameter required."
)
}
...
...
@@ -263,7 +264,7 @@ func (e *Store) GetExportStrategy() rest.RESTExportStrategy {
// List returns a list of items matching labels and field according to the
// store's PredicateFunc.
func
(
e
*
Store
)
List
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
func
(
e
*
Store
)
List
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
label
:=
labels
.
Everything
()
if
options
!=
nil
&&
options
.
LabelSelector
!=
nil
{
label
=
options
.
LabelSelector
...
...
@@ -286,7 +287,7 @@ func (e *Store) List(ctx genericapirequest.Context, options *metainternalversion
// ListPredicate returns a list of all the items matching the given
// SelectionPredicate.
func
(
e
*
Store
)
ListPredicate
(
ctx
genericapireques
t
.
Context
,
p
storage
.
SelectionPredicate
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
func
(
e
*
Store
)
ListPredicate
(
ctx
contex
t
.
Context
,
p
storage
.
SelectionPredicate
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
if
options
==
nil
{
// By default we should serve the request from etcd.
options
=
&
metainternalversion
.
ListOptions
{
ResourceVersion
:
""
}
...
...
@@ -309,7 +310,7 @@ func (e *Store) ListPredicate(ctx genericapirequest.Context, p storage.Selection
}
// Create inserts a new item according to the unique key from the object.
func
(
e
*
Store
)
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
func
(
e
*
Store
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
rest
.
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
{
if
err
:=
rest
.
BeforeCreate
(
e
.
CreateStrategy
,
ctx
,
obj
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -372,7 +373,7 @@ func (e *Store) Create(ctx genericapirequest.Context, obj runtime.Object, create
// WaitForInitialized holds until the object is initialized, or returns an error if the default limit expires.
// This method is exposed publicly for consumers of generic rest tooling.
func
(
e
*
Store
)
WaitForInitialized
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
func
(
e
*
Store
)
WaitForInitialized
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
// return early if we don't have initializers, or if they've completed already
accessor
,
err
:=
meta
.
Accessor
(
obj
)
if
err
!=
nil
{
...
...
@@ -453,7 +454,7 @@ func (e *Store) WaitForInitialized(ctx genericapirequest.Context, obj runtime.Ob
// shouldDeleteDuringUpdate checks if a Update is removing all the object's
// finalizers. If so, it further checks if the object's
// DeletionGracePeriodSeconds is 0.
func
(
e
*
Store
)
shouldDeleteDuringUpdate
(
ctx
genericapireques
t
.
Context
,
key
string
,
obj
,
existing
runtime
.
Object
)
bool
{
func
(
e
*
Store
)
shouldDeleteDuringUpdate
(
ctx
contex
t
.
Context
,
key
string
,
obj
,
existing
runtime
.
Object
)
bool
{
newMeta
,
err
:=
meta
.
Accessor
(
obj
)
if
err
!=
nil
{
utilruntime
.
HandleError
(
err
)
...
...
@@ -469,7 +470,7 @@ func (e *Store) shouldDeleteDuringUpdate(ctx genericapirequest.Context, key stri
// shouldDeleteForFailedInitialization returns true if the provided object is initializing and has
// a failure recorded.
func
(
e
*
Store
)
shouldDeleteForFailedInitialization
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
bool
{
func
(
e
*
Store
)
shouldDeleteForFailedInitialization
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
bool
{
m
,
err
:=
meta
.
Accessor
(
obj
)
if
err
!=
nil
{
utilruntime
.
HandleError
(
err
)
...
...
@@ -483,7 +484,7 @@ func (e *Store) shouldDeleteForFailedInitialization(ctx genericapirequest.Contex
// deleteWithoutFinalizers handles deleting an object ignoring its finalizer list.
// Used for objects that are either been finalized or have never initialized.
func
(
e
*
Store
)
deleteWithoutFinalizers
(
ctx
genericapireques
t
.
Context
,
name
,
key
string
,
obj
runtime
.
Object
,
preconditions
*
storage
.
Preconditions
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
e
*
Store
)
deleteWithoutFinalizers
(
ctx
contex
t
.
Context
,
name
,
key
string
,
obj
runtime
.
Object
,
preconditions
*
storage
.
Preconditions
)
(
runtime
.
Object
,
bool
,
error
)
{
out
:=
e
.
NewFunc
()
glog
.
V
(
6
)
.
Infof
(
"going to delete %s from registry, triggered by update"
,
name
)
if
err
:=
e
.
Storage
.
Delete
(
ctx
,
key
,
out
,
preconditions
);
err
!=
nil
{
...
...
@@ -509,7 +510,7 @@ func (e *Store) deleteWithoutFinalizers(ctx genericapirequest.Context, name, key
// Update performs an atomic update and set of the object. Returns the result of the update
// or an error. If the registry allows create-on-update, the create flow will be executed.
// A bool is returned along with the object and any errors, to indicate object creation.
func
(
e
*
Store
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
e
*
Store
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
key
,
err
:=
e
.
KeyFunc
(
ctx
,
name
)
if
err
!=
nil
{
return
nil
,
false
,
err
...
...
@@ -666,7 +667,7 @@ func (e *Store) Update(ctx genericapirequest.Context, name string, objInfo rest.
}
// Get retrieves the item from storage.
func
(
e
*
Store
)
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
e
*
Store
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
obj
:=
e
.
NewFunc
()
key
,
err
:=
e
.
KeyFunc
(
ctx
,
name
)
if
err
!=
nil
{
...
...
@@ -685,7 +686,7 @@ func (e *Store) Get(ctx genericapirequest.Context, name string, options *metav1.
// qualifiedResourceFromContext attempts to retrieve a GroupResource from the context's request info.
// If the context has no request info, DefaultQualifiedResource is used.
func
(
e
*
Store
)
qualifiedResourceFromContext
(
ctx
genericapireques
t
.
Context
)
schema
.
GroupResource
{
func
(
e
*
Store
)
qualifiedResourceFromContext
(
ctx
contex
t
.
Context
)
schema
.
GroupResource
{
if
info
,
ok
:=
genericapirequest
.
RequestInfoFrom
(
ctx
);
ok
{
return
schema
.
GroupResource
{
Group
:
info
.
APIGroup
,
Resource
:
info
.
Resource
}
}
...
...
@@ -704,7 +705,7 @@ var (
// priority, there are three factors affect whether to add/remove the
// FinalizerOrphanDependents: options, existing finalizers of the object,
// and e.DeleteStrategy.DefaultGarbageCollectionPolicy.
func
shouldOrphanDependents
(
ctx
genericapireques
t
.
Context
,
e
*
Store
,
accessor
metav1
.
Object
,
options
*
metav1
.
DeleteOptions
)
bool
{
func
shouldOrphanDependents
(
ctx
contex
t
.
Context
,
e
*
Store
,
accessor
metav1
.
Object
,
options
*
metav1
.
DeleteOptions
)
bool
{
// Get default GC policy from this REST object type
gcStrategy
,
ok
:=
e
.
DeleteStrategy
.
(
rest
.
GarbageCollectionDeleteStrategy
)
var
defaultGCPolicy
rest
.
GarbageCollectionPolicy
...
...
@@ -754,7 +755,7 @@ func shouldOrphanDependents(ctx genericapirequest.Context, e *Store, accessor me
// priority, there are three factors affect whether to add/remove the
// FinalizerDeleteDependents: options, existing finalizers of the object, and
// e.DeleteStrategy.DefaultGarbageCollectionPolicy.
func
shouldDeleteDependents
(
ctx
genericapireques
t
.
Context
,
e
*
Store
,
accessor
metav1
.
Object
,
options
*
metav1
.
DeleteOptions
)
bool
{
func
shouldDeleteDependents
(
ctx
contex
t
.
Context
,
e
*
Store
,
accessor
metav1
.
Object
,
options
*
metav1
.
DeleteOptions
)
bool
{
// Get default GC policy from this REST object type
if
gcStrategy
,
ok
:=
e
.
DeleteStrategy
.
(
rest
.
GarbageCollectionDeleteStrategy
);
ok
&&
gcStrategy
.
DefaultGarbageCollectionPolicy
(
ctx
)
==
rest
.
Unsupported
{
// return false to indicate that we should NOT delete in foreground
...
...
@@ -797,7 +798,7 @@ func shouldDeleteDependents(ctx genericapirequest.Context, e *Store, accessor me
// The finalizers returned are intended to be handled by the garbage collector.
// If garbage collection is disabled for the store, this function returns false
// to ensure finalizers aren't set which will never be cleared.
func
deletionFinalizersForGarbageCollection
(
ctx
genericapireques
t
.
Context
,
e
*
Store
,
accessor
metav1
.
Object
,
options
*
metav1
.
DeleteOptions
)
(
bool
,
[]
string
)
{
func
deletionFinalizersForGarbageCollection
(
ctx
contex
t
.
Context
,
e
*
Store
,
accessor
metav1
.
Object
,
options
*
metav1
.
DeleteOptions
)
(
bool
,
[]
string
)
{
if
!
e
.
EnableGarbageCollection
{
return
false
,
[]
string
{}
}
...
...
@@ -861,7 +862,7 @@ func markAsDeleting(obj runtime.Object) (err error) {
// should be deleted immediately
// 4. a new output object with the state that was updated
// 5. a copy of the last existing state of the object
func
(
e
*
Store
)
updateForGracefulDeletionAndFinalizers
(
ctx
genericapireques
t
.
Context
,
name
,
key
string
,
options
*
metav1
.
DeleteOptions
,
preconditions
storage
.
Preconditions
,
in
runtime
.
Object
)
(
err
error
,
ignoreNotFound
,
deleteImmediately
bool
,
out
,
lastExisting
runtime
.
Object
)
{
func
(
e
*
Store
)
updateForGracefulDeletionAndFinalizers
(
ctx
contex
t
.
Context
,
name
,
key
string
,
options
*
metav1
.
DeleteOptions
,
preconditions
storage
.
Preconditions
,
in
runtime
.
Object
)
(
err
error
,
ignoreNotFound
,
deleteImmediately
bool
,
out
,
lastExisting
runtime
.
Object
)
{
lastGraceful
:=
int64
(
0
)
var
pendingFinalizers
bool
out
=
e
.
NewFunc
()
...
...
@@ -941,7 +942,7 @@ func (e *Store) updateForGracefulDeletionAndFinalizers(ctx genericapirequest.Con
}
// Delete removes the item from storage.
func
(
e
*
Store
)
Delete
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
e
*
Store
)
Delete
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
{
key
,
err
:=
e
.
KeyFunc
(
ctx
,
name
)
if
err
!=
nil
{
return
nil
,
false
,
err
...
...
@@ -1019,7 +1020,7 @@ func (e *Store) Delete(ctx genericapirequest.Context, name string, options *meta
// are removing all objects of a given type) with the current API (it's technically
// possibly with storage API, but watch is not delivered correctly then).
// It will be possible to fix it with v3 etcd API.
func
(
e
*
Store
)
DeleteCollection
(
ctx
genericapireques
t
.
Context
,
options
*
metav1
.
DeleteOptions
,
listOptions
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
func
(
e
*
Store
)
DeleteCollection
(
ctx
contex
t
.
Context
,
options
*
metav1
.
DeleteOptions
,
listOptions
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
{
if
listOptions
==
nil
{
listOptions
=
&
metainternalversion
.
ListOptions
{}
}
else
{
...
...
@@ -1096,7 +1097,7 @@ func (e *Store) DeleteCollection(ctx genericapirequest.Context, options *metav1.
// finalizeDelete runs the Store's AfterDelete hook if runHooks is set and
// returns the decorated deleted object if appropriate.
func
(
e
*
Store
)
finalizeDelete
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
runHooks
bool
)
(
runtime
.
Object
,
error
)
{
func
(
e
*
Store
)
finalizeDelete
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
runHooks
bool
)
(
runtime
.
Object
,
error
)
{
if
runHooks
&&
e
.
AfterDelete
!=
nil
{
if
err
:=
e
.
AfterDelete
(
obj
);
err
!=
nil
{
return
nil
,
err
...
...
@@ -1131,7 +1132,7 @@ func (e *Store) finalizeDelete(ctx genericapirequest.Context, obj runtime.Object
// WatchPredicate. If possible, you should customize PredicateFunc to produce
// a matcher that matches by key. SelectionPredicate does this for you
// automatically.
func
(
e
*
Store
)
Watch
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
func
(
e
*
Store
)
Watch
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
{
label
:=
labels
.
Everything
()
if
options
!=
nil
&&
options
.
LabelSelector
!=
nil
{
label
=
options
.
LabelSelector
...
...
@@ -1151,7 +1152,7 @@ func (e *Store) Watch(ctx genericapirequest.Context, options *metainternalversio
}
// WatchPredicate starts a watch for the items that matches.
func
(
e
*
Store
)
WatchPredicate
(
ctx
genericapireques
t
.
Context
,
p
storage
.
SelectionPredicate
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
func
(
e
*
Store
)
WatchPredicate
(
ctx
contex
t
.
Context
,
p
storage
.
SelectionPredicate
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
if
name
,
ok
:=
p
.
MatchesSingle
();
ok
{
if
key
,
err
:=
e
.
KeyFunc
(
ctx
,
name
);
err
==
nil
{
w
,
err
:=
e
.
Storage
.
Watch
(
ctx
,
key
,
resourceVersion
,
p
)
...
...
@@ -1213,7 +1214,7 @@ func exportObjectMeta(accessor metav1.Object, exact bool) {
}
// Export implements the rest.Exporter interface
func
(
e
*
Store
)
Export
(
ctx
genericapireques
t
.
Context
,
name
string
,
opts
metav1
.
ExportOptions
)
(
runtime
.
Object
,
error
)
{
func
(
e
*
Store
)
Export
(
ctx
contex
t
.
Context
,
name
string
,
opts
metav1
.
ExportOptions
)
(
runtime
.
Object
,
error
)
{
obj
,
err
:=
e
.
Get
(
ctx
,
name
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -1303,17 +1304,17 @@ func (e *Store) CompleteWithOptions(options *generic.StoreOptions) error {
// Set the default behavior for storage key generation
if
e
.
KeyRootFunc
==
nil
&&
e
.
KeyFunc
==
nil
{
if
isNamespaced
{
e
.
KeyRootFunc
=
func
(
ctx
genericapireques
t
.
Context
)
string
{
e
.
KeyRootFunc
=
func
(
ctx
contex
t
.
Context
)
string
{
return
NamespaceKeyRootFunc
(
ctx
,
prefix
)
}
e
.
KeyFunc
=
func
(
ctx
genericapireques
t
.
Context
,
name
string
)
(
string
,
error
)
{
e
.
KeyFunc
=
func
(
ctx
contex
t
.
Context
,
name
string
)
(
string
,
error
)
{
return
NamespaceKeyFunc
(
ctx
,
prefix
,
name
)
}
}
else
{
e
.
KeyRootFunc
=
func
(
ctx
genericapireques
t
.
Context
)
string
{
e
.
KeyRootFunc
=
func
(
ctx
contex
t
.
Context
)
string
{
return
prefix
}
e
.
KeyFunc
=
func
(
ctx
genericapireques
t
.
Context
,
name
string
)
(
string
,
error
)
{
e
.
KeyFunc
=
func
(
ctx
contex
t
.
Context
,
name
string
)
(
string
,
error
)
{
return
NoNamespaceKeyFunc
(
ctx
,
prefix
,
name
)
}
}
...
...
@@ -1399,7 +1400,7 @@ func (e *Store) startObservingCount(period time.Duration) func() {
return
func
()
{
close
(
stopCh
)
}
}
func
(
e
*
Store
)
ConvertToTable
(
ctx
genericapireques
t
.
Context
,
object
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
func
(
e
*
Store
)
ConvertToTable
(
ctx
contex
t
.
Context
,
object
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
if
e
.
TableConvertor
!=
nil
{
return
e
.
TableConvertor
.
ConvertToTable
(
ctx
,
object
,
tableOptions
)
}
...
...
staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store_test.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
registry
import
(
"context"
"fmt"
"path"
"reflect"
...
...
@@ -72,7 +73,7 @@ type testGracefulStrategy struct {
testRESTStrategy
}
func
(
t
testGracefulStrategy
)
CheckGracefulDelete
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
options
*
metav1
.
DeleteOptions
)
bool
{
func
(
t
testGracefulStrategy
)
CheckGracefulDelete
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
options
*
metav1
.
DeleteOptions
)
bool
{
return
true
}
...
...
@@ -82,7 +83,7 @@ type testOrphanDeleteStrategy struct {
*
testRESTStrategy
}
func
(
t
*
testOrphanDeleteStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
genericapireques
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
func
(
t
*
testOrphanDeleteStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
contex
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
return
rest
.
OrphanDependents
}
...
...
@@ -98,7 +99,7 @@ func (t *testRESTStrategy) NamespaceScoped() bool { return t.namespaceS
func
(
t
*
testRESTStrategy
)
AllowCreateOnUpdate
()
bool
{
return
t
.
allowCreateOnUpdate
}
func
(
t
*
testRESTStrategy
)
AllowUnconditionalUpdate
()
bool
{
return
t
.
allowUnconditionalUpdate
}
func
(
t
*
testRESTStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
t
*
testRESTStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
metaObj
,
err
:=
meta
.
Accessor
(
obj
)
if
err
!=
nil
{
panic
(
err
.
Error
())
...
...
@@ -111,11 +112,11 @@ func (t *testRESTStrategy) PrepareForCreate(ctx genericapirequest.Context, obj r
metaObj
.
SetLabels
(
labels
)
}
func
(
t
*
testRESTStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{}
func
(
t
*
testRESTStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
t
*
testRESTStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{}
func
(
t
*
testRESTStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
return
nil
}
func
(
t
*
testRESTStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
t
*
testRESTStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
nil
}
func
(
t
*
testRESTStrategy
)
Canonicalize
(
obj
runtime
.
Object
)
{}
...
...
@@ -172,7 +173,7 @@ func TestStoreList(t *testing.T) {
in
*
example
.
PodList
m
storage
.
SelectionPredicate
out
runtime
.
Object
context
genericapireques
t
.
Context
context
contex
t
.
Context
}{
"notFound"
:
{
in
:
nil
,
...
...
@@ -579,7 +580,7 @@ func TestStoreCreateInitializedFailed(t *testing.T) {
}
}
func
updateAndVerify
(
t
*
testing
.
T
,
ctx
genericapireques
t
.
Context
,
registry
*
Store
,
pod
*
example
.
Pod
)
bool
{
func
updateAndVerify
(
t
*
testing
.
T
,
ctx
contex
t
.
Context
,
registry
*
Store
,
pod
*
example
.
Pod
)
bool
{
obj
,
_
,
err
:=
registry
.
Update
(
ctx
,
pod
.
Name
,
rest
.
DefaultUpdatedObjectInfo
(
pod
),
rest
.
ValidateAllObjectFunc
,
rest
.
ValidateAllObjectUpdateFunc
)
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
...
...
@@ -733,7 +734,7 @@ func TestNoOpUpdates(t *testing.T) {
type
testPodExport
struct
{}
func
(
t
testPodExport
)
Export
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
{
func
(
t
testPodExport
)
Export
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
{
pod
:=
obj
.
(
*
example
.
Pod
)
if
pod
.
Labels
==
nil
{
pod
.
Labels
=
map
[
string
]
string
{}
...
...
@@ -1774,7 +1775,7 @@ func TestStoreWatch(t *testing.T) {
table
:=
map
[
string
]
struct
{
selectPred
storage
.
SelectionPredicate
context
genericapireques
t
.
Context
context
contex
t
.
Context
}{
"single"
:
{
selectPred
:
matchPodName
(
"foo"
),
...
...
@@ -1865,10 +1866,10 @@ func newTestGenericStoreRegistry(t *testing.T, scheme *runtime.Scheme, hasCacheE
CreateStrategy
:
strategy
,
UpdateStrategy
:
strategy
,
DeleteStrategy
:
strategy
,
KeyRootFunc
:
func
(
ctx
genericapireques
t
.
Context
)
string
{
KeyRootFunc
:
func
(
ctx
contex
t
.
Context
)
string
{
return
podPrefix
},
KeyFunc
:
func
(
ctx
genericapireques
t
.
Context
,
id
string
)
(
string
,
error
)
{
KeyFunc
:
func
(
ctx
contex
t
.
Context
,
id
string
)
(
string
,
error
)
{
if
_
,
ok
:=
genericapirequest
.
NamespaceFrom
(
ctx
);
!
ok
{
return
""
,
fmt
.
Errorf
(
"namespace is required"
)
}
...
...
@@ -2011,7 +2012,7 @@ type fakeStrategy struct {
names
.
NameGenerator
}
func
(
fakeStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
genericapireques
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
func
(
fakeStrategy
)
DefaultGarbageCollectionPolicy
(
ctx
contex
t
.
Context
)
rest
.
GarbageCollectionPolicy
{
appsv1beta1
:=
schema
.
GroupVersion
{
Group
:
"apps"
,
Version
:
"v1beta1"
}
appsv1beta2
:=
schema
.
GroupVersion
{
Group
:
"apps"
,
Version
:
"v1beta2"
}
extensionsv1beta1
:=
schema
.
GroupVersion
{
Group
:
"extensions"
,
Version
:
"v1beta1"
}
...
...
staging/src/k8s.io/apiserver/pkg/registry/generic/testing/BUILD
View file @
54fd2aae
...
...
@@ -12,7 +12,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/fields:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest/resttest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/etcd:go_default_library",
...
...
staging/src/k8s.io/apiserver/pkg/registry/generic/testing/tester.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
tester
import
(
"context"
"fmt"
"testing"
...
...
@@ -26,7 +27,6 @@ import (
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest/resttest"
etcdstorage
"k8s.io/apiserver/pkg/storage/etcd"
...
...
@@ -142,7 +142,7 @@ func (t *Tester) TestWatch(valid runtime.Object, labelsPass, labelsFail []labels
// Helper functions
func
(
t
*
Tester
)
getObject
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
func
(
t
*
Tester
)
getObject
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
accessor
,
err
:=
meta
.
Accessor
(
obj
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -155,7 +155,7 @@ func (t *Tester) getObject(ctx genericapirequest.Context, obj runtime.Object) (r
return
result
,
nil
}
func
(
t
*
Tester
)
createObject
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
error
{
func
(
t
*
Tester
)
createObject
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
error
{
accessor
,
err
:=
meta
.
Accessor
(
obj
)
if
err
!=
nil
{
return
err
...
...
staging/src/k8s.io/apiserver/pkg/registry/rest/create.go
View file @
54fd2aae
...
...
@@ -17,6 +17,8 @@ limitations under the License.
package
rest
import
(
"context"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
genericvalidation
"k8s.io/apimachinery/pkg/api/validation"
...
...
@@ -26,7 +28,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apiserver/pkg/admission"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/features"
"k8s.io/apiserver/pkg/storage/names"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
...
...
@@ -52,12 +53,12 @@ type RESTCreateStrategy interface {
// status. Clear the status because status changes are internal. External
// callers of an api (users) should not be setting an initial status on
// newly created objects.
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
// Validate returns an ErrorList with validation errors or nil. Validate
// is invoked after default fields in the object have been filled in
// before the object is persisted. This method should not mutate the
// object.
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
// Canonicalize allows an object to be mutated into a canonical form. This
// ensures that code that operates on these objects can rely on the common
// form for things like comparison. Canonicalize is invoked after
...
...
@@ -70,7 +71,7 @@ type RESTCreateStrategy interface {
// BeforeCreate ensures that common operations for all resources are performed on creation. It only returns
// errors that can be converted to api.Status. It invokes PrepareForCreate, then GenerateName, then Validate.
// It returns nil if the object should be created.
func
BeforeCreate
(
strategy
RESTCreateStrategy
,
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
error
{
func
BeforeCreate
(
strategy
RESTCreateStrategy
,
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
error
{
objectMeta
,
kind
,
kerr
:=
objectMetaAndKind
(
strategy
,
obj
)
if
kerr
!=
nil
{
return
kerr
...
...
staging/src/k8s.io/apiserver/pkg/registry/rest/delete.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
rest
import
(
"context"
"fmt"
"time"
...
...
@@ -25,7 +26,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/validation"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
)
// RESTDeleteStrategy defines deletion behavior on an object that follows Kubernetes
...
...
@@ -48,7 +48,7 @@ const (
// orphan dependents by default.
type
GarbageCollectionDeleteStrategy
interface
{
// DefaultGarbageCollectionPolicy returns the default garbage collection behavior.
DefaultGarbageCollectionPolicy
(
ctx
genericapireques
t
.
Context
)
GarbageCollectionPolicy
DefaultGarbageCollectionPolicy
(
ctx
contex
t
.
Context
)
GarbageCollectionPolicy
}
// RESTGracefulDeleteStrategy must be implemented by the registry that supports
...
...
@@ -56,7 +56,7 @@ type GarbageCollectionDeleteStrategy interface {
type
RESTGracefulDeleteStrategy
interface
{
// CheckGracefulDelete should return true if the object can be gracefully deleted and set
// any default values on the DeleteOptions.
CheckGracefulDelete
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
options
*
metav1
.
DeleteOptions
)
bool
CheckGracefulDelete
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
options
*
metav1
.
DeleteOptions
)
bool
}
// BeforeDelete tests whether the object can be gracefully deleted.
...
...
@@ -68,7 +68,7 @@ type RESTGracefulDeleteStrategy interface {
// where we set deletionTimestamp is pkg/registry/generic/registry/store.go.
// This function is responsible for setting deletionTimestamp during gracefulDeletion,
// other one for cascading deletions.
func
BeforeDelete
(
strategy
RESTDeleteStrategy
,
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
options
*
metav1
.
DeleteOptions
)
(
graceful
,
gracefulPending
bool
,
err
error
)
{
func
BeforeDelete
(
strategy
RESTDeleteStrategy
,
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
options
*
metav1
.
DeleteOptions
)
(
graceful
,
gracefulPending
bool
,
err
error
)
{
objectMeta
,
gvk
,
kerr
:=
objectMetaAndKind
(
strategy
,
obj
)
if
kerr
!=
nil
{
return
false
,
false
,
kerr
...
...
staging/src/k8s.io/apiserver/pkg/registry/rest/export.go
View file @
54fd2aae
...
...
@@ -17,8 +17,9 @@ limitations under the License.
package
rest
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
)
// RESTExportStrategy is the interface that defines how to export a Kubernetes
...
...
@@ -29,5 +30,5 @@ import (
type
RESTExportStrategy
interface
{
// Export strips fields that can not be set by the user. If 'exact' is false
// fields specific to the cluster are also stripped
Export
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
Export
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
exact
bool
)
error
}
staging/src/k8s.io/apiserver/pkg/registry/rest/meta.go
View file @
54fd2aae
...
...
@@ -17,13 +17,15 @@ limitations under the License.
package
rest
import
(
"context"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/uuid"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
)
// FillObjectMetaSystemFields populates fields that are managed by the system on ObjectMeta.
func
FillObjectMetaSystemFields
(
ctx
genericapireques
t
.
Context
,
meta
metav1
.
Object
)
{
func
FillObjectMetaSystemFields
(
ctx
contex
t
.
Context
,
meta
metav1
.
Object
)
{
meta
.
SetCreationTimestamp
(
metav1
.
Now
())
// allows admission controllers to assign a UID earlier in the request processing
// to support tracking resources pending creation.
...
...
@@ -38,7 +40,7 @@ func FillObjectMetaSystemFields(ctx genericapirequest.Context, meta metav1.Objec
// ValidNamespace returns false if the namespace on the context differs from
// the resource. If the resource has no namespace, it is set to the value in
// the context.
func
ValidNamespace
(
ctx
genericapireques
t
.
Context
,
resource
metav1
.
Object
)
bool
{
func
ValidNamespace
(
ctx
contex
t
.
Context
,
resource
metav1
.
Object
)
bool
{
ns
,
ok
:=
genericapirequest
.
NamespaceFrom
(
ctx
)
if
len
(
resource
.
GetNamespace
())
==
0
{
resource
.
SetNamespace
(
ns
)
...
...
staging/src/k8s.io/apiserver/pkg/registry/rest/rest.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
rest
import
(
"context"
"io"
"net/http"
"net/url"
...
...
@@ -27,7 +28,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
)
//TODO:
...
...
@@ -91,7 +91,7 @@ type Lister interface {
// This object must be a pointer type for use with Codec.DecodeInto([]byte, runtime.Object)
NewList
()
runtime
.
Object
// List selects resources in the storage which match to the selector. 'options' can be nil.
List
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
List
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
}
// Exporter is an object that knows how to strip a RESTful resource for export. A store should implement this interface
...
...
@@ -101,7 +101,7 @@ type Exporter interface {
// Export an object. Fields that are not user specified (e.g. Status, ObjectMeta.ResourceVersion) are stripped out
// Returns the stripped object. If 'exact' is true, fields that are specific to the cluster (e.g. namespace) are
// retained, otherwise they are stripped also.
Export
(
ctx
genericapireques
t
.
Context
,
name
string
,
opts
metav1
.
ExportOptions
)
(
runtime
.
Object
,
error
)
Export
(
ctx
contex
t
.
Context
,
name
string
,
opts
metav1
.
ExportOptions
)
(
runtime
.
Object
,
error
)
}
// Getter is an object that can retrieve a named RESTful resource.
...
...
@@ -109,7 +109,7 @@ type Getter interface {
// Get finds a resource in the storage by name and returns it.
// Although it can return an arbitrary error value, IsNotFound(err) is true for the
// returned error value err when the specified resource is not found.
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
}
// GetterWithOptions is an object that retrieve a named RESTful resource and takes
...
...
@@ -122,7 +122,7 @@ type GetterWithOptions interface {
// The options object passed to it is of the same type returned by the NewGetOptions
// method.
// TODO: Pass metav1.GetOptions.
Get
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
runtime
.
Object
)
(
runtime
.
Object
,
error
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
runtime
.
Object
)
(
runtime
.
Object
,
error
)
// NewGetOptions returns an empty options object that will be used to pass
// options to the Get method. It may return a bool and a string, if true, the
...
...
@@ -134,7 +134,7 @@ type GetterWithOptions interface {
}
type
TableConvertor
interface
{
ConvertToTable
(
ctx
genericapireques
t
.
Context
,
object
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
ConvertToTable
(
ctx
contex
t
.
Context
,
object
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
}
// GracefulDeleter knows how to pass deletion options to allow delayed deletion of a
...
...
@@ -149,7 +149,7 @@ type GracefulDeleter interface {
// information about deletion.
// It also returns a boolean which is set to true if the resource was instantly
// deleted or false if it will be deleted asynchronously.
Delete
(
ctx
genericapireques
t
.
Context
,
name
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
Delete
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
DeleteOptions
)
(
runtime
.
Object
,
bool
,
error
)
}
// CollectionDeleter is an object that can delete a collection
...
...
@@ -160,7 +160,7 @@ type CollectionDeleter interface {
// them or return an invalid request error.
// DeleteCollection may not be atomic - i.e. it may delete some objects and still
// return an error after it. On success, returns a list of deleted objects.
DeleteCollection
(
ctx
genericapireques
t
.
Context
,
options
*
metav1
.
DeleteOptions
,
listOptions
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
DeleteCollection
(
ctx
contex
t
.
Context
,
options
*
metav1
.
DeleteOptions
,
listOptions
*
metainternalversion
.
ListOptions
)
(
runtime
.
Object
,
error
)
}
// Creater is an object that can create an instance of a RESTful object.
...
...
@@ -171,7 +171,7 @@ type Creater interface {
// Create creates a new version of a resource. If includeUninitialized is set, the object may be returned
// without completing initialization.
Create
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
,
createValidation
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
Create
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
,
createValidation
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
}
// NamedCreater is an object that can create an instance of a RESTful object using a name parameter.
...
...
@@ -184,7 +184,7 @@ type NamedCreater interface {
// This is needed for create operations on subresources which include the name of the parent
// resource in the path. If includeUninitialized is set, the object may be returned without
// completing initialization.
Create
(
ctx
genericapireques
t
.
Context
,
name
string
,
obj
runtime
.
Object
,
createValidation
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
Create
(
ctx
contex
t
.
Context
,
name
string
,
obj
runtime
.
Object
,
createValidation
ValidateObjectFunc
,
includeUninitialized
bool
)
(
runtime
.
Object
,
error
)
}
// UpdatedObjectInfo provides information about an updated object to an Updater.
...
...
@@ -197,7 +197,7 @@ type UpdatedObjectInfo interface {
// UpdatedObject returns the updated object, given a context and old object.
// The only time an empty oldObj should be passed in is if a "create on update" is occurring (there is no oldObj).
UpdatedObject
(
ctx
genericapireques
t
.
Context
,
oldObj
runtime
.
Object
)
(
newObj
runtime
.
Object
,
err
error
)
UpdatedObject
(
ctx
contex
t
.
Context
,
oldObj
runtime
.
Object
)
(
newObj
runtime
.
Object
,
err
error
)
}
// ValidateObjectFunc is a function to act on a given object. An error may be returned
...
...
@@ -229,14 +229,14 @@ type Updater interface {
// Update finds a resource in the storage and updates it. Some implementations
// may allow updates creates the object - they should set the created boolean
// to true.
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
UpdatedObjectInfo
,
createValidation
ValidateObjectFunc
,
updateValidation
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
UpdatedObjectInfo
,
createValidation
ValidateObjectFunc
,
updateValidation
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
}
// CreaterUpdater is a storage object that must support both create and update.
// Go prevents embedded interfaces that implement the same method.
type
CreaterUpdater
interface
{
Creater
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
UpdatedObjectInfo
,
createValidation
ValidateObjectFunc
,
updateValidation
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
UpdatedObjectInfo
,
createValidation
ValidateObjectFunc
,
updateValidation
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
}
// CreaterUpdater must satisfy the Updater interface.
...
...
@@ -255,7 +255,7 @@ type Watcher interface {
// are supported; an error should be returned if 'field' tries to select on a field that
// isn't supported. 'resourceVersion' allows for continuing/starting a watch at a
// particular version.
Watch
(
ctx
genericapireques
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
Watch
(
ctx
contex
t
.
Context
,
options
*
metainternalversion
.
ListOptions
)
(
watch
.
Interface
,
error
)
}
// StandardStorage is an interface covering the common verbs. Provided for testing whether a
...
...
@@ -272,7 +272,7 @@ type StandardStorage interface {
// Redirector know how to return a remote resource's location.
type
Redirector
interface
{
// ResourceLocation should return the remote location of the given resource, and an optional transport to use to request it, or an error.
ResourceLocation
(
ctx
genericapireques
t
.
Context
,
id
string
)
(
remoteLocation
*
url
.
URL
,
transport
http
.
RoundTripper
,
err
error
)
ResourceLocation
(
ctx
contex
t
.
Context
,
id
string
)
(
remoteLocation
*
url
.
URL
,
transport
http
.
RoundTripper
,
err
error
)
}
// Responder abstracts the normal response behavior for a REST method and is passed to callers that
...
...
@@ -292,7 +292,7 @@ type Connecter interface {
// code and body, so the ServeHTTP method should exit after invoking the responder. The Handler will
// be used for a single API request and then discarded. The Responder is guaranteed to write to the
// same http.ResponseWriter passed to ServeHTTP.
Connect
(
ctx
genericapireques
t
.
Context
,
id
string
,
options
runtime
.
Object
,
r
Responder
)
(
http
.
Handler
,
error
)
Connect
(
ctx
contex
t
.
Context
,
id
string
,
options
runtime
.
Object
,
r
Responder
)
(
http
.
Handler
,
error
)
// NewConnectOptions returns an empty options object that will be used to pass
// options to the Connect method. If nil, then a nil options object is passed to
...
...
staging/src/k8s.io/apiserver/pkg/registry/rest/resttest/resttest.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
resttest
import
(
"context"
"fmt"
"reflect"
"strings"
...
...
@@ -99,7 +100,7 @@ func (t *Tester) TestNamespace() string {
// TestContext returns a namespaced context that will be used when making storage calls.
// Namespace is determined by TestNamespace()
func
(
t
*
Tester
)
TestContext
()
genericapireques
t
.
Context
{
func
(
t
*
Tester
)
TestContext
()
contex
t
.
Context
{
if
t
.
clusterScope
{
return
genericapirequest
.
NewContext
()
}
...
...
@@ -128,11 +129,11 @@ func (t *Tester) setObjectMeta(obj runtime.Object, name string) {
type
AssignFunc
func
([]
runtime
.
Object
)
[]
runtime
.
Object
type
EmitFunc
func
(
runtime
.
Object
,
string
)
error
type
GetFunc
func
(
genericapireques
t
.
Context
,
runtime
.
Object
)
(
runtime
.
Object
,
error
)
type
GetFunc
func
(
contex
t
.
Context
,
runtime
.
Object
)
(
runtime
.
Object
,
error
)
type
InitWatchFunc
func
()
type
InjectErrFunc
func
(
err
error
)
type
IsErrorFunc
func
(
err
error
)
bool
type
CreateFunc
func
(
genericapireques
t
.
Context
,
runtime
.
Object
)
error
type
CreateFunc
func
(
contex
t
.
Context
,
runtime
.
Object
)
error
type
SetRVFunc
func
(
uint64
)
type
UpdateFunc
func
(
runtime
.
Object
)
runtime
.
Object
...
...
@@ -219,7 +220,7 @@ func (t *Tester) TestWatch(
// =============================================================================
// Creation tests.
func
(
t
*
Tester
)
delete
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
error
{
func
(
t
*
Tester
)
delete
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
error
{
objectMeta
,
err
:=
meta
.
Accessor
(
obj
)
if
err
!=
nil
{
return
err
...
...
@@ -576,7 +577,7 @@ func (t *Tester) testUpdateRetrievesOldObject(obj runtime.Object, createFn Creat
// Make sure a custom transform is called, and sees the expected updatedObject and oldObject
// This tests the mechanism used to pass the old and new object to admission
calledUpdatedObject
:=
0
noopTransform
:=
func
(
_
genericapireques
t
.
Context
,
updatedObject
runtime
.
Object
,
oldObject
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
noopTransform
:=
func
(
_
contex
t
.
Context
,
updatedObject
runtime
.
Object
,
oldObject
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
if
!
reflect
.
DeepEqual
(
storedFoo
,
oldObject
)
{
t
.
Errorf
(
"Expected
\n\t
%#v
\n
got
\n\t
%#v"
,
storedFoo
,
oldObject
)
}
...
...
@@ -618,7 +619,7 @@ func (t *Tester) testUpdatePropagatesUpdatedObjectError(obj runtime.Object, crea
// Make sure our transform is called, and sees the expected updatedObject and oldObject
propagateErr
:=
fmt
.
Errorf
(
"custom updated object error for %v"
,
foo
)
noopTransform
:=
func
(
_
genericapireques
t
.
Context
,
updatedObject
runtime
.
Object
,
oldObject
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
noopTransform
:=
func
(
_
contex
t
.
Context
,
updatedObject
runtime
.
Object
,
oldObject
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
return
nil
,
propagateErr
}
...
...
staging/src/k8s.io/apiserver/pkg/registry/rest/table.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
rest
import
(
"context"
"fmt"
"net/http"
"time"
...
...
@@ -26,7 +27,6 @@ import (
metav1beta1
"k8s.io/apimachinery/pkg/apis/meta/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
)
type
defaultTableConvertor
struct
{
...
...
@@ -40,7 +40,7 @@ func NewDefaultTableConvertor(resource schema.GroupResource) TableConvertor {
var
swaggerMetadataDescriptions
=
metav1
.
ObjectMeta
{}
.
SwaggerDoc
()
func
(
c
defaultTableConvertor
)
ConvertToTable
(
ctx
genericapireques
t
.
Context
,
object
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
func
(
c
defaultTableConvertor
)
ConvertToTable
(
ctx
contex
t
.
Context
,
object
runtime
.
Object
,
tableOptions
runtime
.
Object
)
(
*
metav1beta1
.
Table
,
error
)
{
var
table
metav1beta1
.
Table
fn
:=
func
(
obj
runtime
.
Object
)
error
{
m
,
err
:=
meta
.
Accessor
(
obj
)
...
...
staging/src/k8s.io/apiserver/pkg/registry/rest/update.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
rest
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/api/errors"
...
...
@@ -27,7 +28,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apiserver/pkg/admission"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/features"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
)
...
...
@@ -46,11 +46,11 @@ type RESTUpdateStrategy interface {
// the object. For example: remove fields that are not to be persisted,
// sort order-insensitive list fields, etc. This should not remove fields
// whose presence would be considered a validation error.
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
// ValidateUpdate is invoked after default fields in the object have been
// filled in before the object is persisted. This method should not mutate
// the object.
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
// Canonicalize allows an object to be mutated into a canonical form. This
// ensures that code that operates on these objects can rely on the common
// form for things like comparison. Canonicalize is invoked after
...
...
@@ -83,7 +83,7 @@ func validateCommonFields(obj, old runtime.Object, strategy RESTUpdateStrategy)
// BeforeUpdate ensures that common operations for all resources are performed on update. It only returns
// errors that can be converted to api.Status. It will invoke update validation with the provided existing
// and updated objects.
func
BeforeUpdate
(
strategy
RESTUpdateStrategy
,
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
error
{
func
BeforeUpdate
(
strategy
RESTUpdateStrategy
,
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
error
{
objectMeta
,
kind
,
kerr
:=
objectMetaAndKind
(
strategy
,
obj
)
if
kerr
!=
nil
{
return
kerr
...
...
@@ -130,7 +130,7 @@ func BeforeUpdate(strategy RESTUpdateStrategy, ctx genericapirequest.Context, ob
}
// TransformFunc is a function to transform and return newObj
type
TransformFunc
func
(
ctx
genericapireques
t
.
Context
,
newObj
runtime
.
Object
,
oldObj
runtime
.
Object
)
(
transformedNewObj
runtime
.
Object
,
err
error
)
type
TransformFunc
func
(
ctx
contex
t
.
Context
,
newObj
runtime
.
Object
,
oldObj
runtime
.
Object
)
(
transformedNewObj
runtime
.
Object
,
err
error
)
// defaultUpdatedObjectInfo implements UpdatedObjectInfo
type
defaultUpdatedObjectInfo
struct
{
...
...
@@ -167,7 +167,7 @@ func (i *defaultUpdatedObjectInfo) Preconditions() *metav1.Preconditions {
// UpdatedObject satisfies the UpdatedObjectInfo interface.
// It returns a copy of the held obj, passed through any configured transformers.
func
(
i
*
defaultUpdatedObjectInfo
)
UpdatedObject
(
ctx
genericapireques
t
.
Context
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
func
(
i
*
defaultUpdatedObjectInfo
)
UpdatedObject
(
ctx
contex
t
.
Context
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
var
err
error
// Start with the configured object
newObj
:=
i
.
obj
...
...
@@ -214,7 +214,7 @@ func (i *wrappedUpdatedObjectInfo) Preconditions() *metav1.Preconditions {
// UpdatedObject satisfies the UpdatedObjectInfo interface.
// It delegates to the wrapped objInfo and passes the result through any configured transformers.
func
(
i
*
wrappedUpdatedObjectInfo
)
UpdatedObject
(
ctx
genericapireques
t
.
Context
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
func
(
i
*
wrappedUpdatedObjectInfo
)
UpdatedObject
(
ctx
contex
t
.
Context
,
oldObj
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
newObj
,
err
:=
i
.
objInfo
.
UpdatedObject
(
ctx
,
oldObj
)
if
err
!=
nil
{
return
newObj
,
err
...
...
staging/src/k8s.io/apiserver/pkg/server/BUILD
View file @
54fd2aae
...
...
@@ -30,7 +30,6 @@ go_test(
"//vendor/k8s.io/apiserver/pkg/authorization/authorizer:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/discovery:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/filters:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
"//vendor/k8s.io/apiserver/pkg/server/filters:go_default_library",
"//vendor/k8s.io/apiserver/pkg/server/healthz:go_default_library",
...
...
staging/src/k8s.io/apiserver/pkg/server/genericapiserver_test.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
server
import
(
"context"
"encoding/json"
"fmt"
"io"
...
...
@@ -47,7 +48,6 @@ import (
"k8s.io/apiserver/pkg/authorization/authorizer"
"k8s.io/apiserver/pkg/endpoints/discovery"
genericapifilters
"k8s.io/apiserver/pkg/endpoints/filters"
apirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
genericfilters
"k8s.io/apiserver/pkg/server/filters"
"k8s.io/client-go/informers"
...
...
@@ -468,7 +468,7 @@ func (p *testGetterStorage) New() runtime.Object {
}
}
func
(
p
*
testGetterStorage
)
Get
(
ctx
apireques
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
func
(
p
*
testGetterStorage
)
Get
(
ctx
contex
t
.
Context
,
name
string
,
options
*
metav1
.
GetOptions
)
(
runtime
.
Object
,
error
)
{
return
nil
,
nil
}
...
...
staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/BUILD
View file @
54fd2aae
...
...
@@ -14,7 +14,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
...
...
staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/etcd/BUILD
View file @
54fd2aae
...
...
@@ -11,7 +11,6 @@ go_library(
importpath = "k8s.io/kube-aggregator/pkg/registry/apiservice/etcd",
deps = [
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/rest:go_default_library",
...
...
staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/etcd/etcd.go
View file @
54fd2aae
...
...
@@ -17,8 +17,9 @@ limitations under the License.
package
etcd
import
(
"context"
"k8s.io/apimachinery/pkg/runtime"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry
"k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
...
...
@@ -72,6 +73,6 @@ func (r *StatusREST) New() runtime.Object {
}
// Update alters the status subset of an object.
func
(
r
*
StatusREST
)
Update
(
ctx
genericapireques
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
func
(
r
*
StatusREST
)
Update
(
ctx
contex
t
.
Context
,
name
string
,
objInfo
rest
.
UpdatedObjectInfo
,
createValidation
rest
.
ValidateObjectFunc
,
updateValidation
rest
.
ValidateObjectUpdateFunc
)
(
runtime
.
Object
,
bool
,
error
)
{
return
r
.
store
.
Update
(
ctx
,
name
,
objInfo
,
createValidation
,
updateValidation
)
}
staging/src/k8s.io/kube-aggregator/pkg/registry/apiservice/strategy.go
View file @
54fd2aae
...
...
@@ -17,13 +17,13 @@ limitations under the License.
package
apiservice
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage/names"
...
...
@@ -45,7 +45,7 @@ func (apiServerStrategy) NamespaceScoped() bool {
return
false
}
func
(
apiServerStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
apiServerStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
apiservice
:=
obj
.
(
*
apiregistration
.
APIService
)
apiservice
.
Status
=
apiregistration
.
APIServiceStatus
{}
...
...
@@ -55,13 +55,13 @@ func (apiServerStrategy) PrepareForCreate(ctx genericapirequest.Context, obj run
}
}
func
(
apiServerStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
apiServerStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newAPIService
:=
obj
.
(
*
apiregistration
.
APIService
)
oldAPIService
:=
old
.
(
*
apiregistration
.
APIService
)
newAPIService
.
Status
=
oldAPIService
.
Status
}
func
(
apiServerStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
apiServerStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateAPIService
(
obj
.
(
*
apiregistration
.
APIService
))
}
...
...
@@ -76,7 +76,7 @@ func (apiServerStrategy) AllowUnconditionalUpdate() bool {
func
(
apiServerStrategy
)
Canonicalize
(
obj
runtime
.
Object
)
{
}
func
(
apiServerStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
apiServerStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateAPIServiceUpdate
(
obj
.
(
*
apiregistration
.
APIService
),
old
.
(
*
apiregistration
.
APIService
))
}
...
...
@@ -93,7 +93,7 @@ func (apiServerStatusStrategy) NamespaceScoped() bool {
return
false
}
func
(
apiServerStatusStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
apiServerStatusStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
newAPIService
:=
obj
.
(
*
apiregistration
.
APIService
)
oldAPIService
:=
old
.
(
*
apiregistration
.
APIService
)
newAPIService
.
Spec
=
oldAPIService
.
Spec
...
...
@@ -114,7 +114,7 @@ func (apiServerStatusStrategy) AllowUnconditionalUpdate() bool {
func
(
apiServerStatusStrategy
)
Canonicalize
(
obj
runtime
.
Object
)
{
}
func
(
apiServerStatusStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
apiServerStatusStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
validation
.
ValidateAPIServiceStatusUpdate
(
obj
.
(
*
apiregistration
.
APIService
),
old
.
(
*
apiregistration
.
APIService
))
}
...
...
staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/fischer/BUILD
View file @
54fd2aae
...
...
@@ -17,7 +17,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
...
...
staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/fischer/strategy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
fischer
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/fields"
...
...
@@ -27,7 +28,6 @@ import (
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage/names"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/sample-apiserver/pkg/apis/wardle"
)
...
...
@@ -70,13 +70,13 @@ func (fischerStrategy) NamespaceScoped() bool {
return
false
}
func
(
fischerStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
fischerStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
}
func
(
fischerStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
fischerStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
}
func
(
fischerStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
fischerStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
return
field
.
ErrorList
{}
}
...
...
@@ -91,6 +91,6 @@ func (fischerStrategy) AllowUnconditionalUpdate() bool {
func
(
fischerStrategy
)
Canonicalize
(
obj
runtime
.
Object
)
{
}
func
(
fischerStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
fischerStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
field
.
ErrorList
{}
}
staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/flunder/BUILD
View file @
54fd2aae
...
...
@@ -17,7 +17,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
...
...
staging/src/k8s.io/sample-apiserver/pkg/registry/wardle/flunder/strategy.go
View file @
54fd2aae
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
flunder
import
(
"context"
"fmt"
"k8s.io/apimachinery/pkg/fields"
...
...
@@ -28,7 +29,6 @@ import (
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/sample-apiserver/pkg/apis/wardle/validation"
genericapirequest
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/sample-apiserver/pkg/apis/wardle"
)
...
...
@@ -71,13 +71,13 @@ func (flunderStrategy) NamespaceScoped() bool {
return
true
}
func
(
flunderStrategy
)
PrepareForCreate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
{
func
(
flunderStrategy
)
PrepareForCreate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
{
}
func
(
flunderStrategy
)
PrepareForUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
func
(
flunderStrategy
)
PrepareForUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
{
}
func
(
flunderStrategy
)
Validate
(
ctx
genericapireques
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
func
(
flunderStrategy
)
Validate
(
ctx
contex
t
.
Context
,
obj
runtime
.
Object
)
field
.
ErrorList
{
flunder
:=
obj
.
(
*
wardle
.
Flunder
)
return
validation
.
ValidateFlunder
(
flunder
)
}
...
...
@@ -93,6 +93,6 @@ func (flunderStrategy) AllowUnconditionalUpdate() bool {
func
(
flunderStrategy
)
Canonicalize
(
obj
runtime
.
Object
)
{
}
func
(
flunderStrategy
)
ValidateUpdate
(
ctx
genericapireques
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
func
(
flunderStrategy
)
ValidateUpdate
(
ctx
contex
t
.
Context
,
obj
,
old
runtime
.
Object
)
field
.
ErrorList
{
return
field
.
ErrorList
{}
}
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