...

Source file src/k8s.io/kubernetes/pkg/registry/discovery/rest/storage_discovery.go

Documentation: k8s.io/kubernetes/pkg/registry/discovery/rest

     1  /*
     2  Copyright 2019 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 rest
    18  
    19  import (
    20  	discoveryv1 "k8s.io/api/discovery/v1"
    21  	"k8s.io/apiserver/pkg/registry/generic"
    22  	"k8s.io/apiserver/pkg/registry/rest"
    23  	genericapiserver "k8s.io/apiserver/pkg/server"
    24  	serverstorage "k8s.io/apiserver/pkg/server/storage"
    25  	"k8s.io/kubernetes/pkg/api/legacyscheme"
    26  	"k8s.io/kubernetes/pkg/apis/discovery"
    27  	endpointslicestorage "k8s.io/kubernetes/pkg/registry/discovery/endpointslice/storage"
    28  )
    29  
    30  // StorageProvider is a REST storage provider for discovery.k8s.io.
    31  type StorageProvider struct{}
    32  
    33  // NewRESTStorage returns a new storage provider.
    34  func (p StorageProvider) NewRESTStorage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (genericapiserver.APIGroupInfo, error) {
    35  	apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(discovery.GroupName, legacyscheme.Scheme, legacyscheme.ParameterCodec, legacyscheme.Codecs)
    36  	// If you add a version here, be sure to add an entry in `k8s.io/kubernetes/cmd/kube-apiserver/app/aggregator.go with specific priorities.
    37  	// TODO refactor the plumbing to provide the information in the APIGroupInfo
    38  
    39  	if storageMap, err := p.v1Storage(apiResourceConfigSource, restOptionsGetter); err != nil {
    40  		return genericapiserver.APIGroupInfo{}, err
    41  	} else if len(storageMap) > 0 {
    42  		apiGroupInfo.VersionedResourcesStorageMap[discoveryv1.SchemeGroupVersion.Version] = storageMap
    43  	}
    44  
    45  	return apiGroupInfo, nil
    46  }
    47  
    48  func (p StorageProvider) v1Storage(apiResourceConfigSource serverstorage.APIResourceConfigSource, restOptionsGetter generic.RESTOptionsGetter) (map[string]rest.Storage, error) {
    49  	storage := map[string]rest.Storage{}
    50  
    51  	if resource := "endpointslices"; apiResourceConfigSource.ResourceEnabled(discoveryv1.SchemeGroupVersion.WithResource(resource)) {
    52  		endpointSliceStorage, err := endpointslicestorage.NewREST(restOptionsGetter)
    53  		if err != nil {
    54  			return storage, err
    55  		}
    56  		storage[resource] = endpointSliceStorage
    57  	}
    58  
    59  	return storage, nil
    60  }
    61  
    62  // GroupName is the group name for the storage provider.
    63  func (p StorageProvider) GroupName() string {
    64  	return discovery.GroupName
    65  }
    66  

View as plain text