Skip to content

Commit

Permalink
feat: display effective status, and state in 'status' (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav-14 authored and David Ragot committed Nov 2, 2023
1 parent e20b628 commit b5f5463
Show file tree
Hide file tree
Showing 11 changed files with 634 additions and 42 deletions.
10 changes: 7 additions & 3 deletions components/fctl/cmd/stack/internal/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ func PrintStackInformation(out io.Writer, profile *fctl.Profile, stack *membersh
return err
}

err = printVersion(out, baseUrlStr, versions, stack)
if versions != nil {
err = printVersion(out, baseUrlStr, versions, stack)

if err != nil {
return err
if err != nil {
return err
}
}

err = printMetadata(out, stack)
Expand All @@ -42,6 +44,8 @@ func printInformation(out io.Writer, stack *membershipclient.Stack) error {
tableData = append(tableData, []string{pterm.LightCyan("ID"), stack.Id, ""})
tableData = append(tableData, []string{pterm.LightCyan("Name"), stack.Name, ""})
tableData = append(tableData, []string{pterm.LightCyan("Region"), stack.RegionID, ""})
tableData = append(tableData, []string{pterm.LightCyan("Status"), stack.State, ""})
tableData = append(tableData, []string{pterm.LightCyan("Effective status"), stack.Status, ""})
return pterm.DefaultTable.
WithWriter(out).
WithData(tableData).
Expand Down
37 changes: 22 additions & 15 deletions components/fctl/cmd/stack/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

const (
deletedFlag = "deleted"
disabledFlag = "disabled"
allFlag = "all"
deletedFlag = "deleted"
)

type Stack struct {
Expand All @@ -23,6 +23,7 @@ type Stack struct {
RegionID string `json:"region"`
DisabledAt *string `json:"disabledAt"`
DeletedAt *string `json:"deletedAt"`
Status string `json:"status"`
}
type StackListStore struct {
Stacks []Stack `json:"stacks"`
Expand Down Expand Up @@ -53,7 +54,8 @@ func NewListCommand() *cobra.Command {
fctl.WithShortDescription("List stacks"),
fctl.WithArgs(cobra.ExactArgs(0)),
fctl.WithBoolFlag(deletedFlag, false, "Display deleted stacks"),
fctl.WithBoolFlag(disabledFlag, false, "Display disabled stacks"),
fctl.WithBoolFlag(allFlag, false, "Display deleted stacks"),
fctl.WithDeprecatedFlag(deletedFlag, "Use --all instead"),
fctl.WithController[*StackListStore](NewStackListController()),
)
}
Expand Down Expand Up @@ -81,8 +83,8 @@ func (c *StackListController) Run(cmd *cobra.Command, args []string) (fctl.Rende
}

rsp, _, err := apiClient.DefaultApi.ListStacks(cmd.Context(), organization).
All(fctl.GetBool(cmd, allFlag)).
Deleted(fctl.GetBool(cmd, deletedFlag)).
Disabled(fctl.GetBool(cmd, disabledFlag)).
Execute()
if err != nil {
return nil, errors.Wrap(err, "listing stacks")
Expand All @@ -99,6 +101,7 @@ func (c *StackListController) Run(cmd *cobra.Command, args []string) (fctl.Rende
Name: stack.Name,
Dashboard: c.profile.ServicesBaseUrl(&stack).String(),
RegionID: stack.RegionID,
Status: stack.State,
DisabledAt: func() *string {
if stack.DisabledAt != nil {
t := stack.DisabledAt.Format(time.RFC3339)
Expand Down Expand Up @@ -131,32 +134,36 @@ func (c *StackListController) Render(cmd *cobra.Command, args []string) error {
stack.Name,
stack.Dashboard,
stack.RegionID,
stack.Status,
}
if fctl.GetBool(cmd, disabledFlag) {
if fctl.GetBool(cmd, allFlag) {

if stack.DisabledAt != nil {
data = append(data, *stack.DisabledAt)
} else {
data = append(data, "")
}
}
if fctl.GetBool(cmd, deletedFlag) {

if stack.DeletedAt != nil {
data = append(data, *stack.DeletedAt)
} else {
data = append(data, "")
if stack.Status != "DELETED" {
data = append(data, "")

} else {

data = append(data, "<retention period>")
}
}
}

return data
})

headers := []string{"ID", "Name", "Dashboard", "Region"}
if fctl.GetBool(cmd, disabledFlag) {
headers = append(headers, "Disabled at")
headers := []string{"ID", "Name", "Dashboard", "Region", "Status"}
if fctl.GetBool(cmd, allFlag) {
headers = append(headers, "Disabled At", "Deleted At")
}
if fctl.GetBool(cmd, deletedFlag) {
headers = append(headers, "Deleted at")
}

tableData = fctl.Prepend(tableData, headers)

return pterm.DefaultTable.
Expand Down
13 changes: 11 additions & 2 deletions components/fctl/cmd/stack/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,32 @@ func (c *StackShowController) Run(cmd *cobra.Command, args []string) (fctl.Rende
return nil, errStackNotFound
}

c.store.Stack = stack
c.config = cfg

// the stack is not active, we can't get the running versions
// Maybe add something in the process with sync status and store it in membership

if stack.Status != "ACTIVE" {
return c, nil
}

stackClient, err := fctl.NewStackClient(cmd, cfg, stack)
if err != nil {
return nil, err
}

versions, err := stackClient.GetVersions(cmd.Context())
if err != nil {

return nil, err
}

if versions.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code %d when reading versions", versions.StatusCode)
}

c.store.Stack = stack
c.store.Versions = versions.GetVersionsResponse
c.config = cfg

return c, nil

Expand Down
46 changes: 42 additions & 4 deletions components/fctl/membership-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/CreateOrganizationResponse'
400:
description: Error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'

/organizations/expanded:
get:
summary: List organizations of the connected user with expanded data
Expand Down Expand Up @@ -197,15 +204,16 @@ paths:
schema:
type: string
required: true
- name: deleted
- name: all
in: query
description: Include deleted stacks
description: Include deleted and disabled stacks
schema:
type: boolean
required: false
- name: disabled
- name: deleted
in: query
description: Include disabled stacks
description: Include deleted stacks
deprecated: true
schema:
type: boolean
required: false
Expand Down Expand Up @@ -784,6 +792,11 @@ components:
- regionID
- stargateEnabled
- status
- state
- expectedStatus
- lastStateUpdate
- lastExpectedStatusUpdate
- lastStatusUpdate
properties:
id:
type: string
Expand Down Expand Up @@ -814,6 +827,31 @@ components:
- UNKNOWN
- PROGRESSING
- READY
- DISABLED
- DELETED
state:
type: string
enum:
- ACTIVE
- DISABLED
- DELETED
expectedStatus:
type: string
enum:
- UNKNOWN
- PROGRESSING
- READY
- DISABLED
- DELETED
lastStateUpdate:
type: string
format: date-time
lastExpectedStatusUpdate:
type: string
format: date-time
lastStatusUpdate:
type: string
format: date-time
UpdatableUserData:
type: object
properties:
Expand Down
45 changes: 41 additions & 4 deletions components/fctl/membershipclient/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ paths:
schema:
$ref: '#/components/schemas/CreateOrganizationResponse'
description: Organization created
"400":
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
description: Error
summary: Create organization
/organizations/expanded:
get:
Expand Down Expand Up @@ -241,18 +247,19 @@ paths:
schema:
type: string
style: simple
- description: Include deleted stacks
- description: Include deleted and disabled stacks
explode: true
in: query
name: deleted
name: all
required: false
schema:
type: boolean
style: form
- description: Include disabled stacks
- deprecated: true
description: Include deleted stacks
explode: true
in: query
name: disabled
name: deleted
required: false
schema:
type: boolean
Expand Down Expand Up @@ -1208,12 +1215,42 @@ components:
- UNKNOWN
- PROGRESSING
- READY
- DISABLED
- DELETED
type: string
state:
enum:
- ACTIVE
- DISABLED
- DELETED
type: string
expectedStatus:
enum:
- UNKNOWN
- PROGRESSING
- READY
- DISABLED
- DELETED
type: string
lastStateUpdate:
format: date-time
type: string
lastExpectedStatusUpdate:
format: date-time
type: string
lastStatusUpdate:
format: date-time
type: string
required:
- expectedStatus
- id
- lastExpectedStatusUpdate
- lastStateUpdate
- lastStatusUpdate
- organizationId
- regionID
- stargateEnabled
- state
- status
- uri
type: object
Expand Down
31 changes: 21 additions & 10 deletions components/fctl/membershipclient/api_default.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b5f5463

Please sign in to comment.