-
Notifications
You must be signed in to change notification settings - Fork 1.3k
ssh plugin: allow custom SSH port configuration #5047
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
Merged
+85
−8
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,13 @@ limitations under the License. | |
| package ssh | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| v1 "k8s.io/api/core/v1" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this pass gofmt? It looks wierd that it has an enter beneath.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passed fmt, this is fine. |
||
|
|
||
| batch "volcano.sh/apis/pkg/apis/batch/v1alpha1" | ||
| pluginsinterface "volcano.sh/volcano/pkg/controllers/job/plugins/interface" | ||
| ) | ||
|
|
||
|
|
@@ -31,26 +36,38 @@ func TestSSHPlugin(t *testing.T) { | |
| sshKeyFilePath string | ||
| sshPrivateKey string | ||
| sshPublicKey string | ||
| sshPort int | ||
| }{ | ||
| { | ||
| name: "no params specified", | ||
| sshKeyFilePath: SSHAbsolutePath, | ||
| sshPrivateKey: "", | ||
| sshPublicKey: "", | ||
| sshPort: 22, | ||
| }, | ||
| { | ||
| name: "--ssh-key-file-path=/a/b", | ||
| params: []string{"--ssh-key-file-path=/a/b"}, | ||
| sshKeyFilePath: "/a/b", | ||
| sshPrivateKey: "", | ||
| sshPublicKey: "", | ||
| sshPort: 22, | ||
| }, | ||
| { | ||
| name: "with user provided ssh keys", | ||
| params: []string{"--ssh-private-key=-----BEGIN RSA PRIVATE KEY-----\\nMIIEpAIBAAKCAQEAyeyZjWDx5Na9bw1f61M4s+QlLT/kyrB37AR2j5Sb/A9hvJak\\nLNQQpNC+KVfYNl4jePG+6lwHqye//pcC9+0SWsHWwgaahjMLnAthR2k8JAakNA9x\\nV/wHz0YU99OKEetaOuxXpWZPXCHX0zuQO87YbdKzRbgxACirM3Phkwr7XLtQtWZk\\nyXG34CQXZQWgBIS1Fl+PlGOpVpOPnWoZPMpbAK74i/Tz4sP8Zhqc6dya1hrbUwY3\\nYfMZNYXpaAw7wWVjq8grfs0+Fl3SxHrzTXge2m+eZAZ6iPJ8cX4uYKxi0ZmxpM/a\\ngI6Mmjq0MU75Vxpq22LaUvHIpOfX5UxhkrsxlwIDAQABAoIBAQDGOuIb6zpNn4rl\\nBMpPqamW4LimjX08hrWUHGWQWyIu96LJk1GlOKMGSm8FA1odNZm5WApG5QYaPrG7\\na+DcJ/7G3ljIrdbxPBd/n6RmiKcj7ukwuqBY8fFwyKo5CZEYOmagRfldRO1P02Gf\\n22+jZ1MNrbWVElf4gfRgVLj0s+lEhFkzhi+QGMmMpjEJnnG98xxVGEvWMw1rnKJm\\n3Gi771Gltbg3GuEPs3IeoBgba3EaHmSxJnBivAL4zsO8UUCAXB13cUiXx8qO7y1e\\nCSWSenRmK2ugbL6v0co12O0n0pxF9xlJ6fALdRWzpJsFlN3ttkY9N5GrQc/pVjOa\\nvqa172RRAoGBAOSAIMNLT6QjgYDk5Z7ZxjNnxH/lMso+cx6bxk9YMKRrw0fDQh8m\\ncBAihX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rNFuDEAKKszc+GTCvtcu1C1ZmTJcbfgJBdlBaAEhLUWX4+UY6lWk4+dahk8ylsArviL9PPiw/xmGpzp3JrWGttTBjdh8xk1heloDDvBZWOryCt+zT4WXdLEevNNeB7ab55kBnqI8nxxfi5grGLRmbGkz9qAjoyaOrQxTvlXGmrbYtpS8cik59flTGGSuzGX root@aiplatform", | ||
| sshPort: 22, | ||
| }, | ||
| { | ||
| name: "with custom ssh port", | ||
| params: []string{"--ssh-port=2026"}, | ||
| sshKeyFilePath: SSHAbsolutePath, | ||
| sshPrivateKey: "", | ||
| sshPublicKey: "", | ||
| sshPort: 2026, | ||
| }, | ||
aadhil2k4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
|
|
@@ -68,6 +85,46 @@ func TestSSHPlugin(t *testing.T) { | |
| if plugin.sshPublicKey != test.sshPublicKey { | ||
| t.Errorf("Expected sshPublicKey=%s, got %s", test.sshPublicKey, plugin.sshPublicKey) | ||
| } | ||
| if plugin.sshPort != test.sshPort { | ||
| t.Errorf("Expected sshPort=%d, got %d", test.sshPort, plugin.sshPort) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGenerateSSHConfigWithCustomPort(t *testing.T) { | ||
| job := &batch.Job{ | ||
| Spec: batch.JobSpec{ | ||
| Tasks: []batch.TaskSpec{ | ||
| { | ||
| Name: "worker", | ||
| Replicas: 1, | ||
| Template: v1.PodTemplateSpec{ | ||
| Spec: v1.PodSpec{}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| port := 2026 | ||
| config := generateSSHConfig(job, port) | ||
|
|
||
| expected := fmt.Sprintf("Port %d", port) | ||
| if !strings.Contains(config, expected) { | ||
| t.Errorf("expected SSH config to contain %q, got:\n%s", expected, config) | ||
| } | ||
| } | ||
|
|
||
| func TestInvalidSSHPortFallsBackToDefault(t *testing.T) { | ||
| params := []string{"--ssh-port=-10"} | ||
|
|
||
| pluginInterface := New(pluginsinterface.PluginClientset{}, params) | ||
| plugin := pluginInterface.(*sshPlugin) | ||
|
|
||
| plugin.validateSSHPort() | ||
|
|
||
| if plugin.sshPort != 22 { | ||
| t.Errorf("Expected sshPort to fall back to 22, got %d", plugin.sshPort) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.