-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
WIP: create tunnel for qemu #14615
Closed
Closed
WIP: create tunnel for qemu #14615
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c52d52b
create tunnel for qemu
klaases df08c37
remove preliminary bail
klaases 8905c53
allow qemu vde network flag
klaases 6270a80
add vde default ip
klaases e57a721
add vde port default
klaases da72145
try qemu network socket
klaases e16e2bc
adjust socket network prefix
klaases bb84140
debug -nic parameters
klaases 32caaef
allow Qemu to provide direct IP connectivity
klaases 18c319f
update qemu IPs
klaases 8ce675c
remove qemu machine IP overwrite
klaases f79429c
add todo for Macports fix
klaases 3978c70
disable daemonize
klaases 96cdc66
enable display monitor
klaases e10ac35
allow qemu to trySSH()
klaases 815b317
disable Qemu getPort()
klaases abcbb23
disable bail on qemu tunnel
klaases dd81ab8
prefer defaultSSHUser to "docker"
klaases 433ed72
fix 4x %v for strings
klaases 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 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 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 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package qemu | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
typed_core "k8s.io/client-go/kubernetes/typed/core/v1" | ||
|
||
"k8s.io/klog/v2" | ||
) | ||
|
||
// ServiceTunnel ... | ||
type ServiceTunnel struct { | ||
sshPort string | ||
sshKey string | ||
v1Core typed_core.CoreV1Interface | ||
sshConn *sshConn | ||
suppressStdOut bool | ||
} | ||
|
||
// NewServiceTunnel ... | ||
func NewServiceTunnel(sshPort, sshKey string, v1Core typed_core.CoreV1Interface, suppressStdOut bool) *ServiceTunnel { | ||
return &ServiceTunnel{ | ||
sshPort: sshPort, | ||
sshKey: sshKey, | ||
v1Core: v1Core, | ||
suppressStdOut: suppressStdOut, | ||
} | ||
} | ||
|
||
// Start ... | ||
func (t *ServiceTunnel) Start(svcName, namespace string) ([]string, error) { | ||
svc, err := t.v1Core.Services(namespace).Get(context.Background(), svcName, metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "Service %s was not found in %q namespace. You may select another namespace by using 'minikube service %s -n <namespace>", svcName, namespace, svcName) | ||
} | ||
|
||
t.sshConn, err = createSSHConnWithRandomPorts(svcName, t.sshPort, t.sshKey, svc) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "creating ssh conn") | ||
} | ||
|
||
go func() { | ||
t.sshConn.suppressStdOut = t.suppressStdOut | ||
err = t.sshConn.startAndWait() | ||
if err != nil { | ||
klog.Errorf("error starting ssh tunnel: %v", err) | ||
} | ||
}() | ||
|
||
urls := make([]string, 0, len(svc.Spec.Ports)) | ||
for _, port := range t.sshConn.ports { | ||
urls = append(urls, fmt.Sprintf("http://127.0.0.1:%d", port)) | ||
} | ||
|
||
return urls, nil | ||
} | ||
|
||
// Stop ... | ||
func (t *ServiceTunnel) Stop() { | ||
err := t.sshConn.stop() | ||
if err != nil { | ||
klog.Warningf("Failed to stop ssh tunnel", err) | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious how is this code different form the one in KIC, is there a way to reuse that code ? so when we need to improve one dont have to do it in two places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is the same code, I am not sure why it was originally placed into the
kic
folder but I'll find out.