Files
fission-src/tpr/tpr.go
T
Soam VasaniandGitHub 6f017cf400 Split out the Package type into a first class Kubernetes resource (#295)
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
2017-08-25 13:40:45 -07:00

116 lines
2.8 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/kubernetes"
"k8s.io/client-go/1.5/pkg/api/errors"
"k8s.io/client-go/1.5/pkg/api/v1"
"k8s.io/client-go/1.5/pkg/apis/extensions/v1beta1"
)
// ensureTPR checks if the given TPR type exists, and creates it if
// needed. (Note that this creates the TPR type; it doesn't create any
// _instances_ of that type.)
func ensureTPR(clientset *kubernetes.Clientset, tpr *v1beta1.ThirdPartyResource) error {
_, err := clientset.Extensions().ThirdPartyResources().Get(tpr.ObjectMeta.Name)
if err != nil {
if errors.IsNotFound(err) {
_, err := clientset.Extensions().ThirdPartyResources().Create(tpr)
if err != nil {
return err
}
}
}
return nil
}
func EnsureFissionTPRs(clientset *kubernetes.Clientset) error {
tprs := []v1beta1.ThirdPartyResource{
{
ObjectMeta: v1.ObjectMeta{
Name: "function.fission.io",
},
Versions: []v1beta1.APIVersion{
{Name: "v1"},
},
Description: "Functions",
},
{
ObjectMeta: v1.ObjectMeta{
Name: "environment.fission.io",
},
Versions: []v1beta1.APIVersion{
{Name: "v1"},
},
Description: "Environments (function containers)",
},
{
ObjectMeta: v1.ObjectMeta{
Name: "httptrigger.fission.io",
},
Versions: []v1beta1.APIVersion{
{Name: "v1"},
},
Description: "HTTP triggers for functions",
},
{
ObjectMeta: v1.ObjectMeta{
Name: "kuberneteswatchtrigger.fission.io",
},
Versions: []v1beta1.APIVersion{
{Name: "v1"},
},
Description: "Kubernetes watch triggers for functions",
},
{
ObjectMeta: v1.ObjectMeta{
Name: "timetrigger.fission.io",
},
Versions: []v1beta1.APIVersion{
{Name: "v1"},
},
Description: "Time-based triggers for functions",
},
{
ObjectMeta: v1.ObjectMeta{
Name: "messagequeuetrigger.fission.io",
},
Versions: []v1beta1.APIVersion{
{Name: "v1"},
},
Description: "Message queue triggers for functions",
},
{
ObjectMeta: v1.ObjectMeta{
Name: "package.fission.io",
},
Versions: []v1beta1.APIVersion{
{Name: "v1"},
},
Description: "Packages: archives containing source or binaries for one or more functions",
},
}
for _, tpr := range tprs {
err := ensureTPR(clientset, &tpr)
if err != nil {
return err
}
}
return nil
}