From a98b2bc3a80d63d3f1747a162b74216eeb382512 Mon Sep 17 00:00:00 2001 From: Vishal Date: Thu, 14 Jun 2018 12:32:40 +0530 Subject: [PATCH] Added a flag to control the extraction of archive based on user input (#675) For certain environments, the archive should not be extracted and kept as it is (For ex. for Java the jar file should not be extracted). This change enables an environment level flag to control this behaviour. --- buildermgr/common.go | 7 ++++--- environments/fetcher/fetcher.go | 19 ++++++++++--------- executor/newdeploy/newdeploy.go | 7 ++++--- executor/poolmgr/gp.go | 7 ++++--- fission/environment.go | 6 ++++++ fission/main.go | 5 +++-- pkg/apis/fission.io/v1/typefields.go | 4 ++++ 7 files changed, 35 insertions(+), 20 deletions(-) diff --git a/buildermgr/common.go b/buildermgr/common.go index e432dd16e..81f3990e8 100644 --- a/buildermgr/common.go +++ b/buildermgr/common.go @@ -54,9 +54,10 @@ func buildPackage(fissionClient *crd.FissionClient, envBuilderNamespace string, builderC := builderClient.MakeClient(fmt.Sprintf("http://%v:8001", svcName)) fetchReq := &fetcher.FetchRequest{ - FetchType: fetcher.FETCH_SOURCE, - Package: pkg.Metadata, - Filename: srcPkgFilename, + FetchType: fetcher.FETCH_SOURCE, + Package: pkg.Metadata, + Filename: srcPkgFilename, + ExtractArchive: true, } // send fetch request to fetcher diff --git a/environments/fetcher/fetcher.go b/environments/fetcher/fetcher.go index 9872ec2ff..090e77f76 100644 --- a/environments/fetcher/fetcher.go +++ b/environments/fetcher/fetcher.go @@ -29,13 +29,14 @@ type ( FetchRequestType int FetchRequest struct { - FetchType FetchRequestType `json:"fetchType"` - Package metav1.ObjectMeta `json:"package"` - Url string `json:"url"` - StorageSvcUrl string `json:"storagesvcurl"` - Filename string `json:"filename"` - Secrets []fission.SecretReference `json:"secretList"` - ConfigMaps []fission.ConfigMapReference `json:"configMapList"` + FetchType FetchRequestType `json:"fetchType"` + Package metav1.ObjectMeta `json:"package"` + Url string `json:"url"` + StorageSvcUrl string `json:"storagesvcurl"` + Filename string `json:"filename"` + Secrets []fission.SecretReference `json:"secretList"` + ConfigMaps []fission.ConfigMapReference `json:"configMapList"` + ExtractArchive bool `json:"extractarchive"` } // UploadRequest send from builder manager describes which @@ -292,8 +293,7 @@ func (fetcher *Fetcher) Fetch(req FetchRequest) (int, error) { } } - // check file type here, if the file is a zip file unarchive it. - if archiver.Zip.Match(tmpPath) { + if archiver.Zip.Match(tmpPath) && req.ExtractArchive { // unarchive tmp file to a tmp unarchive path tmpUnarchivePath := filepath.Join(fetcher.sharedVolumePath, uuid.NewV4().String()) err := fetcher.unarchive(tmpPath, tmpUnarchivePath) @@ -301,6 +301,7 @@ func (fetcher *Fetcher) Fetch(req FetchRequest) (int, error) { log.Println(err.Error()) return http.StatusInternalServerError, err } + tmpPath = tmpUnarchivePath } diff --git a/executor/newdeploy/newdeploy.go b/executor/newdeploy/newdeploy.go index c80e16c82..2de9ce3ee 100644 --- a/executor/newdeploy/newdeploy.go +++ b/executor/newdeploy/newdeploy.go @@ -158,9 +158,10 @@ func (deploy *NewDeploy) getDeploymentSpec(fn *crd.Function, env *crd.Environmen Namespace: fn.Spec.Package.PackageRef.Namespace, Name: fn.Spec.Package.PackageRef.Name, }, - Filename: targetFilename, - Secrets: fn.Spec.Secrets, - ConfigMaps: fn.Spec.ConfigMaps, + Filename: targetFilename, + Secrets: fn.Spec.Secrets, + ConfigMaps: fn.Spec.ConfigMaps, + ExtractArchive: env.Spec.ExtractArchive, } loadReq := fission.FunctionLoadRequest{ diff --git a/executor/poolmgr/gp.go b/executor/poolmgr/gp.go index 21565e4de..86c5ebeaa 100644 --- a/executor/poolmgr/gp.go +++ b/executor/poolmgr/gp.go @@ -387,9 +387,10 @@ func (gp *GenericPool) specializePod(pod *apiv1.Pod, metadata *metav1.ObjectMeta Namespace: fn.Spec.Package.PackageRef.Namespace, Name: fn.Spec.Package.PackageRef.Name, }, - Filename: targetFilename, - Secrets: fn.Spec.Secrets, - ConfigMaps: fn.Spec.ConfigMaps, + Filename: targetFilename, + Secrets: fn.Spec.Secrets, + ConfigMaps: fn.Spec.ConfigMaps, + ExtractArchive: gp.env.Spec.ExtractArchive, }) if err != nil { return err diff --git a/fission/environment.go b/fission/environment.go index f99af6b2e..b00f7665b 100644 --- a/fission/environment.go +++ b/fission/environment.go @@ -93,6 +93,11 @@ func envCreate(c *cli.Context) error { } } + extractArchive := true + if c.IsSet("extract") { + extractArchive = c.Bool("extract") + } + // Environment API interface version is not specified and // builder image is empty, set default interface version if envVersion == 0 { @@ -119,6 +124,7 @@ func envCreate(c *cli.Context) error { Resources: resourceReq, AllowAccessToExternalNetwork: envExternalNetwork, TerminationGracePeriod: envGracePeriod, + ExtractArchive: extractArchive, }, } diff --git a/fission/main.go b/fission/main.go index e83e5f8e7..af1573a08 100644 --- a/fission/main.go +++ b/fission/main.go @@ -200,13 +200,14 @@ func main() { envImageFlag := cli.StringFlag{Name: "image", Usage: "Environment image URL"} envBuilderImageFlag := cli.StringFlag{Name: "builder", Usage: "Environment builder image URL (optional)"} envBuildCmdFlag := cli.StringFlag{Name: "buildcmd", Usage: "Build command for environment builder to build source package (optional)"} + envExtractArchiveFlag := cli.BoolFlag{Name: "extractarchive, extract", Usage: "Extract the archive into a directory, defaults to true"} envExternalNetworkFlag := cli.BoolFlag{Name: "externalnetwork", Usage: "Allow environment access external network when istio feature enabled (optional, defaults to false)"} envTerminationGracePeriodFlag := cli.Int64Flag{Name: "graceperiod, period", Value: 360, Usage: "The grace time (in seconds) for pod to perform connection draining before termination (optional)"} envVersionFlag := cli.IntFlag{Name: "version", Value: 1, Usage: "Environment API version (1 means v1 interface)"} envSubcommands := []cli.Command{ - {Name: "create", Aliases: []string{"add"}, Usage: "Add an environment", Flags: []cli.Flag{envNameFlag, envNamespaceFlag, envPoolsizeFlag, envImageFlag, envBuilderImageFlag, envBuildCmdFlag, minCpu, maxCpu, minMem, maxMem, envVersionFlag, envExternalNetworkFlag, envTerminationGracePeriodFlag, specSaveFlag}, Action: envCreate}, + {Name: "create", Aliases: []string{"add"}, Usage: "Add an environment", Flags: []cli.Flag{envNameFlag, envNamespaceFlag, envPoolsizeFlag, envImageFlag, envBuilderImageFlag, envBuildCmdFlag, envExtractArchiveFlag, minCpu, maxCpu, minMem, maxMem, envVersionFlag, envExternalNetworkFlag, envTerminationGracePeriodFlag, specSaveFlag}, Action: envCreate}, {Name: "get", Usage: "Get environment details", Flags: []cli.Flag{envNameFlag, envNamespaceFlag}, Action: envGet}, - {Name: "update", Usage: "Update environment", Flags: []cli.Flag{envNameFlag, envNamespaceFlag, envPoolsizeFlag, envImageFlag, envBuilderImageFlag, envBuildCmdFlag, minCpu, maxCpu, minMem, maxMem, envExternalNetworkFlag, envTerminationGracePeriodFlag}, Action: envUpdate}, + {Name: "update", Usage: "Update environment", Flags: []cli.Flag{envNameFlag, envNamespaceFlag, envPoolsizeFlag, envImageFlag, envBuilderImageFlag, envBuildCmdFlag, envExtractArchiveFlag, minCpu, maxCpu, minMem, maxMem, envExternalNetworkFlag, envTerminationGracePeriodFlag}, Action: envUpdate}, {Name: "delete", Usage: "Delete environment", Flags: []cli.Flag{envNameFlag, envNamespaceFlag}, Action: envDelete}, {Name: "list", Usage: "List all environments", Flags: []cli.Flag{envNamespaceFlag}, Action: envList}, } diff --git a/pkg/apis/fission.io/v1/typefields.go b/pkg/apis/fission.io/v1/typefields.go index 5bc56cad1..44087ac0f 100644 --- a/pkg/apis/fission.io/v1/typefields.go +++ b/pkg/apis/fission.io/v1/typefields.go @@ -270,6 +270,10 @@ type ( // The grace time for pod to perform connection draining before termination. The unit is in seconds. // Optional, defaults to 360 seconds TerminationGracePeriod int64 + + // ExtractArchive is used by fetcher to determine if the extracted archive + // or unarchived file should be placed, which is then used by specialize handler + ExtractArchive bool `json:"extractarchive,extract"` } AllowedFunctionsPerContainer string