github.com/deemoprobe/k8s-first-commit@v0.0.0-20230430165612-a541f1982be3/pkg/registry/controller_registry.go (about)

     1  /*
     2  Copyright 2014 Google Inc. All rights reserved.
     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  package registry
    17  
    18  import (
    19  	"encoding/json"
    20  	"net/url"
    21  
    22  	. "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
    23  	"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
    24  )
    25  
    26  // Implementation of RESTStorage for the api server.
    27  type ControllerRegistryStorage struct {
    28  	registry ControllerRegistry
    29  }
    30  
    31  func MakeControllerRegistryStorage(registry ControllerRegistry) apiserver.RESTStorage {
    32  	return &ControllerRegistryStorage{
    33  		registry: registry,
    34  	}
    35  }
    36  
    37  func (storage *ControllerRegistryStorage) List(*url.URL) (interface{}, error) {
    38  	var result ReplicationControllerList
    39  	controllers, err := storage.registry.ListControllers()
    40  	if err == nil {
    41  		result = ReplicationControllerList{
    42  			Items: controllers,
    43  		}
    44  	}
    45  	return result, err
    46  }
    47  
    48  func (storage *ControllerRegistryStorage) Get(id string) (interface{}, error) {
    49  	return storage.registry.GetController(id)
    50  }
    51  
    52  func (storage *ControllerRegistryStorage) Delete(id string) error {
    53  	return storage.registry.DeleteController(id)
    54  }
    55  
    56  func (storage *ControllerRegistryStorage) Extract(body string) (interface{}, error) {
    57  	result := ReplicationController{}
    58  	err := json.Unmarshal([]byte(body), &result)
    59  	return result, err
    60  }
    61  
    62  func (storage *ControllerRegistryStorage) Create(controller interface{}) error {
    63  	return storage.registry.CreateController(controller.(ReplicationController))
    64  }
    65  
    66  func (storage *ControllerRegistryStorage) Update(controller interface{}) error {
    67  	return storage.registry.UpdateController(controller.(ReplicationController))
    68  }