Add annotation flag support to the deploy and store-deploy

Adding support for annotations through annotation flag
to the faas-cli deploy and store-deploy.

Signed-off-by: Martin Dekov (VMware) <mdekov@vmware.com>
This commit is contained in:
Martin Dekov (VMware)
2018-08-09 03:18:52 -07:00
committed by Alex Ellis
parent d8ff52e8bb
commit 8c7957d4d0
3 changed files with 32 additions and 6 deletions

View File

@@ -35,6 +35,7 @@ type DeployFlags struct {
constraints []string
secrets []string
labelOpts []string
annotationOpts []string
sendRegistryAuth bool
}
@@ -55,6 +56,8 @@ func init() {
deployCmd.Flags().StringArrayVarP(&deployFlags.labelOpts, "label", "l", []string{}, "Set one or more label (LABEL=VALUE)")
deployCmd.Flags().StringArrayVarP(&deployFlags.annotationOpts, "annotation", "", []string{}, "Set one or more annotation (ANNOTATION=VALUE)")
deployCmd.Flags().BoolVar(&deployFlags.replace, "replace", false, "Remove and re-create existing function(s)")
deployCmd.Flags().BoolVar(&deployFlags.update, "update", true, "Perform rolling update on existing function(s)")
@@ -83,7 +86,8 @@ var deployCmd = &cobra.Command{
[--handler HANDLER_DIR]
[--fprocess PROCESS]
[--env ENVVAR=VALUE ...]
[--label LABEL=VALUE ...]
[--label LABEL=VALUE ...]
[--annotation ANNOTATION=VALUE ...]
[--replace=false]
[--update=false]
[--constraint PLACEMENT_CONSTRAINT ...]
@@ -100,6 +104,7 @@ via flags. Note: --replace and --update are mutually exclusive.`,
Example: ` faas-cli deploy -f https://domain/path/myfunctions.yml
faas-cli deploy -f ./stack.yml
faas-cli deploy -f ./stack.yml --label canary=true
faas-cli deploy -f ./stack.yml --annotation user=true
faas-cli deploy -f ./stack.yml --filter "*gif*" --secret dockerhuborg
faas-cli deploy -f ./stack.yml --regex "fn[0-9]_.*"
faas-cli deploy -f ./stack.yml --replace=false --update=true
@@ -230,6 +235,13 @@ Error: %s`, fprocessErr.Error())
annotations = *function.Annotations
}
annotationArgs, annotationErr := parseMap(deployFlags.annotationOpts, "annotation")
if annotationErr != nil {
return fmt.Errorf("error parsing annotations: %v", labelErr)
}
allAnnotations := mergeMap(annotations, annotationArgs)
tagMode := schema.DefaultFormat
var sha string
if strings.ToLower(tag) == "sha" {
@@ -249,7 +261,7 @@ Error: %s`, fprocessErr.Error())
function.ReadOnlyRootFilesystem = deployFlags.readOnlyRootFilesystem
}
statusCode := proxy.DeployFunction(function.FProcess, services.Provider.GatewayURL, function.Name, function.Image, function.RegistryAuth, function.Language, deployFlags.replace, allEnvironment, services.Provider.Network, functionConstraints, deployFlags.update, deployFlags.secrets, allLabels, annotations, functionResourceRequest1, function.ReadOnlyRootFilesystem, tlsInsecure)
statusCode := proxy.DeployFunction(function.FProcess, services.Provider.GatewayURL, function.Name, function.Image, function.RegistryAuth, function.Language, deployFlags.replace, allEnvironment, services.Provider.Network, functionConstraints, deployFlags.update, deployFlags.secrets, allLabels, allAnnotations, functionResourceRequest1, function.ReadOnlyRootFilesystem, tlsInsecure)
if badStatusCode(statusCode) {
failedStatusCodes[k] = statusCode
}
@@ -315,13 +327,18 @@ func deployImage(
return statusCode, fmt.Errorf("error parsing labels: %v", labelErr)
}
annotationMap, annotationErr := parseMap(deployFlags.annotationOpts, "annotation")
if annotationErr != nil {
return statusCode, fmt.Errorf("error parsing annotations: %v", annotationErr)
}
functionResourceRequest1 := proxy.FunctionResourceRequest{}
var noAnnotations map[string]string = nil
statusCode = proxy.DeployFunction(fprocess, gateway, functionName,
image, registryAuth, language,
deployFlags.replace, envvars, network,
deployFlags.constraints, deployFlags.update, deployFlags.secrets,
labelMap, noAnnotations, functionResourceRequest1, readOnlyRFS, tlsInsecure)
labelMap, annotationMap, functionResourceRequest1, readOnlyRFS, tlsInsecure)
return statusCode, nil
}

View File

@@ -24,7 +24,7 @@ func init() {
storeDeployCmd.Flags().StringArrayVar(&storeDeployFlags.constraints, "constraint", []string{}, "Apply a constraint to the function")
storeDeployCmd.Flags().StringArrayVar(&storeDeployFlags.secrets, "secret", []string{}, "Give the function access to a secure secret")
storeDeployCmd.Flags().BoolVarP(&storeDeployFlags.sendRegistryAuth, "send-registry-auth", "a", false, "send registryAuth from Docker credentials manager with the request")
storeDeployCmd.Flags().StringArrayVarP(&storeDeployFlags.annotationOpts, "annotation", "", []string{}, "Set one or more annotation (ANNOTATION=VALUE)")
// Set bash-completion.
_ = storeDeployCmd.Flags().SetAnnotation("handler", cobra.BashCompSubdirsInDir, []string{})
@@ -37,7 +37,8 @@ var storeDeployCmd = &cobra.Command{
[--gateway GATEWAY_URL]
[--network NETWORK_NAME]
[--env ENVVAR=VALUE ...]
[--label LABEL=VALUE ...]
[--label LABEL=VALUE ...]
[--annotation ANNOTATION=VALUE ...]
[--replace=false]
[--update=true]
[--constraint PLACEMENT_CONSTRAINT ...]
@@ -85,6 +86,13 @@ func runStoreDeploy(cmd *cobra.Command, args []string) error {
}
}
if item.Annotations != nil {
for k, v := range item.Annotations {
annotation := fmt.Sprintf("%s=%s", k, v)
storeDeployFlags.annotationOpts = append(storeDeployFlags.annotationOpts, annotation)
}
}
// Use the network from manifest if not changed by user
if !cmd.Flag("network").Changed {
network = item.Network

View File

@@ -12,5 +12,6 @@ type StoreItem struct {
RepoURL string `json:"repo_url"`
Environment map[string]string `json:"environment"`
Labels map[string]string `json:"labels"`
Annotations map[string]string `json:"annotations"`
ReadOnlyRootFilesystem bool `json:"readOnlyRootFilesystem"`
}