From 61569d1c38a57e7e05ee06ef005e14a6f68726a1 Mon Sep 17 00:00:00 2001 From: Ta-Ching Chen Date: Fri, 6 Jul 2018 03:13:07 +0800 Subject: [PATCH] Change flag name to KeepArchive for backward compatibility (#787) --- buildermgr/common.go | 8 ++++---- environments/fetcher/fetcher.go | 18 +++++++++--------- executor/newdeploy/newdeploy.go | 8 ++++---- executor/poolmgr/gp.go | 8 ++++---- fission/environment.go | 11 ++++++----- fission/main.go | 6 +++--- pkg/apis/fission.io/v1/typefields.go | 4 ++-- test/tests/test_environments/test_java_env.sh | 4 ++-- 8 files changed, 34 insertions(+), 33 deletions(-) diff --git a/buildermgr/common.go b/buildermgr/common.go index 81f3990e..84cb8625 100644 --- a/buildermgr/common.go +++ b/buildermgr/common.go @@ -54,10 +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, - ExtractArchive: true, + FetchType: fetcher.FETCH_SOURCE, + Package: pkg.Metadata, + Filename: srcPkgFilename, + KeepArchive: false, } // send fetch request to fetcher diff --git a/environments/fetcher/fetcher.go b/environments/fetcher/fetcher.go index 090e77f7..a527f0fb 100644 --- a/environments/fetcher/fetcher.go +++ b/environments/fetcher/fetcher.go @@ -29,14 +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"` - ExtractArchive bool `json:"extractarchive"` + 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"` + KeepArchive bool `json:"keeparchive"` } // UploadRequest send from builder manager describes which @@ -293,7 +293,7 @@ func (fetcher *Fetcher) Fetch(req FetchRequest) (int, error) { } } - if archiver.Zip.Match(tmpPath) && req.ExtractArchive { + if archiver.Zip.Match(tmpPath) && !req.KeepArchive { // unarchive tmp file to a tmp unarchive path tmpUnarchivePath := filepath.Join(fetcher.sharedVolumePath, uuid.NewV4().String()) err := fetcher.unarchive(tmpPath, tmpUnarchivePath) diff --git a/executor/newdeploy/newdeploy.go b/executor/newdeploy/newdeploy.go index 1387c0fe..56192c8b 100644 --- a/executor/newdeploy/newdeploy.go +++ b/executor/newdeploy/newdeploy.go @@ -158,10 +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, - ExtractArchive: env.Spec.ExtractArchive, + Filename: targetFilename, + Secrets: fn.Spec.Secrets, + ConfigMaps: fn.Spec.ConfigMaps, + KeepArchive: env.Spec.KeepArchive, } loadReq := fission.FunctionLoadRequest{ diff --git a/executor/poolmgr/gp.go b/executor/poolmgr/gp.go index 21f78c2a..c1f2ba37 100644 --- a/executor/poolmgr/gp.go +++ b/executor/poolmgr/gp.go @@ -387,10 +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, - ExtractArchive: gp.env.Spec.ExtractArchive, + Filename: targetFilename, + Secrets: fn.Spec.Secrets, + ConfigMaps: fn.Spec.ConfigMaps, + KeepArchive: gp.env.Spec.KeepArchive, }) if err != nil { return err diff --git a/fission/environment.go b/fission/environment.go index b00f7665..dc79fe27 100644 --- a/fission/environment.go +++ b/fission/environment.go @@ -93,10 +93,7 @@ func envCreate(c *cli.Context) error { } } - extractArchive := true - if c.IsSet("extract") { - extractArchive = c.Bool("extract") - } + keepArchive := c.Bool("keeparchive") // Environment API interface version is not specified and // builder image is empty, set default interface version @@ -124,7 +121,7 @@ func envCreate(c *cli.Context) error { Resources: resourceReq, AllowAccessToExternalNetwork: envExternalNetwork, TerminationGracePeriod: envGracePeriod, - ExtractArchive: extractArchive, + KeepArchive: keepArchive, }, } @@ -214,6 +211,10 @@ func envUpdate(c *cli.Context) error { env.Spec.TerminationGracePeriod = c.Int64("period") } + if c.IsSet("keeparchive") { + env.Spec.KeepArchive = c.Bool("keeparchive") + } + env.Spec.AllowAccessToExternalNetwork = envExternalNetwork _, err = client.EnvironmentUpdate(env) diff --git a/fission/main.go b/fission/main.go index 3d1e11b2..3362aef1 100644 --- a/fission/main.go +++ b/fission/main.go @@ -202,14 +202,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"} + envKeepArchiveFlag := cli.BoolFlag{Name: "keeparchive", Usage: "Keep the archive instead of extracting it into a directory (optional, defaults to false)"} 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, envExtractArchiveFlag, 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, envKeepArchiveFlag, 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, envExtractArchiveFlag, minCpu, maxCpu, minMem, maxMem, envExternalNetworkFlag, envTerminationGracePeriodFlag}, Action: envUpdate}, + {Name: "update", Usage: "Update environment", Flags: []cli.Flag{envNameFlag, envNamespaceFlag, envPoolsizeFlag, envImageFlag, envBuilderImageFlag, envBuildCmdFlag, envKeepArchiveFlag, 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 81a87172..879157cf 100644 --- a/pkg/apis/fission.io/v1/typefields.go +++ b/pkg/apis/fission.io/v1/typefields.go @@ -271,9 +271,9 @@ type ( // Optional, defaults to 360 seconds TerminationGracePeriod int64 - // ExtractArchive is used by fetcher to determine if the extracted archive + // KeepArchive 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"` + KeepArchive bool `json:"keeparchive"` } AllowedFunctionsPerContainer string diff --git a/test/tests/test_environments/test_java_env.sh b/test/tests/test_environments/test_java_env.sh index 2193307a..9f53b8e0 100755 --- a/test/tests/test_environments/test_java_env.sh +++ b/test/tests/test_environments/test_java_env.sh @@ -32,7 +32,7 @@ log "Creating the jar from application" docker run -it --rm -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.5-jdk-8 mvn clean package log "Creating environment for Java" -fission env create --name jvm --image gcr.io/fission-ci/jvm-env:test --version 2 --extract=false +fission env create --name jvm --image gcr.io/fission-ci/jvm-env:test --version 2 --keeparchive=true log "Creating pool manager & new deployment function for Java" fission fn create --name hellop --deploy target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar --env jvm --entrypoint io.fission.HelloWorld @@ -52,4 +52,4 @@ log "Testing pool manager function" timeout 60 bash -c "test_fn hellop 'Hello'" log "Testing new deployment function" -timeout 60 bash -c "test_fn hellon 'Hello'" \ No newline at end of file +timeout 60 bash -c "test_fn hellon 'Hello'"