Codebase cleanup & optimization (#1493)

Remove old v1 types that are no longer used and move fetcher structs to fetcher directory.
This commit is contained in:
Ta-Ching Chen
2020-01-16 16:47:32 +08:00
committed by GitHub
parent 574fb55fcf
commit bb3e6d6907
37 changed files with 305 additions and 498 deletions
+1 -2
View File
@@ -30,7 +30,6 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"github.com/fission/fission/pkg/fetcher" "github.com/fission/fission/pkg/fetcher"
"github.com/fission/fission/pkg/types"
) )
func registerTraceExporter(collectorEndpoint string) error { func registerTraceExporter(collectorEndpoint string) error {
@@ -94,7 +93,7 @@ func Run(logger *zap.Logger) {
// do specialization in other goroutine to prevent blocking in newdeploy // do specialization in other goroutine to prevent blocking in newdeploy
go func() { go func() {
if *specializeOnStart { if *specializeOnStart {
var specializeReq types.FunctionSpecializeRequest var specializeReq fetcher.FunctionSpecializeRequest
err := json.Unmarshal([]byte(*specializePayload), &specializeReq) err := json.Unmarshal([]byte(*specializePayload), &specializeReq)
if err != nil { if err != nil {
+10 -11
View File
@@ -29,7 +29,6 @@ import (
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/crd" "github.com/fission/fission/pkg/crd"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
) )
@@ -190,33 +189,33 @@ func (client *PreUpgradeTaskClient) SetupRoleBindings() {
// the fact that we're here implies that there had been a prior installation of fission and objects are present still // the fact that we're here implies that there had been a prior installation of fission and objects are present still
// so, we go ahead and create the role-bindings necessary for the fission-fetcher and fission-builder Service Accounts. // so, we go ahead and create the role-bindings necessary for the fission-fetcher and fission-builder Service Accounts.
err := utils.SetupRoleBinding(client.logger, client.k8sClient, types.PackageGetterRB, metav1.NamespaceDefault, types.PackageGetterCR, types.ClusterRole, types.FissionFetcherSA, client.fnPodNs) err := utils.SetupRoleBinding(client.logger, client.k8sClient, fv1.PackageGetterRB, metav1.NamespaceDefault, fv1.PackageGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, client.fnPodNs)
if err != nil { if err != nil {
client.logger.Fatal("error setting up rolebinding for service account", client.logger.Fatal("error setting up rolebinding for service account",
zap.Error(err), zap.Error(err),
zap.String("role_binding", types.PackageGetterRB), zap.String("role_binding", fv1.PackageGetterRB),
zap.String("service_account", types.FissionFetcherSA), zap.String("service_account", fv1.FissionFetcherSA),
zap.String("service_account_namespace", client.fnPodNs)) zap.String("service_account_namespace", client.fnPodNs))
} }
err = utils.SetupRoleBinding(client.logger, client.k8sClient, types.PackageGetterRB, metav1.NamespaceDefault, types.PackageGetterCR, types.ClusterRole, types.FissionBuilderSA, client.envBuilderNs) err = utils.SetupRoleBinding(client.logger, client.k8sClient, fv1.PackageGetterRB, metav1.NamespaceDefault, fv1.PackageGetterCR, fv1.ClusterRole, fv1.FissionBuilderSA, client.envBuilderNs)
if err != nil { if err != nil {
client.logger.Fatal("error setting up rolebinding for service account", client.logger.Fatal("error setting up rolebinding for service account",
zap.Error(err), zap.Error(err),
zap.String("role_binding", types.PackageGetterRB), zap.String("role_binding", fv1.PackageGetterRB),
zap.String("service_account", types.FissionBuilderSA), zap.String("service_account", fv1.FissionBuilderSA),
zap.String("service_account_namespace", client.envBuilderNs)) zap.String("service_account_namespace", client.envBuilderNs))
} }
err = utils.SetupRoleBinding(client.logger, client.k8sClient, types.SecretConfigMapGetterRB, metav1.NamespaceDefault, types.SecretConfigMapGetterCR, types.ClusterRole, types.FissionFetcherSA, client.fnPodNs) err = utils.SetupRoleBinding(client.logger, client.k8sClient, fv1.SecretConfigMapGetterRB, metav1.NamespaceDefault, fv1.SecretConfigMapGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, client.fnPodNs)
if err != nil { if err != nil {
client.logger.Fatal("error setting up rolebinding for service account", client.logger.Fatal("error setting up rolebinding for service account",
zap.Error(err), zap.Error(err),
zap.String("role_binding", types.SecretConfigMapGetterRB), zap.String("role_binding", fv1.SecretConfigMapGetterRB),
zap.String("service_account", types.FissionFetcherSA), zap.String("service_account", fv1.FissionFetcherSA),
zap.String("service_account_namespace", client.fnPodNs)) zap.String("service_account_namespace", client.fnPodNs))
} }
client.logger.Info("created rolebindings in default namespace", client.logger.Info("created rolebindings in default namespace",
zap.Strings("role_bindings", []string{types.PackageGetterRB, types.SecretConfigMapGetterRB})) zap.Strings("role_bindings", []string{fv1.PackageGetterRB, fv1.SecretConfigMapGetterRB}))
} }
+39
View File
@@ -105,3 +105,42 @@ const (
const ( const (
DefaultSpecializationTimeOut = 120 DefaultSpecializationTimeOut = 120
) )
const (
FETCH_SOURCE = iota
FETCH_DEPLOYMENT
FETCH_URL
)
// executor kubernetes object label key
const (
ENVIRONMENT_NAMESPACE = "environmentNamespace"
ENVIRONMENT_NAME = "environmentName"
ENVIRONMENT_UID = "environmentUid"
FUNCTION_NAMESPACE = "functionNamespace"
FUNCTION_NAME = "functionName"
FUNCTION_UID = "functionUid"
FUNCTION_RESOURCE_VERSION = "functionResourceVersion"
EXECUTOR_TYPE = "executorType"
)
const (
ANNOTATION_SVC_HOST = "svcHost"
)
const (
ArchiveLiteralSizeLimit int64 = 256 * 1024
)
const (
FissionBuilderSA = "fission-builder"
FissionFetcherSA = "fission-fetcher"
SecretConfigMapGetterCR = "secret-configmap-getter"
SecretConfigMapGetterRB = "secret-configmap-getter-binding"
PackageGetterCR = "package-getter"
PackageGetterRB = "package-getter-binding"
ClusterRole = "ClusterRole"
)
+8 -8
View File
@@ -19,7 +19,6 @@ package buildermgr
import ( import (
"context" "context"
"fmt" "fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"net/http" "net/http"
"strings" "strings"
"time" "time"
@@ -27,14 +26,15 @@ import (
"github.com/dchest/uniuri" "github.com/dchest/uniuri"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/builder" "github.com/fission/fission/pkg/builder"
builderClient "github.com/fission/fission/pkg/builder/client" builderClient "github.com/fission/fission/pkg/builder/client"
"github.com/fission/fission/pkg/crd" "github.com/fission/fission/pkg/crd"
ferror "github.com/fission/fission/pkg/error" ferror "github.com/fission/fission/pkg/error"
"github.com/fission/fission/pkg/fetcher"
fetcherClient "github.com/fission/fission/pkg/fetcher/client" fetcherClient "github.com/fission/fission/pkg/fetcher/client"
"github.com/fission/fission/pkg/types"
) )
// buildPackage helps to build source package into deployment package. // buildPackage helps to build source package into deployment package.
@@ -45,7 +45,7 @@ import (
// 4. Return upload response and build logs. // 4. Return upload response and build logs.
// *. Return build logs and error if any one of steps above failed. // *. Return build logs and error if any one of steps above failed.
func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.FissionClient, envBuilderNamespace string, func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.FissionClient, envBuilderNamespace string,
storageSvcUrl string, pkg *fv1.Package) (uploadResp *types.ArchiveUploadResponse, buildLogs string, err error) { storageSvcUrl string, pkg *fv1.Package) (uploadResp *fetcher.ArchiveUploadResponse, buildLogs string, err error) {
env, err := fissionClient.V1().Environments(pkg.Spec.Environment.Namespace).Get(pkg.Spec.Environment.Name, metav1.GetOptions{}) env, err := fissionClient.V1().Environments(pkg.Spec.Environment.Namespace).Get(pkg.Spec.Environment.Name, metav1.GetOptions{})
if err != nil { if err != nil {
@@ -60,8 +60,8 @@ func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.Fi
fetcherC := fetcherClient.MakeClient(logger, fmt.Sprintf("http://%v:8000", svcName)) fetcherC := fetcherClient.MakeClient(logger, fmt.Sprintf("http://%v:8000", svcName))
builderC := builderClient.MakeClient(logger, fmt.Sprintf("http://%v:8001", svcName)) builderC := builderClient.MakeClient(logger, fmt.Sprintf("http://%v:8001", svcName))
fetchReq := &types.FunctionFetchRequest{ fetchReq := &fetcher.FunctionFetchRequest{
FetchType: types.FETCH_SOURCE, FetchType: fv1.FETCH_SOURCE,
Package: pkg.ObjectMeta, Package: pkg.ObjectMeta,
Filename: srcPkgFilename, Filename: srcPkgFilename,
KeepArchive: false, KeepArchive: false,
@@ -103,7 +103,7 @@ func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.Fi
archivePackage := !env.Spec.KeepArchive archivePackage := !env.Spec.KeepArchive
uploadReq := &types.ArchiveUploadRequest{ uploadReq := &fetcher.ArchiveUploadRequest{
Filename: buildResp.ArtifactFilename, Filename: buildResp.ArtifactFilename,
StorageSvcUrl: storageSvcUrl, StorageSvcUrl: storageSvcUrl,
ArchivePackage: archivePackage, ArchivePackage: archivePackage,
@@ -123,7 +123,7 @@ func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.Fi
func updatePackage(logger *zap.Logger, fissionClient *crd.FissionClient, func updatePackage(logger *zap.Logger, fissionClient *crd.FissionClient,
pkg *fv1.Package, status fv1.BuildStatus, buildLogs string, pkg *fv1.Package, status fv1.BuildStatus, buildLogs string,
uploadResp *types.ArchiveUploadResponse) (*fv1.Package, error) { uploadResp *fetcher.ArchiveUploadResponse) (*fv1.Package, error) {
pkg.Status = fv1.PackageStatus{ pkg.Status = fv1.PackageStatus{
BuildStatus: status, BuildStatus: status,
@@ -133,7 +133,7 @@ func updatePackage(logger *zap.Logger, fissionClient *crd.FissionClient,
if uploadResp != nil { if uploadResp != nil {
pkg.Spec.Deployment = fv1.Archive{ pkg.Spec.Deployment = fv1.Archive{
Type: types.ArchiveTypeUrl, Type: fv1.ArchiveTypeUrl,
URL: uploadResp.ArchiveDownloadUrl, URL: uploadResp.ArchiveDownloadUrl,
Checksum: uploadResp.Checksum, Checksum: uploadResp.Checksum,
} }
+2 -3
View File
@@ -36,7 +36,6 @@ import (
"github.com/fission/fission/pkg/crd" "github.com/fission/fission/pkg/crd"
"github.com/fission/fission/pkg/executor/util" "github.com/fission/fission/pkg/executor/util"
fetcherConfig "github.com/fission/fission/pkg/fetcher/config" fetcherConfig "github.com/fission/fission/pkg/fetcher/config"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
) )
@@ -346,9 +345,9 @@ func (envw *environmentWatcher) createBuilder(env *fv1.Environment, ns string) (
// there should be only one deploy in deployList // there should be only one deploy in deployList
if len(deployList) == 0 { if len(deployList) == 0 {
// create builder SA in this ns, if not already created // create builder SA in this ns, if not already created
_, err := utils.SetupSA(envw.kubernetesClient, types.FissionBuilderSA, ns) _, err := utils.SetupSA(envw.kubernetesClient, fv1.FissionBuilderSA, ns)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "error creating %q in ns: %s", types.FissionBuilderSA, ns) return nil, errors.Wrapf(err, "error creating %q in ns: %s", fv1.FissionBuilderSA, ns)
} }
deploy, err = envw.createBuilderDeployment(env, ns) deploy, err = envw.createBuilderDeployment(env, ns)
+7 -8
View File
@@ -32,7 +32,6 @@ import (
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/cache" "github.com/fission/fission/pkg/cache"
"github.com/fission/fission/pkg/crd" "github.com/fission/fission/pkg/crd"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
) )
@@ -157,17 +156,17 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *fv1.Package)
// Add the package getter rolebinding to builder sa // Add the package getter rolebinding to builder sa
// we continue here if role binding was not setup succeesffully. this is because without this, the fetcher wont be able to fetch the source pkg into the container and // we continue here if role binding was not setup succeesffully. this is because without this, the fetcher wont be able to fetch the source pkg into the container and
// the build will fail eventually // the build will fail eventually
err := utils.SetupRoleBinding(pkgw.logger, pkgw.k8sClient, types.PackageGetterRB, pkg.ObjectMeta.Namespace, types.PackageGetterCR, types.ClusterRole, types.FissionBuilderSA, builderNs) err := utils.SetupRoleBinding(pkgw.logger, pkgw.k8sClient, fv1.PackageGetterRB, pkg.ObjectMeta.Namespace, fv1.PackageGetterCR, fv1.ClusterRole, fv1.FissionBuilderSA, builderNs)
if err != nil { if err != nil {
pkgw.logger.Error("error setting up role binding for package", pkgw.logger.Error("error setting up role binding for package",
zap.Error(err), zap.Error(err),
zap.String("role_binding", types.PackageGetterRB), zap.String("role_binding", fv1.PackageGetterRB),
zap.String("package_name", pkg.ObjectMeta.Name), zap.String("package_name", pkg.ObjectMeta.Name),
zap.String("package_namespace", pkg.ObjectMeta.Namespace)) zap.String("package_namespace", pkg.ObjectMeta.Namespace))
continue continue
} else { } else {
pkgw.logger.Info("setup rolebinding for sa package", pkgw.logger.Info("setup rolebinding for sa package",
zap.String("sa", fmt.Sprintf("%s.%s", types.FissionBuilderSA, builderNs)), zap.String("sa", fmt.Sprintf("%s.%s", fv1.FissionBuilderSA, builderNs)),
zap.String("package", fmt.Sprintf("%s.%s", pkg.ObjectMeta.Name, pkg.ObjectMeta.Namespace))) zap.String("package", fmt.Sprintf("%s.%s", pkg.ObjectMeta.Name, pkg.ObjectMeta.Namespace)))
} }
@@ -175,7 +174,7 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *fv1.Package)
uploadResp, buildLogs, err := buildPackage(ctx, pkgw.logger, pkgw.fissionClient, builderNs, pkgw.storageSvcUrl, pkg) uploadResp, buildLogs, err := buildPackage(ctx, pkgw.logger, pkgw.fissionClient, builderNs, pkgw.storageSvcUrl, pkg)
if err != nil { if err != nil {
pkgw.logger.Error("error building package", zap.Error(err), zap.String("package_name", pkg.ObjectMeta.Name)) pkgw.logger.Error("error building package", zap.Error(err), zap.String("package_name", pkg.ObjectMeta.Name))
updatePackage(pkgw.logger, pkgw.fissionClient, pkg, types.BuildStatusFailed, buildLogs, nil) updatePackage(pkgw.logger, pkgw.fissionClient, pkg, fv1.BuildStatusFailed, buildLogs, nil)
return return
} }
@@ -210,10 +209,10 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *fv1.Package)
} }
_, err = updatePackage(pkgw.logger, pkgw.fissionClient, pkg, _, err = updatePackage(pkgw.logger, pkgw.fissionClient, pkg,
types.BuildStatusSucceeded, buildLogs, uploadResp) fv1.BuildStatusSucceeded, buildLogs, uploadResp)
if err != nil { if err != nil {
pkgw.logger.Error("error updating package info", zap.Error(err), zap.String("package_name", pkg.ObjectMeta.Name)) pkgw.logger.Error("error updating package info", zap.Error(err), zap.String("package_name", pkg.ObjectMeta.Name))
updatePackage(pkgw.logger, pkgw.fissionClient, pkg, types.BuildStatusFailed, buildLogs, nil) updatePackage(pkgw.logger, pkgw.fissionClient, pkg, fv1.BuildStatusFailed, buildLogs, nil)
return return
} }
@@ -223,7 +222,7 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *fv1.Package)
} }
// build timeout // build timeout
updatePackage(pkgw.logger, pkgw.fissionClient, pkg, updatePackage(pkgw.logger, pkgw.fissionClient, pkg,
types.BuildStatusFailed, "Build timeout due to environment builder not ready", nil) fv1.BuildStatusFailed, "Build timeout due to environment builder not ready", nil)
pkgw.logger.Error("max retries exceeded in building source package, timeout due to environment builder not ready", pkgw.logger.Error("max retries exceeded in building source package, timeout due to environment builder not ready",
zap.String("package", fmt.Sprintf("%s.%s", pkg.ObjectMeta.Name, pkg.ObjectMeta.Namespace))) zap.String("package", fmt.Sprintf("%s.%s", pkg.ObjectMeta.Name, pkg.ObjectMeta.Namespace)))
+7 -8
View File
@@ -35,7 +35,6 @@ import (
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/crd" "github.com/fission/fission/pkg/crd"
"github.com/fission/fission/pkg/types"
) )
const ( const (
@@ -112,7 +111,7 @@ func (canaryCfgMgr *canaryConfigMgr) initCanaryConfigController() (k8sCache.Stor
k8sCache.ResourceEventHandlerFuncs{ k8sCache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) { AddFunc: func(obj interface{}) {
canaryConfig := obj.(*fv1.CanaryConfig) canaryConfig := obj.(*fv1.CanaryConfig)
if canaryConfig.Status.Status == types.CanaryConfigStatusPending { if canaryConfig.Status.Status == fv1.CanaryConfigStatusPending {
go canaryCfgMgr.addCanaryConfig(canaryConfig) go canaryCfgMgr.addCanaryConfig(canaryConfig)
} }
}, },
@@ -124,7 +123,7 @@ func (canaryCfgMgr *canaryConfigMgr) initCanaryConfigController() (k8sCache.Stor
oldConfig := oldObj.(*fv1.CanaryConfig) oldConfig := oldObj.(*fv1.CanaryConfig)
newConfig := newObj.(*fv1.CanaryConfig) newConfig := newObj.(*fv1.CanaryConfig)
if oldConfig.ObjectMeta.ResourceVersion != newConfig.ObjectMeta.ResourceVersion && if oldConfig.ObjectMeta.ResourceVersion != newConfig.ObjectMeta.ResourceVersion &&
newConfig.Status.Status == types.CanaryConfigStatusPending { newConfig.Status.Status == fv1.CanaryConfigStatusPending {
canaryCfgMgr.logger.Info("update canary config invoked", canaryCfgMgr.logger.Info("update canary config invoked",
zap.String("name", newConfig.ObjectMeta.Name), zap.String("name", newConfig.ObjectMeta.Name),
zap.String("namespace", newConfig.ObjectMeta.Namespace), zap.String("namespace", newConfig.ObjectMeta.Namespace),
@@ -267,7 +266,7 @@ func (canaryCfgMgr *canaryConfigMgr) RollForwardOrBack(canaryConfig *fv1.CanaryC
} }
// handle a race between ticker.Stop and receiving a notification on ticker.C // handle a race between ticker.Stop and receiving a notification on ticker.C
if canaryConfig.Status.Status != types.CanaryConfigStatusPending { if canaryConfig.Status.Status != fv1.CanaryConfigStatusPending {
canaryCfgMgr.logger.Info("no need of processing the config, not pending anymore", canaryCfgMgr.logger.Info("no need of processing the config, not pending anymore",
zap.String("name", canaryConfig.ObjectMeta.Name), zap.String("name", canaryConfig.ObjectMeta.Name),
zap.String("namespace", canaryConfig.ObjectMeta.Namespace), zap.String("namespace", canaryConfig.ObjectMeta.Namespace),
@@ -275,7 +274,7 @@ func (canaryCfgMgr *canaryConfigMgr) RollForwardOrBack(canaryConfig *fv1.CanaryC
return return
} }
if triggerObj.Spec.FunctionReference.Type == types.FunctionReferenceTypeFunctionWeights && if triggerObj.Spec.FunctionReference.Type == fv1.FunctionReferenceTypeFunctionWeights &&
triggerObj.Spec.FunctionReference.FunctionWeights[canaryConfig.Spec.NewFunction] != 0 { triggerObj.Spec.FunctionReference.FunctionWeights[canaryConfig.Spec.NewFunction] != 0 {
failurePercent, err := canaryCfgMgr.promClient.GetFunctionFailurePercentage(triggerObj.Spec.RelativeURL, triggerObj.Spec.Method, failurePercent, err := canaryCfgMgr.promClient.GetFunctionFailurePercentage(triggerObj.Spec.RelativeURL, triggerObj.Spec.Method,
canaryConfig.Spec.NewFunction, canaryConfig.ObjectMeta.Namespace, canaryConfig.Spec.WeightIncrementDuration) canaryConfig.Spec.NewFunction, canaryConfig.ObjectMeta.Namespace, canaryConfig.Spec.WeightIncrementDuration)
@@ -341,7 +340,7 @@ func (canaryCfgMgr *canaryConfigMgr) RollForwardOrBack(canaryConfig *fv1.CanaryC
// update the status of canary config as done processing, we dont care if we arent able to update because // update the status of canary config as done processing, we dont care if we arent able to update because
// resync takes care of the update // resync takes care of the update
err = canaryCfgMgr.updateCanaryConfigStatusWithRetries(canaryConfig.ObjectMeta.Name, canaryConfig.ObjectMeta.Namespace, err = canaryCfgMgr.updateCanaryConfigStatusWithRetries(canaryConfig.ObjectMeta.Name, canaryConfig.ObjectMeta.Namespace,
types.CanaryConfigStatusSucceeded) fv1.CanaryConfigStatusSucceeded)
if err != nil { if err != nil {
// cant do much after max retries other than logging it. // cant do much after max retries other than logging it.
canaryCfgMgr.logger.Error("error updating canary config after max retries", canaryCfgMgr.logger.Error("error updating canary config after max retries",
@@ -452,7 +451,7 @@ func (canaryCfgMgr *canaryConfigMgr) rollback(canaryConfig *fv1.CanaryConfig, tr
} }
err = canaryCfgMgr.updateCanaryConfigStatusWithRetries(canaryConfig.ObjectMeta.Name, canaryConfig.ObjectMeta.Namespace, err = canaryCfgMgr.updateCanaryConfigStatusWithRetries(canaryConfig.ObjectMeta.Name, canaryConfig.ObjectMeta.Namespace,
types.CanaryConfigStatusFailed) fv1.CanaryConfigStatusFailed)
return err return err
} }
@@ -487,7 +486,7 @@ func (canaryCfgMgr *canaryConfigMgr) reSyncCanaryConfigs() {
for _, obj := range canaryCfgMgr.canaryConfigStore.List() { for _, obj := range canaryCfgMgr.canaryConfigStore.List() {
canaryConfig := obj.(*fv1.CanaryConfig) canaryConfig := obj.(*fv1.CanaryConfig)
_, err := canaryCfgMgr.canaryCfgCancelFuncMap.lookup(&canaryConfig.ObjectMeta) _, err := canaryCfgMgr.canaryCfgCancelFuncMap.lookup(&canaryConfig.ObjectMeta)
if err != nil && canaryConfig.Status.Status == types.CanaryConfigStatusPending { if err != nil && canaryConfig.Status.Status == fv1.CanaryConfigStatusPending {
canaryCfgMgr.logger.Debug("adding canary config from resync loop", canaryCfgMgr.logger.Debug("adding canary config from resync loop",
zap.String("name", canaryConfig.ObjectMeta.Name), zap.String("name", canaryConfig.ObjectMeta.Name),
zap.String("namespace", canaryConfig.ObjectMeta.Namespace), zap.String("namespace", canaryConfig.ObjectMeta.Namespace),
+3 -4
View File
@@ -41,7 +41,6 @@ import (
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
ferror "github.com/fission/fission/pkg/error" ferror "github.com/fission/fission/pkg/error"
"github.com/fission/fission/pkg/types"
) )
func RegisterFunctionRoute(ws *restful.WebService) { func RegisterFunctionRoute(ws *restful.WebService) {
@@ -307,9 +306,9 @@ func (a *API) FunctionPodLogs(w http.ResponseWriter, r *http.Request) {
// Get function Pods first // Get function Pods first
selector := map[string]string{ selector := map[string]string{
types.FUNCTION_UID: string(f.ObjectMeta.UID), fv1.FUNCTION_UID: string(f.ObjectMeta.UID),
types.ENVIRONMENT_NAME: f.Spec.Environment.Name, fv1.ENVIRONMENT_NAME: f.Spec.Environment.Name,
types.ENVIRONMENT_NAMESPACE: f.Spec.Environment.Namespace, fv1.ENVIRONMENT_NAMESPACE: f.Spec.Environment.Namespace,
} }
podList, err := a.kubernetesClient.CoreV1().Pods(podNs).List(metav1.ListOptions{ podList, err := a.kubernetesClient.CoreV1().Pods(podNs).List(metav1.ListOptions{
LabelSelector: labels.Set(selector).AsSelector().String(), LabelSelector: labels.Set(selector).AsSelector().String(),
+4 -5
View File
@@ -25,7 +25,6 @@ import (
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/emicklei/go-restful" "github.com/emicklei/go-restful"
restfulspec "github.com/emicklei/go-restful-openapi" restfulspec "github.com/emicklei/go-restful-openapi"
"github.com/fission/fission/pkg/types"
"github.com/go-openapi/spec" "github.com/go-openapi/spec"
"github.com/gorilla/mux" "github.com/gorilla/mux"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -136,15 +135,15 @@ func (a *API) PackageApiCreate(w http.ResponseWriter, r *http.Request) {
} }
// Ensure size limits // Ensure size limits
if len(f.Spec.Source.Literal) > int(types.ArchiveLiteralSizeLimit) { if len(f.Spec.Source.Literal) > int(fv1.ArchiveLiteralSizeLimit) {
err := ferror.MakeError(ferror.ErrorInvalidArgument, err := ferror.MakeError(ferror.ErrorInvalidArgument,
fmt.Sprintf("Package literal larger than %s", humanize.Bytes(uint64(types.ArchiveLiteralSizeLimit)))) fmt.Sprintf("Package literal larger than %s", humanize.Bytes(uint64(fv1.ArchiveLiteralSizeLimit))))
a.respondWithError(w, err) a.respondWithError(w, err)
return return
} }
if len(f.Spec.Deployment.Literal) > int(types.ArchiveLiteralSizeLimit) { if len(f.Spec.Deployment.Literal) > int(fv1.ArchiveLiteralSizeLimit) {
err := ferror.MakeError(ferror.ErrorInvalidArgument, err := ferror.MakeError(ferror.ErrorInvalidArgument,
fmt.Sprintf("Package literal larger than %s", humanize.Bytes(uint64(types.ArchiveLiteralSizeLimit)))) fmt.Sprintf("Package literal larger than %s", humanize.Bytes(uint64(fv1.ArchiveLiteralSizeLimit))))
a.respondWithError(w, err) a.respondWithError(w, err)
return return
} }
@@ -35,7 +35,6 @@ import (
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/executor/util" "github.com/fission/fission/pkg/executor/util"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
) )
@@ -127,7 +126,7 @@ func (deploy *NewDeploy) setupRBACObjs(deployNamespace string, fn *fv1.Function)
if err != nil { if err != nil {
deploy.logger.Error("error creating fission fetcher service account for function", deploy.logger.Error("error creating fission fetcher service account for function",
zap.Error(err), zap.Error(err),
zap.String("service_account_name", types.FissionFetcherSA), zap.String("service_account_name", fv1.FissionFetcherSA),
zap.String("service_account_namespace", deployNamespace), zap.String("service_account_namespace", deployNamespace),
zap.String("function_name", fn.ObjectMeta.Name), zap.String("function_name", fn.ObjectMeta.Name),
zap.String("function_namespace", fn.ObjectMeta.Namespace)) zap.String("function_namespace", fn.ObjectMeta.Namespace))
@@ -135,22 +134,22 @@ func (deploy *NewDeploy) setupRBACObjs(deployNamespace string, fn *fv1.Function)
} }
// create a cluster role binding for the fetcher SA, if not already created, granting access to do a get on packages in any ns // create a cluster role binding for the fetcher SA, if not already created, granting access to do a get on packages in any ns
err = utils.SetupRoleBinding(deploy.logger, deploy.kubernetesClient, types.PackageGetterRB, fn.Spec.Package.PackageRef.Namespace, types.PackageGetterCR, types.ClusterRole, types.FissionFetcherSA, deployNamespace) err = utils.SetupRoleBinding(deploy.logger, deploy.kubernetesClient, fv1.PackageGetterRB, fn.Spec.Package.PackageRef.Namespace, fv1.PackageGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, deployNamespace)
if err != nil { if err != nil {
deploy.logger.Error("error creating role binding for function", deploy.logger.Error("error creating role binding for function",
zap.Error(err), zap.Error(err),
zap.String("role_binding", types.PackageGetterRB), zap.String("role_binding", fv1.PackageGetterRB),
zap.String("function_name", fn.ObjectMeta.Name), zap.String("function_name", fn.ObjectMeta.Name),
zap.String("function_namespace", fn.ObjectMeta.Namespace)) zap.String("function_namespace", fn.ObjectMeta.Namespace))
return err return err
} }
// create rolebinding in function namespace for fetcherSA.envNamespace to be able to get secrets and configmaps // create rolebinding in function namespace for fetcherSA.envNamespace to be able to get secrets and configmaps
err = utils.SetupRoleBinding(deploy.logger, deploy.kubernetesClient, types.SecretConfigMapGetterRB, fn.ObjectMeta.Namespace, types.SecretConfigMapGetterCR, types.ClusterRole, types.FissionFetcherSA, deployNamespace) err = utils.SetupRoleBinding(deploy.logger, deploy.kubernetesClient, fv1.SecretConfigMapGetterRB, fn.ObjectMeta.Namespace, fv1.SecretConfigMapGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, deployNamespace)
if err != nil { if err != nil {
deploy.logger.Error("error creating role binding for function", deploy.logger.Error("error creating role binding for function",
zap.Error(err), zap.Error(err),
zap.String("role_binding", types.SecretConfigMapGetterRB), zap.String("role_binding", fv1.SecretConfigMapGetterRB),
zap.String("function_name", fn.ObjectMeta.Name), zap.String("function_name", fn.ObjectMeta.Name),
zap.String("function_namespace", fn.ObjectMeta.Namespace)) zap.String("function_namespace", fn.ObjectMeta.Namespace))
return err return err
@@ -46,7 +46,6 @@ import (
"github.com/fission/fission/pkg/executor/reaper" "github.com/fission/fission/pkg/executor/reaper"
fetcherConfig "github.com/fission/fission/pkg/fetcher/config" fetcherConfig "github.com/fission/fission/pkg/fetcher/config"
"github.com/fission/fission/pkg/throttler" "github.com/fission/fission/pkg/throttler"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
) )
@@ -278,7 +277,7 @@ func (deploy *NewDeploy) CleanupOldExecutorObjects() {
errs := &multierror.Error{} errs := &multierror.Error{}
listOpts := metav1.ListOptions{ listOpts := metav1.ListOptions{
LabelSelector: labels.Set(map[string]string{types.EXECUTOR_TYPE: string(fv1.ExecutorTypeNewdeploy)}).AsSelector().String(), LabelSelector: labels.Set(map[string]string{fv1.EXECUTOR_TYPE: string(fv1.ExecutorTypeNewdeploy)}).AsSelector().String(),
} }
err := reaper.CleanupHpa(deploy.logger, deploy.kubernetesClient, deploy.instanceID, listOpts) err := reaper.CleanupHpa(deploy.logger, deploy.kubernetesClient, deploy.instanceID, listOpts)
@@ -744,20 +743,20 @@ func (deploy *NewDeploy) getObjName(fn *fv1.Function) string {
func (deploy *NewDeploy) getDeployLabels(fnMeta metav1.ObjectMeta, envMeta metav1.ObjectMeta) map[string]string { func (deploy *NewDeploy) getDeployLabels(fnMeta metav1.ObjectMeta, envMeta metav1.ObjectMeta) map[string]string {
return map[string]string{ return map[string]string{
types.EXECUTOR_TYPE: string(fv1.ExecutorTypeNewdeploy), fv1.EXECUTOR_TYPE: string(fv1.ExecutorTypeNewdeploy),
types.ENVIRONMENT_NAME: envMeta.Name, fv1.ENVIRONMENT_NAME: envMeta.Name,
types.ENVIRONMENT_NAMESPACE: envMeta.Namespace, fv1.ENVIRONMENT_NAMESPACE: envMeta.Namespace,
types.ENVIRONMENT_UID: string(envMeta.UID), fv1.ENVIRONMENT_UID: string(envMeta.UID),
types.FUNCTION_NAME: fnMeta.Name, fv1.FUNCTION_NAME: fnMeta.Name,
types.FUNCTION_NAMESPACE: fnMeta.Namespace, fv1.FUNCTION_NAMESPACE: fnMeta.Namespace,
types.FUNCTION_UID: string(fnMeta.UID), fv1.FUNCTION_UID: string(fnMeta.UID),
} }
} }
func (deploy *NewDeploy) getDeployAnnotations(fnMeta metav1.ObjectMeta) map[string]string { func (deploy *NewDeploy) getDeployAnnotations(fnMeta metav1.ObjectMeta) map[string]string {
return map[string]string{ return map[string]string{
types.EXECUTOR_INSTANCEID_LABEL: deploy.instanceID, fv1.EXECUTOR_INSTANCEID_LABEL: deploy.instanceID,
types.FUNCTION_RESOURCE_VERSION: fnMeta.ResourceVersion, fv1.FUNCTION_RESOURCE_VERSION: fnMeta.ResourceVersion,
} }
} }
@@ -19,7 +19,6 @@ package poolmgr
import ( import (
"time" "time"
"github.com/fission/fission/pkg/types"
"go.uber.org/zap" "go.uber.org/zap"
apiv1 "k8s.io/api/core/v1" apiv1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors" kerrors "k8s.io/apimachinery/pkg/api/errors"
@@ -74,12 +73,12 @@ func (gpm *GenericPoolManager) makeFuncController(fissionClient *crd.FissionClie
// setup rolebinding is tried, if it fails, we dont return. we just log an error and move on, because : // setup rolebinding is tried, if it fails, we dont return. we just log an error and move on, because :
// 1. not all functions have secrets and/or configmaps, so things will work without this rolebinding in that case. // 1. not all functions have secrets and/or configmaps, so things will work without this rolebinding in that case.
// 2. on the contrary, when the route is tried, the env fetcher logs will show a 403 forbidden message and same will be relayed to executor. // 2. on the contrary, when the route is tried, the env fetcher logs will show a 403 forbidden message and same will be relayed to executor.
err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, types.SecretConfigMapGetterRB, fn.ObjectMeta.Namespace, types.SecretConfigMapGetterCR, types.ClusterRole, types.FissionFetcherSA, envNs) err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, fv1.SecretConfigMapGetterRB, fn.ObjectMeta.Namespace, fv1.SecretConfigMapGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, envNs)
if err != nil { if err != nil {
gpm.logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", types.SecretConfigMapGetterRB)) gpm.logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", fv1.SecretConfigMapGetterRB))
} else { } else {
gpm.logger.Debug("successfully set up rolebinding for fetcher service account for function", gpm.logger.Debug("successfully set up rolebinding for fetcher service account for function",
zap.String("service_account", types.FissionFetcherSA), zap.String("service_account", fv1.FissionFetcherSA),
zap.String("service_account_namepsace", envNs), zap.String("service_account_namepsace", envNs),
zap.String("function_name", fn.ObjectMeta.Name), zap.String("function_name", fn.ObjectMeta.Name),
zap.String("function_namespace", fn.ObjectMeta.Namespace)) zap.String("function_namespace", fn.ObjectMeta.Namespace))
@@ -187,15 +186,15 @@ func (gpm *GenericPoolManager) makeFuncController(fissionClient *crd.FissionClie
envNs = newFunc.Spec.Environment.Namespace envNs = newFunc.Spec.Environment.Namespace
} }
err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, types.SecretConfigMapGetterRB, err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, fv1.SecretConfigMapGetterRB,
newFunc.ObjectMeta.Namespace, types.SecretConfigMapGetterCR, types.ClusterRole, newFunc.ObjectMeta.Namespace, fv1.SecretConfigMapGetterCR, fv1.ClusterRole,
types.FissionFetcherSA, envNs) fv1.FissionFetcherSA, envNs)
if err != nil { if err != nil {
gpm.logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", types.SecretConfigMapGetterRB)) gpm.logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", fv1.SecretConfigMapGetterRB))
} else { } else {
gpm.logger.Debug("successfully set up rolebinding for fetcher service account for function", gpm.logger.Debug("successfully set up rolebinding for fetcher service account for function",
zap.String("service_account", types.FissionFetcherSA), zap.String("service_account", fv1.FissionFetcherSA),
zap.String("service_account_namepsace", envNs), zap.String("service_account_namepsace", envNs),
zap.String("function_name", newFunc.ObjectMeta.Name), zap.String("function_name", newFunc.ObjectMeta.Name),
zap.String("function_namespace", newFunc.ObjectMeta.Namespace)) zap.String("function_namespace", newFunc.ObjectMeta.Namespace))
+11 -12
View File
@@ -26,7 +26,6 @@ import (
"time" "time"
"github.com/dchest/uniuri" "github.com/dchest/uniuri"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
multierror "github.com/hashicorp/go-multierror" multierror "github.com/hashicorp/go-multierror"
"github.com/pkg/errors" "github.com/pkg/errors"
@@ -148,11 +147,11 @@ func MakeGenericPool(
func (gp *GenericPool) getEnvironmentPoolLabels() map[string]string { func (gp *GenericPool) getEnvironmentPoolLabels() map[string]string {
return map[string]string{ return map[string]string{
types.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr), fv1.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr),
types.ENVIRONMENT_NAME: gp.env.ObjectMeta.Name, fv1.ENVIRONMENT_NAME: gp.env.ObjectMeta.Name,
types.ENVIRONMENT_NAMESPACE: gp.env.ObjectMeta.Namespace, fv1.ENVIRONMENT_NAMESPACE: gp.env.ObjectMeta.Namespace,
types.ENVIRONMENT_UID: string(gp.env.ObjectMeta.UID), fv1.ENVIRONMENT_UID: string(gp.env.ObjectMeta.UID),
"managed": "true", // this allows us to easily find pods managed by the deployment "managed": "true", // this allows us to easily find pods managed by the deployment
} }
} }
@@ -241,7 +240,7 @@ func (gp *GenericPool) _choosePod(newLabels map[string]string) (*apiv1.Pod, erro
// and make a good scheduling decision. // and make a good scheduling decision.
chosenPod := readyPods[rand.Intn(len(readyPods))] chosenPod := readyPods[rand.Intn(len(readyPods))]
if gp.env.Spec.AllowedFunctionsPerContainer != types.AllowedFunctionsPerContainerInfinite { if gp.env.Spec.AllowedFunctionsPerContainer != fv1.AllowedFunctionsPerContainerInfinite {
// Relabel. If the pod already got picked and // Relabel. If the pod already got picked and
// modified, this should fail; in that case just // modified, this should fail; in that case just
// retry. // retry.
@@ -265,10 +264,10 @@ func (gp *GenericPool) _choosePod(newLabels map[string]string) (*apiv1.Pod, erro
func (gp *GenericPool) labelsForFunction(metadata *metav1.ObjectMeta) map[string]string { func (gp *GenericPool) labelsForFunction(metadata *metav1.ObjectMeta) map[string]string {
label := gp.getEnvironmentPoolLabels() label := gp.getEnvironmentPoolLabels()
label[types.FUNCTION_NAME] = metadata.Name label[fv1.FUNCTION_NAME] = metadata.Name
label[types.FUNCTION_UID] = string(metadata.UID) label[fv1.FUNCTION_UID] = string(metadata.UID)
label[types.FUNCTION_NAMESPACE] = metadata.Namespace // function CRD must stay within same namespace of environment CRD label[fv1.FUNCTION_NAMESPACE] = metadata.Namespace // function CRD must stay within same namespace of environment CRD
label["managed"] = "false" // this allows us to easily find pods not managed by the deployment label["managed"] = "false" // this allows us to easily find pods not managed by the deployment
return label return label
} }
@@ -634,7 +633,7 @@ func (gp *GenericPool) getFuncSvc(ctx context.Context, fn *fv1.Function) (*fscac
// patch svc-host and resource version to the pod annotations for new executor to adopt the pod // patch svc-host and resource version to the pod annotations for new executor to adopt the pod
patch := fmt.Sprintf(`{"metadata":{"annotations":{"%v":"%v","%v":"%v"}}}`, patch := fmt.Sprintf(`{"metadata":{"annotations":{"%v":"%v","%v":"%v"}}}`,
types.ANNOTATION_SVC_HOST, svcHost, types.FUNCTION_RESOURCE_VERSION, fn.ObjectMeta.ResourceVersion) fv1.ANNOTATION_SVC_HOST, svcHost, fv1.FUNCTION_RESOURCE_VERSION, fn.ObjectMeta.ResourceVersion)
p, err := gp.kubernetesClient.CoreV1().Pods(pod.Namespace).Patch(pod.Name, k8sTypes.StrategicMergePatchType, []byte(patch)) p, err := gp.kubernetesClient.CoreV1().Pods(pod.Namespace).Patch(pod.Name, k8sTypes.StrategicMergePatchType, []byte(patch))
if err != nil { if err != nil {
// just log the error since it won't affect the function serving // just log the error since it won't affect the function serving
+12 -13
View File
@@ -43,7 +43,6 @@ import (
"github.com/fission/fission/pkg/executor/fscache" "github.com/fission/fission/pkg/executor/fscache"
"github.com/fission/fission/pkg/executor/reaper" "github.com/fission/fission/pkg/executor/reaper"
fetcherConfig "github.com/fission/fission/pkg/fetcher/config" fetcherConfig "github.com/fission/fission/pkg/fetcher/config"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
) )
@@ -278,7 +277,7 @@ func (gpm *GenericPoolManager) AdoptExistingResources() {
} }
l := map[string]string{ l := map[string]string{
types.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr), fv1.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr),
} }
podList, err := gpm.kubernetesClient.CoreV1().Pods(metav1.NamespaceAll).List(metav1.ListOptions{ podList, err := gpm.kubernetesClient.CoreV1().Pods(metav1.NamespaceAll).List(metav1.ListOptions{
@@ -303,7 +302,7 @@ func (gpm *GenericPoolManager) AdoptExistingResources() {
// avoid too many requests arrive Kubernetes API server at the same time. // avoid too many requests arrive Kubernetes API server at the same time.
time.Sleep(time.Duration(rand.Intn(30)) * time.Millisecond) time.Sleep(time.Duration(rand.Intn(30)) * time.Millisecond)
patch := fmt.Sprintf(`{"metadata":{"annotations":{"%v":"%v"}}}`, types.EXECUTOR_INSTANCEID_LABEL, gpm.instanceId) patch := fmt.Sprintf(`{"metadata":{"annotations":{"%v":"%v"}}}`, fv1.EXECUTOR_INSTANCEID_LABEL, gpm.instanceId)
pod, err = gpm.kubernetesClient.CoreV1().Pods(pod.Namespace).Patch(pod.Name, k8sTypes.StrategicMergePatchType, []byte(patch)) pod, err = gpm.kubernetesClient.CoreV1().Pods(pod.Namespace).Patch(pod.Name, k8sTypes.StrategicMergePatchType, []byte(patch))
if err != nil { if err != nil {
// just log the error since it won't affect the function serving // just log the error since it won't affect the function serving
@@ -317,13 +316,13 @@ func (gpm *GenericPoolManager) AdoptExistingResources() {
return return
} }
fnName, ok1 := pod.Labels[types.FUNCTION_NAME] fnName, ok1 := pod.Labels[fv1.FUNCTION_NAME]
fnNS, ok2 := pod.Labels[types.FUNCTION_NAMESPACE] fnNS, ok2 := pod.Labels[fv1.FUNCTION_NAMESPACE]
fnUID, ok3 := pod.Labels[types.FUNCTION_UID] fnUID, ok3 := pod.Labels[fv1.FUNCTION_UID]
fnRV, ok4 := pod.Annotations[types.FUNCTION_RESOURCE_VERSION] fnRV, ok4 := pod.Annotations[fv1.FUNCTION_RESOURCE_VERSION]
envName, ok5 := pod.Labels[types.ENVIRONMENT_NAME] envName, ok5 := pod.Labels[fv1.ENVIRONMENT_NAME]
envNS, ok6 := pod.Labels[types.ENVIRONMENT_NAMESPACE] envNS, ok6 := pod.Labels[fv1.ENVIRONMENT_NAMESPACE]
svcHost, ok7 := pod.Annotations[types.ANNOTATION_SVC_HOST] svcHost, ok7 := pod.Annotations[fv1.ANNOTATION_SVC_HOST]
env, ok8 := envMap[fmt.Sprintf("%v/%v", envNS, envName)] env, ok8 := envMap[fmt.Sprintf("%v/%v", envNS, envName)]
if !(ok1 && ok2 && ok3 && ok4 && ok5 && ok6 && ok7 && ok8) { if !(ok1 && ok2 && ok3 && ok4 && ok5 && ok6 && ok7 && ok8) {
@@ -382,7 +381,7 @@ func (gpm *GenericPoolManager) CleanupOldExecutorObjects() {
errs := &multierror.Error{} errs := &multierror.Error{}
listOpts := metav1.ListOptions{ listOpts := metav1.ListOptions{
LabelSelector: labels.Set(map[string]string{types.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr)}).AsSelector().String(), LabelSelector: labels.Set(map[string]string{fv1.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr)}).AsSelector().String(),
} }
err := reaper.CleanupDeployments(gpm.logger, gpm.kubernetesClient, gpm.instanceId, listOpts) err := reaper.CleanupDeployments(gpm.logger, gpm.kubernetesClient, gpm.instanceId, listOpts)
@@ -412,7 +411,7 @@ func (gpm *GenericPoolManager) service() {
if !ok { if !ok {
poolsize := gpm.getEnvPoolsize(req.env) poolsize := gpm.getEnvPoolsize(req.env)
switch req.env.Spec.AllowedFunctionsPerContainer { switch req.env.Spec.AllowedFunctionsPerContainer {
case types.AllowedFunctionsPerContainerInfinite: case fv1.AllowedFunctionsPerContainerInfinite:
poolsize = 1 poolsize = 1
} }
@@ -589,7 +588,7 @@ func (gpm *GenericPoolManager) idleObjectReaper() {
zap.String("function", fsvc.Name)) zap.String("function", fsvc.Name))
} }
if fsvc.Environment.Spec.AllowedFunctionsPerContainer == types.AllowedFunctionsPerContainerInfinite { if fsvc.Environment.Spec.AllowedFunctionsPerContainer == fv1.AllowedFunctionsPerContainerInfinite {
continue continue
} }
@@ -19,7 +19,6 @@ package poolmgr
import ( import (
"time" "time"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
"go.uber.org/zap" "go.uber.org/zap"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -53,18 +52,18 @@ func (gpm *GenericPoolManager) makePkgController(fissionClient *crd.FissionClien
// here, we return if we hit an error during rolebinding setup. this is because this rolebinding is mandatory for // here, we return if we hit an error during rolebinding setup. this is because this rolebinding is mandatory for
// every function's package to be loaded into its env. without that, there's no point to move forward. // every function's package to be loaded into its env. without that, there's no point to move forward.
err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, types.PackageGetterRB, pkg.ObjectMeta.Namespace, types.PackageGetterCR, types.ClusterRole, types.FissionFetcherSA, envNs) err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, fv1.PackageGetterRB, pkg.ObjectMeta.Namespace, fv1.PackageGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, envNs)
if err != nil { if err != nil {
gpm.logger.Error("error creating rolebinding for package", gpm.logger.Error("error creating rolebinding for package",
zap.Error(err), zap.Error(err),
zap.String("role_binding", types.PackageGetterRB), zap.String("role_binding", fv1.PackageGetterRB),
zap.String("package_name", pkg.ObjectMeta.Name), zap.String("package_name", pkg.ObjectMeta.Name),
zap.String("package_namespace", pkg.ObjectMeta.Namespace)) zap.String("package_namespace", pkg.ObjectMeta.Namespace))
return return
} }
gpm.logger.Debug("successfully set up rolebinding for fetcher service account", gpm.logger.Debug("successfully set up rolebinding for fetcher service account",
zap.String("service_account", types.FissionFetcherSA), zap.String("service_account", fv1.FissionFetcherSA),
zap.String("service_account_namespace", envNs), zap.String("service_account_namespace", envNs),
zap.String("package_name", pkg.ObjectMeta.Name), zap.String("package_name", pkg.ObjectMeta.Name),
zap.String("package_namespace", pkg.ObjectMeta.Namespace)) zap.String("package_namespace", pkg.ObjectMeta.Namespace))
@@ -87,20 +86,20 @@ func (gpm *GenericPoolManager) makePkgController(fissionClient *crd.FissionClien
envNs = newPkg.Spec.Environment.Namespace envNs = newPkg.Spec.Environment.Namespace
} }
err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, types.PackageGetterRB, err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, fv1.PackageGetterRB,
newPkg.ObjectMeta.Namespace, types.PackageGetterCR, types.ClusterRole, newPkg.ObjectMeta.Namespace, fv1.PackageGetterCR, fv1.ClusterRole,
types.FissionFetcherSA, envNs) fv1.FissionFetcherSA, envNs)
if err != nil { if err != nil {
gpm.logger.Error("error updating rolebinding for package", gpm.logger.Error("error updating rolebinding for package",
zap.Error(err), zap.Error(err),
zap.String("role_binding", types.PackageGetterRB), zap.String("role_binding", fv1.PackageGetterRB),
zap.String("package_name", newPkg.ObjectMeta.Name), zap.String("package_name", newPkg.ObjectMeta.Name),
zap.String("package_namespace", newPkg.ObjectMeta.Namespace)) zap.String("package_namespace", newPkg.ObjectMeta.Namespace))
return return
} }
gpm.logger.Debug("successfully updated rolebinding for fetcher service account", gpm.logger.Debug("successfully updated rolebinding for fetcher service account",
zap.String("service_account", types.FissionFetcherSA), zap.String("service_account", fv1.FissionFetcherSA),
zap.String("service_account_namespace", envNs), zap.String("service_account_namespace", envNs),
zap.String("package_name", newPkg.ObjectMeta.Name), zap.String("package_name", newPkg.ObjectMeta.Name),
zap.String("package_namespace", newPkg.ObjectMeta.Namespace)) zap.String("package_namespace", newPkg.ObjectMeta.Namespace))
+13 -14
View File
@@ -27,7 +27,6 @@ import (
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/crd" "github.com/fission/fission/pkg/crd"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
) )
@@ -75,10 +74,10 @@ func CleanupDeployments(logger *zap.Logger, client *kubernetes.Clientset, instan
return err return err
} }
for _, dep := range deploymentList.Items { for _, dep := range deploymentList.Items {
id, ok := dep.ObjectMeta.Annotations[types.EXECUTOR_INSTANCEID_LABEL] id, ok := dep.ObjectMeta.Annotations[fv1.EXECUTOR_INSTANCEID_LABEL]
if !ok { if !ok {
// Backward compatibility with older label name // Backward compatibility with older label name
id, ok = dep.ObjectMeta.Labels[types.EXECUTOR_INSTANCEID_LABEL] id, ok = dep.ObjectMeta.Labels[fv1.EXECUTOR_INSTANCEID_LABEL]
} }
if ok && id != instanceId { if ok && id != instanceId {
logger.Info("cleaning up deployment", zap.String("deployment", dep.ObjectMeta.Name)) logger.Info("cleaning up deployment", zap.String("deployment", dep.ObjectMeta.Name))
@@ -101,10 +100,10 @@ func CleanupPods(logger *zap.Logger, client *kubernetes.Clientset, instanceId st
return err return err
} }
for _, pod := range podList.Items { for _, pod := range podList.Items {
id, ok := pod.ObjectMeta.Annotations[types.EXECUTOR_INSTANCEID_LABEL] id, ok := pod.ObjectMeta.Annotations[fv1.EXECUTOR_INSTANCEID_LABEL]
if !ok { if !ok {
// Backward compatibility with older label name // Backward compatibility with older label name
id, ok = pod.ObjectMeta.Labels[types.EXECUTOR_INSTANCEID_LABEL] id, ok = pod.ObjectMeta.Labels[fv1.EXECUTOR_INSTANCEID_LABEL]
} }
if ok && id != instanceId { if ok && id != instanceId {
logger.Info("cleaning up pod", zap.String("pod", pod.ObjectMeta.Name)) logger.Info("cleaning up pod", zap.String("pod", pod.ObjectMeta.Name))
@@ -127,10 +126,10 @@ func CleanupServices(logger *zap.Logger, client *kubernetes.Clientset, instanceI
return err return err
} }
for _, svc := range svcList.Items { for _, svc := range svcList.Items {
id, ok := svc.ObjectMeta.Annotations[types.EXECUTOR_INSTANCEID_LABEL] id, ok := svc.ObjectMeta.Annotations[fv1.EXECUTOR_INSTANCEID_LABEL]
if !ok { if !ok {
// Backward compatibility with older label name // Backward compatibility with older label name
id, ok = svc.ObjectMeta.Labels[types.EXECUTOR_INSTANCEID_LABEL] id, ok = svc.ObjectMeta.Labels[fv1.EXECUTOR_INSTANCEID_LABEL]
} }
if ok && id != instanceId { if ok && id != instanceId {
logger.Info("cleaning up service", zap.String("service", svc.ObjectMeta.Name)) logger.Info("cleaning up service", zap.String("service", svc.ObjectMeta.Name))
@@ -154,10 +153,10 @@ func CleanupHpa(logger *zap.Logger, client *kubernetes.Clientset, instanceId str
} }
for _, hpa := range hpaList.Items { for _, hpa := range hpaList.Items {
id, ok := hpa.ObjectMeta.Annotations[types.EXECUTOR_INSTANCEID_LABEL] id, ok := hpa.ObjectMeta.Annotations[fv1.EXECUTOR_INSTANCEID_LABEL]
if !ok { if !ok {
// Backward compatibility with older label name // Backward compatibility with older label name
id, ok = hpa.ObjectMeta.Labels[types.EXECUTOR_INSTANCEID_LABEL] id, ok = hpa.ObjectMeta.Labels[fv1.EXECUTOR_INSTANCEID_LABEL]
} }
if ok && id != instanceId { if ok && id != instanceId {
logger.Info("cleaning up HPA", zap.String("hpa", hpa.ObjectMeta.Name)) logger.Info("cleaning up HPA", zap.String("hpa", hpa.ObjectMeta.Name))
@@ -199,7 +198,7 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi
} }
// ignore role-bindings not created by fission // ignore role-bindings not created by fission
if roleBinding.Name != types.PackageGetterRB && roleBinding.Name != types.SecretConfigMapGetterRB { if roleBinding.Name != fv1.PackageGetterRB && roleBinding.Name != fv1.SecretConfigMapGetterRB {
continue continue
} }
@@ -250,7 +249,7 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi
// if its a package-getter-rb, we have 2 kinds of SAs and each of them is handled differently // if its a package-getter-rb, we have 2 kinds of SAs and each of them is handled differently
// else if its a secret-configmap-rb, we have only one SA which is fission-fetcher // else if its a secret-configmap-rb, we have only one SA which is fission-fetcher
if roleBinding.Name == types.PackageGetterRB { if roleBinding.Name == fv1.PackageGetterRB {
// check if there is an env obj in saNs // check if there is an env obj in saNs
envList, err := fissionClient.V1().Environments(saNs).List(meta_v1.ListOptions{}) envList, err := fissionClient.V1().Environments(saNs).List(meta_v1.ListOptions{})
if err != nil { if err != nil {
@@ -263,7 +262,7 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi
// if there's at least one function in the role-binding namespace with env reference // if there's at least one function in the role-binding namespace with env reference
// to the SA's namespace. // to the SA's namespace.
// if neither, then we can remove this SA from this role-binding // if neither, then we can remove this SA from this role-binding
if subj.Name == types.FissionBuilderSA { if subj.Name == fv1.FissionBuilderSA {
if len(envList.Items) == 0 && !funcEnvReference { if len(envList.Items) == 0 && !funcEnvReference {
saToRemove[utils.MakeSAMapKey(subj.Name, subj.Namespace)] = true saToRemove[utils.MakeSAMapKey(subj.Name, subj.Namespace)] = true
} }
@@ -273,13 +272,13 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi
// we also need to check if there's at least one function with executor type New deploy // we also need to check if there's at least one function with executor type New deploy
// in the rolebinding's namespace. // in the rolebinding's namespace.
// if none of them are true, then remove this SA from this role-binding // if none of them are true, then remove this SA from this role-binding
if subj.Name == types.FissionFetcherSA { if subj.Name == fv1.FissionFetcherSA {
if len(envList.Items) == 0 && !ndmFunc && !funcEnvReference { if len(envList.Items) == 0 && !ndmFunc && !funcEnvReference {
// remove SA from rolebinding // remove SA from rolebinding
saToRemove[utils.MakeSAMapKey(subj.Name, subj.Namespace)] = true saToRemove[utils.MakeSAMapKey(subj.Name, subj.Namespace)] = true
} }
} }
} else if roleBinding.Name == types.SecretConfigMapGetterRB { } else if roleBinding.Name == fv1.SecretConfigMapGetterRB {
// if there's not even one function in the role-binding's namespace and there's not even // if there's not even one function in the role-binding's namespace and there's not even
// one function with env reference to the SA's namespace, then remove that SA // one function with env reference to the SA's namespace, then remove that SA
// from this role-binding // from this role-binding
+5 -5
View File
@@ -15,7 +15,7 @@ import (
"golang.org/x/net/context/ctxhttp" "golang.org/x/net/context/ctxhttp"
ferror "github.com/fission/fission/pkg/error" ferror "github.com/fission/fission/pkg/error"
"github.com/fission/fission/pkg/types" "github.com/fission/fission/pkg/fetcher"
) )
type ( type (
@@ -48,23 +48,23 @@ func (c *Client) getUploadUrl() string {
return c.url + "/upload" return c.url + "/upload"
} }
func (c *Client) Specialize(ctx context.Context, req *types.FunctionSpecializeRequest) error { func (c *Client) Specialize(ctx context.Context, req *fetcher.FunctionSpecializeRequest) error {
_, err := sendRequest(c.logger, ctx, c.httpClient, req, c.getSpecializeUrl()) _, err := sendRequest(c.logger, ctx, c.httpClient, req, c.getSpecializeUrl())
return err return err
} }
func (c *Client) Fetch(ctx context.Context, fr *types.FunctionFetchRequest) error { func (c *Client) Fetch(ctx context.Context, fr *fetcher.FunctionFetchRequest) error {
_, err := sendRequest(c.logger, ctx, c.httpClient, fr, c.getFetchUrl()) _, err := sendRequest(c.logger, ctx, c.httpClient, fr, c.getFetchUrl())
return err return err
} }
func (c *Client) Upload(ctx context.Context, fr *types.ArchiveUploadRequest) (*types.ArchiveUploadResponse, error) { func (c *Client) Upload(ctx context.Context, fr *fetcher.ArchiveUploadRequest) (*fetcher.ArchiveUploadResponse, error) {
body, err := sendRequest(c.logger, ctx, c.httpClient, fr, c.getUploadUrl()) body, err := sendRequest(c.logger, ctx, c.httpClient, fr, c.getUploadUrl())
if err != nil { if err != nil {
return nil, err return nil, err
} }
uploadResp := types.ArchiveUploadResponse{} uploadResp := fetcher.ArchiveUploadResponse{}
err = json.Unmarshal(body, &uploadResp) err = json.Unmarshal(body, &uploadResp)
if err != nil { if err != nil {
return nil, err return nil, err
+16 -16
View File
@@ -16,7 +16,7 @@ import (
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/types" "github.com/fission/fission/pkg/fetcher"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
) )
@@ -88,14 +88,14 @@ func MakeFetcherConfig(sharedMountPath string) (*Config, error) {
sharedSecretPath: "/secrets", sharedSecretPath: "/secrets",
sharedCfgMapPath: "/configs", sharedCfgMapPath: "/configs",
jaegerCollectorEndpoint: os.Getenv("TRACE_JAEGER_COLLECTOR_ENDPOINT"), jaegerCollectorEndpoint: os.Getenv("TRACE_JAEGER_COLLECTOR_ENDPOINT"),
serviceAccount: types.FissionFetcherSA, serviceAccount: fv1.FissionFetcherSA,
}, nil }, nil
} }
func (cfg *Config) SetupServiceAccount(kubernetesClient *kubernetes.Clientset, namespace string, context interface{}) error { func (cfg *Config) SetupServiceAccount(kubernetesClient *kubernetes.Clientset, namespace string, context interface{}) error {
_, err := utils.SetupSA(kubernetesClient, types.FissionFetcherSA, namespace) _, err := utils.SetupSA(kubernetesClient, fv1.FissionFetcherSA, namespace)
if err != nil { if err != nil {
log.Printf("Error : %v creating %s in ns : %s for: %#v", err, types.FissionFetcherSA, namespace, context) log.Printf("Error : %v creating %s in ns : %s for: %#v", err, fv1.FissionFetcherSA, namespace, context)
return err return err
} }
@@ -106,7 +106,7 @@ func (cfg *Config) SharedMountPath() string {
return cfg.sharedMountPath return cfg.sharedMountPath
} }
func (cfg *Config) NewSpecializeRequest(fn *fv1.Function, env *fv1.Environment) types.FunctionSpecializeRequest { func (cfg *Config) NewSpecializeRequest(fn *fv1.Function, env *fv1.Environment) fetcher.FunctionSpecializeRequest {
// for backward compatibility, since most v1 env // for backward compatibility, since most v1 env
// still try to load user function from hard coded // still try to load user function from hard coded
// path /userfunc/user // path /userfunc/user
@@ -115,9 +115,9 @@ func (cfg *Config) NewSpecializeRequest(fn *fv1.Function, env *fv1.Environment)
targetFilename = string(fn.ObjectMeta.UID) targetFilename = string(fn.ObjectMeta.UID)
} }
return types.FunctionSpecializeRequest{ return fetcher.FunctionSpecializeRequest{
FetchReq: types.FunctionFetchRequest{ FetchReq: fetcher.FunctionFetchRequest{
FetchType: types.FETCH_DEPLOYMENT, FetchType: fv1.FETCH_DEPLOYMENT,
Package: metav1.ObjectMeta{ Package: metav1.ObjectMeta{
Namespace: fn.Spec.Package.PackageRef.Namespace, Namespace: fn.Spec.Package.PackageRef.Namespace,
Name: fn.Spec.Package.PackageRef.Name, Name: fn.Spec.Package.PackageRef.Name,
@@ -127,7 +127,7 @@ func (cfg *Config) NewSpecializeRequest(fn *fv1.Function, env *fv1.Environment)
ConfigMaps: fn.Spec.ConfigMaps, ConfigMaps: fn.Spec.ConfigMaps,
KeepArchive: env.Spec.KeepArchive, KeepArchive: env.Spec.KeepArchive,
}, },
LoadReq: types.FunctionLoadRequest{ LoadReq: fetcher.FunctionLoadRequest{
FilePath: filepath.Join(cfg.sharedMountPath, targetFilename), FilePath: filepath.Join(cfg.sharedMountPath, targetFilename),
FunctionName: fn.Spec.Package.FunctionName, FunctionName: fn.Spec.Package.FunctionName,
FunctionMetadata: &fn.ObjectMeta, FunctionMetadata: &fn.ObjectMeta,
@@ -172,19 +172,19 @@ func (cfg *Config) fetcherCommand(extraArgs ...string) []string {
func (cfg *Config) volumesWithMounts() ([]apiv1.Volume, []apiv1.VolumeMount) { func (cfg *Config) volumesWithMounts() ([]apiv1.Volume, []apiv1.VolumeMount) {
volumes := []apiv1.Volume{ volumes := []apiv1.Volume{
{ {
Name: types.SharedVolumeUserfunc, Name: fv1.SharedVolumeUserfunc,
VolumeSource: apiv1.VolumeSource{ VolumeSource: apiv1.VolumeSource{
EmptyDir: &apiv1.EmptyDirVolumeSource{}, EmptyDir: &apiv1.EmptyDirVolumeSource{},
}, },
}, },
{ {
Name: types.SharedVolumeSecrets, Name: fv1.SharedVolumeSecrets,
VolumeSource: apiv1.VolumeSource{ VolumeSource: apiv1.VolumeSource{
EmptyDir: &apiv1.EmptyDirVolumeSource{}, EmptyDir: &apiv1.EmptyDirVolumeSource{},
}, },
}, },
{ {
Name: types.SharedVolumeConfigmaps, Name: fv1.SharedVolumeConfigmaps,
VolumeSource: apiv1.VolumeSource{ VolumeSource: apiv1.VolumeSource{
EmptyDir: &apiv1.EmptyDirVolumeSource{}, EmptyDir: &apiv1.EmptyDirVolumeSource{},
}, },
@@ -192,15 +192,15 @@ func (cfg *Config) volumesWithMounts() ([]apiv1.Volume, []apiv1.VolumeMount) {
} }
mounts := []apiv1.VolumeMount{ mounts := []apiv1.VolumeMount{
{ {
Name: types.SharedVolumeUserfunc, Name: fv1.SharedVolumeUserfunc,
MountPath: cfg.sharedMountPath, MountPath: cfg.sharedMountPath,
}, },
{ {
Name: types.SharedVolumeSecrets, Name: fv1.SharedVolumeSecrets,
MountPath: cfg.sharedSecretPath, MountPath: cfg.sharedSecretPath,
}, },
{ {
Name: types.SharedVolumeConfigmaps, Name: fv1.SharedVolumeConfigmaps,
MountPath: cfg.sharedCfgMapPath, MountPath: cfg.sharedCfgMapPath,
}, },
} }
@@ -289,7 +289,7 @@ func (cfg *Config) addFetcherToPodSpecWithCommand(podSpec *apiv1.PodSpec, mainCo
podSpec.Volumes = append(podSpec.Volumes, volumes...) podSpec.Volumes = append(podSpec.Volumes, volumes...)
podSpec.Containers = append(podSpec.Containers, c) podSpec.Containers = append(podSpec.Containers, c)
if podSpec.ServiceAccountName == "" { if podSpec.ServiceAccountName == "" {
podSpec.ServiceAccountName = types.FissionFetcherSA podSpec.ServiceAccountName = fv1.FissionFetcherSA
} }
return nil return nil
+12 -13
View File
@@ -42,7 +42,6 @@ import (
"github.com/fission/fission/pkg/error/network" "github.com/fission/fission/pkg/error/network"
"github.com/fission/fission/pkg/info" "github.com/fission/fission/pkg/info"
storageSvcClient "github.com/fission/fission/pkg/storagesvc/client" storageSvcClient "github.com/fission/fission/pkg/storagesvc/client"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
) )
@@ -139,7 +138,7 @@ func (fetcher *Fetcher) FetchHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
var req types.FunctionFetchRequest var req FunctionFetchRequest
err = json.Unmarshal(body, &req) err = json.Unmarshal(body, &req)
if err != nil { if err != nil {
fetcher.logger.Error("error parsing request body", zap.Error(err)) fetcher.logger.Error("error parsing request body", zap.Error(err))
@@ -187,7 +186,7 @@ func (fetcher *Fetcher) SpecializeHandler(w http.ResponseWriter, r *http.Request
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
var req types.FunctionSpecializeRequest var req FunctionSpecializeRequest
err = json.Unmarshal(body, &req) err = json.Unmarshal(body, &req)
if err != nil { if err != nil {
fetcher.logger.Error("error parsing request body", zap.Error(err)) fetcher.logger.Error("error parsing request body", zap.Error(err))
@@ -208,7 +207,7 @@ func (fetcher *Fetcher) SpecializeHandler(w http.ResponseWriter, r *http.Request
// Fetch takes FetchRequest and makes the fetch call // Fetch takes FetchRequest and makes the fetch call
// It returns the HTTP code and error if any // It returns the HTTP code and error if any
func (fetcher *Fetcher) Fetch(ctx context.Context, pkg *fv1.Package, req types.FunctionFetchRequest) (int, error) { func (fetcher *Fetcher) Fetch(ctx context.Context, pkg *fv1.Package, req FunctionFetchRequest) (int, error) {
// check that the requested filename is not an empty string and error out if so // check that the requested filename is not an empty string and error out if so
if len(req.Filename) == 0 { if len(req.Filename) == 0 {
e := "fetch request received for an empty file name" e := "fetch request received for an empty file name"
@@ -227,7 +226,7 @@ func (fetcher *Fetcher) Fetch(ctx context.Context, pkg *fv1.Package, req types.F
tmpFile := req.Filename + ".tmp" tmpFile := req.Filename + ".tmp"
tmpPath := filepath.Join(fetcher.sharedVolumePath, tmpFile) tmpPath := filepath.Join(fetcher.sharedVolumePath, tmpFile)
if req.FetchType == types.FETCH_URL { if req.FetchType == fv1.FETCH_URL {
// fetch the file and save it to the tmp path // fetch the file and save it to the tmp path
err := utils.DownloadUrl(ctx, fetcher.httpClient, req.Url, tmpPath) err := utils.DownloadUrl(ctx, fetcher.httpClient, req.Url, tmpPath)
if err != nil { if err != nil {
@@ -237,15 +236,15 @@ func (fetcher *Fetcher) Fetch(ctx context.Context, pkg *fv1.Package, req types.F
} }
} else { } else {
var archive *fv1.Archive var archive *fv1.Archive
if req.FetchType == types.FETCH_SOURCE { if req.FetchType == fv1.FETCH_SOURCE {
archive = &pkg.Spec.Source archive = &pkg.Spec.Source
} else if req.FetchType == types.FETCH_DEPLOYMENT { } else if req.FetchType == fv1.FETCH_DEPLOYMENT {
// sometimes, the user may invoke the function even before the source code is built into a deploy pkg. // sometimes, the user may invoke the function even before the source code is built into a deploy pkg.
// this results in executor sending a fetch request of type FETCH_DEPLOYMENT and since pkg.Spec.Deployment.Url will be empty, // this results in executor sending a fetch request of type FETCH_DEPLOYMENT and since pkg.Spec.Deployment.Url will be empty,
// we hit this "Get : unsupported protocol scheme "" error. // we hit this "Get : unsupported protocol scheme "" error.
// it may be useful to the user if we can send a more meaningful error in such a scenario. // it may be useful to the user if we can send a more meaningful error in such a scenario.
if pkg.Status.BuildStatus != types.BuildStatusSucceeded && pkg.Status.BuildStatus != types.BuildStatusNone { if pkg.Status.BuildStatus != fv1.BuildStatusSucceeded && pkg.Status.BuildStatus != fv1.BuildStatusNone {
e := fmt.Sprintf("cannot fetch deployment: package build status was not %q", types.BuildStatusSucceeded) e := fmt.Sprintf("cannot fetch deployment: package build status was not %q", fv1.BuildStatusSucceeded)
fetcher.logger.Error(e, fetcher.logger.Error(e,
zap.String("package_name", pkg.ObjectMeta.Name), zap.String("package_name", pkg.ObjectMeta.Name),
zap.String("package_namespace", pkg.ObjectMeta.Namespace), zap.String("package_namespace", pkg.ObjectMeta.Namespace),
@@ -441,7 +440,7 @@ func (fetcher *Fetcher) UploadHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
var req types.ArchiveUploadRequest var req ArchiveUploadRequest
err = json.Unmarshal(body, &req) err = json.Unmarshal(body, &req)
if err != nil { if err != nil {
fetcher.logger.Error("error parsing request body", zap.Error(err)) fetcher.logger.Error("error parsing request body", zap.Error(err))
@@ -491,7 +490,7 @@ func (fetcher *Fetcher) UploadHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
resp := types.ArchiveUploadResponse{ resp := ArchiveUploadResponse{
ArchiveDownloadUrl: ssClient.GetUrl(fileID), ArchiveDownloadUrl: ssClient.GetUrl(fileID),
Checksum: *sum, Checksum: *sum,
} }
@@ -548,7 +547,7 @@ func (fetcher *Fetcher) unarchive(src string, dst string) error {
} }
// getPkgInformation gets package information from k8s api server. // getPkgInformation gets package information from k8s api server.
func (fetcher *Fetcher) getPkgInformation(req types.FunctionFetchRequest) (pkg *fv1.Package, err error) { func (fetcher *Fetcher) getPkgInformation(req FunctionFetchRequest) (pkg *fv1.Package, err error) {
maxRetries := 5 maxRetries := 5
for i := 0; i < maxRetries; i++ { for i := 0; i < maxRetries; i++ {
pkg, err = fetcher.fissionClient.V1().Packages(req.Package.Namespace).Get(req.Package.Name, metav1.GetOptions{}) pkg, err = fetcher.fissionClient.V1().Packages(req.Package.Namespace).Get(req.Package.Name, metav1.GetOptions{})
@@ -569,7 +568,7 @@ func (fetcher *Fetcher) getPkgInformation(req types.FunctionFetchRequest) (pkg *
return nil, err return nil, err
} }
func (fetcher *Fetcher) SpecializePod(ctx context.Context, fetchReq types.FunctionFetchRequest, loadReq types.FunctionLoadRequest) error { func (fetcher *Fetcher) SpecializePod(ctx context.Context, fetchReq FunctionFetchRequest, loadReq FunctionLoadRequest) error {
startTime := time.Now() startTime := time.Now()
defer func() { defer func() {
elapsed := time.Since(startTime) elapsed := time.Since(startTime)
+85
View File
@@ -0,0 +1,85 @@
/*
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 fetcher
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
)
//
// Fission-Environment interface. The following types are not
// exposed in the Fission API, but rather used by Fission to
// talk to environments.
//
type (
FetchRequestType int
FunctionSpecializeRequest struct {
FetchReq FunctionFetchRequest
LoadReq FunctionLoadRequest
}
FunctionFetchRequest struct {
FetchType FetchRequestType `json:"fetchType"`
Package metav1.ObjectMeta `json:"package"`
Url string `json:"url"`
StorageSvcUrl string `json:"storagesvcurl"`
Filename string `json:"filename"`
Secrets []fv1.SecretReference `json:"secretList"`
ConfigMaps []fv1.ConfigMapReference `json:"configMapList"`
KeepArchive bool `json:"keeparchive"`
}
FunctionLoadRequest struct {
// FilePath is an absolute filesystem path to the
// function. What exactly is stored here is
// env-specific. Optional.
FilePath string `json:"filepath"`
// FunctionName has an environment-specific meaning;
// usually, it defines a function within a module
// containing multiple functions. Optional; default is
// environment-specific.
FunctionName string `json:"functionName"`
// URL to expose this function at. Optional; defaults
// to "/".
URL string `json:"url"`
// Metatdata
FunctionMetadata *metav1.ObjectMeta
EnvVersion int `json:"envVersion"`
}
// ArchiveUploadRequest send from builder manager describes which
// deployment package should be upload to storage service.
ArchiveUploadRequest struct {
Filename string `json:"filename"`
StorageSvcUrl string `json:"storagesvcurl"`
ArchivePackage bool `json:"archivepackage"`
}
// ArchiveUploadResponse defines the download url of an archive and
// its checksum.
ArchiveUploadResponse struct {
ArchiveDownloadUrl string `json:"archiveDownloadUrl"`
Checksum fv1.Checksum `json:"checksum"`
}
)
+1 -2
View File
@@ -28,7 +28,6 @@ import (
"github.com/fission/fission/pkg/fission-cli/cmd" "github.com/fission/fission/pkg/fission-cli/cmd"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key" flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util" "github.com/fission/fission/pkg/fission-cli/util"
"github.com/fission/fission/pkg/types"
) )
type CreateSubCommand struct { type CreateSubCommand struct {
@@ -76,7 +75,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
} }
// check that the trigger has function reference type function weights // check that the trigger has function reference type function weights
if htTrigger.Spec.FunctionReference.Type != types.FunctionReferenceTypeFunctionWeights { if htTrigger.Spec.FunctionReference.Type != fv1.FunctionReferenceTypeFunctionWeights {
return errors.New("canary config cannot be created for http triggers that do not reference functions by weights") return errors.New("canary config cannot be created for http triggers that do not reference functions by weights")
} }
+8 -9
View File
@@ -30,7 +30,6 @@ import (
"github.com/fission/fission/pkg/fission-cli/console" "github.com/fission/fission/pkg/fission-cli/console"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key" flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util" "github.com/fission/fission/pkg/fission-cli/util"
"github.com/fission/fission/pkg/types"
) )
type CreateSubCommand struct { type CreateSubCommand struct {
@@ -62,13 +61,13 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
var mqType fv1.MessageQueueType var mqType fv1.MessageQueueType
switch input.String(flagkey.MqtMQType) { switch input.String(flagkey.MqtMQType) {
case "": case "":
mqType = types.MessageQueueTypeNats mqType = fv1.MessageQueueTypeNats
case types.MessageQueueTypeNats: case fv1.MessageQueueTypeNats:
mqType = types.MessageQueueTypeNats mqType = fv1.MessageQueueTypeNats
case types.MessageQueueTypeASQ: case fv1.MessageQueueTypeASQ:
mqType = types.MessageQueueTypeASQ mqType = fv1.MessageQueueTypeASQ
case types.MessageQueueTypeKafka: case fv1.MessageQueueTypeKafka:
mqType = types.MessageQueueTypeKafka mqType = fv1.MessageQueueTypeKafka
default: default:
return errors.New("Unknown message queue type, currently only \"nats-streaming, azure-storage-queue, kafka \" is supported") return errors.New("Unknown message queue type, currently only \"nats-streaming, azure-storage-queue, kafka \" is supported")
} }
@@ -131,7 +130,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
}, },
Spec: fv1.MessageQueueTriggerSpec{ Spec: fv1.MessageQueueTriggerSpec{
FunctionReference: fv1.FunctionReference{ FunctionReference: fv1.FunctionReference{
Type: types.FunctionReferenceTypeFunctionName, Type: fv1.FunctionReferenceTypeFunctionName,
Name: fnName, Name: fnName,
}, },
MessageQueueType: mqType, MessageQueueType: mqType,
+1 -2
View File
@@ -33,7 +33,6 @@ import (
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/controller/client" "github.com/fission/fission/pkg/controller/client"
storageSvcClient "github.com/fission/fission/pkg/storagesvc/client" storageSvcClient "github.com/fission/fission/pkg/storagesvc/client"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
) )
@@ -45,7 +44,7 @@ func UploadArchiveFile(ctx context.Context, client client.Interface, fileName st
return nil, err return nil, err
} }
if size < types.ArchiveLiteralSizeLimit { if size < fv1.ArchiveLiteralSizeLimit {
archive.Type = fv1.ArchiveTypeLiteral archive.Type = fv1.ArchiveTypeLiteral
archive.Literal, err = GetContents(fileName) archive.Literal, err = GetContents(fileName)
if err != nil { if err != nil {
+1 -2
View File
@@ -40,7 +40,6 @@ import (
"github.com/fission/fission/pkg/fission-cli/console" "github.com/fission/fission/pkg/fission-cli/console"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key" flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util" "github.com/fission/fission/pkg/fission-cli/util"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
) )
@@ -474,7 +473,7 @@ func localArchiveFromSpec(specDir string, aus *spectypes.ArchiveUploadSpec) (*fv
} }
// figure out if we're making a literal or a URL-based archive // figure out if we're making a literal or a URL-based archive
if size < types.ArchiveLiteralSizeLimit { if size < fv1.ArchiveLiteralSizeLimit {
contents, err := pkgutil.GetContents(archiveFileName) contents, err := pkgutil.GetContents(archiveFileName)
if err != nil { if err != nil {
return nil, err return nil, err
+5 -6
View File
@@ -27,7 +27,6 @@ import (
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/controller/client" "github.com/fission/fission/pkg/controller/client"
"github.com/fission/fission/pkg/fission-cli/cmd/package/util" "github.com/fission/fission/pkg/fission-cli/cmd/package/util"
"github.com/fission/fission/pkg/types"
) )
type ( type (
@@ -83,11 +82,11 @@ func (w *packageBuildWatcher) watch(ctx context.Context) {
if !ok { if !ok {
continue continue
} }
if pkg.Status.BuildStatus == types.BuildStatusNone { if pkg.Status.BuildStatus == fv1.BuildStatusNone {
continue continue
} }
if pkg.Status.BuildStatus == types.BuildStatusPending || if pkg.Status.BuildStatus == fv1.BuildStatusPending ||
pkg.Status.BuildStatus == types.BuildStatusRunning { pkg.Status.BuildStatus == fv1.BuildStatusRunning {
keepWaiting = true keepWaiting = true
} }
buildpkgs = append(buildpkgs, pkg) buildpkgs = append(buildpkgs, pkg)
@@ -99,8 +98,8 @@ func (w *packageBuildWatcher) watch(ctx context.Context) {
if _, printed := w.finished[k]; printed { if _, printed := w.finished[k]; printed {
continue continue
} }
if pkg.Status.BuildStatus == types.BuildStatusFailed || if pkg.Status.BuildStatus == fv1.BuildStatusFailed ||
pkg.Status.BuildStatus == types.BuildStatusSucceeded { pkg.Status.BuildStatus == fv1.BuildStatusSucceeded {
w.finished[k] = true w.finished[k] = true
fmt.Printf("------\n") fmt.Printf("------\n")
util.PrintPackageSummary(os.Stdout, &pkg) util.PrintPackageSummary(os.Stdout, &pkg)
+1 -2
View File
@@ -24,7 +24,6 @@ import (
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/controller/client" "github.com/fission/fission/pkg/controller/client"
"github.com/fission/fission/pkg/fission-cli/console" "github.com/fission/fission/pkg/fission-cli/console"
"github.com/fission/fission/pkg/types"
) )
const ( const (
@@ -114,7 +113,7 @@ func (res CrdDumper) Dump(dumpDir string) {
case CrdMessageQueueTrigger: case CrdMessageQueueTrigger:
var triggers []fv1.MessageQueueTrigger var triggers []fv1.MessageQueueTrigger
for _, mqType := range []string{types.MessageQueueTypeNats, types.MessageQueueTypeASQ} { for _, mqType := range []string{fv1.MessageQueueTypeNats, fv1.MessageQueueTypeASQ, fv1.MessageQueueTypeKafka} {
l, err := res.client.V1().MessageQueueTrigger().List(mqType, metav1.NamespaceAll) l, err := res.client.V1().MessageQueueTrigger().List(mqType, metav1.NamespaceAll)
if err != nil { if err != nil {
console.Warn(fmt.Sprintf("Error getting %v list: %v", res.crdType, err)) console.Warn(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
+6 -6
View File
@@ -24,8 +24,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils"
"go.uber.org/zap" "go.uber.org/zap"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -33,7 +31,9 @@ import (
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
k8sCache "k8s.io/client-go/tools/cache" k8sCache "k8s.io/client-go/tools/cache"
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/crd" "github.com/fission/fission/pkg/crd"
"github.com/fission/fission/pkg/utils"
) )
var nodeName = os.Getenv("NODE_NAME") var nodeName = os.Getenv("NODE_NAME")
@@ -55,7 +55,7 @@ func makePodLoggerController(zapLogger *zap.Logger, k8sClientSet *kubernetes.Cli
} }
err := createLogSymlinks(zapLogger, pod) err := createLogSymlinks(zapLogger, pod)
if err != nil { if err != nil {
funcName := pod.Labels[types.FUNCTION_NAME] funcName := pod.Labels[fv1.FUNCTION_NAME]
zapLogger.Error("error creating symlink", zapLogger.Error("error creating symlink",
zap.String("function", funcName), zap.Error(err)) zap.String("function", funcName), zap.Error(err))
} }
@@ -67,7 +67,7 @@ func makePodLoggerController(zapLogger *zap.Logger, k8sClientSet *kubernetes.Cli
} }
err := createLogSymlinks(zapLogger, pod) err := createLogSymlinks(zapLogger, pod)
if err != nil { if err != nil {
funcName := pod.Labels[types.FUNCTION_NAME] funcName := pod.Labels[fv1.FUNCTION_NAME]
zapLogger.Error("error creating symlink", zapLogger.Error("error creating symlink",
zap.String("function", funcName), zap.Error(err)) zap.String("function", funcName), zap.Error(err))
} }
@@ -115,8 +115,8 @@ func isValidFunctionPodOnNode(pod *corev1.Pod) bool {
if pod.Spec.NodeName != nodeName { if pod.Spec.NodeName != nodeName {
return false return false
} }
labels := []string{types.ENVIRONMENT_NAMESPACE, types.ENVIRONMENT_NAME, types.ENVIRONMENT_UID, labels := []string{fv1.ENVIRONMENT_NAMESPACE, fv1.ENVIRONMENT_NAME, fv1.ENVIRONMENT_UID,
types.FUNCTION_NAMESPACE, types.FUNCTION_NAME, types.FUNCTION_UID, types.EXECUTOR_TYPE} fv1.FUNCTION_NAMESPACE, fv1.FUNCTION_NAME, fv1.FUNCTION_UID, fv1.EXECUTOR_TYPE}
for _, l := range labels { for _, l := range labels {
if len(pod.Labels[l]) == 0 { if len(pod.Labels[l]) == 0 {
return false return false
+1 -2
View File
@@ -29,7 +29,6 @@ import (
"time" "time"
"github.com/Azure/azure-sdk-for-go/storage" "github.com/Azure/azure-sdk-for-go/storage"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
@@ -204,7 +203,7 @@ func newAzureStorageConnection(logger *zap.Logger, routerURL string, config Mess
func (asc AzureStorageConnection) subscribe(trigger *fv1.MessageQueueTrigger) (messageQueueSubscription, error) { func (asc AzureStorageConnection) subscribe(trigger *fv1.MessageQueueTrigger) (messageQueueSubscription, error) {
asc.logger.Info("subscribing to Azure storage queue", zap.String("queue", trigger.Spec.Topic)) asc.logger.Info("subscribing to Azure storage queue", zap.String("queue", trigger.Spec.Topic))
if trigger.Spec.FunctionReference.Type != types.FunctionReferenceTypeFunctionName { if trigger.Spec.FunctionReference.Type != fv1.FunctionReferenceTypeFunctionName {
return nil, fmt.Errorf("unsupported function reference type (%v) for trigger %q", trigger.Spec.FunctionReference.Type, trigger.ObjectMeta.Name) return nil, fmt.Errorf("unsupported function reference type (%v) for trigger %q", trigger.Spec.FunctionReference.Type, trigger.ObjectMeta.Name)
} }
+6 -7
View File
@@ -26,7 +26,6 @@ import (
"time" "time"
"github.com/Azure/azure-sdk-for-go/storage" "github.com/Azure/azure-sdk-for-go/storage"
"github.com/fission/fission/pkg/types"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.uber.org/zap" "go.uber.org/zap"
@@ -114,7 +113,7 @@ func TestNewStorageConnectionMissingAccountName(t *testing.T) {
panicIf(err) panicIf(err)
connection, err := newAzureStorageConnection(logger, DummyRouterURL, MessageQueueConfig{ connection, err := newAzureStorageConnection(logger, DummyRouterURL, MessageQueueConfig{
MQType: types.MessageQueueTypeASQ, MQType: fv1.MessageQueueTypeASQ,
Url: "", Url: "",
}) })
require.Nil(t, connection) require.Nil(t, connection)
@@ -127,7 +126,7 @@ func TestNewStorageConnectionMissingAccessKey(t *testing.T) {
_ = os.Setenv("AZURE_STORAGE_ACCOUNT_NAME", "accountname") _ = os.Setenv("AZURE_STORAGE_ACCOUNT_NAME", "accountname")
connection, err := newAzureStorageConnection(logger, DummyRouterURL, MessageQueueConfig{ connection, err := newAzureStorageConnection(logger, DummyRouterURL, MessageQueueConfig{
MQType: types.MessageQueueTypeASQ, MQType: fv1.MessageQueueTypeASQ,
Url: "", Url: "",
}) })
_ = os.Unsetenv("AZURE_STORAGE_ACCOUNT_NAME") _ = os.Unsetenv("AZURE_STORAGE_ACCOUNT_NAME")
@@ -309,10 +308,10 @@ func TestAzureStorageQueuePoisonMessage(t *testing.T) {
}, },
Spec: fv1.MessageQueueTriggerSpec{ Spec: fv1.MessageQueueTriggerSpec{
FunctionReference: fv1.FunctionReference{ FunctionReference: fv1.FunctionReference{
Type: types.FunctionReferenceTypeFunctionName, Type: fv1.FunctionReferenceTypeFunctionName,
Name: FunctionName, Name: FunctionName,
}, },
MessageQueueType: types.MessageQueueTypeASQ, MessageQueueType: fv1.MessageQueueTypeASQ,
Topic: QueueName, Topic: QueueName,
ContentType: ContentType, ContentType: ContentType,
}, },
@@ -457,10 +456,10 @@ func runAzureStorageQueueTest(t *testing.T, count int, output bool) {
}, },
Spec: fv1.MessageQueueTriggerSpec{ Spec: fv1.MessageQueueTriggerSpec{
FunctionReference: fv1.FunctionReference{ FunctionReference: fv1.FunctionReference{
Type: types.FunctionReferenceTypeFunctionName, Type: fv1.FunctionReferenceTypeFunctionName,
Name: FunctionName, Name: FunctionName,
}, },
MessageQueueType: types.MessageQueueTypeASQ, MessageQueueType: fv1.MessageQueueTypeASQ,
Topic: QueueName, Topic: QueueName,
ResponseTopic: responseTopic, ResponseTopic: responseTopic,
ContentType: ContentType, ContentType: ContentType,
+2 -3
View File
@@ -28,12 +28,11 @@ import (
sarama "github.com/Shopify/sarama" sarama "github.com/Shopify/sarama"
cluster "github.com/bsm/sarama-cluster" cluster "github.com/bsm/sarama-cluster"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/utils"
) )
type ( type (
@@ -202,7 +201,7 @@ func (kafka Kafka) unsubscribe(subscription messageQueueSubscription) error {
func kafkaMsgHandler(kafka *Kafka, producer sarama.SyncProducer, trigger *fv1.MessageQueueTrigger, msg *sarama.ConsumerMessage, consumer *cluster.Consumer) { func kafkaMsgHandler(kafka *Kafka, producer sarama.SyncProducer, trigger *fv1.MessageQueueTrigger, msg *sarama.ConsumerMessage, consumer *cluster.Consumer) {
var value string = string(msg.Value[:]) var value string = string(msg.Value[:])
// Support other function ref types // Support other function ref types
if trigger.Spec.FunctionReference.Type != types.FunctionReferenceTypeFunctionName { if trigger.Spec.FunctionReference.Type != fv1.FunctionReferenceTypeFunctionName {
kafka.logger.Fatal("unsupported function reference type for trigger", kafka.logger.Fatal("unsupported function reference type for trigger",
zap.Any("function_reference_type", trigger.Spec.FunctionReference.Type), zap.Any("function_reference_type", trigger.Spec.FunctionReference.Type),
zap.String("trigger", trigger.ObjectMeta.Name)) zap.String("trigger", trigger.ObjectMeta.Name))
+3 -4
View File
@@ -21,7 +21,6 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
"go.uber.org/zap" "go.uber.org/zap"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -87,11 +86,11 @@ func MakeMessageQueueTriggerManager(logger *zap.Logger, fissionClient *crd.Fissi
fissionClient: fissionClient, fissionClient: fissionClient,
} }
switch mqConfig.MQType { switch mqConfig.MQType {
case types.MessageQueueTypeNats: case fv1.MessageQueueTypeNats:
messageQueue, err = makeNatsMessageQueue(logger, routerUrl, mqConfig) messageQueue, err = makeNatsMessageQueue(logger, routerUrl, mqConfig)
case types.MessageQueueTypeASQ: case fv1.MessageQueueTypeASQ:
messageQueue, err = newAzureStorageConnection(logger, routerUrl, mqConfig) messageQueue, err = newAzureStorageConnection(logger, routerUrl, mqConfig)
case types.MessageQueueTypeKafka: case fv1.MessageQueueTypeKafka:
messageQueue, err = makeKafkaMessageQueue(logger, routerUrl, mqConfig) messageQueue, err = makeKafkaMessageQueue(logger, routerUrl, mqConfig)
default: default:
err = fmt.Errorf("no supported message queue type found for %q", mqConfig.MQType) err = fmt.Errorf("no supported message queue type found for %q", mqConfig.MQType)
+1 -2
View File
@@ -28,7 +28,6 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/types"
"github.com/fission/fission/pkg/utils" "github.com/fission/fission/pkg/utils"
) )
@@ -106,7 +105,7 @@ func msgHandler(nats *Nats, trigger *fv1.MessageQueueTrigger) func(*ns.Msg) {
return func(msg *ns.Msg) { return func(msg *ns.Msg) {
// Support other function ref types // Support other function ref types
if trigger.Spec.FunctionReference.Type != types.FunctionReferenceTypeFunctionName { if trigger.Spec.FunctionReference.Type != fv1.FunctionReferenceTypeFunctionName {
nats.logger.Fatal("unsupported function reference type for trigger", nats.logger.Fatal("unsupported function reference type for trigger",
zap.Any("function_reference_type", trigger.Spec.FunctionReference.Type), zap.Any("function_reference_type", trigger.Spec.FunctionReference.Type),
zap.String("trigger", trigger.ObjectMeta.Name)) zap.String("trigger", trigger.ObjectMeta.Name))
+1 -2
View File
@@ -40,7 +40,6 @@ import (
"github.com/fission/fission/pkg/error/network" "github.com/fission/fission/pkg/error/network"
executorClient "github.com/fission/fission/pkg/executor/client" executorClient "github.com/fission/fission/pkg/executor/client"
"github.com/fission/fission/pkg/throttler" "github.com/fission/fission/pkg/throttler"
"github.com/fission/fission/pkg/types"
) )
const ( const (
@@ -367,7 +366,7 @@ func (fh *functionHandler) tapService(fn *fv1.Function, serviceUrl *url.URL) {
} }
func (fh functionHandler) handler(responseWriter http.ResponseWriter, request *http.Request) { func (fh functionHandler) handler(responseWriter http.ResponseWriter, request *http.Request) {
if fh.httpTrigger != nil && fh.httpTrigger.Spec.FunctionReference.Type == types.FunctionReferenceTypeFunctionWeights { if fh.httpTrigger != nil && fh.httpTrigger.Spec.FunctionReference.Type == fv1.FunctionReferenceTypeFunctionWeights {
// canary deployment. need to determine the function to send request to now // canary deployment. need to determine the function to send request to now
fn := getCanaryBackend(fh.functionMap, fh.fnWeightDistributionList) fn := getCanaryBackend(fh.functionMap, fh.fnWeightDistributionList)
if fn == nil { if fn == nil {
+1 -2
View File
@@ -31,7 +31,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
"github.com/fission/fission/pkg/types"
) )
func createBackendService(testResponseString string) *url.URL { func createBackendService(testResponseString string) *url.URL {
@@ -72,7 +71,7 @@ func TestFunctionProxying(t *testing.T) {
}, },
Spec: fv1.HTTPTriggerSpec{ Spec: fv1.HTTPTriggerSpec{
FunctionReference: fv1.FunctionReference{ FunctionReference: fv1.FunctionReference{
Type: types.FunctionReferenceTypeFunctionName, Type: fv1.FunctionReferenceTypeFunctionName,
}, },
}, },
} }
+1 -2
View File
@@ -22,7 +22,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/fission/fission/pkg/types"
"go.uber.org/zap" "go.uber.org/zap"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -36,7 +35,7 @@ func TestRouter(t *testing.T) {
// and a reference to it // and a reference to it
fr := fv1.FunctionReference{ fr := fv1.FunctionReference{
Type: types.FunctionReferenceTypeFunctionName, Type: fv1.FunctionReferenceTypeFunctionName,
Name: fnMeta.Name, Name: fnMeta.Name,
} }
-188
View File
@@ -1,188 +0,0 @@
/*
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 types
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
)
//
// Fission-Environment interface. The following types are not
// exposed in the Fission API, but rather used by Fission to
// talk to environments.
//
type (
FetchRequestType int
FunctionSpecializeRequest struct {
FetchReq FunctionFetchRequest
LoadReq FunctionLoadRequest
}
FunctionFetchRequest struct {
FetchType FetchRequestType `json:"fetchType"`
Package metav1.ObjectMeta `json:"package"`
Url string `json:"url"`
StorageSvcUrl string `json:"storagesvcurl"`
Filename string `json:"filename"`
Secrets []fv1.SecretReference `json:"secretList"`
ConfigMaps []fv1.ConfigMapReference `json:"configMapList"`
KeepArchive bool `json:"keeparchive"`
}
FunctionLoadRequest struct {
// FilePath is an absolute filesystem path to the
// function. What exactly is stored here is
// env-specific. Optional.
FilePath string `json:"filepath"`
// FunctionName has an environment-specific meaning;
// usually, it defines a function within a module
// containing multiple functions. Optional; default is
// environment-specific.
FunctionName string `json:"functionName"`
// URL to expose this function at. Optional; defaults
// to "/".
URL string `json:"url"`
// Metatdata
FunctionMetadata *metav1.ObjectMeta
EnvVersion int `json:"envVersion"`
}
// ArchiveUploadRequest send from builder manager describes which
// deployment package should be upload to storage service.
ArchiveUploadRequest struct {
Filename string `json:"filename"`
StorageSvcUrl string `json:"storagesvcurl"`
ArchivePackage bool `json:"archivepackage"`
}
// ArchiveUploadResponse defines the download url of an archive and
// its checksum.
ArchiveUploadResponse struct {
ArchiveDownloadUrl string `json:"archiveDownloadUrl"`
Checksum fv1.Checksum `json:"checksum"`
}
)
const (
FETCH_SOURCE = iota
FETCH_DEPLOYMENT
FETCH_URL // remove this?
)
const EXECUTOR_INSTANCEID_LABEL = fv1.EXECUTOR_INSTANCEID_LABEL
const (
ChecksumTypeSHA256 = fv1.ChecksumTypeSHA256
)
const (
// ArchiveTypeLiteral means the package contents are specified in the Literal field of
// resource itself.
ArchiveTypeLiteral = fv1.ArchiveTypeLiteral
// ArchiveTypeUrl means the package contents are at the specified URL.
ArchiveTypeUrl = fv1.ArchiveTypeUrl
)
const (
BuildStatusPending = fv1.BuildStatusPending
BuildStatusRunning = fv1.BuildStatusRunning
BuildStatusSucceeded = fv1.BuildStatusSucceeded
BuildStatusFailed = fv1.BuildStatusFailed
BuildStatusNone = fv1.BuildStatusNone
)
const (
AllowedFunctionsPerContainerSingle = fv1.AllowedFunctionsPerContainerSingle
AllowedFunctionsPerContainerInfinite = fv1.AllowedFunctionsPerContainerInfinite
)
// executor kubernetes object label key
const (
ENVIRONMENT_NAMESPACE = "environmentNamespace"
ENVIRONMENT_NAME = "environmentName"
ENVIRONMENT_UID = "environmentUid"
FUNCTION_NAMESPACE = "functionNamespace"
FUNCTION_NAME = "functionName"
FUNCTION_UID = "functionUid"
FUNCTION_RESOURCE_VERSION = "functionResourceVersion"
EXECUTOR_TYPE = "executorType"
)
const (
ANNOTATION_SVC_HOST = "svcHost"
)
const (
SharedVolumeUserfunc = fv1.SharedVolumeUserfunc
SharedVolumePackages = fv1.SharedVolumePackages
SharedVolumeSecrets = fv1.SharedVolumeSecrets
SharedVolumeConfigmaps = fv1.SharedVolumeConfigmaps
)
const (
MessageQueueTypeNats = fv1.MessageQueueTypeNats
MessageQueueTypeASQ = fv1.MessageQueueTypeASQ
MessageQueueTypeKafka = fv1.MessageQueueTypeKafka
)
const (
// FunctionReferenceFunctionName means that the function
// reference is simply by function name.
FunctionReferenceTypeFunctionName = fv1.FunctionReferenceTypeFunctionName
// Set of function references (recursively), by percentage of traffic
FunctionReferenceTypeFunctionWeights = fv1.FunctionReferenceTypeFunctionWeights
// Other function reference types we'd like to support:
// Versioned function, latest version
// Versioned function. by semver "latest compatible"
)
const (
ArchiveLiteralSizeLimit int64 = 256 * 1024
)
const (
FissionBuilderSA = "fission-builder"
FissionFetcherSA = "fission-fetcher"
SecretConfigMapGetterCR = "secret-configmap-getter"
SecretConfigMapGetterRB = "secret-configmap-getter-binding"
PackageGetterCR = "package-getter"
PackageGetterRB = "package-getter-binding"
ClusterRole = "ClusterRole"
)
const (
FailureTypeStatusCode = fv1.FailureTypeStatusCode
CanaryConfigStatusPending = fv1.CanaryConfigStatusPending
CanaryConfigStatusSucceeded = fv1.CanaryConfigStatusSucceeded
CanaryConfigStatusFailed = fv1.CanaryConfigStatusFailed
CanaryConfigStatusAborted = fv1.CanaryConfigStatusAborted
MaxIterationsForCanaryConfig = fv1.MaxIterationsForCanaryConfig
)
-100
View File
@@ -1,100 +0,0 @@
/*
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 v1
//
// These are types from the v1 API, and are only preserved for
// compatibility. They should never be changed.
//
type (
// ObjectMeta is used as the general identifier for all kinds of
// resources managed by the controller.
Metadata struct {
Name string `json:"name"`
Uid string `json:"uid,omitempty"`
}
// Function is a unit of executable code. Though it's called
// a function, the code may have more than one function; it's
// usually some sort of module or package.
Function struct {
Metadata `json:"metadata"`
Environment Metadata `json:"environment"`
Code string `json:"code"`
}
// Environment identifies the language and OS specific
// resources that a function depends on. For now this
// includes only the function run container image. Later,
// this will also include build containers, as well as support
// tools like debuggers, profilers, etc.
Environment struct {
Metadata `json:"metadata"`
RunContainerImageUrl string `json:"runContainerImageUrl"`
}
// HTTPTrigger maps URL patterns to functions. Function.UID
// is optional; if absent, the latest version of the function
// will automatically be selected.
HTTPTrigger struct {
Metadata `json:"metadata"`
UrlPattern string `json:"urlpattern"`
Method string `json:"method"`
Function Metadata `json:"function"`
}
MessageQueueTrigger struct {
Metadata `json:"metadata"`
Function Metadata `json:"function"`
MessageQueueType string `json:"messageQueueType"`
Topic string `json:"topic"`
ResponseTopic string `json:"respTopic,omitempty"`
}
// Watch is a specification of Kubernetes watch along with a URL to post events to.
Watch struct {
Metadata `json:"metadata"`
Namespace string `json:"namespace"`
ObjType string `json:"objtype"`
LabelSelector string `json:"labelselector"`
FieldSelector string `json:"fieldselector"`
Function Metadata `json:"function"`
Target string `json:"target"` // Watch publish target (URL, NATS stream, etc)
}
// TimeTrigger invokes the specific function at a time or
// times specified by a cron string.
TimeTrigger struct {
Metadata `json:"metadata"`
Cron string `json:"cron"`
Function Metadata `json:"function"`
}
// Errors returned by the Fission API.
Error struct {
Code errorCode `json:"code"`
Message string `json:"message"`
}
errorCode int
)