...

Source file src/k8s.io/kubernetes/pkg/registry/registrytest/validate.go

Documentation: k8s.io/kubernetes/pkg/registry/registrytest

     1  /*
     2  Copyright 2017 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 registrytest
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"k8s.io/apiserver/pkg/registry/generic/registry"
    23  	"k8s.io/apiserver/pkg/registry/rest"
    24  )
    25  
    26  // ValidateStorageStrategies ensures any instances of the generic registry.Store in the given storage map
    27  // have expected strategies defined.
    28  func ValidateStorageStrategies(storageMap map[string]rest.Storage) []error {
    29  	errs := []error{}
    30  
    31  	for k, storage := range storageMap {
    32  		switch t := storage.(type) {
    33  		case registry.GenericStore:
    34  			// At this point it appears all uses of the generic registry store should have a create, update, and
    35  			// delete strategy set:
    36  			if t.GetCreateStrategy() == nil {
    37  				errs = append(errs, fmt.Errorf("store for type [%v] does not have a CreateStrategy", k))
    38  			}
    39  			if t.GetUpdateStrategy() == nil {
    40  				errs = append(errs, fmt.Errorf("store for type [%v] does not have an UpdateStrategy", k))
    41  			}
    42  			if t.GetDeleteStrategy() == nil {
    43  				errs = append(errs, fmt.Errorf("store for type [%v] does not have a DeleteStrategy", k))
    44  			}
    45  		}
    46  	}
    47  
    48  	return errs
    49  }
    50  

View as plain text