Skip to content
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

cli: status command #768

Merged
merged 11 commits into from
Oct 25, 2021
Merged

cli: status command #768

merged 11 commits into from
Oct 25, 2021

Conversation

sadjamz
Copy link
Contributor

@sadjamz sadjamz commented Oct 7, 2021

Based off of a demo branch worked on here: https://github.com/hashicorp/consul-k8s-cli/tree/status

Changes proposed in this PR:

  • consul-k8s status checks the status of your Helm install and some Kubernetes components like the clients, servers, and webhook deployments.
  • The checkHelmInstallation() function uses the Helm Go SDK to run a helm status, printing the status of the release, the version, and the config. Config is all of the values overridden from values.yaml. This function also iterates through each of the hooks and prints the phase of each 'pre-install' or 'pre-upgrade' hook.
  • checkConsulServers() and checkConsulClients() lists the Stateful Sets and Daemon Sets and compares the desired replicas to the ready ones. This determines if all the clients/servers are healthy or not.

How I've tested this PR:
Manual testing, along with writing a few unit tests.

How I expect reviewers to test this PR:

  1. Code review
  2. Test it out:
    cd cli
    go build -o ./bin/consul-k8s
    ./bin/consul-k8s status
  3. Run the two unit tests in cli/cmd/status/status_test.go

Checklist:

  • Tests added
  • CHANGELOG entry added

    HashiCorp engineers only, community PRs should not add a changelog entry.
    Entries should use present tense (e.g. Add support for...)

@ndhanushkodi ndhanushkodi requested review from a team and ishustava and removed request for a team October 7, 2021 16:27
Copy link
Contributor

@ndhanushkodi ndhanushkodi left a comment

Choose a reason for hiding this comment

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

Did a quick code review, will test out the command and give a more thorough review soon! Great work on this so far!!!

cli/cmd/status/status.go Outdated Show resolved Hide resolved
cli/cmd/status/status.go Outdated Show resolved Hide resolved
cli/cmd/status/status.go Outdated Show resolved Hide resolved
cli/cmd/status/status.go Outdated Show resolved Hide resolved
@t-eckert t-eckert requested review from t-eckert and removed request for ishustava October 11, 2021 18:12
@t-eckert
Copy link
Contributor

About to start looking at the code. I pulled this down and tried to run it but I got this response:

Error returned from `consul-k8s status`
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb01dfacedebac1e pc=0x7fff2038cc9e]

runtime stack:
runtime: unexpected return pc for runtime.sigpanic called from 0x7fff2038cc9e
stack: frame={sp:0x7ffeefbff6d8, fp:0x7ffeefbff728} stack=[0x7ffeefb80778,0x7ffeefbff7e0)
0x00007ffeefbff5d8:  0x01007ffeefbff5f8  0x0000000000000004 
0x00007ffeefbff5e8:  0x000000000000001f  0x00007fff2038cc9e 
0x00007ffeefbff5f8:  0x0b01dfacedebac1e  0x0000000000000001 
0x00007ffeefbff608:  0x0000000004037571 <runtime.throw+0x0000000000000071>  0x00007ffeefbff6a8 
0x00007ffeefbff618:  0x0000000005856d16  0x00007ffeefbff660 
0x00007ffeefbff628:  0x0000000004037828 <runtime.fatalthrow.func1+0x0000000000000048>  0x0000000006a1b1c0 
0x00007ffeefbff638:  0x0000000000000001  0x0000000000000001 
0x00007ffeefbff648:  0x00007ffeefbff6a8  0x0000000004037571 <runtime.throw+0x0000000000000071> 
0x00007ffeefbff658:  0x0000000006a1b1c0  0x00007ffeefbff698 
0x00007ffeefbff668:  0x00000000040377b0 <runtime.fatalthrow+0x0000000000000050>  0x00007ffeefbff678 
0x00007ffeefbff678:  0x00000000040377e0 <runtime.fatalthrow.func1+0x0000000000000000>  0x0000000006a1b1c0 
0x00007ffeefbff688:  0x0000000004037571 <runtime.throw+0x0000000000000071>  0x00007ffeefbff6a8 
0x00007ffeefbff698:  0x00007ffeefbff6c8  0x0000000004037571 <runtime.throw+0x0000000000000071> 
0x00007ffeefbff6a8:  0x00007ffeefbff6b0  0x00000000040375a0 <runtime.throw.func1+0x0000000000000000> 
0x00007ffeefbff6b8:  0x000000000586e2da  0x000000000000002a 
0x00007ffeefbff6c8:  0x00007ffeefbff718  0x000000000404d3b6 <runtime.sigpanic+0x0000000000000396> 
0x00007ffeefbff6d8: <0x000000000586e2da  0x000000000401c005 <runtime.(*fixalloc).alloc+0x0000000000000085> 
0x00007ffeefbff6e8:  0x00007ffeefbff758  0x00000000040297c6 <runtime.(*mheap).allocSpan+0x0000000000000546> 
0x00007ffeefbff6f8:  0x000000c00013c000  0x0000000000002000 
0x00007ffeefbff708:  0x000000c000000008  0x000000000407dfe0 <syscall.libc_stat64_trampoline+0x0000000000000000> 
0x00007ffeefbff718:  0x00007ffeefbff760 !0x00007fff2038cc9e 
0x00007ffeefbff728: >0x00007ffeefbff760  0x000000000691c000 
0x00007ffeefbff738:  0x000000000000049b  0x000000000410c085 <golang.org/x/sys/unix.libc_ioctl_trampoline+0x0000000000000005> 
0x00007ffeefbff748:  0x000000000406aa9f <runtime.syscall+0x000000000000001f>  0x000000c00008a980 
0x00007ffeefbff758:  0x00007ffeefbff7a0  0x000000c00008a950 
0x00007ffeefbff768:  0x0000000004068910 <runtime.asmcgocall+0x0000000000000070>  0x0000000000000001 
0x00007ffeefbff778:  0x000000c000110800  0x0800000005917670 
0x00007ffeefbff788:  0x0000000000000010  0x00000000055af580 
0x00007ffeefbff798:  0x00000000000006d8  0x000000c0000001a0 
0x00007ffeefbff7a8:  0x0000000004066a29 <runtime.systemstack+0x0000000000000049>  0x0000000000000004 
0x00007ffeefbff7b8:  0x0000000005a84fe0  0x0000000006a1b1c0 
0x00007ffeefbff7c8:  0x00007ffeefbff818  0x0000000004066925 <runtime.mstart+0x0000000000000005> 
0x00007ffeefbff7d8:  0x00000000040668dd <runtime.rt0_go+0x000000000000013d> 
runtime.throw({0x586e2da, 0x401c005})
	/usr/local/opt/go/libexec/src/runtime/panic.go:1198 +0x71
runtime: unexpected return pc for runtime.sigpanic called from 0x7fff2038cc9e
stack: frame={sp:0x7ffeefbff6d8, fp:0x7ffeefbff728} stack=[0x7ffeefb80778,0x7ffeefbff7e0)
0x00007ffeefbff5d8:  0x01007ffeefbff5f8  0x0000000000000004 
0x00007ffeefbff5e8:  0x000000000000001f  0x00007fff2038cc9e 
0x00007ffeefbff5f8:  0x0b01dfacedebac1e  0x0000000000000001 
0x00007ffeefbff608:  0x0000000004037571 <runtime.throw+0x0000000000000071>  0x00007ffeefbff6a8 
0x00007ffeefbff618:  0x0000000005856d16  0x00007ffeefbff660 
0x00007ffeefbff628:  0x0000000004037828 <runtime.fatalthrow.func1+0x0000000000000048>  0x0000000006a1b1c0 
0x00007ffeefbff638:  0x0000000000000001  0x0000000000000001 
0x00007ffeefbff648:  0x00007ffeefbff6a8  0x0000000004037571 <runtime.throw+0x0000000000000071> 
0x00007ffeefbff658:  0x0000000006a1b1c0  0x00007ffeefbff698 
0x00007ffeefbff668:  0x00000000040377b0 <runtime.fatalthrow+0x0000000000000050>  0x00007ffeefbff678 
0x00007ffeefbff678:  0x00000000040377e0 <runtime.fatalthrow.func1+0x0000000000000000>  0x0000000006a1b1c0 
0x00007ffeefbff688:  0x0000000004037571 <runtime.throw+0x0000000000000071>  0x00007ffeefbff6a8 
0x00007ffeefbff698:  0x00007ffeefbff6c8  0x0000000004037571 <runtime.throw+0x0000000000000071> 
0x00007ffeefbff6a8:  0x00007ffeefbff6b0  0x00000000040375a0 <runtime.throw.func1+0x0000000000000000> 
0x00007ffeefbff6b8:  0x000000000586e2da  0x000000000000002a 
0x00007ffeefbff6c8:  0x00007ffeefbff718  0x000000000404d3b6 <runtime.sigpanic+0x0000000000000396> 
0x00007ffeefbff6d8: <0x000000000586e2da  0x000000000401c005 <runtime.(*fixalloc).alloc+0x0000000000000085> 
0x00007ffeefbff6e8:  0x00007ffeefbff758  0x00000000040297c6 <runtime.(*mheap).allocSpan+0x0000000000000546> 
0x00007ffeefbff6f8:  0x000000c00013c000  0x0000000000002000 
0x00007ffeefbff708:  0x000000c000000008  0x000000000407dfe0 <syscall.libc_stat64_trampoline+0x0000000000000000> 
0x00007ffeefbff718:  0x00007ffeefbff760 !0x00007fff2038cc9e 
0x00007ffeefbff728: >0x00007ffeefbff760  0x000000000691c000 
0x00007ffeefbff738:  0x000000000000049b  0x000000000410c085 <golang.org/x/sys/unix.libc_ioctl_trampoline+0x0000000000000005> 
0x00007ffeefbff748:  0x000000000406aa9f <runtime.syscall+0x000000000000001f>  0x000000c00008a980 
0x00007ffeefbff758:  0x00007ffeefbff7a0  0x000000c00008a950 
0x00007ffeefbff768:  0x0000000004068910 <runtime.asmcgocall+0x0000000000000070>  0x0000000000000001 
0x00007ffeefbff778:  0x000000c000110800  0x0800000005917670 
0x00007ffeefbff788:  0x0000000000000010  0x00000000055af580 
0x00007ffeefbff798:  0x00000000000006d8  0x000000c0000001a0 
0x00007ffeefbff7a8:  0x0000000004066a29 <runtime.systemstack+0x0000000000000049>  0x0000000000000004 
0x00007ffeefbff7b8:  0x0000000005a84fe0  0x0000000006a1b1c0 
0x00007ffeefbff7c8:  0x00007ffeefbff818  0x0000000004066925 <runtime.mstart+0x0000000000000005> 
0x00007ffeefbff7d8:  0x00000000040668dd <runtime.rt0_go+0x000000000000013d> 
runtime.sigpanic()
	/usr/local/opt/go/libexec/src/runtime/signal_unix.go:719 +0x396

goroutine 1 [syscall, locked to thread]:
syscall.syscall(0x410c080, 0x1, 0x40487413, 0xc00008aa10)
	/usr/local/opt/go/libexec/src/runtime/sys_darwin.go:22 +0x3b fp=0xc00008a980 sp=0xc00008a960 pc=0x40654db
syscall.syscall(0x4075106, 0x40101d4, 0xc00008aa38, 0x4075038)
	<autogenerated>:1 +0x26 fp=0xc00008a9c8 sp=0xc00008a980 pc=0x406b266
golang.org/x/sys/unix.ioctl(0x582dbb7, 0x4, 0x1000000000008)
	/Users/thomaseckert/go/pkg/mod/golang.org/x/sys@v0.0.0-20210426230700-d19ff857e887/unix/zsyscall_darwin_amd64.go:690 +0x39 fp=0xc00008a9f8 sp=0xc00008a9c8 pc=0x410bbd9
golang.org/x/sys/unix.IoctlGetTermios(...)
	/Users/thomaseckert/go/pkg/mod/golang.org/x/sys@v0.0.0-20210426230700-d19ff857e887/unix/ioctl.go:73
github.com/mattn/go-isatty.IsTerminal(0x582dbb7)
	/Users/thomaseckert/go/pkg/mod/github.com/mattn/go-isatty@v0.0.12/isatty_bsd.go:10 +0x50 fp=0xc00008aa68 sp=0xc00008a9f8 pc=0x410c150
github.com/fatih/color.init()
	/Users/thomaseckert/go/pkg/mod/github.com/fatih/color@v1.9.0/color.go:21 +0x7a fp=0xc00008aaa0 sp=0xc00008aa68 pc=0x410e17a
runtime.doInit(0x69295e0)
	/usr/local/opt/go/libexec/src/runtime/proc.go:6498 +0x123 fp=0xc00008abd8 sp=0xc00008aaa0 pc=0x4047023
runtime.doInit(0x692f920)
	/usr/local/opt/go/libexec/src/runtime/proc.go:6475 +0x71 fp=0xc00008ad10 sp=0xc00008abd8 pc=0x4046f71
runtime.doInit(0x692e700)
	/usr/local/opt/go/libexec/src/runtime/proc.go:6475 +0x71 fp=0xc00008ae48 sp=0xc00008ad10 pc=0x4046f71
runtime.doInit(0x692dd80)
	/usr/local/opt/go/libexec/src/runtime/proc.go:6475 +0x71 fp=0xc00008af80 sp=0xc00008ae48 pc=0x4046f71
runtime.main()
	/usr/local/opt/go/libexec/src/runtime/proc.go:238 +0x1e6 fp=0xc00008afe0 sp=0xc00008af80 pc=0x4039e86
runtime.goexit()
	/usr/local/opt/go/libexec/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc00008afe8 sp=0xc00008afe0 pc=0x4068c01

cli/cmd/status/status.go Outdated Show resolved Hide resolved
cli/cmd/status/status.go Outdated Show resolved Hide resolved
@t-eckert
Copy link
Contributor

image

I get this response when running against a cluster that does not have Consul installed.

@t-eckert
Copy link
Contributor

About to start looking at the code. I pulled this down and tried to run it but I got this response:

Error returned from consul-k8s status

Note that I only saw this running go 1.17.1. When I downgraded to 1.16.9 the issue went away. 🤷

cli/cmd/status/status.go Outdated Show resolved Hide resolved
cli/cmd/status/status.go Outdated Show resolved Hide resolved
cli/cmd/status/status.go Outdated Show resolved Hide resolved
Copy link
Contributor

@t-eckert t-eckert left a comment

Choose a reason for hiding this comment

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

You are doing great so far, Saad. I added some comments and will re-review later.

Outside of the scope of this PR, some of the content has me thinking that logic could be separated out so that a consul and a helm package exist. I think you'll have a lot of repeated logic across the different commands which might be consolidated using a cleaner architecture.

@sadjamz
Copy link
Contributor Author

sadjamz commented Oct 18, 2021

image

I get this response when running against a cluster that does not have Consul installed.

image

I get this response when running against a cluster that does not have Consul installed.

@ishustava and @NicoletaPopoviciu's bug fix while completing the following asana task fixed this issue!

https://app.asana.com/0/1200500259727746/1201122360111852/f

cli/cmd/status/status.go Outdated Show resolved Hide resolved
Copy link
Contributor

@t-eckert t-eckert left a comment

Choose a reason for hiding this comment

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

I think this is pretty solid on the whole! Definitely fix the time formatting and make the linter happy, then it's good in my book.

Copy link
Contributor

@ndhanushkodi ndhanushkodi left a comment

Choose a reason for hiding this comment

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

This is coming together great Saad! I think the date/time rendering is the main fix, everything else is small nits!

Edit: I see you got to the date/time rendering before I submitted to the review :)

cli/cmd/status/status.go Outdated Show resolved Hide resolved
cli/cmd/status/status.go Outdated Show resolved Hide resolved
cli/cmd/status/status.go Outdated Show resolved Hide resolved
cli/cmd/status/status.go Outdated Show resolved Hide resolved
cli/cmd/status/status.go Outdated Show resolved Hide resolved
cli/cmd/status/status.go Outdated Show resolved Hide resolved
cli/cmd/status/status.go Outdated Show resolved Hide resolved

func (c *Command) Help() string {
c.once.Do(c.init)
s := "Usage: consul-k8s status" + "\n\n" + "Get the status of the current Consul installation." + "\n" +
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
s := "Usage: consul-k8s status" + "\n\n" + "Get the status of the current Consul installation." + "\n" +
s := "Usage: consul-k8s status" + "\n" + "Get the status of the current Consul installation." + "\n\n"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Little lost here, why do we need two new-lines? Interestingly enough the help command outputs the same thing either way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok, nvm then. I noticed that the Global options displayed right underneath the help text so I thought adding an extra newline would make the output look more consistent with the install command's help message

cli/cmd/status/status.go Outdated Show resolved Hide resolved
cli/cmd/uninstall/uninstall.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ndhanushkodi ndhanushkodi left a comment

Choose a reason for hiding this comment

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

Amazing work on this! Just needs a changelog entry before merging

@ndhanushkodi
Copy link
Contributor

Hey Saad! I just rebased the branch and pushed up a changelog so we can merge!

@sadjamz sadjamz merged commit a185c0a into main Oct 25, 2021
@sadjamz sadjamz deleted the cli-status branch October 25, 2021 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants