Skip to content

Commit d0d2052

Browse files
authored
Support labels value for client API add application endpoint (#6724)
* Support labels value for client API add application endpoint Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com> * Update pipectl add application command to support labels Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com> --------- Signed-off-by: khanhtc1202 <khanhtc1202@gmail.com>
1 parent 0549f6a commit d0d2052

5 files changed

Lines changed: 600 additions & 562 deletions

File tree

pkg/app/pipectl/cmd/application/add.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package application
1717
import (
1818
"context"
1919
"fmt"
20+
"strings"
2021

2122
"github.com/spf13/cobra"
2223

@@ -30,6 +31,7 @@ type add struct {
3031

3132
appName string
3233
appKind string
34+
labels string
3335
pipedID string
3436
platformProvider string
3537
description string
@@ -52,6 +54,7 @@ func newAddCommand(root *command) *cobra.Command {
5254

5355
cmd.Flags().StringVar(&c.appName, "app-name", c.appName, "The application name.")
5456
cmd.Flags().StringVar(&c.appKind, "app-kind", c.appKind, "The kind of application. (KUBERNETES|TERRAFORM|LAMBDA|CLOUDRUN|ECS)")
57+
cmd.Flags().StringVar(&c.labels, "labels", c.labels, "The labels of the application. Multiple labels can be separated by commas (eg. key1=value1,key2=value2)")
5558
cmd.Flags().StringVar(&c.pipedID, "piped-id", c.pipedID, "The ID of piped that should handle this application.")
5659
cmd.Flags().StringVar(&c.platformProvider, "platform-provider", c.platformProvider, "The platform provider name. One of the registered providers in the piped configuration. Previous name of this field is cloud-provider.")
5760

@@ -82,6 +85,17 @@ func (c *add) run(ctx context.Context, input cli.Input) error {
8285
return fmt.Errorf("unsupported application kind %s", c.appKind)
8386
}
8487

88+
labels := make(map[string]string)
89+
if c.labels != "" {
90+
labelsList := strings.Split(c.labels, ",")
91+
for _, label := range labelsList {
92+
parts := strings.Split(label, "=")
93+
if len(parts) == 2 {
94+
labels[parts[0]] = parts[1]
95+
}
96+
}
97+
}
98+
8599
req := &apiservice.AddApplicationRequest{
86100
Name: c.appName,
87101
PipedId: c.pipedID,
@@ -95,6 +109,7 @@ func (c *add) run(ctx context.Context, input cli.Input) error {
95109
Kind: model.ApplicationKind(appKind),
96110
PlatformProvider: c.platformProvider,
97111
Description: c.description,
112+
Labels: labels,
98113
}
99114

100115
resp, err := cli.AddApplication(ctx, req)

pkg/app/server/grpcapi/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func (a *API) AddApplication(ctx context.Context, req *apiservice.AddApplication
166166
PlatformProvider: req.PlatformProvider,
167167
CloudProvider: req.PlatformProvider,
168168
Description: req.Description,
169+
Labels: req.Labels,
169170
}
170171
if err := a.applicationStore.Add(ctx, &app); err != nil {
171172
return nil, gRPCStoreError(err, fmt.Sprintf("add application %s", app.Id))

0 commit comments

Comments
 (0)