Split out the Package type into a first class Kubernetes resource. Before this change, packages were implicitly tied to functions. This wasn't ideal because: * Functions will need to share packages * A package storage system may be more generally useful than just functions (for example, for storing static assets) This change does the following: * Updates the fission and tpr types to add a new Package and PackageSpec. It also creates a PackageRef type, and a FunctionPackageRef type. The PackageRef simply references a package, but the FunctionPackageRef includes the name of a function within the package. This allows us to share packages between different functions. * Updates fetcher and other components for first-class packages * Allows customization of fetcher image pull policy in the helm charts
120 lines
2.7 KiB
Go
120 lines
2.7 KiB
Go
/*
|
|
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 tpr
|
|
|
|
import (
|
|
"k8s.io/client-go/1.5/pkg/api"
|
|
"k8s.io/client-go/1.5/pkg/watch"
|
|
"k8s.io/client-go/1.5/rest"
|
|
)
|
|
|
|
type (
|
|
PackageInterface interface {
|
|
Create(*Package) (*Package, error)
|
|
Get(name string) (*Package, error)
|
|
Update(*Package) (*Package, error)
|
|
Delete(name string, options *api.DeleteOptions) error
|
|
List(opts api.ListOptions) (*PackageList, error)
|
|
Watch(opts api.ListOptions) (watch.Interface, error)
|
|
}
|
|
|
|
packageClient struct {
|
|
client *rest.RESTClient
|
|
namespace string
|
|
}
|
|
)
|
|
|
|
func MakePackageInterface(tprClient *rest.RESTClient, namespace string) PackageInterface {
|
|
return &packageClient{
|
|
client: tprClient,
|
|
namespace: namespace,
|
|
}
|
|
}
|
|
|
|
func (c *packageClient) Create(f *Package) (*Package, error) {
|
|
var result Package
|
|
err := c.client.Post().
|
|
Resource("packages").
|
|
Namespace(c.namespace).
|
|
Body(f).
|
|
Do().Into(&result)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
func (c *packageClient) Get(name string) (*Package, error) {
|
|
var result Package
|
|
err := c.client.Get().
|
|
Resource("packages").
|
|
Namespace(c.namespace).
|
|
Name(name).
|
|
Do().Into(&result)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
func (c *packageClient) Update(f *Package) (*Package, error) {
|
|
var result Package
|
|
err := c.client.Put().
|
|
Resource("packages").
|
|
Namespace(c.namespace).
|
|
Name(f.Metadata.Name).
|
|
Body(f).
|
|
Do().Into(&result)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
func (c *packageClient) Delete(name string, opts *api.DeleteOptions) error {
|
|
return c.client.Delete().
|
|
Namespace(c.namespace).
|
|
Resource("packages").
|
|
Name(name).
|
|
Body(opts).
|
|
Do().
|
|
Error()
|
|
}
|
|
|
|
func (c *packageClient) List(opts api.ListOptions) (*PackageList, error) {
|
|
var result PackageList
|
|
err := c.client.Get().
|
|
Namespace(c.namespace).
|
|
Resource("packages").
|
|
VersionedParams(&opts, api.ParameterCodec).
|
|
Do().
|
|
Into(&result)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
func (c *packageClient) Watch(opts api.ListOptions) (watch.Interface, error) {
|
|
return c.client.Get().
|
|
Prefix("watch").
|
|
Namespace(c.namespace).
|
|
Resource("packages").
|
|
VersionedParams(&opts, api.ParameterCodec).
|
|
Watch()
|
|
}
|