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.
This commit is contained in:
Vishal
2018-06-14 12:32:40 +05:30
committed by GitHub
parent 6d08e6e0bc
commit 1b86c367a0
7 changed files with 35 additions and 20 deletions
+4 -3
View File
@@ -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
+10 -9
View File
@@ -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
}
+4 -3
View File
@@ -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{
+4 -3
View File
@@ -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
+6
View File
@@ -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,
},
}
+3 -2
View File
@@ -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},
}
+4
View File
@@ -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