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

support kubectl attach in KubeEdge #4734

Merged
merged 2 commits into from
Jun 30, 2023

Conversation

wenchajun
Copy link
Contributor

@wenchajun wenchajun commented Apr 15, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

Currently, in a native kubernetes cluster, kubectl exec command can execute a command in a container. kubectl logs command can print the logs for a container in a pod. kubectl attach command can attach to a running container.
Users can execute these commands in the cloud and do not need to operate on the nodes.
we plan to implement kubectl exec, kubectl logs and kubectl attach feature based on edge computing scenarios.
These two commands(kubectl exec, kubectl logs) are currently integrated, and this PR is to integrate the kubectl attach command.

Which issue(s) this PR fixes:

Fixes #4424

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

The user can use the `kubectl attach` command to access the pod of the edge node.

Signed-off-by: Shelley-BaoYue <baoyue2@huawei.com>
(cherry picked from commit 7cee5b0)
Signed-off-by: dehaocheng <dehaocheng@kubesphere.io>
@kubeedge-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign qizha after the PR has been reviewed.
You can assign the PR to them by writing /assign @qizha in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeedge-bot kubeedge-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 15, 2023
@wenchajun
Copy link
Contributor Author

@Shelley-BaoYue Can you give us some advice?

// first send connect message
connector, err := ah.SendConnection()
if err != nil {
klog.Errorf("%s send %s info error %v", ah.String(), stream.MessageTypeExecConnect, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Try changing it to MessageTypeAttachConnect.

@Shelley-BaoYue
Copy link
Collaborator

@Shelley-BaoYue Can you give us some advice?

I will debug it in my local environment, it may take some time to give you feedback.

@Shelley-BaoYue Shelley-BaoYue added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 18, 2023
@@ -104,6 +119,10 @@ func (s *TunnelSession) ServeConnection(m *stream.Message) {
if err := s.serveMetricsConnection(m); err != nil {
klog.Errorf("Serve Metrics connection error %s", m.String())
}
case stream.MessageTypeAttachConnect:
if err := s.serveContainerAttachConnection(m); err != nil {
klog.Errorf("Serve Metrics connection error %s", m.String())
Copy link
Collaborator

Choose a reason for hiding this comment

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

log info error, need to be Serve Attach

if err != nil {
return nil, err
}
return NewMessage(ah.MessID, MessageTypeExecConnect, data), nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

MessageTypeExecConnect --> MessageTypeAttachConnect

"context"
"errors"
"fmt"
"github.com/kubeedge/kubeedge/common/constants"
Copy link
Collaborator

Choose a reason for hiding this comment

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

The import sequence needs to be adjusted. Generally, the import sequence is the standard lib, third-party lib, and local
lib.

"errors"
"fmt"
"io"
"k8s.io/apimachinery/pkg/util/httpstream/spdy"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Adjusting the import sequence

}

func (ah *EdgedAttachConnection) receiveFromCloudStream(con net.Conn, stop chan struct{}) {
// todo: read msg from cloudstream
Copy link
Collaborator

Choose a reason for hiding this comment

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

todo flag can be removed now

}

func (ah *EdgedAttachConnection) write2CloudStream(tunnel SafeWriteTunneler, con net.Conn, stop chan struct{}) {
// todo: write response to tunnel
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

}

func (ah *EdgedAttachConnection) Serve(tunnel SafeWriteTunneler) error {
// todo: serve msg from clousstream, send req to edged and write response to tunnel
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

@Shelley-BaoYue
Copy link
Collaborator

@wenchajun I have successfully debugged locally. You can adjust it according to my modification suggestions and try again.

@wenchajun
Copy link
Contributor Author

@wenchajun I have successfully debugged locally. You can adjust it according to my modification suggestions and try again.

Thanks for your reply, I have fixed the problems.

@Shelley-BaoYue Shelley-BaoYue removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 24, 2023
@wenchajun wenchajun closed this Apr 24, 2023
@wenchajun wenchajun reopened this Apr 24, 2023
@wenchajun
Copy link
Contributor Author

In the CI just now, I see that the error is reported as an extra blank line added. I modified it, can you help me rerun this CI? @Shelley-BaoYue

@Shelley-BaoYue
Copy link
Collaborator

In the CI just now, I see that the error is reported as an extra blank line added. I modified it, can you help me rerun this CI? @Shelley-BaoYue

OK. And the description of this pr could be added, including associated issues #4424 , proposal: #4690 .

@@ -8,6 +8,7 @@ const (
const (
MessageTypeLogsConnect MessageType = iota
MessageTypeExecConnect
MessageTypeAttachConnect
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here is a compatibility problem. We hope CloudCore can be compatible with EdgeCore of earlier versions generally. If MessageTypeAttachConnect is inserted here, when CloudCore send MessageTypeData,EdgeCore will identify it as MessageTypeRemoveConnect. I suggest adding MessageTypeAttachConnect at the end, and the judgment at line 195 of edge/pkg/edgestream/tunnel needs to be changed accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@wenchajun wenchajun changed the title Kubectl attach support kubectl attach in KubeEdge Apr 25, 2023
@@ -172,7 +191,7 @@ func (s *TunnelSession) Serve() error {
return fmt.Errorf("close tunnel stream connection, error:%s", string(mess.Data))
}

if mess.MessageType < stream.MessageTypeData {
if (mess.MessageType < stream.MessageTypeData) || (mess.MessageType == stream.MessageTypeAttachConnect) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

mess.MessageType >= stream.MessageTypeAttachConnect maybe better for expansion

Copy link
Contributor Author

@wenchajun wenchajun Apr 25, 2023

Choose a reason for hiding this comment

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

const (
	MessageTypeLogsConnect MessageType = iota
	MessageTypeExecConnect
	MessageTypeMetricConnect
	MessageTypeData
	MessageTypeRemoveConnect
	MessageTypeCloseConnect
	MessageTypeAttachConnect

What should this field be adjusted to be greater than or equal to if it is increased by 1 each time here?

(mess.MessageType < stream.MessageTypeData) || (mess.MessageType >= stream.MessageTypeAttachConnect)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

const (
	MessageTypeLogsConnect MessageType = iota
	MessageTypeExecConnect
	MessageTypeMetricConnect
	MessageTypeData
	MessageTypeRemoveConnect
	MessageTypeCloseConnect
	MessageTypeAttachConnect

What should this field be adjusted to be greater than or equal to if it is increased by 1 each time here?

I guess that in order to ensure compatibility, new message type will be added at the end. If we add more capabilities of kubectl in the future, we don't need to change that judgment, just using mess.MessageType >= stream.MessageTypeAttachConnect is OK. It's just my suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get it .thanks

Signed-off-by: dehaocheng <dehaocheng@kubesphere.io>
@wenchajun
Copy link
Contributor Author

All changes have been made, are there any questions so far? @Shelley-BaoYue

@wenchajun
Copy link
Contributor Author

It looks like there is a slight error in action, please check codecov/codecov-action#598

@Shelley-BaoYue
Copy link
Collaborator

PTAL @fisherxu @wackxu

@kubeedge-bot kubeedge-bot merged commit 01ce58b into kubeedge:master Jun 30, 2023
22 of 24 checks passed
@fisherxu fisherxu added this to the v1.14 milestone Aug 24, 2023
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support kubectl attach in KubeEdge
4 participants