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:
@@ -15,7 +15,7 @@ import (
|
||||
"golang.org/x/net/context/ctxhttp"
|
||||
|
||||
ferror "github.com/fission/fission/pkg/error"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"github.com/fission/fission/pkg/fetcher"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -48,23 +48,23 @@ func (c *Client) getUploadUrl() string {
|
||||
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())
|
||||
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())
|
||||
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())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uploadResp := types.ArchiveUploadResponse{}
|
||||
uploadResp := fetcher.ArchiveUploadResponse{}
|
||||
err = json.Unmarshal(body, &uploadResp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -88,14 +88,14 @@ func MakeFetcherConfig(sharedMountPath string) (*Config, error) {
|
||||
sharedSecretPath: "/secrets",
|
||||
sharedCfgMapPath: "/configs",
|
||||
jaegerCollectorEndpoint: os.Getenv("TRACE_JAEGER_COLLECTOR_ENDPOINT"),
|
||||
serviceAccount: types.FissionFetcherSA,
|
||||
serviceAccount: fv1.FissionFetcherSA,
|
||||
}, nil
|
||||
}
|
||||
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (cfg *Config) SharedMountPath() string {
|
||||
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
|
||||
// still try to load user function from hard coded
|
||||
// path /userfunc/user
|
||||
@@ -115,9 +115,9 @@ func (cfg *Config) NewSpecializeRequest(fn *fv1.Function, env *fv1.Environment)
|
||||
targetFilename = string(fn.ObjectMeta.UID)
|
||||
}
|
||||
|
||||
return types.FunctionSpecializeRequest{
|
||||
FetchReq: types.FunctionFetchRequest{
|
||||
FetchType: types.FETCH_DEPLOYMENT,
|
||||
return fetcher.FunctionSpecializeRequest{
|
||||
FetchReq: fetcher.FunctionFetchRequest{
|
||||
FetchType: fv1.FETCH_DEPLOYMENT,
|
||||
Package: metav1.ObjectMeta{
|
||||
Namespace: fn.Spec.Package.PackageRef.Namespace,
|
||||
Name: fn.Spec.Package.PackageRef.Name,
|
||||
@@ -127,7 +127,7 @@ func (cfg *Config) NewSpecializeRequest(fn *fv1.Function, env *fv1.Environment)
|
||||
ConfigMaps: fn.Spec.ConfigMaps,
|
||||
KeepArchive: env.Spec.KeepArchive,
|
||||
},
|
||||
LoadReq: types.FunctionLoadRequest{
|
||||
LoadReq: fetcher.FunctionLoadRequest{
|
||||
FilePath: filepath.Join(cfg.sharedMountPath, targetFilename),
|
||||
FunctionName: fn.Spec.Package.FunctionName,
|
||||
FunctionMetadata: &fn.ObjectMeta,
|
||||
@@ -172,19 +172,19 @@ func (cfg *Config) fetcherCommand(extraArgs ...string) []string {
|
||||
func (cfg *Config) volumesWithMounts() ([]apiv1.Volume, []apiv1.VolumeMount) {
|
||||
volumes := []apiv1.Volume{
|
||||
{
|
||||
Name: types.SharedVolumeUserfunc,
|
||||
Name: fv1.SharedVolumeUserfunc,
|
||||
VolumeSource: apiv1.VolumeSource{
|
||||
EmptyDir: &apiv1.EmptyDirVolumeSource{},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: types.SharedVolumeSecrets,
|
||||
Name: fv1.SharedVolumeSecrets,
|
||||
VolumeSource: apiv1.VolumeSource{
|
||||
EmptyDir: &apiv1.EmptyDirVolumeSource{},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: types.SharedVolumeConfigmaps,
|
||||
Name: fv1.SharedVolumeConfigmaps,
|
||||
VolumeSource: apiv1.VolumeSource{
|
||||
EmptyDir: &apiv1.EmptyDirVolumeSource{},
|
||||
},
|
||||
@@ -192,15 +192,15 @@ func (cfg *Config) volumesWithMounts() ([]apiv1.Volume, []apiv1.VolumeMount) {
|
||||
}
|
||||
mounts := []apiv1.VolumeMount{
|
||||
{
|
||||
Name: types.SharedVolumeUserfunc,
|
||||
Name: fv1.SharedVolumeUserfunc,
|
||||
MountPath: cfg.sharedMountPath,
|
||||
},
|
||||
{
|
||||
Name: types.SharedVolumeSecrets,
|
||||
Name: fv1.SharedVolumeSecrets,
|
||||
MountPath: cfg.sharedSecretPath,
|
||||
},
|
||||
{
|
||||
Name: types.SharedVolumeConfigmaps,
|
||||
Name: fv1.SharedVolumeConfigmaps,
|
||||
MountPath: cfg.sharedCfgMapPath,
|
||||
},
|
||||
}
|
||||
@@ -289,7 +289,7 @@ func (cfg *Config) addFetcherToPodSpecWithCommand(podSpec *apiv1.PodSpec, mainCo
|
||||
podSpec.Volumes = append(podSpec.Volumes, volumes...)
|
||||
podSpec.Containers = append(podSpec.Containers, c)
|
||||
if podSpec.ServiceAccountName == "" {
|
||||
podSpec.ServiceAccountName = types.FissionFetcherSA
|
||||
podSpec.ServiceAccountName = fv1.FissionFetcherSA
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
+12
-13
@@ -42,7 +42,6 @@ import (
|
||||
"github.com/fission/fission/pkg/error/network"
|
||||
"github.com/fission/fission/pkg/info"
|
||||
storageSvcClient "github.com/fission/fission/pkg/storagesvc/client"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"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)
|
||||
return
|
||||
}
|
||||
var req types.FunctionFetchRequest
|
||||
var req FunctionFetchRequest
|
||||
err = json.Unmarshal(body, &req)
|
||||
if err != nil {
|
||||
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)
|
||||
return
|
||||
}
|
||||
var req types.FunctionSpecializeRequest
|
||||
var req FunctionSpecializeRequest
|
||||
err = json.Unmarshal(body, &req)
|
||||
if err != nil {
|
||||
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
|
||||
// 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
|
||||
if len(req.Filename) == 0 {
|
||||
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"
|
||||
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
|
||||
err := utils.DownloadUrl(ctx, fetcher.httpClient, req.Url, tmpPath)
|
||||
if err != nil {
|
||||
@@ -237,15 +236,15 @@ func (fetcher *Fetcher) Fetch(ctx context.Context, pkg *fv1.Package, req types.F
|
||||
}
|
||||
} else {
|
||||
var archive *fv1.Archive
|
||||
if req.FetchType == types.FETCH_SOURCE {
|
||||
if req.FetchType == fv1.FETCH_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.
|
||||
// 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.
|
||||
// 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 {
|
||||
e := fmt.Sprintf("cannot fetch deployment: package build status was not %q", types.BuildStatusSucceeded)
|
||||
if pkg.Status.BuildStatus != fv1.BuildStatusSucceeded && pkg.Status.BuildStatus != fv1.BuildStatusNone {
|
||||
e := fmt.Sprintf("cannot fetch deployment: package build status was not %q", fv1.BuildStatusSucceeded)
|
||||
fetcher.logger.Error(e,
|
||||
zap.String("package_name", pkg.ObjectMeta.Name),
|
||||
zap.String("package_namespace", pkg.ObjectMeta.Namespace),
|
||||
@@ -441,7 +440,7 @@ func (fetcher *Fetcher) UploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var req types.ArchiveUploadRequest
|
||||
var req ArchiveUploadRequest
|
||||
err = json.Unmarshal(body, &req)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
resp := types.ArchiveUploadResponse{
|
||||
resp := ArchiveUploadResponse{
|
||||
ArchiveDownloadUrl: ssClient.GetUrl(fileID),
|
||||
Checksum: *sum,
|
||||
}
|
||||
@@ -548,7 +547,7 @@ func (fetcher *Fetcher) unarchive(src string, dst string) error {
|
||||
}
|
||||
|
||||
// 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
|
||||
for i := 0; i < maxRetries; i++ {
|
||||
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
|
||||
}
|
||||
|
||||
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()
|
||||
defer func() {
|
||||
elapsed := time.Since(startTime)
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user