Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions pkg/app/pipectl/cmd/application/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
Expand All @@ -17,14 +17,3 @@ go_library(
"@com_github_spf13_cobra//:go_default_library",
],
)

go_test(
name = "go_default_test",
size = "small",
srcs = ["sync_test.go"],
embed = [":go_default_library"],
deps = [
"//pkg/model:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
],
)
26 changes: 3 additions & 23 deletions pkg/app/pipectl/cmd/application/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type sync struct {
root *command

appID string
status []string
statuses []string
checkInterval time.Duration
timeout time.Duration
}
Expand All @@ -49,7 +49,7 @@ func newSyncCommand(root *command) *cobra.Command {
}

cmd.Flags().StringVar(&c.appID, "app-id", c.appID, "The application ID.")
cmd.Flags().StringSliceVar(&c.status, "wait-status", c.status, fmt.Sprintf("The list of waiting statuses. Empty means returning immediately after triggered. (%s)", strings.Join(availableStatuses(), "|")))
cmd.Flags().StringSliceVar(&c.statuses, "wait-status", c.statuses, fmt.Sprintf("The list of waiting statuses. Empty means returning immediately after triggered. (%s)", strings.Join(model.DeploymentStatusStrings(), "|")))
cmd.Flags().DurationVar(&c.checkInterval, "check-interval", c.checkInterval, "The interval of checking the requested command.")
cmd.Flags().DurationVar(&c.timeout, "timeout", c.timeout, "Maximum execution time.")

Expand All @@ -59,7 +59,7 @@ func newSyncCommand(root *command) *cobra.Command {
}

func (c *sync) run(ctx context.Context, t cli.Telemetry) error {
statuses, err := makeStatuses(c.status)
statuses, err := model.DeploymentStatusesFromStrings(c.statuses)
if err != nil {
return fmt.Errorf("invalid deployment status: %w", err)
}
Expand Down Expand Up @@ -92,23 +92,3 @@ func (c *sync) run(ctx context.Context, t cli.Telemetry) error {
t.Logger,
)
}

func makeStatuses(statuses []string) ([]model.DeploymentStatus, error) {
out := make([]model.DeploymentStatus, 0, len(statuses))
for _, s := range statuses {
status, ok := model.DeploymentStatus_value["DEPLOYMENT_"+s]
if !ok {
return nil, fmt.Errorf("bad status %s", s)
}
out = append(out, model.DeploymentStatus(status))
}
return out, nil
}

func availableStatuses() []string {
out := make([]string, 0, len(model.DeploymentStatus_value))
for s := range model.DeploymentStatus_value {
out = append(out, strings.TrimPrefix(s, "DEPLOYMENT_"))
}
return out
}
63 changes: 0 additions & 63 deletions pkg/app/pipectl/cmd/application/sync_test.go

This file was deleted.

13 changes: 1 addition & 12 deletions pkg/app/pipectl/cmd/deployment/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
Expand All @@ -15,14 +15,3 @@ go_library(
"@com_github_spf13_cobra//:go_default_library",
],
)

go_test(
name = "go_default_test",
size = "small",
srcs = ["waitstatus_test.go"],
embed = [":go_default_library"],
deps = [
"//pkg/model:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
],
)
26 changes: 3 additions & 23 deletions pkg/app/pipectl/cmd/deployment/waitstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type waitStatus struct {
root *command

deploymentID string
status []string
statuses []string
checkInterval time.Duration
timeout time.Duration
}
Expand All @@ -49,7 +49,7 @@ func newWaitStatusCommand(root *command) *cobra.Command {
}

cmd.Flags().StringVar(&c.deploymentID, "deployment-id", c.deploymentID, "The deployment ID.")
cmd.Flags().StringSliceVar(&c.status, "status", c.status, fmt.Sprintf("The list of waiting statuses. (%s)", strings.Join(availableStatuses(), "|")))
cmd.Flags().StringSliceVar(&c.statuses, "status", c.statuses, fmt.Sprintf("The list of waiting statuses. (%s)", strings.Join(model.DeploymentStatusStrings(), "|")))
cmd.Flags().DurationVar(&c.checkInterval, "check-interval", c.checkInterval, "The interval of checking the deployment status.")
cmd.Flags().DurationVar(&c.timeout, "timeout", c.timeout, "Maximum execution time.")

Expand All @@ -60,7 +60,7 @@ func newWaitStatusCommand(root *command) *cobra.Command {
}

func (c *waitStatus) run(ctx context.Context, t cli.Telemetry) error {
statuses, err := makeStatuses(c.status)
statuses, err := model.DeploymentStatusesFromStrings(c.statuses)
if err != nil {
return fmt.Errorf("invalid deployment status: %w", err)
}
Expand All @@ -81,23 +81,3 @@ func (c *waitStatus) run(ctx context.Context, t cli.Telemetry) error {
t.Logger,
)
}

func makeStatuses(statuses []string) ([]model.DeploymentStatus, error) {
out := make([]model.DeploymentStatus, 0, len(statuses))
for _, s := range statuses {
status, ok := model.DeploymentStatus_value["DEPLOYMENT_"+s]
if !ok {
return nil, fmt.Errorf("bad status %s", s)
}
out = append(out, model.DeploymentStatus(status))
}
return out, nil
}

func availableStatuses() []string {
out := make([]string, 0, len(model.DeploymentStatus_value))
for s := range model.DeploymentStatus_value {
out = append(out, strings.TrimPrefix(s, "DEPLOYMENT_"))
}
return out
}
63 changes: 0 additions & 63 deletions pkg/app/pipectl/cmd/deployment/waitstatus_test.go

This file was deleted.

24 changes: 24 additions & 0 deletions pkg/model/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package model

import (
"fmt"

"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -166,3 +168,25 @@ func (d *Deployment) FindRollbackStage() (*PipelineStage, bool) {
}
return nil, false
}

// DeploymentStatusesFromStrings converts a list of strings to list of DeploymentStatus.
func DeploymentStatusesFromStrings(statuses []string) ([]DeploymentStatus, error) {
out := make([]DeploymentStatus, 0, len(statuses))
for _, s := range statuses {
status, ok := DeploymentStatus_value[s]
if !ok {
return nil, fmt.Errorf("invalid status %s", s)
}
out = append(out, DeploymentStatus(status))
}
return out, nil
}

// DeploymentStatusStrings returns a list of available deployment statuses in string.
func DeploymentStatusStrings() []string {
out := make([]string, 0, len(DeploymentStatus_value))
for s := range DeploymentStatus_value {
out = append(out, s)
}
return out
}