This changes the core fission function, environment and trigger types. It also changes Fission's storage to use ThirdPartyResources. - Functions are now specified by packages. Functions can also have both source and deployment packages. A package can be specified by a literal, or by a URL. - Environments have a build and runtime component. - Triggers reference functions by a FunctionReference. This is a layer of indirection between triggers and functions, and will allow things like incremental function upgrades in future releases. See Documentation/wip/env-v2.md for design discussion about points 1 and 2. Changes: * V2 Types All types now have a spec, following the pattern of K8s objects. Functions now have source and deployment packages. A Package can be specified by literal, or by URL. Environments now have a builder and runtime component. All triggers use a new FunctionReference to specify the function. This for now only uses a function name, but in the future can be extended to be more flexible. A new FunctionLoadRequest type is added for specialization requests to the environment runtime. * TPR types, TPR init code, and a "fission client" Implements TPR types using the spec types in fission/types.go. Adds code for adding creating TPR types, and convenient types for crud operations on each of our resource types. Adds code for connecting to K8s API and configuring a REST client with fission types set up. * Change old stateful controller into a thin apiserver This apiserver is now simply a stateless api layer on top of the TPR types. At the moment it doesn't do anything that couldn't be done by simply talking to the TPR types. In the future we can have better validation and potentially some higher level APIs (like versioning for example) in here. * Split controller client into files and update for v2 types. * Update CLI for v2 types. As far as possible we keep the CLI flags the same. We'll have to add flags for source/deploy packages and builder/runtime environments. That will come in the next change. * Update poolmgr and fetcher for v2 types. Also adds a poolmgr_test. * Update router for new types. Also adds a function reference resolver, which separates out the job of resolving a FunctionReference to a function. * Update kubewatcher and timer for v2 types. * Update Message Queue trigger type for v2 types. * Minor odds and ends. * Fission bundle CLI updates Remove controllerUrl flag, since we don't need it any more. * Remove etcd deployment (replaced by storing state in TPR) Also update the poolmgr commandline, and use an env var for the fetcher image URL. * Explicit ChecksumType and consts * Clarify separation of environment interface types
209 lines
6.2 KiB
Go
209 lines
6.2 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/api/meta"
|
|
"k8s.io/client-go/1.5/pkg/api/unversioned"
|
|
|
|
"github.com/fission/fission"
|
|
)
|
|
|
|
//
|
|
// To add a Fission TPR type:
|
|
// 1. Create a "spec" type, for everything in the type except metadata
|
|
// 2. Create the type with metadata + the spec
|
|
// 3. Create a list type (for example see FunctionList and Function, below)
|
|
// 4. Add methods at the bottom of this file for satisfying Object and List interfaces
|
|
// 5. Add the type to configureClient in client.go
|
|
// 6. Add the type to EnsureFissionTPRs in tpr.go
|
|
// 7. Add tests to tpr_test.go
|
|
//
|
|
|
|
type (
|
|
// Functions.
|
|
Function struct {
|
|
unversioned.TypeMeta `json:",inline"`
|
|
Metadata api.ObjectMeta `json:"metadata"`
|
|
Spec fission.FunctionSpec `json:"spec"`
|
|
}
|
|
FunctionList struct {
|
|
unversioned.TypeMeta `json:",inline"`
|
|
Metadata unversioned.ListMeta `json:"metadata"`
|
|
|
|
Items []Function `json:"items"`
|
|
}
|
|
|
|
// Environments.
|
|
Environment struct {
|
|
unversioned.TypeMeta `json:",inline"`
|
|
Metadata api.ObjectMeta `json:"metadata"`
|
|
Spec fission.EnvironmentSpec `json:"spec"`
|
|
}
|
|
EnvironmentList struct {
|
|
unversioned.TypeMeta `json:",inline"`
|
|
Metadata unversioned.ListMeta `json:"metadata"`
|
|
|
|
Items []Environment `json:"items"`
|
|
}
|
|
|
|
// HTTP Triggers. (Something in the TPR reflection stuff wants
|
|
// it to be spelled "Httptrigger" not "HTTPTrigger" or even
|
|
// "HttpTrigger". Bleh.)
|
|
Httptrigger struct {
|
|
unversioned.TypeMeta `json:",inline"`
|
|
Metadata api.ObjectMeta `json:"metadata"`
|
|
Spec fission.HTTPTriggerSpec `json:"spec"`
|
|
}
|
|
HttptriggerList struct {
|
|
unversioned.TypeMeta `json:",inline"`
|
|
Metadata unversioned.ListMeta `json:"metadata"`
|
|
|
|
Items []Httptrigger `json:"items"`
|
|
}
|
|
|
|
// Kubernetes Watches as triggers
|
|
Kuberneteswatchtrigger struct {
|
|
unversioned.TypeMeta `json:",inline"`
|
|
Metadata api.ObjectMeta `json:"metadata"`
|
|
Spec fission.KubernetesWatchTriggerSpec `json:"spec"`
|
|
}
|
|
KuberneteswatchtriggerList struct {
|
|
unversioned.TypeMeta `json:",inline"`
|
|
Metadata unversioned.ListMeta `json:"metadata"`
|
|
|
|
Items []Kuberneteswatchtrigger `json:"items"`
|
|
}
|
|
|
|
// Time triggers
|
|
Timetrigger struct {
|
|
unversioned.TypeMeta `json:",inline"`
|
|
Metadata api.ObjectMeta `json:"metadata"`
|
|
Spec fission.TimeTriggerSpec `json:"spec"`
|
|
}
|
|
TimetriggerList struct {
|
|
unversioned.TypeMeta `json:",inline"`
|
|
Metadata unversioned.ListMeta `json:"metadata"`
|
|
|
|
Items []Timetrigger `json:"items"`
|
|
}
|
|
|
|
// Message Queue triggers
|
|
Messagequeuetrigger struct {
|
|
unversioned.TypeMeta `json:",inline"`
|
|
Metadata api.ObjectMeta `json:"metadata"`
|
|
Spec fission.MessageQueueTriggerSpec `json:"spec"`
|
|
}
|
|
MessagequeuetriggerList struct {
|
|
unversioned.TypeMeta `json:",inline"`
|
|
Metadata unversioned.ListMeta `json:"metadata"`
|
|
|
|
Items []Messagequeuetrigger `json:"items"`
|
|
}
|
|
)
|
|
|
|
// Each TPR type needs:
|
|
// GetObjectKind (to satisfy the Object interface)
|
|
//
|
|
// In addition, each singular TPR type needs:
|
|
// GetObjectMeta (to satisfy the ObjectMetaAccessor interface)
|
|
//
|
|
// And each list TPR type needs:
|
|
// GetListMeta (to satisfy the ListMetaAccessor interface)
|
|
|
|
func (f *Function) GetObjectKind() unversioned.ObjectKind {
|
|
return &f.TypeMeta
|
|
}
|
|
func (e *Environment) GetObjectKind() unversioned.ObjectKind {
|
|
return &e.TypeMeta
|
|
}
|
|
func (ht *Httptrigger) GetObjectKind() unversioned.ObjectKind {
|
|
return &ht.TypeMeta
|
|
}
|
|
func (w *Kuberneteswatchtrigger) GetObjectKind() unversioned.ObjectKind {
|
|
return &w.TypeMeta
|
|
}
|
|
func (w *Timetrigger) GetObjectKind() unversioned.ObjectKind {
|
|
return &w.TypeMeta
|
|
}
|
|
func (w *Messagequeuetrigger) GetObjectKind() unversioned.ObjectKind {
|
|
return &w.TypeMeta
|
|
}
|
|
|
|
func (f *Function) GetObjectMeta() meta.Object {
|
|
return &f.Metadata
|
|
}
|
|
func (e *Environment) GetObjectMeta() meta.Object {
|
|
return &e.Metadata
|
|
}
|
|
func (ht *Httptrigger) GetObjectMeta() meta.Object {
|
|
return &ht.Metadata
|
|
}
|
|
func (w *Kuberneteswatchtrigger) GetObjectMeta() meta.Object {
|
|
return &w.Metadata
|
|
}
|
|
func (w *Timetrigger) GetObjectMeta() meta.Object {
|
|
return &w.Metadata
|
|
}
|
|
func (w *Messagequeuetrigger) GetObjectMeta() meta.Object {
|
|
return &w.Metadata
|
|
}
|
|
|
|
func (fl *FunctionList) GetObjectKind() unversioned.ObjectKind {
|
|
return &fl.TypeMeta
|
|
}
|
|
func (el *EnvironmentList) GetObjectKind() unversioned.ObjectKind {
|
|
return &el.TypeMeta
|
|
}
|
|
func (hl *HttptriggerList) GetObjectKind() unversioned.ObjectKind {
|
|
return &hl.TypeMeta
|
|
}
|
|
func (wl *KuberneteswatchtriggerList) GetObjectKind() unversioned.ObjectKind {
|
|
return &wl.TypeMeta
|
|
}
|
|
func (wl *TimetriggerList) GetObjectKind() unversioned.ObjectKind {
|
|
return &wl.TypeMeta
|
|
}
|
|
func (wl *MessagequeuetriggerList) GetObjectKind() unversioned.ObjectKind {
|
|
return &wl.TypeMeta
|
|
}
|
|
|
|
func (fl *FunctionList) GetListMeta() unversioned.List {
|
|
return &fl.Metadata
|
|
}
|
|
func (el *EnvironmentList) GetListMeta() unversioned.List {
|
|
return &el.Metadata
|
|
}
|
|
func (hl *HttptriggerList) GetListMeta() unversioned.List {
|
|
return &hl.Metadata
|
|
}
|
|
func (wl *KuberneteswatchtriggerList) GetListMeta() unversioned.List {
|
|
return &wl.Metadata
|
|
}
|
|
func (wl *TimetriggerList) GetListMeta() unversioned.List {
|
|
return &wl.Metadata
|
|
}
|
|
func (wl *MessagequeuetriggerList) GetListMeta() unversioned.List {
|
|
return &wl.Metadata
|
|
}
|
|
|
|
// In the client-go TPR example, UnmarshalJSON is defined here for the
|
|
// singular and list types. That's supposed to be a workaround for
|
|
// some ugorji bug. But we don't seem to need it, and all our tests
|
|
// pass without it, so we don't define any UnmarshalJSON methods.
|