/* Copyright 2016 The Fission Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package crd import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" ) type ( EnvironmentInterface interface { Create(*Environment) (*Environment, error) Get(name string) (*Environment, error) Update(*Environment) (*Environment, error) Delete(name string, options *metav1.DeleteOptions) error List(opts metav1.ListOptions) (*EnvironmentList, error) Watch(opts metav1.ListOptions) (watch.Interface, error) } environmentClient struct { client *rest.RESTClient namespace string } ) func MakeEnvironmentInterface(crdClient *rest.RESTClient, namespace string) EnvironmentInterface { return &environmentClient{ client: crdClient, namespace: namespace, } } func (ec *environmentClient) Create(e *Environment) (*Environment, error) { var result Environment err := ec.client.Post(). Resource("environments"). Namespace(ec.namespace). Body(e). Do().Into(&result) if err != nil { return nil, err } return &result, nil } func (ec *environmentClient) Get(name string) (*Environment, error) { var result Environment err := ec.client.Get(). Resource("environments"). Namespace(ec.namespace). Name(name). Do().Into(&result) if err != nil { return nil, err } return &result, nil } func (ec *environmentClient) Update(e *Environment) (*Environment, error) { var result Environment err := ec.client.Put(). Resource("environments"). Namespace(ec.namespace). Name(e.Metadata.Name). Body(e). Do().Into(&result) if err != nil { return nil, err } return &result, nil } func (ec *environmentClient) Delete(name string, opts *metav1.DeleteOptions) error { return ec.client.Delete(). Namespace(ec.namespace). Resource("environments"). Name(name). Body(opts). Do(). Error() } func (ec *environmentClient) List(opts metav1.ListOptions) (*EnvironmentList, error) { var result EnvironmentList err := ec.client.Get(). Namespace(ec.namespace). Resource("environments"). VersionedParams(&opts, scheme.ParameterCodec). Do(). Into(&result) if err != nil { return nil, err } return &result, nil } func (ec *environmentClient) Watch(opts metav1.ListOptions) (watch.Interface, error) { return ec.client.Get(). Prefix("watch"). Namespace(ec.namespace). Resource("environments"). VersionedParams(&opts, scheme.ParameterCodec). Watch() }