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

Feature/remove public key after destroyed #910

Merged

Conversation

9547
Copy link
Contributor

@9547 9547 commented Nov 16, 2020

What problem does this PR solve?

Try to implement #898

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Code changes

  • Has exported function/method change
  • Has exported variable/fields change
  • Has interface methods change
  • Has persistent data change

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

  • Need to cherry-pick to the release branch
  • Need to update the documentation

Release notes:

Remove SSH public key if the cluster was destroyed 

@codecov-io
Copy link

codecov-io commented Nov 16, 2020

Codecov Report

Merging #910 (8f82e4f) into master (1f0cbac) will decrease coverage by 0.89%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #910      +/-   ##
==========================================
- Coverage   55.70%   54.81%   -0.90%     
==========================================
  Files         263      263              
  Lines       19389    19427      +38     
==========================================
- Hits        10800    10648     -152     
- Misses       6875     7080     +205     
+ Partials     1714     1699      -15     
Flag Coverage Δ
cluster 42.23% <51.72%> (-1.22%) ⬇️
dm 24.14% <42.42%> (+0.21%) ⬆️
integrate 49.02% <50.00%> (-0.93%) ⬇️
playground 20.21% <ø> (ø)
tiup 16.90% <0.00%> (-0.02%) ⬇️
unittest 23.01% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/cluster/operation/operation.go 78.26% <ø> (ø)
components/dm/command/scale_in.go 65.33% <37.50%> (-2.32%) ⬇️
pkg/cluster/operation/destroy.go 50.15% <46.34%> (-4.74%) ⬇️
pkg/cluster/executor/executor.go 60.60% <50.00%> (-2.36%) ⬇️
pkg/cluster/operation/action.go 58.25% <100.00%> (-1.30%) ⬇️
pkg/cluster/operation/scale_in.go 46.49% <100.00%> (-13.38%) ⬇️
pkg/cluster/task/env_init.go 55.88% <100.00%> (+2.39%) ⬆️
pkg/cluster/task/task.go 74.10% <100.00%> (+0.23%) ⬆️
components/cluster/command/prune.go 23.80% <0.00%> (-33.34%) ⬇️
pkg/cluster/api/binlog.go 12.17% <0.00%> (-26.96%) ⬇️
... and 16 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 1f0cbac...8f82e4f. Read the comment docs.

@9547 9547 force-pushed the feature/remove-public-key-after-destroyed branch from 5c9d625 to 4d3b121 Compare November 16, 2020 23:16
Copy link
Contributor

@AstroProfundis AstroProfundis left a comment

Choose a reason for hiding this comment

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

And as we support deploying cluster with user specified SSH key (instead of generating new), so it would be better to check for duplicate during deploy process, and also not deleting the public key by default on scaling in and destroying.

@@ -73,7 +73,7 @@ func destroyTombstoneIfNeed(clusterName string, metadata *spec.ClusterMeta, opt
return perrs.AddStack(err)
}

nodes, err := operator.DestroyTombstone(ctx, topo, true /* returnNodesOnly */, opt, tlsCfg)
nodes, err := operator.DestroyTombstone(ctx, topo, true /* returnNodesOnly */, opt, tlsCfg, ctx.PublicKeyPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

ctx is passed to DestroyTombstone() so I don't think it's necessary to pass ctx.PublicKeyPath again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first argument inside DestoryTombestone() is ExecutorGetter interface:

func DestroyTombstone(
getter ExecutorGetter,
cluster *spec.Specification,
returNodesOnly bool,
options Options,
tlsCfg *tls.Config,
) (nodes []string, err error) {
So I need to cast it into task.Context, but this results in import cycle error. Please let me know if I've misssed something.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can define another interface for the first param of DestroyTombstone:

type SSHExecutorGetter interface {
    ExecutorGetter
    GetSSHKeySet() (string, string) // return both priv and public key
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lucklove Or should we extend the original ExecutorGetter interface with:

type ExecutorGetter interface {
	Get(host string) (e executor.Executor)
	GetSSHKeySet() (string, string)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lucklove I did it this way first, if you have any question, please let me know.

Copy link
Member

Choose a reason for hiding this comment

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

@lucklove Or should we extend the original ExecutorGetter interface with:

type ExecutorGetter interface {
	Get(host string) (e executor.Executor)
	GetSSHKeySet() (string, string)
}

It's OK at this time. In the future there may be some executors that don't relay on ssh, at that time we can refactor this.

components/dm/command/scale_in.go Outdated Show resolved Hide resolved
pkg/cluster/manager.go Outdated Show resolved Hide resolved
pkg/cluster/manager.go Outdated Show resolved Hide resolved
pkg/cluster/operation/destroy.go Show resolved Hide resolved
@lucklove
Copy link
Member

Seems test broken: cannot stat '~/.tiup/storage/dm/clusters/test_cmd/ssh/id_rsa'
May related to this PR.

@9547 9547 force-pushed the feature/remove-public-key-after-destroyed branch from 4d3b121 to bf61123 Compare November 17, 2020 14:53
@lucklove
Copy link
Member

@9547 9547 force-pushed the feature/remove-public-key-after-destroyed branch from f7590f2 to 7c7cfea Compare November 23, 2020 15:10
@9547
Copy link
Contributor Author

9547 commented Nov 23, 2020

@lucklove PTAL

Copy link
Member

@lucklove lucklove left a comment

Choose a reason for hiding this comment

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

Rest LGTM

components/dm/command/scale_in.go Outdated Show resolved Hide resolved
pkg/cluster/operation/destroy.go Outdated Show resolved Hide resolved
@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 25, 2020
@AstroProfundis
Copy link
Contributor

/merge

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 30, 2020
@ti-chi-bot
Copy link
Member

Can merge label has been added.

Git tree hash: 8f82e4f

@ti-chi-bot
Copy link
Member

@9547: Your PR has out-of-dated and I have automatically updated it for you.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the tidb-community-bots/ti-community-prow repository.

@CLAassistant
Copy link

CLAassistant commented Nov 30, 2020

CLA assistant check
All committers have signed the CLA.

@ti-chi-bot ti-chi-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 30, 2020
@ti-chi-bot ti-chi-bot merged commit 5366a48 into pingcap:master Nov 30, 2020
@9547 9547 deleted the feature/remove-public-key-after-destroyed branch December 5, 2020 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants