Skip to content

Commit

Permalink
Merge pull request #49 from seungkyua/20230426_rollback
Browse files Browse the repository at this point in the history
add rollback
  • Loading branch information
seungkyua authored Apr 26, 2023
2 parents 7f777e2 + 2c92d94 commit 4df3142
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
62 changes: 62 additions & 0 deletions internal/commands/appserve-rollback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package commands

import (
"errors"
"fmt"
_apiClient "github.com/openinfradev/tks-api/pkg/api-client"
"github.com/openinfradev/tks-client/internal/helper"
"github.com/spf13/cobra"
)

type rollback struct {
TaskId string `yaml:"task_id" json:"taskId"`
}

func NewAppserveRollbackCmd(globalOpts *GlobalOptions) *cobra.Command {
var (
organizationId string
appId string
)
var command = &cobra.Command{
Use: "rollback",
Short: "Rollback an app to revision",
Long: `Rollback an app to revision.
Example:
tks appserve rollback <TASK_ID> --organization-id <ORG_ID> --app-id <APP_ID>`,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
taskId := args[0]
if len(taskId) < 1 {
return errors.New("TASK_ID is mandatory! Run 'tks appserve rollback --help'")
}

if organizationId == "" {
return errors.New("--organization-id is mandatory param")
}
if appId == "" {
return errors.New("--app-id is mandatory param")
}

apiClient, err := _apiClient.New(globalOpts.ServerAddr, globalOpts.AuthToken)
helper.CheckError(err)

url := fmt.Sprintf("organizations/%v/app-serve-apps/%v/rollback", organizationId, appId)
params := rollback{TaskId: taskId}

body, err := apiClient.Post(url, params)
if err != nil {
return err
}

fmt.Printf("Response: %T Type\n %v\n", body, fmt.Sprintf("%v", body))

return nil
},
}

command.Flags().StringVar(&organizationId, "organization-id", "", "a organizationId")
command.Flags().StringVar(&appId, "app-id", "", "a appId")

return command
}
4 changes: 2 additions & 2 deletions internal/commands/appserve-show.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ func printAppServeShow(d domain.AppServeApp, long bool) {
t.Style().Options.SeparateHeader = false
t.Style().Options.SeparateRows = false
if long {
t.AppendHeader(table.Row{"Version", "Status", "Strategy", "Revision",
t.AppendHeader(table.Row{"ID", "Version", "Status", "Strategy", "Revision",
"Image URL", "Profile", "CREATED_AT", "UPDATED_AT"})
for _, i := range d.AppServeAppTasks {
tCreatedAt := helper.ParseTime(i.CreatedAt)
var tUpdatedAt string
if i.UpdatedAt != nil {
tUpdatedAt = helper.ParseTime(*i.UpdatedAt)
}
t.AppendRow(table.Row{i.Version, i.Status, i.Strategy, strconv.Itoa(int(i.HelmRevision)),
t.AppendRow(table.Row{i.ID, i.Version, i.Status, i.Strategy, strconv.Itoa(int(i.HelmRevision)),
i.ImageUrl, i.Profile, tCreatedAt, tUpdatedAt})
}
} else {
Expand Down
1 change: 1 addition & 0 deletions internal/commands/appserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func NewAppserveCommand(globalOpts *GlobalOptions) *cobra.Command {
command.AddCommand(NewAppserveDeleteCmd(globalOpts))
command.AddCommand(NewAppservePromoteCmd(globalOpts))
command.AddCommand(NewAppserveAbortCmd(globalOpts))
command.AddCommand(NewAppserveRollbackCmd(globalOpts))

return command
}

0 comments on commit 4df3142

Please sign in to comment.