2015-12-14 13:31:23 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2015 The Kubernetes Authors.
|
2015-12-14 13:31:23 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package podsecuritypolicy
|
|
|
|
|
|
|
|
import (
|
2018-04-24 15:10:34 +00:00
|
|
|
"context"
|
|
|
|
|
2017-01-11 14:09:48 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
2017-02-02 09:25:56 +00:00
|
|
|
"k8s.io/apiserver/pkg/registry/rest"
|
2017-01-13 19:56:52 +00:00
|
|
|
"k8s.io/apiserver/pkg/storage/names"
|
2017-10-16 11:41:50 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
2018-03-21 16:30:31 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/policy"
|
|
|
|
"k8s.io/kubernetes/pkg/apis/policy/validation"
|
2015-12-14 13:31:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// strategy implements behavior for PodSecurityPolicy objects
|
|
|
|
type strategy struct {
|
|
|
|
runtime.ObjectTyper
|
2017-01-13 19:56:52 +00:00
|
|
|
names.NameGenerator
|
2015-12-14 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Strategy is the default logic that applies when creating and updating PodSecurityPolicy
|
|
|
|
// objects via the REST API.
|
2017-10-16 11:41:50 +00:00
|
|
|
var Strategy = strategy{legacyscheme.Scheme, names.SimpleNameGenerator}
|
2015-12-14 13:31:23 +00:00
|
|
|
|
|
|
|
var _ = rest.RESTCreateStrategy(Strategy)
|
|
|
|
|
|
|
|
var _ = rest.RESTUpdateStrategy(Strategy)
|
|
|
|
|
|
|
|
func (strategy) NamespaceScoped() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (strategy) AllowCreateOnUpdate() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (strategy) AllowUnconditionalUpdate() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-04-24 15:10:34 +00:00
|
|
|
func (strategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
|
2015-12-14 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 15:10:34 +00:00
|
|
|
func (strategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
|
2015-12-14 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (strategy) Canonicalize(obj runtime.Object) {
|
|
|
|
}
|
|
|
|
|
2018-04-24 15:10:34 +00:00
|
|
|
func (strategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
|
2018-03-21 16:30:31 +00:00
|
|
|
return validation.ValidatePodSecurityPolicy(obj.(*policy.PodSecurityPolicy))
|
2015-12-14 13:31:23 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 15:10:34 +00:00
|
|
|
func (strategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
|
2018-03-21 16:30:31 +00:00
|
|
|
return validation.ValidatePodSecurityPolicyUpdate(old.(*policy.PodSecurityPolicy), obj.(*policy.PodSecurityPolicy))
|
2015-12-14 13:31:23 +00:00
|
|
|
}
|