...

Source file src/k8s.io/kubernetes/pkg/registry/coordination/lease/strategy.go

Documentation: k8s.io/kubernetes/pkg/registry/coordination/lease

     1  /*
     2  Copyright 2018 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 lease
    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  	"k8s.io/kubernetes/pkg/apis/coordination"
    27  	"k8s.io/kubernetes/pkg/apis/coordination/validation"
    28  )
    29  
    30  // leaseStrategy implements verification logic for Leases.
    31  type leaseStrategy struct {
    32  	runtime.ObjectTyper
    33  	names.NameGenerator
    34  }
    35  
    36  // Strategy is the default logic that applies when creating and updating Lease objects.
    37  var Strategy = leaseStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
    38  
    39  // NamespaceScoped returns true because all Lease' need to be within a namespace.
    40  func (leaseStrategy) NamespaceScoped() bool {
    41  	return true
    42  }
    43  
    44  // PrepareForCreate prepares Lease for creation.
    45  func (leaseStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
    46  }
    47  
    48  // PrepareForUpdate clears fields that are not allowed to be set by end users on update.
    49  func (leaseStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
    50  }
    51  
    52  // Validate validates a new Lease.
    53  func (leaseStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
    54  	lease := obj.(*coordination.Lease)
    55  	return validation.ValidateLease(lease)
    56  }
    57  
    58  // WarningsOnCreate returns warnings for the creation of the given object.
    59  func (leaseStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { return nil }
    60  
    61  // Canonicalize normalizes the object after validation.
    62  func (leaseStrategy) Canonicalize(obj runtime.Object) {
    63  }
    64  
    65  // AllowCreateOnUpdate is true for Lease; this means you may create one with a PUT request.
    66  func (leaseStrategy) AllowCreateOnUpdate() bool {
    67  	return true
    68  }
    69  
    70  // ValidateUpdate is the default update validation for an end user.
    71  func (leaseStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
    72  	return validation.ValidateLeaseUpdate(obj.(*coordination.Lease), old.(*coordination.Lease))
    73  }
    74  
    75  // WarningsOnUpdate returns warnings for the given update.
    76  func (leaseStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
    77  	return nil
    78  }
    79  
    80  // AllowUnconditionalUpdate is the default update policy for Lease objects.
    81  func (leaseStrategy) AllowUnconditionalUpdate() bool {
    82  	return false
    83  }
    84  

View as plain text