...

Source file src/k8s.io/kubernetes/pkg/registry/networking/ipaddress/strategy.go

Documentation: k8s.io/kubernetes/pkg/registry/networking/ipaddress

     1  /*
     2  Copyright 2022 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 ipaddress
    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/registry/rest"
    25  	"k8s.io/apiserver/pkg/storage/names"
    26  	"k8s.io/kubernetes/pkg/api/legacyscheme"
    27  	"k8s.io/kubernetes/pkg/apis/networking"
    28  	"k8s.io/kubernetes/pkg/apis/networking/validation"
    29  )
    30  
    31  // ipAddressStrategy implements verification logic for Replication.
    32  type ipAddressStrategy struct {
    33  	runtime.ObjectTyper
    34  	names.NameGenerator
    35  }
    36  
    37  // noopNameGenerator does not generate names, it just returns the base.
    38  type noopNameGenerator struct{}
    39  
    40  func (noopNameGenerator) GenerateName(base string) string {
    41  	return base
    42  }
    43  
    44  // Strategy is the default logic that applies when creating and updating Replication IPAddress objects.
    45  var Strategy = ipAddressStrategy{legacyscheme.Scheme, noopNameGenerator{}}
    46  
    47  // Strategy should implement rest.RESTCreateStrategy
    48  var _ rest.RESTCreateStrategy = Strategy
    49  
    50  // Strategy should implement rest.RESTUpdateStrategy
    51  var _ rest.RESTUpdateStrategy = Strategy
    52  
    53  // NamespaceScoped returns false because all IPAddresses is cluster scoped.
    54  func (ipAddressStrategy) NamespaceScoped() bool {
    55  	return false
    56  }
    57  
    58  // PrepareForCreate clears the status of an IPAddress before creation.
    59  func (ipAddressStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
    60  	_ = obj.(*networking.IPAddress)
    61  
    62  }
    63  
    64  // PrepareForUpdate clears fields that are not allowed to be set by end users on update.
    65  func (ipAddressStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
    66  	newIPAddress := obj.(*networking.IPAddress)
    67  	oldIPAddress := old.(*networking.IPAddress)
    68  
    69  	_, _ = newIPAddress, oldIPAddress
    70  }
    71  
    72  // Validate validates a new IPAddress.
    73  func (ipAddressStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
    74  	ipAddress := obj.(*networking.IPAddress)
    75  	err := validation.ValidateIPAddress(ipAddress)
    76  	return err
    77  }
    78  
    79  // Canonicalize normalizes the object after validation.
    80  func (ipAddressStrategy) Canonicalize(obj runtime.Object) {
    81  }
    82  
    83  // AllowCreateOnUpdate is false for IPAddress; this means POST is needed to create one.
    84  func (ipAddressStrategy) AllowCreateOnUpdate() bool {
    85  	return false
    86  }
    87  
    88  // ValidateUpdate is the default update validation for an end user.
    89  func (ipAddressStrategy) ValidateUpdate(ctx context.Context, new, old runtime.Object) field.ErrorList {
    90  	newIPAddress := new.(*networking.IPAddress)
    91  	oldIPAddress := old.(*networking.IPAddress)
    92  	errList := validation.ValidateIPAddress(newIPAddress)
    93  	errList = append(errList, validation.ValidateIPAddressUpdate(newIPAddress, oldIPAddress)...)
    94  	return errList
    95  }
    96  
    97  // AllowUnconditionalUpdate is the default update policy for IPAddress objects.
    98  func (ipAddressStrategy) AllowUnconditionalUpdate() bool {
    99  	return true
   100  }
   101  
   102  // WarningsOnCreate returns warnings for the creation of the given object.
   103  func (ipAddressStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
   104  	return nil
   105  }
   106  
   107  // WarningsOnUpdate returns warnings for the given update.
   108  func (ipAddressStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
   109  	return nil
   110  }
   111  

View as plain text