feat: Add missing fields to the describe output
Add the function * constraints * environment variables * secrets * requests and limits This can be tested as follows: Create a test cluster using KinD ```sh kind create cluster --config=cluster.yaml arkade install openfaas -a=false --function-pull-policy=IfNotPresent --wait faas-cli store deploy nodeinfo --annotation sample=true --label status=418 ``` Now deploy a sample function ```sh $ faas-cli describe nodeinfo Name: nodeinfo Status: Ready Replicas: 1 Available replicas: 1 Invocations: 0 Image: ghcr.io/openfaas/nodeinfo:latest Function process: <default> URL: http://127.0.0.1:8080/function/nodeinfo Async URL: http://127.0.0.1:8080/async-function/nodeinfo Labels faas_function : nodeinfo status : 418 Annotations sample : true prometheus.io.scrape : false Constraints <none> Environment <none> Secrets <none> Requests <none> Limits <none> ``` Now we add some more interesting values, like a secret and env variables. ```sh $ faas-cli secret create db-password --from-literal=password Creating secret: db-password. Created: 202 Accepted $ faas-cli store deploy nodeinfo --annotation sample=true --label status=418 --secret db-password --env db-user=postgres --env db-host=rds.aws.example.com Deployed. 202 Accepted. URL: http://127.0.0.1:8080/function/nodeinfo $ faas-cli describe nodeinfo Name: nodeinfo Status: Ready Replicas: 1 Available replicas: 1 Invocations: 0 Image: ghcr.io/openfaas/nodeinfo:latest Function process: <default> URL: http://127.0.0.1:8080/function/nodeinfo Async URL: http://127.0.0.1:8080/async-function/nodeinfo Labels: faas_function: nodeinfo status: 418 uid: 736815901 Annotations: prometheus.io.scrape: false sample: true Constraints: <none> Environment: <none> Secrets: - db-password Requests: <none> Limits: <none> ``` To see how multiple Secrets and the Requests and Limits are rendered, use ```yaml version: 1.0 provider: name: openfaas gateway: http://127.0.0.1:8080 functions: nodeinfo: lang: Dockerfile image: ghcr.io/openfaas/nodeinfo:latest secrets: - cache-password - db-password environment: db-host: rds.aws.example.com cache-host: redis.aws.example.com labels: status: 481 annotations: sample: "true" requests: cpu: 100m memory: 128Mi limits: cpu: 200m memory: 256Mi ``` then ```sh $ faas-cli secret create cache-password --from-literal=password Creating secret: cache-password. Created: 202 Accepted $ faas-cli deploy Deploying: nodeinfo. Deployed. 202 Accepted. URL: http://127.0.0.1:8080/function/nodeinfo $ faas-cli describe nodeinfo Name: nodeinfo Status: Ready Replicas: 1 Available replicas: 1 Invocations: 0 Image: ghcr.io/openfaas/nodeinfo:latest Function process: <default> URL: http://127.0.0.1:8080/function/nodeinfo Async URL: http://127.0.0.1:8080/async-function/nodeinfo Labels: faas_function: nodeinfo status: 481 uid: 679245186 Annotations: prometheus.io.scrape: false sample: true Constraints: <none> Environment: <none> Secrets: - cache-password - db-password Requests: CPU: 100m Memory: 128Mi Limits: CPU: 200m Memory: 256Mi ``` Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
56b1a7db77
commit
b65e279f9f
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/openfaas/faas-cli/proxy"
|
||||
"github.com/openfaas/faas-cli/schema"
|
||||
"github.com/openfaas/faas-cli/stack"
|
||||
"github.com/openfaas/faas-provider/types"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -103,20 +104,11 @@ func runDescribe(cmd *cobra.Command, args []string) error {
|
||||
url, asyncURL := getFunctionURLs(gatewayAddress, functionName, functionNamespace)
|
||||
|
||||
funcDesc := schema.FunctionDescription{
|
||||
Name: function.Name,
|
||||
Status: status,
|
||||
Replicas: int(function.Replicas),
|
||||
AvailableReplicas: int(function.AvailableReplicas),
|
||||
InvocationCount: int(invocationCount),
|
||||
Image: function.Image,
|
||||
EnvProcess: function.EnvProcess,
|
||||
URL: url,
|
||||
AsyncURL: asyncURL,
|
||||
Labels: function.Labels,
|
||||
Annotations: function.Annotations,
|
||||
}
|
||||
if function.Usage != nil {
|
||||
funcDesc.Usage = function.Usage
|
||||
FunctionStatus: function,
|
||||
Status: status,
|
||||
InvocationCount: int(invocationCount),
|
||||
URL: url,
|
||||
AsyncURL: asyncURL,
|
||||
}
|
||||
|
||||
printFunctionDescription(funcDesc)
|
||||
@@ -140,17 +132,26 @@ func getFunctionURLs(gateway string, functionName string, functionNamespace stri
|
||||
|
||||
func printFunctionDescription(funcDesc schema.FunctionDescription) {
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.TabIndent)
|
||||
process := "<default>"
|
||||
if funcDesc.EnvProcess != "" {
|
||||
process = funcDesc.EnvProcess
|
||||
}
|
||||
fmt.Fprintln(w, "Name:\t "+funcDesc.Name)
|
||||
fmt.Fprintln(w, "Status:\t "+funcDesc.Status)
|
||||
fmt.Fprintln(w, "Replicas:\t "+strconv.Itoa(funcDesc.Replicas))
|
||||
fmt.Fprintln(w, "Available replicas:\t "+strconv.Itoa(funcDesc.AvailableReplicas))
|
||||
fmt.Fprintln(w, "Replicas:\t "+strconv.Itoa(int(funcDesc.Replicas)))
|
||||
fmt.Fprintln(w, "Available replicas:\t "+strconv.Itoa(int(funcDesc.AvailableReplicas)))
|
||||
fmt.Fprintln(w, "Invocations:\t "+strconv.Itoa(funcDesc.InvocationCount))
|
||||
fmt.Fprintln(w, "Image:\t "+funcDesc.Image)
|
||||
fmt.Fprintln(w, "Function process:\t "+funcDesc.EnvProcess)
|
||||
fmt.Fprintln(w, "Function process:\t "+process)
|
||||
fmt.Fprintln(w, "URL:\t "+funcDesc.URL)
|
||||
fmt.Fprintln(w, "Async URL:\t "+funcDesc.AsyncURL)
|
||||
printMap(w, "Labels", *funcDesc.Labels)
|
||||
printMap(w, "Annotations", *funcDesc.Annotations)
|
||||
printList(w, "Constraints", funcDesc.Constraints)
|
||||
printMap(w, "Environment", funcDesc.EnvVars)
|
||||
printList(w, "Secrets", funcDesc.Secrets)
|
||||
printResources(w, "Requests", funcDesc.Requests)
|
||||
printResources(w, "Limits", funcDesc.Limits)
|
||||
if funcDesc.Usage != nil {
|
||||
fmt.Println()
|
||||
|
||||
@@ -160,14 +161,13 @@ func printFunctionDescription(funcDesc schema.FunctionDescription) {
|
||||
cpu = 1
|
||||
}
|
||||
fmt.Fprintf(w, "CPU:\t %.0f Mi\n", (cpu))
|
||||
|
||||
}
|
||||
|
||||
w.Flush()
|
||||
}
|
||||
|
||||
func printMap(w *tabwriter.Writer, name string, m map[string]string) {
|
||||
fmt.Fprintf(w, name)
|
||||
fmt.Fprintf(w, name+":")
|
||||
|
||||
if len(m) == 0 {
|
||||
fmt.Fprintln(w, " \t <none>")
|
||||
@@ -175,8 +175,37 @@ func printMap(w *tabwriter.Writer, name string, m map[string]string) {
|
||||
}
|
||||
|
||||
for key, value := range m {
|
||||
fmt.Fprintln(w, " \t "+key+" : "+value)
|
||||
fmt.Fprintln(w, " \t "+key+": "+value)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func printList(w *tabwriter.Writer, name string, data []string) {
|
||||
fmt.Fprintf(w, name+":")
|
||||
|
||||
if len(data) == 0 {
|
||||
fmt.Fprintln(w, " \t <none>")
|
||||
return
|
||||
}
|
||||
|
||||
for _, value := range data {
|
||||
fmt.Fprintln(w, " \t - "+value)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func printResources(w *tabwriter.Writer, name string, data *types.FunctionResources) {
|
||||
fmt.Fprintf(w, name+":")
|
||||
|
||||
if data == nil {
|
||||
fmt.Fprintln(w, " \t <none>")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprintln(w, " \t CPU: "+data.CPU)
|
||||
fmt.Fprintln(w, " \t Memory: "+data.Memory)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -7,16 +7,9 @@ import "github.com/openfaas/faas-provider/types"
|
||||
|
||||
//FunctionDescription information related to a function
|
||||
type FunctionDescription struct {
|
||||
Name string
|
||||
Status string
|
||||
Replicas int
|
||||
AvailableReplicas int
|
||||
InvocationCount int
|
||||
Image string
|
||||
EnvProcess string
|
||||
URL string
|
||||
AsyncURL string
|
||||
Labels *map[string]string
|
||||
Annotations *map[string]string
|
||||
Usage *types.FunctionUsage
|
||||
types.FunctionStatus
|
||||
Status string
|
||||
InvocationCount int
|
||||
URL string
|
||||
AsyncURL string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user