mirror of https://github.com/k3s-io/k3s
107 lines
3.5 KiB
Go
107 lines
3.5 KiB
Go
![]() |
/*
|
||
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||
|
|
||
|
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 ingress
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"reflect"
|
||
|
|
||
|
"k8s.io/kubernetes/pkg/api"
|
||
|
"k8s.io/kubernetes/pkg/apis/experimental"
|
||
|
"k8s.io/kubernetes/pkg/apis/experimental/validation"
|
||
|
"k8s.io/kubernetes/pkg/fields"
|
||
|
"k8s.io/kubernetes/pkg/labels"
|
||
|
"k8s.io/kubernetes/pkg/registry/generic"
|
||
|
"k8s.io/kubernetes/pkg/runtime"
|
||
|
"k8s.io/kubernetes/pkg/util/fielderrors"
|
||
|
)
|
||
|
|
||
|
// ingressStrategy implements verification logic for Replication Ingresss.
|
||
|
type ingressStrategy struct {
|
||
|
runtime.ObjectTyper
|
||
|
api.NameGenerator
|
||
|
}
|
||
|
|
||
|
// Strategy is the default logic that applies when creating and updating Replication Ingress objects.
|
||
|
var Strategy = ingressStrategy{api.Scheme, api.SimpleNameGenerator}
|
||
|
|
||
|
// NamespaceScoped returns true because all Ingress' need to be within a namespace.
|
||
|
func (ingressStrategy) NamespaceScoped() bool {
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
func (ingressStrategy) PrepareForCreate(obj runtime.Object) {
|
||
|
}
|
||
|
|
||
|
func (ingressStrategy) PrepareForUpdate(obj, old runtime.Object) {
|
||
|
newIngress := obj.(*experimental.Ingress)
|
||
|
oldIngress := old.(*experimental.Ingress)
|
||
|
|
||
|
// Any changes to the spec increment the generation number, any changes to the
|
||
|
// status should reflect the generation number of the corresponding object.
|
||
|
// See api.ObjectMeta description for more information on Generation.
|
||
|
if !reflect.DeepEqual(oldIngress.Spec, newIngress.Spec) {
|
||
|
newIngress.Generation = oldIngress.Generation + 1
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
func (ingressStrategy) Validate(ctx api.Context, obj runtime.Object) fielderrors.ValidationErrorList {
|
||
|
ingress := obj.(*experimental.Ingress)
|
||
|
err := validation.ValidateIngress(ingress)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (ingressStrategy) AllowCreateOnUpdate() bool {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
// ValidateUpdate is the default update validation for an end user.
|
||
|
func (ingressStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {
|
||
|
validationErrorList := validation.ValidateIngress(obj.(*experimental.Ingress))
|
||
|
updateErrorList := validation.ValidateIngressUpdate(old.(*experimental.Ingress), obj.(*experimental.Ingress))
|
||
|
return append(validationErrorList, updateErrorList...)
|
||
|
}
|
||
|
|
||
|
func (ingressStrategy) AllowUnconditionalUpdate() bool {
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
// IngressToSelectableFields returns a label set that represents the object.
|
||
|
func IngressToSelectableFields(ingress *experimental.Ingress) fields.Set {
|
||
|
return fields.Set{
|
||
|
"metadata.name": ingress.Name,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// MatchIngress is the filter used by the generic etcd backend to ingress
|
||
|
// watch events from etcd to clients of the apiserver only interested in specific
|
||
|
// labels/fields.
|
||
|
func MatchIngress(label labels.Selector, field fields.Selector) generic.Matcher {
|
||
|
return &generic.SelectionPredicate{
|
||
|
Label: label,
|
||
|
Field: field,
|
||
|
GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {
|
||
|
ingress, ok := obj.(*experimental.Ingress)
|
||
|
if !ok {
|
||
|
return nil, nil, fmt.Errorf("Given object is not an Ingress.")
|
||
|
}
|
||
|
return labels.Set(ingress.ObjectMeta.Labels), IngressToSelectableFields(ingress), nil
|
||
|
},
|
||
|
}
|
||
|
}
|