mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
Change validation now that namespace is on ObjectMeta
This commit is contained in:
parent
55163a7df1
commit
09800643e2
@ -70,7 +70,7 @@ func Namespace(ctx Context) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
// 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 Context, resource *TypeMeta) bool {
|
func ValidNamespace(ctx Context, resource *ObjectMeta) bool {
|
||||||
ns, ok := NamespaceFrom(ctx)
|
ns, ok := NamespaceFrom(ctx)
|
||||||
if len(resource.Namespace) == 0 {
|
if len(resource.Namespace) == 0 {
|
||||||
resource.Namespace = ns
|
resource.Namespace = ns
|
||||||
|
@ -59,7 +59,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("not a replication controller: %#v", obj)
|
return nil, fmt.Errorf("not a replication controller: %#v", obj)
|
||||||
}
|
}
|
||||||
if !api.ValidNamespace(ctx, &controller.TypeMeta) {
|
if !api.ValidNamespace(ctx, &controller.ObjectMeta) {
|
||||||
return nil, errors.NewConflict("controller", controller.Namespace, fmt.Errorf("Controller.Namespace does not match the provided context"))
|
return nil, errors.NewConflict("controller", controller.Namespace, fmt.Errorf("Controller.Namespace does not match the provided context"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Obje
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("not a replication controller: %#v", obj)
|
return nil, fmt.Errorf("not a replication controller: %#v", obj)
|
||||||
}
|
}
|
||||||
if !api.ValidNamespace(ctx, &controller.TypeMeta) {
|
if !api.ValidNamespace(ctx, &controller.ObjectMeta) {
|
||||||
return nil, errors.NewConflict("controller", controller.Namespace, fmt.Errorf("Controller.Namespace does not match the provided context"))
|
return nil, errors.NewConflict("controller", controller.Namespace, fmt.Errorf("Controller.Namespace does not match the provided context"))
|
||||||
}
|
}
|
||||||
if errs := validation.ValidateReplicationController(controller); len(errs) > 0 {
|
if errs := validation.ValidateReplicationController(controller); len(errs) > 0 {
|
||||||
|
@ -90,7 +90,7 @@ func NewREST(config *RESTConfig) *REST {
|
|||||||
|
|
||||||
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||||
pod := obj.(*api.Pod)
|
pod := obj.(*api.Pod)
|
||||||
if !api.ValidNamespace(ctx, &pod.TypeMeta) {
|
if !api.ValidNamespace(ctx, &pod.ObjectMeta) {
|
||||||
return nil, errors.NewConflict("pod", pod.Namespace, fmt.Errorf("Pod.Namespace does not match the provided context"))
|
return nil, errors.NewConflict("pod", pod.Namespace, fmt.Errorf("Pod.Namespace does not match the provided context"))
|
||||||
}
|
}
|
||||||
pod.DesiredState.Manifest.UUID = uuid.NewUUID().String()
|
pod.DesiredState.Manifest.UUID = uuid.NewUUID().String()
|
||||||
@ -186,7 +186,7 @@ func (*REST) New() runtime.Object {
|
|||||||
|
|
||||||
func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||||
pod := obj.(*api.Pod)
|
pod := obj.(*api.Pod)
|
||||||
if !api.ValidNamespace(ctx, &pod.TypeMeta) {
|
if !api.ValidNamespace(ctx, &pod.ObjectMeta) {
|
||||||
return nil, errors.NewConflict("pod", pod.Namespace, fmt.Errorf("Pod.Namespace does not match the provided context"))
|
return nil, errors.NewConflict("pod", pod.Namespace, fmt.Errorf("Pod.Namespace does not match the provided context"))
|
||||||
}
|
}
|
||||||
if errs := validation.ValidatePod(pod); len(errs) > 0 {
|
if errs := validation.ValidatePod(pod); len(errs) > 0 {
|
||||||
|
@ -81,7 +81,7 @@ func reloadIPsFromStorage(ipa *ipAllocator, registry Registry) {
|
|||||||
|
|
||||||
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
func (rs *REST) Create(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||||
service := obj.(*api.Service)
|
service := obj.(*api.Service)
|
||||||
if !api.ValidNamespace(ctx, &service.TypeMeta) {
|
if !api.ValidNamespace(ctx, &service.ObjectMeta) {
|
||||||
return nil, errors.NewConflict("service", service.Namespace, fmt.Errorf("Service.Namespace does not match the provided context"))
|
return nil, errors.NewConflict("service", service.Namespace, fmt.Errorf("Service.Namespace does not match the provided context"))
|
||||||
}
|
}
|
||||||
if errs := validation.ValidateService(service); len(errs) > 0 {
|
if errs := validation.ValidateService(service); len(errs) > 0 {
|
||||||
@ -213,7 +213,7 @@ func GetServiceEnvironmentVariables(ctx api.Context, registry Registry, machine
|
|||||||
|
|
||||||
func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
func (rs *REST) Update(ctx api.Context, obj runtime.Object) (<-chan runtime.Object, error) {
|
||||||
service := obj.(*api.Service)
|
service := obj.(*api.Service)
|
||||||
if !api.ValidNamespace(ctx, &service.TypeMeta) {
|
if !api.ValidNamespace(ctx, &service.ObjectMeta) {
|
||||||
return nil, errors.NewConflict("service", service.Namespace, fmt.Errorf("Service.Namespace does not match the provided context"))
|
return nil, errors.NewConflict("service", service.Namespace, fmt.Errorf("Service.Namespace does not match the provided context"))
|
||||||
}
|
}
|
||||||
if errs := validation.ValidateService(service); len(errs) > 0 {
|
if errs := validation.ValidateService(service); len(errs) > 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user