containers as functions (#1681)
PR adds a new executortype which supports running containers as functions. New CLI under functions is added to create container as functions. Co-authored-by: Harsh Thakur <harshthakur9030@gmail.com> Co-authored-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
co-authored by
Harsh Thakur
Sanket Sudake
parent
f3e1f9df90
commit
a82281ad1c
@@ -285,18 +285,6 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
Namespace: fnNamespace,
|
||||
},
|
||||
Spec: fv1.FunctionSpec{
|
||||
Environment: fv1.EnvironmentReference{
|
||||
Name: envName,
|
||||
Namespace: envNamespace,
|
||||
},
|
||||
Package: fv1.FunctionPackageRef{
|
||||
FunctionName: entrypoint,
|
||||
PackageRef: fv1.PackageRef{
|
||||
Namespace: pkgMetadata.Namespace,
|
||||
Name: pkgMetadata.Name,
|
||||
ResourceVersion: pkgMetadata.ResourceVersion,
|
||||
},
|
||||
},
|
||||
Secrets: secrets,
|
||||
ConfigMaps: cfgmaps,
|
||||
Resources: *resourceReq,
|
||||
@@ -313,6 +301,18 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts.function.Spec.Environment = fv1.EnvironmentReference{
|
||||
Name: envName,
|
||||
Namespace: envNamespace,
|
||||
}
|
||||
opts.function.Spec.Package = fv1.FunctionPackageRef{
|
||||
FunctionName: entrypoint,
|
||||
PackageRef: fv1.PackageRef{
|
||||
Namespace: pkgMetadata.Namespace,
|
||||
Name: pkgMetadata.Name,
|
||||
ResourceVersion: pkgMetadata.ResourceVersion,
|
||||
},
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -392,13 +392,19 @@ func getInvokeStrategy(input cli.Input, existingInvokeStrategy *fv1.InvokeStrate
|
||||
var es *fv1.ExecutionStrategy
|
||||
|
||||
if existingInvokeStrategy == nil {
|
||||
es, err = getExecutionStrategy(input)
|
||||
executorType, err := getExecutorType(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
es, err = getExecutionStrategy(executorType, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
es, err = updateExecutionStrategy(input, &existingInvokeStrategy.ExecutionStrategy)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &fv1.InvokeStrategy{
|
||||
@@ -407,20 +413,23 @@ func getInvokeStrategy(input cli.Input, existingInvokeStrategy *fv1.InvokeStrate
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getExecutionStrategy(input cli.Input) (strategy *fv1.ExecutionStrategy, err error) {
|
||||
var fnExecutor fv1.ExecutorType
|
||||
|
||||
func getExecutorType(input cli.Input) (executorType fv1.ExecutorType, err error) {
|
||||
switch input.String(flagkey.FnExecutorType) {
|
||||
case "":
|
||||
fallthrough
|
||||
case string(fv1.ExecutorTypePoolmgr):
|
||||
fnExecutor = fv1.ExecutorTypePoolmgr
|
||||
executorType = fv1.ExecutorTypePoolmgr
|
||||
case string(fv1.ExecutorTypeNewdeploy):
|
||||
fnExecutor = fv1.ExecutorTypeNewdeploy
|
||||
executorType = fv1.ExecutorTypeNewdeploy
|
||||
case string(fv1.ExecutorTypeContainer):
|
||||
executorType = fv1.ExecutorTypeContainer
|
||||
default:
|
||||
return nil, errors.Errorf("executor type must be one of '%v' or '%v'", fv1.ExecutorTypePoolmgr, fv1.ExecutorTypeNewdeploy)
|
||||
err = errors.Errorf("executor type must be one of '%v', '%v' or '%v'", fv1.ExecutorTypePoolmgr, fv1.ExecutorTypeNewdeploy, fv1.ExecutorTypeContainer)
|
||||
}
|
||||
return executorType, err
|
||||
}
|
||||
|
||||
func getExecutionStrategy(fnExecutor fv1.ExecutorType, input cli.Input) (strategy *fv1.ExecutionStrategy, err error) {
|
||||
specializationTimeout := fv1.DefaultSpecializationTimeOut
|
||||
|
||||
if input.IsSet(flagkey.FnSpecializationTimeout) {
|
||||
@@ -495,8 +504,10 @@ func updateExecutionStrategy(input cli.Input, existingExecutionStrategy *fv1.Exe
|
||||
fnExecutor = fv1.ExecutorTypePoolmgr
|
||||
case string(fv1.ExecutorTypeNewdeploy):
|
||||
fnExecutor = fv1.ExecutorTypeNewdeploy
|
||||
case string(fv1.ExecutorTypeContainer):
|
||||
fnExecutor = fv1.ExecutorTypeContainer
|
||||
default:
|
||||
return nil, errors.Errorf("executor type must be one of '%v' or '%v'", fv1.ExecutorTypePoolmgr, fv1.ExecutorTypeNewdeploy)
|
||||
return nil, errors.Errorf("executor type must be one of '%v', %v or '%v'", fv1.ExecutorTypePoolmgr, fv1.ExecutorTypeNewdeploy, fv1.ExecutorTypeContainer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user