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

feat: chaosctl for print debug info #1074

Merged
merged 51 commits into from Dec 17, 2020
Merged

Conversation

Yiyiyimu
Copy link
Member

@Yiyiyimu Yiyiyimu commented Oct 18, 2020

Signed-off-by: yiyiyimu wosoyoung@gmail.com

What's this PR did

fix #694

Checklist

SUPPORT CHAOS

  • NetworkChaos
  • StressChaos
  • IoChaos

DEBUG

  • compare with expected (a demo for networkChaos)
  • move to ctrl.client from shell
  • chaos applied on multiple pods (larger radius): use utils.selectPods
  • replace extractFromJson with type assert (as how controllers do)
  • create daemon client locally to get pid more robustly
  • add test case
  • add backup for pod that not has ls, ps and cat
  • add feature to print log from all chaos-mesh components as chaosctl logs

CTL

  • add color to output title
  • use format "chaosctl debug xxxchaos"
  • support chaos in certain namespace
  • use kubectl compatible auto-completion as chaosctl debug xxxchaos CHAOSNAME -n NAMESPACE

@Yiyiyimu
Copy link
Member Author

Yiyiyimu commented Oct 18, 2020

Should open in personal repo
Reopen for review

@Yiyiyimu Yiyiyimu reopened this Oct 19, 2020
@Yiyiyimu Yiyiyimu marked this pull request as draft October 19, 2020 10:00
@codecov-io
Copy link

codecov-io commented Oct 19, 2020

Codecov Report

Merging #1074 (befa280) into master (7e9ff3f) will decrease coverage by 2.34%.
The diff coverage is 52.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1074      +/-   ##
==========================================
- Coverage   55.78%   53.43%   -2.35%     
==========================================
  Files          68       83      +15     
  Lines        4383     5225     +842     
==========================================
+ Hits         2445     2792     +347     
- Misses       1768     2165     +397     
- Partials      170      268      +98     
Impacted Files Coverage Δ
api/v1alpha1/common_types.go 0.00% <0.00%> (ø)
api/v1alpha1/common_webhook.go 100.00% <ø> (ø)
api/v1alpha1/dnschaos_type.go 0.00% <0.00%> (ø)
api/v1alpha1/dnschaos_webhook.go 0.00% <0.00%> (ø)
api/v1alpha1/httpchaos_types.go 0.00% <0.00%> (ø)
api/v1alpha1/iochaos_types.go 0.00% <ø> (-40.00%) ⬇️
api/v1alpha1/jvmchaos_webhook.go 0.00% <0.00%> (ø)
api/v1alpha1/kernelchaos_types.go 0.00% <ø> (-20.00%) ⬇️
api/v1alpha1/kernelchaos_webhook.go 100.00% <ø> (+14.81%) ⬆️
api/v1alpha1/kinds.go 27.27% <ø> (+0.60%) ⬆️
... and 120 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6adde61...befa280. Read the comment docs.

@Yiyiyimu
Copy link
Member Author

Yiyiyimu commented Oct 19, 2020

It seems that make check on the local environment could not fix the current issue in Github Action
fix by upgrade cobra to v1.1.1, details in spf13/cobra#1259

Signed-off-by: yiyiyimu <wosoyoung@gmail.com>

add cobra based CTL

Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
@Yiyiyimu Yiyiyimu marked this pull request as ready for review October 20, 2020 05:38
@Yiyiyimu Yiyiyimu changed the title NetworkChaos Debug Info & Basic CTL Debug tools & Basic CTL Oct 22, 2020
Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
Copy link
Member

@YangKeao YangKeao left a comment

Choose a reason for hiding this comment

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

It seems that you have misunderstood programming on kubernetes. I will talk with you in detail 😢

pkg/debug/networkchaos/networkchaos.go Outdated Show resolved Hide resolved
pkg/debug/common/common.go Outdated Show resolved Hide resolved
…tput

Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
pkg/chaosctl/cmd/debug.go Show resolved Hide resolved
}

func flagCompletion(cmd *cobra.Command) error {
k8sConfig, err := config.GetConfig()
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to switch to https://github.com/kubernetes/cli-runtime and use its factory to initialize the k8s config and client.

This supports more kubectl options like --context, --server by default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure I'll try to only use one type of client

pkg/debug/common/common.go Outdated Show resolved Hide resolved
pkg/debug/networkchaos/networkchaos.go Outdated Show resolved Hide resolved
pkg/debug/common/common.go Outdated Show resolved Hide resolved
Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
…Json

Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
pkg/debug/common/common.go Outdated Show resolved Hide resolved
Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
@Yiyiyimu
Copy link
Member Author

Yiyiyimu commented Dec 8, 2020

@YangKeao @STRRL Thanks for the review! PTAL

Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
// we need to enter mount namespace to get file related infomation
// but enter mnt ns would prevent us to access `cat`/`ls` in daemon
// so use `nsexec` to achieve using nsenter and cat together
newCmd := fmt.Sprintf("/usr/local/bin/nsexec %s %s", strconv.Itoa(pid), cmd)
Copy link
Member

Choose a reason for hiding this comment

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

I came up with a better idea to implement a more general nsexec 🍻 . You can find the source code and documents at https://github.com/YangKeao/nsexec, and it will be brought to chaos-daemon in #1260 .

I don't know whether it's a big project to migrate to YangKeao/nsexec.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool I test it and it works fine. I'll commit the change till #1260 got merged.

Copy link
Member Author

Choose a reason for hiding this comment

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

@YangKeao Updated to #1260, PTAL

pkg/chaosctl/common/exec.go Outdated Show resolved Hide resolved
Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
@Yiyiyimu
Copy link
Member Author

Hi @YangKeao @STRRL PTAL

Copy link
Member

@STRRL STRRL left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks for your contribution @Yiyiyimu!

Copy link
Member

@YangKeao YangKeao left a comment

Choose a reason for hiding this comment

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

LGTM

It finally arrives! (Maybe we need a document later 😺 ) 🍻

@YangKeao
Copy link
Member

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit d9c7291 into chaos-mesh:master Dec 17, 2020
@ti-srebot
Copy link
Contributor

cherry pick to release-1.0 failed

@zhouqiang-cl
Copy link
Contributor

Is there have readme about this tool? @Yiyiyimu

Yiyiyimu added a commit to Yiyiyimu/chaos-mesh that referenced this pull request Dec 18, 2020
Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
YangKeao pushed a commit that referenced this pull request Dec 18, 2020
* feat: chaosctl for print debug info (#1074)

Signed-off-by: yiyiyimu <wosoyoung@gmail.com>

* move genrateNNodes out of test file

Signed-off-by: yiyiyimu <wosoyoung@gmail.com>
@dcalvin dcalvin mentioned this pull request Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Debug information collector for chaos-mesh
8 participants