...

Source file src/k8s.io/kubernetes/pkg/registry/core/endpoint/strategy.go

Documentation: k8s.io/kubernetes/pkg/registry/core/endpoint

     1  /*
     2  Copyright 2014 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package endpoint
    18  
    19  import (
    20  	"context"
    21  
    22  	"k8s.io/apimachinery/pkg/runtime"
    23  	"k8s.io/apimachinery/pkg/util/validation/field"
    24  	"k8s.io/apiserver/pkg/storage/names"
    25  	"k8s.io/kubernetes/pkg/api/legacyscheme"
    26  	api "k8s.io/kubernetes/pkg/apis/core"
    27  	"k8s.io/kubernetes/pkg/apis/core/validation"
    28  )
    29  
    30  // endpointsStrategy implements behavior for Endpoints
    31  type endpointsStrategy struct {
    32  	runtime.ObjectTyper
    33  	names.NameGenerator
    34  }
    35  
    36  // Strategy is the default logic that applies when creating and updating Endpoint
    37  // objects via the REST API.
    38  var Strategy = endpointsStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
    39  
    40  // NamespaceScoped is true for endpoints.
    41  func (endpointsStrategy) NamespaceScoped() bool {
    42  	return true
    43  }
    44  
    45  // PrepareForCreate clears fields that are not allowed to be set by end users on creation.
    46  func (endpointsStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
    47  }
    48  
    49  // PrepareForUpdate clears fields that are not allowed to be set by end users on update.
    50  func (endpointsStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
    51  }
    52  
    53  // Validate validates a new endpoints.
    54  func (endpointsStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
    55  	return validation.ValidateEndpointsCreate(obj.(*api.Endpoints))
    56  }
    57  
    58  // WarningsOnCreate returns warnings for the creation of the given object.
    59  func (endpointsStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
    60  	return nil
    61  }
    62  
    63  // Canonicalize normalizes the object after validation.
    64  func (endpointsStrategy) Canonicalize(obj runtime.Object) {
    65  }
    66  
    67  // AllowCreateOnUpdate is true for endpoints.
    68  func (endpointsStrategy) AllowCreateOnUpdate() bool {
    69  	return true
    70  }
    71  
    72  // ValidateUpdate is the default update validation for an end user.
    73  func (endpointsStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
    74  	return validation.ValidateEndpointsUpdate(obj.(*api.Endpoints), old.(*api.Endpoints))
    75  }
    76  
    77  // WarningsOnUpdate returns warnings for the given update.
    78  func (endpointsStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
    79  	return nil
    80  }
    81  
    82  func (endpointsStrategy) AllowUnconditionalUpdate() bool {
    83  	return true
    84  }
    85  

View as plain text