Skip to content

Conversation

LordAbhishek
Copy link

Changes proposed in this PR

  • Updated the status command to output the consul client & deployments status in tabular format, along with the existing status.
  • Updated the consul server status to output in tabular format in terminal, too.

@LordAbhishek LordAbhishek requested a review from a team as a code owner September 22, 2025 07:55
Copy link

hashicorp-cla-app bot commented Sep 22, 2025

CLA assistant check
All committers have signed the CLA.

@LordAbhishek LordAbhishek added area/cli CLI pr/no-backport signals that a PR will not contain a backport label labels Sep 22, 2025
@LordAbhishek LordAbhishek changed the title CSL-10969: Updated the status command to output the consul client & deployments status as well along with existing ones. CSL-10969: Update the status command to output the consul client & deployments status as well along with existing ones. Sep 22, 2025
return 1
err = c.checkConsulComponentsStatus(namespace)
if err != nil {
return 1 // Only for testing

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?

Copy link
Author

@LordAbhishek LordAbhishek Sep 25, 2025

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.

Copy link
Contributor

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

return 1
err = c.checkConsulComponentsStatus(namespace)
if err != nil {
return 1 // Only for testing
Copy link
Contributor

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

// 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
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

// 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{})
Copy link
Contributor

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

Copy link
Author

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.

}

// checkConsulClients list the Consul Clients and their ready status (number of pods ready/desired)
func (c *Command) checkConsulClients(namespace string) error {
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to getConsulClientsTable

}

// checkConsulServers list the Consul Servers and their ready status (number of pods ready/desired),
func (c *Command) checkConsulServers(namespace string) error {
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to getConsulServerTable

}

// checkConsulDeployments list the Consul Deployed Deployments and their ready status (number of pods ready/desired),
func (c *Command) checkConsulDeployments(namespace string) error {
Copy link
Contributor

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

Copy link
Author

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.

}

// checkConsulDeployments list the Consul Deployed Deployments and their ready status (number of pods ready/desired),
func (c *Command) checkConsulDeployments(namespace string) error {
Copy link
Contributor

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

Copy link
Author

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 {
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

sriramr98
sriramr98 previously approved these changes Sep 26, 2025
Copy link

@Copilot Copilot AI left a 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.

// 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{})
Copy link
Preview

Copilot AI Sep 29, 2025

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.

Suggested change
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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated..

}
var tbl *terminal.Table
if len(clients.Items) != 0 {
tbl = terminal.NewTable("NAME", "READY", "AGE", "CONTAINERS", "IMAGES")
Copy link
Contributor

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.

Copy link
Author

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)
Copy link
Contributor

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?

Copy link
Author

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.

c.kubernetes = fake.NewSimpleClientset()

// Deploy clients if needed.
if name != "No deployments" {
Copy link
Contributor

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.

Copy link
Author

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)
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli CLI pr/no-backport signals that a PR will not contain a backport label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants