-
Notifications
You must be signed in to change notification settings - Fork 327
CSL-10969: Update the status command to output the consul client & deployments status as well along with existing ones. #4790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This reverts commit b391ef8.
cli/cmd/status/status.go
Outdated
return 1 | ||
err = c.checkConsulComponentsStatus(namespace) | ||
if err != nil { | ||
return 1 // Only for testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unable to infer from the command, is this for local testing? If so, do we need to keep it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkConsulComponentsStatus is doing the main core work along with printing the errors.
The purpose of returning error is only in unit tests, to check if command run() is exiting with correct error codes.
If we dont output error code, the unit test at line 165 will will not be able to assert if the checkConsulComponentsStatus returned any error or it passed successfully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the comment since the method expects an integer return value anyways :D
cli/cmd/status/status.go
Outdated
return 1 | ||
err = c.checkConsulComponentsStatus(namespace) | ||
if err != nil { | ||
return 1 // Only for testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the comment since the method expects an integer return value anyways :D
cli/cmd/status/status.go
Outdated
// checkConsulServers prints the status of Consul servers if they | ||
// are expected to be found in the Kubernetes cluster. It does not check for | ||
// server status if they are not running within the Kubernetes cluster. | ||
// checkConsulComponentsStatus lists status of different consul components |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more detailed comment will be great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
cli/cmd/status/status.go
Outdated
// checkConsulServers list the Consul Servers and their ready status (number of pods ready/desired), | ||
func (c *Command) checkConsulServers(namespace string) error { | ||
servers, err := c.kubernetes.AppsV1().StatefulSets(namespace).List(c.Ctx, metav1.ListOptions{LabelSelector: "app=consul,chart=consul-helm,component=server"}) | ||
servers, err := c.kubernetes.AppsV1().StatefulSets(namespace).List(c.Ctx, metav1.ListOptions{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a breaking change? The behaviour of this flow will change as we're removing the label selector filters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this, added label selector for both consul servers and clients.
cli/cmd/status/status.go
Outdated
} | ||
|
||
// checkConsulClients list the Consul Clients and their ready status (number of pods ready/desired) | ||
func (c *Command) checkConsulClients(namespace string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printConsulClients
might be a more apt name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to getConsulClientsTable
cli/cmd/status/status.go
Outdated
} | ||
|
||
// checkConsulServers list the Consul Servers and their ready status (number of pods ready/desired), | ||
func (c *Command) checkConsulServers(namespace string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printConsulServers
might be a more apt name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to getConsulServerTable
cli/cmd/status/status.go
Outdated
} | ||
|
||
// checkConsulDeployments list the Consul Deployed Deployments and their ready status (number of pods ready/desired), | ||
func (c *Command) checkConsulDeployments(namespace string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printConsulDeployments
might be a more apt name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated checkConsulDeployments
to getConsulDeoploymentTable
which returns tbl to caller and then caller calls printComponentStatus
for printing component status.
and in testing directly using getConsulDeoploymentTable
to assert the table instance instead of buffer.
cli/cmd/status/status.go
Outdated
} | ||
|
||
// checkConsulDeployments list the Consul Deployed Deployments and their ready status (number of pods ready/desired), | ||
func (c *Command) checkConsulDeployments(namespace string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better if this returns tbl
so that unit tests can just use go native structs for assertions.
The line c.UI.Table(tbl)
can be moved to the caller
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
require.NoError(t, err) | ||
|
||
actual := buf.String() | ||
if tc.desired > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For testing, it'll be better if checkConsulServers
returns an instance of terminal.Table
and it can be used for assertions directly. Asserting the stdout as string is not a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the Consul CLI status command to display comprehensive status information for Consul components in tabular format. The change replaces simple text-based server status output with structured tables for servers, clients, and deployments.
- Updated status command to show Consul clients, servers, and deployments status in tabular format
- Refactored server status checking to use table-based output instead of plain text
- Added comprehensive test coverage for the new client and deployment status functionality
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
cli/cmd/status/status.go | Refactored status checking logic to support tabular output for clients, servers, and deployments |
cli/cmd/status/status_test.go | Added comprehensive tests for client and deployment status checking, updated existing server tests |
.changelog/4790.txt | Added changelog entry documenting the new feature |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
cli/cmd/status/status.go
Outdated
// getConsulDeploymentsTable returns the table instance with the Consul Deployed Deployments | ||
// and their ready status (number of pods ready/desired), | ||
func (c *Command) getConsulDeploymentsTable(namespace string) (*terminal.Table, error) { | ||
deployments, err := c.kubernetes.AppsV1().Deployments(namespace).List(c.Ctx, metav1.ListOptions{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deployments query lacks a label selector to filter for Consul-related deployments only. This will return all deployments in the namespace, not just Consul ones. Add a label selector like LabelSelector: \"app=consul,chart=consul-helm\"
to match the pattern used for clients and servers.
deployments, err := c.kubernetes.AppsV1().Deployments(namespace).List(c.Ctx, metav1.ListOptions{}) | |
deployments, err := c.kubernetes.AppsV1().Deployments(namespace).List(c.Ctx, metav1.ListOptions{LabelSelector: "app=consul,chart=consul-helm"}) |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated..
cli/cmd/status/status.go
Outdated
} | ||
var tbl *terminal.Table | ||
if len(clients.Items) != 0 { | ||
tbl = terminal.NewTable("NAME", "READY", "AGE", "CONTAINERS", "IMAGES") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FOR FUTURE : This can be constants scoped to the package so that they can be reused in tests. No need to hold the PR for this now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updates this one too
expectedHeaders := []string{"NAME", "READY", "AGE", "CONTAINERS", "IMAGES"} | ||
assert.Equal(t, expectedHeaders, tbl.Headers) | ||
|
||
require.Len(t, tbl.Rows, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come the test case 3 clients expected, 3 healthy
is passing when clearly 3 is epxected, but we assert for 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am creating only one daemonset at line 100 and for that 3 replica is expected and 3 healthy..
so in table, that will be in a single row... (asserting the number of rows{daemonsets})
for expected vs healthy, i am asserting at line 117.
cli/cmd/status/status_test.go
Outdated
c.kubernetes = fake.NewSimpleClientset() | ||
|
||
// Deploy clients if needed. | ||
if name != "No deployments" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Future: This is not extendable code. Ideally the testCase should have a boolean parameter which defines if a deployment should be created incase the scope changes in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one is also updated...
expectedHeaders := []string{"NAME", "READY", "AGE", "CONTAINERS", "IMAGES"} | ||
assert.Equal(t, expectedHeaders, tbl.Headers) | ||
|
||
require.Len(t, tbl.Rows, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as above. I assume that it's 1 deployment, 3 instances, 3 healthy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated..
Changes proposed in this PR