Move pkg/api.{Context,RequestContextMapper} into pkg/genericapiserver/api/request
This commit is contained in:
@@ -20,6 +20,7 @@ go_library(
|
||||
"//pkg/apis/batch:go_default_library",
|
||||
"//pkg/apis/batch/validation:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
@@ -38,5 +39,6 @@ go_test(
|
||||
"//pkg/api/testing:go_default_library",
|
||||
"//pkg/apis/batch:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@@ -13,10 +13,10 @@ go_library(
|
||||
srcs = ["etcd.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/rest:go_default_library",
|
||||
"//pkg/apis/batch:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/registry/batch/cronjob:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/registry/generic/registry:go_default_library",
|
||||
|
@@ -17,10 +17,10 @@ limitations under the License.
|
||||
package etcd
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/registry/batch/cronjob"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
genericregistry "k8s.io/kubernetes/pkg/registry/generic/registry"
|
||||
@@ -68,11 +68,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 api.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
func (r *StatusREST) Get(ctx genericapirequest.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 api.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
return r.store.Update(ctx, name, objInfo)
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
"k8s.io/kubernetes/pkg/apis/batch/validation"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
@@ -45,20 +46,20 @@ func (scheduledJobStrategy) NamespaceScoped() bool {
|
||||
}
|
||||
|
||||
// PrepareForCreate clears the status of a scheduled job before creation.
|
||||
func (scheduledJobStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
|
||||
func (scheduledJobStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
||||
scheduledJob := obj.(*batch.CronJob)
|
||||
scheduledJob.Status = batch.CronJobStatus{}
|
||||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
func (scheduledJobStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (scheduledJobStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newCronJob := obj.(*batch.CronJob)
|
||||
oldCronJob := old.(*batch.CronJob)
|
||||
newCronJob.Status = oldCronJob.Status
|
||||
}
|
||||
|
||||
// Validate validates a new scheduled job.
|
||||
func (scheduledJobStrategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList {
|
||||
func (scheduledJobStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList {
|
||||
scheduledJob := obj.(*batch.CronJob)
|
||||
return validation.ValidateCronJob(scheduledJob)
|
||||
}
|
||||
@@ -77,7 +78,7 @@ func (scheduledJobStrategy) AllowCreateOnUpdate() bool {
|
||||
}
|
||||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (scheduledJobStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (scheduledJobStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateCronJob(obj.(*batch.CronJob))
|
||||
}
|
||||
|
||||
@@ -87,13 +88,13 @@ type scheduledJobStatusStrategy struct {
|
||||
|
||||
var StatusStrategy = scheduledJobStatusStrategy{Strategy}
|
||||
|
||||
func (scheduledJobStatusStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (scheduledJobStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newJob := obj.(*batch.CronJob)
|
||||
oldJob := old.(*batch.CronJob)
|
||||
newJob.Spec = oldJob.Spec
|
||||
}
|
||||
|
||||
func (scheduledJobStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (scheduledJobStatusStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return field.ErrorList{}
|
||||
}
|
||||
|
||||
|
@@ -23,6 +23,7 @@ import (
|
||||
apitesting "k8s.io/kubernetes/pkg/api/testing"
|
||||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
)
|
||||
|
||||
func newBool(a bool) *bool {
|
||||
@@ -32,7 +33,7 @@ func newBool(a bool) *bool {
|
||||
}
|
||||
|
||||
func TestCronJobStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if !Strategy.NamespaceScoped() {
|
||||
t.Errorf("CronJob must be namespace scoped")
|
||||
}
|
||||
@@ -94,7 +95,7 @@ func TestCronJobStrategy(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCronJobStatusStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if !StatusStrategy.NamespaceScoped() {
|
||||
t.Errorf("CronJob must be namespace scoped")
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ go_library(
|
||||
"//pkg/apis/batch/validation:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/fields:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/labels:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/runtime:go_default_library",
|
||||
@@ -40,6 +41,7 @@ go_test(
|
||||
"//pkg/api/testing:go_default_library",
|
||||
"//pkg/apis/batch:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/types:go_default_library",
|
||||
],
|
||||
)
|
||||
|
@@ -13,10 +13,10 @@ go_library(
|
||||
srcs = ["etcd.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/api:go_default_library",
|
||||
"//pkg/api/rest:go_default_library",
|
||||
"//pkg/apis/batch:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/genericapiserver/api/request:go_default_library",
|
||||
"//pkg/registry/batch/job:go_default_library",
|
||||
"//pkg/registry/generic:go_default_library",
|
||||
"//pkg/registry/generic/registry:go_default_library",
|
||||
|
@@ -17,10 +17,10 @@ limitations under the License.
|
||||
package etcd
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/registry/batch/job"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
genericregistry "k8s.io/kubernetes/pkg/registry/generic/registry"
|
||||
@@ -83,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 api.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||
func (r *StatusREST) Get(ctx genericapirequest.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 api.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
func (r *StatusREST) Update(ctx genericapirequest.Context, name string, objInfo rest.UpdatedObjectInfo) (runtime.Object, bool, error) {
|
||||
return r.store.Update(ctx, name, objInfo)
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/apis/batch/validation"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/registry/generic"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
@@ -47,20 +48,20 @@ func (jobStrategy) NamespaceScoped() bool {
|
||||
}
|
||||
|
||||
// PrepareForCreate clears the status of a job before creation.
|
||||
func (jobStrategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
|
||||
func (jobStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
||||
job := obj.(*batch.Job)
|
||||
job.Status = batch.JobStatus{}
|
||||
}
|
||||
|
||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||
func (jobStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (jobStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newJob := obj.(*batch.Job)
|
||||
oldJob := old.(*batch.Job)
|
||||
newJob.Status = oldJob.Status
|
||||
}
|
||||
|
||||
// Validate validates a new job.
|
||||
func (jobStrategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList {
|
||||
func (jobStrategy) Validate(ctx genericapirequest.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 {
|
||||
@@ -133,7 +134,7 @@ func (jobStrategy) AllowCreateOnUpdate() bool {
|
||||
}
|
||||
|
||||
// ValidateUpdate is the default update validation for an end user.
|
||||
func (jobStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (jobStrategy) ValidateUpdate(ctx genericapirequest.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...)
|
||||
@@ -145,13 +146,13 @@ type jobStatusStrategy struct {
|
||||
|
||||
var StatusStrategy = jobStatusStrategy{Strategy}
|
||||
|
||||
func (jobStatusStrategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
|
||||
func (jobStatusStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||
newJob := obj.(*batch.Job)
|
||||
oldJob := old.(*batch.Job)
|
||||
newJob.Spec = oldJob.Spec
|
||||
}
|
||||
|
||||
func (jobStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
|
||||
func (jobStatusStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||
return validation.ValidateJobUpdateStatus(obj.(*batch.Job), old.(*batch.Job))
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,7 @@ import (
|
||||
apitesting "k8s.io/kubernetes/pkg/api/testing"
|
||||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
genericapirequest "k8s.io/kubernetes/pkg/genericapiserver/api/request"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
)
|
||||
|
||||
@@ -35,7 +36,7 @@ func newBool(a bool) *bool {
|
||||
}
|
||||
|
||||
func TestJobStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if !Strategy.NamespaceScoped() {
|
||||
t.Errorf("Job must be namespace scoped")
|
||||
}
|
||||
@@ -102,7 +103,7 @@ func TestJobStrategy(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestJobStrategyWithGeneration(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
|
||||
theUID := types.UID("1a2b3c4d5e6f7g8h9i0k")
|
||||
|
||||
@@ -152,7 +153,7 @@ func TestJobStrategyWithGeneration(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestJobStatusStrategy(t *testing.T) {
|
||||
ctx := api.NewDefaultContext()
|
||||
ctx := genericapirequest.NewDefaultContext()
|
||||
if !StatusStrategy.NamespaceScoped() {
|
||||
t.Errorf("Job must be namespace scoped")
|
||||
}
|
||||
|
Reference in New Issue
Block a user