Skip to content

Support offline-operations of data surface resources#5901

Merged
kubeedge-bot merged 1 commit into
kubeedge:masterfrom
dcdc831:offline-data-control
Oct 30, 2024
Merged

Support offline-operations of data surface resources#5901
kubeedge-bot merged 1 commit into
kubeedge:masterfrom
dcdc831:offline-data-control

Conversation

@dcdc831

@dcdc831 dcdc831 commented Sep 29, 2024

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

In edge computing scenarios, edge nodes are usually under different networks from the cloud and are often offline due to network fluctuations and other issues. If the edge node is offline, users can only wait for the edge node to come online to perform operations from the cloud if they find any abnormality in the pod or device.

However, the data related to pods and devices are stored locally on the edge nodes, and due to the existence of edged, it is feasible in principle to obtain the data and operate the resources on the edge nodes. The support of this feature will reduce the network resource consumption of the edge node for debugging and resource adjustment, and avoid the situation that some functions of the KubeEdge platform are not available when the edge node is offline.

Which issue(s) this PR fixes:

Fixes #5587

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@kubeedge-bot kubeedge-bot added kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Sep 29, 2024
@kubeedge-bot kubeedge-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Sep 29, 2024

@wbc6080 wbc6080 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Need to make verify CI check pass. You can refer to https://kubeedge.io/docs/developer/make_verify

Comment on lines +24 to +28
"github.com/kubeedge/kubeedge/edge/pkg/edged/config"
"github.com/kubeedge/kubeedge/edge/pkg/metamanager/metaserver/common"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sort the import. Packages starting with github.com/kubeedge should be placed in the third part

"github.com/kubeedge/kubeedge/keadm/cmd/keadm/app/cmd/common"
"github.com/kubeedge/kubeedge/keadm/cmd/keadm/app/cmd/ctl/client"
"github.com/kubeedge/kubeedge/keadm/cmd/keadm/app/cmd/util"
"github.com/spf13/cobra"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

remove github.com/spf13/cobra to the second part

if device.Spec.NodeName == nodeName {
deviceListFilter.Items = append(deviceListFilter.Items, *device)
} else {
fmt.Printf("can't query device: \"%s\" for node: \"%s\"\n", device.Name, device.Spec.NodeName)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use klog instead of fmt. Please check the rest of the code as well

"github.com/kubeedge/kubeedge/keadm/cmd/keadm/app/cmd/common"
"github.com/kubeedge/kubeedge/keadm/cmd/keadm/app/cmd/ctl/client"
"github.com/kubeedge/kubeedge/keadm/cmd/keadm/app/cmd/util"
"github.com/spf13/cobra"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ditto

Comment on lines +32 to +33
"github.com/moby/term"
"github.com/spf13/cobra"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ditto

Comment on lines +32 to +33
"github.com/kubeedge/kubeedge/keadm/cmd/keadm/app/cmd/ctl/client"
"github.com/spf13/cobra"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ditto

@luomengY

Copy link
Copy Markdown
Member

These interfaces need to add tests

@dcdc831

dcdc831 commented Oct 15, 2024

Copy link
Copy Markdown
Contributor Author

Need to make verify CI check pass. You can refer to https://kubeedge.io/docs/developer/make_verify

Thank you for your suggestion. I will sort the import and run make verify before commit.

@wbc6080 wbc6080 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Now that #5894 has been merged, it should be able to get the correct DeviceList via MetaServer's API. You can rebase the latest code for testing.
@dcdc831

@dcdc831 dcdc831 force-pushed the offline-data-control branch from 2ce68e4 to 7092f6b Compare October 25, 2024 02:29
@dcdc831

dcdc831 commented Oct 25, 2024

Copy link
Copy Markdown
Contributor Author

I pushed the latest commit with the following major changes:

  1. Added tests for the MetaServer interfaces of exec and logs;
  2. Added a test for MetaManager send messages to DeviceTwin.
  3. Sort non-standard imports.
  4. Change fmt to klog in the CLI tool.
  5. Rebase the latest code.
  6. run make lint and make verify before push.

@dcdc831 dcdc831 changed the title WIP: Support offline-operations of data surface resources Support offline-operations of data surface resources Oct 25, 2024
@kubeedge-bot kubeedge-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Oct 25, 2024
@dcdc831 dcdc831 force-pushed the offline-data-control branch from 7092f6b to 408146a Compare October 26, 2024 08:24
@kubeedge-bot kubeedge-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 26, 2024
@dcdc831 dcdc831 closed this Oct 28, 2024
@dcdc831 dcdc831 reopened this Oct 28, 2024
ls.Factory.Delete().ServeHTTP(w, req)
case reqInfo.Verb == "update":
ls.Factory.Update(reqInfo).ServeHTTP(w, req)
if reqInfo.Resource == "devices" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Device is a type of CRD, and K8S APIServer has a unified API interface. It is not appropriate to exhaustively list specific CRD types in this way.

}

if err := scanner.Err(); err != nil {
http.Error(w, fmt.Sprintf("Error reading logs: %v", err), http.StatusInternalServerError)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here err != nil, don't it need a return?

Stdin bool
Stdout bool
Stderr bool
TTY bool

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is TTY? Please add code comments.


exec, err := remotecommand.NewSPDYExecutor(config, "POST", req.URL())
if err != nil {
return nil, fmt.Errorf("fail to create executor: %v", err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("fail to create executor: %v", err)
return nil, fmt.Errorf("failed to create executor: %v", err)

if cases.isGetLogsFail {
return &types.LogsResponse{
LogMessages: []string{},
ErrMessages: []string{"fail to get logs for container"},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
ErrMessages: []string{"fail to get logs for container"},
ErrMessages: []string{"failed to get logs for container"},

return req
}

func disableEcho(fd uintptr) (func(), error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add function comments

"github.com/kubeedge/kubeedge/keadm/cmd/keadm/app/cmd/util"
)

var edgeDescribeDeviceShortDescription = `Describe devices in edge node`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
var edgeDescribeDeviceShortDescription = `Describe devices in edge node`
var edgeDescribeDeviceShortDescription = `Describe device in edge node`

"github.com/kubeedge/kubeedge/keadm/cmd/keadm/app/cmd/util"
)

var edgeDescribePodShortDescription = `Describe pods in edge node`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
var edgeDescribePodShortDescription = `Describe pods in edge node`
var edgeDescribePodShortDescription = `Describe pod in edge node`

}
pod, err := podRequest.GetPod(ctx)
if err != nil {
klog.Info(err.Error())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why klog.Info() ,not klog.Error() ?

err := json.Unmarshal(body, &logsResponse)
assert.NoError(t, err)
expectedResponse := types.LogsResponse{}
json.Unmarshal([]byte(tt.expectedBody), &expectedResponse)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
json.Unmarshal([]byte(tt.expectedBody), &expectedResponse)
err := json.Unmarshal([]byte(tt.expectedBody), &expectedResponse)
....

Please add error handling.

stderrStr := queryparams.Get("stderr")
ttyStr := queryparams.Get("tty")

stdin := (stdinStr == trueStr)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
stdin := (stdinStr == trueStr)
stdin := stdinStr == trueStr

ttyStr := queryparams.Get("tty")

stdin := (stdinStr == trueStr)
stdout := (stdoutStr == trueStr)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
stdout := (stdoutStr == trueStr)
stdout := stdoutStr == trueStr


stdin := (stdinStr == trueStr)
stdout := (stdoutStr == trueStr)
stderr := (stderrStr == trueStr)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
stderr := (stderrStr == trueStr)
stderr := stderrStr == trueStr

stdin := (stdinStr == trueStr)
stdout := (stdoutStr == trueStr)
stderr := (stderrStr == trueStr)
tty := (ttyStr == trueStr)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
tty := (ttyStr == trueStr)
tty := ttyStr == trueStr

CoreAPIPrefix = "api"
CoreAPIGroupVersion = schema.GroupVersion{Group: "", Version: "v1"}
Prefix = "apis"
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Delete these unused constants.

package restful

const (
CONTAINERLOGS string = "/containerLogs"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggest deleting this file:
edge/pkg/metamanager/metaserver/kubernetes/storage/restful/constants.go,Put CONTAINERLOGS string = "/containerLogs" into edge/pkg/metamanager/metaserver/kubernetes/storage/restful/request.go.

@dcdc831 dcdc831 force-pushed the offline-data-control branch from 408146a to a65cf88 Compare October 28, 2024 08:58
@dcdc831 dcdc831 closed this Oct 29, 2024
@dcdc831 dcdc831 reopened this Oct 29, 2024
Timestamps string `query:"timestamps"`
}

type ExecInfo struct {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why param. in ExecInfo don't need the format query:"xxx" like LogsInfo?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The logs is run on the edged restful API, these tags is used to generate query parameters. exec calls the remoteRuntimeService methods (ExecSync and Exec) without generating query parameters.

@@ -0,0 +1,286 @@
package handlerfactory

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add copyright for new file

@@ -0,0 +1,96 @@
/*

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please djust the copyright format, like adding blank line between L5-6 and L6-7

case cloudmodules.PolicyControllerModuleName:
resp := message.NewRespByMessage(&message, OK)
sendToCloud(resp)
case modules.MetaManagerModuleName:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It may cause confused using metamanager module here because we already have a module named meta. How about name this module metaserver because it seems the request are from metaserver? but metaserver is not an independent module, I'm not sure if metaserver is suitable. @fisherxu @luomengY @WillardHu @wbc6080

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It may cause confused using metamanager module here because we already have a module named meta. How about name this module metaserver because it seems the request are from metaserver? but metaserver is not an independent module, I'm not sure if metaserver is suitable. @fisherxu @luomengY @WillardHu @wbc6080

I think using a metaserver is possible, as the source here comes from the metaserver.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It may cause confused using metamanager module here because we already have a module named meta. How about name this module metaserver because it seems the request are from metaserver? but metaserver is not an independent module, I'm not sure if metaserver is suitable. @fisherxu @luomengY @WillardHu @wbc6080

@WillardHu @fisherxu

@wbc6080 wbc6080 Oct 30, 2024

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think using a metaserver is possible, as the source here comes from the metaserver.

+1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, I added and registered metaserver module, and set the msgsource to metaserver.

if device.Spec.NodeName == nodeName {
deviceListFilter.Items = append(deviceListFilter.Items, *device)
} else {
klog.Infof("can't query device: \"%s\" for node: \"%s\"", device.Name, device.Spec.NodeName)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
klog.Infof("can't query device: \"%s\" for node: \"%s\"", device.Name, device.Spec.NodeName)
klog.Errof("can't query device: \"%s\" for node: \"%s\"", device.Name, device.Spec.NodeName)

return fmt.Errorf("unable to find describer for %v", m)
}

first := true

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's the actual effect of first?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

describe supports printing information about multiple resources. If the first is false, blank lines is printed to separate resources.

if pod.Spec.NodeName == nodeName {
var apiPod api.Pod
if err := k8s_v1_api.Convert_v1_Pod_To_core_Pod(pod, &apiPod, nil); err != nil {
klog.Infof("failed to convert pod with err:%v\n", err)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
klog.Infof("failed to convert pod with err:%v\n", err)
klog.Errof("failed to convert pod with err:%v\n", err)

There are several other places using Infof but not Errof. What's the consideration?

@dcdc831

dcdc831 commented Oct 29, 2024

Copy link
Copy Markdown
Contributor Author

I have some questions about the results of integrationtest. The error occurred in eventbus test, and I did not change eventbus code.
image

But I executed the 'make Integrationtest' in my local development environment and found that the above error was possible. There are also cases where the test was successfully passed:
image

go version and ginkgo version:

  • go version: 1.21.13
  • Ginkgo CLI Version: 2.9.5 (Then I run make integrationtest several times with Ginkgo CLI Version:2.20.2, this error seems not happening again.)

@Shelley-BaoYue

Copy link
Copy Markdown
Collaborator

@dcdc831 integration test error is not introduced by this PR. You can ignore it.

Signed-off-by: YulinLi <1826549123@qq.com>
@dcdc831 dcdc831 force-pushed the offline-data-control branch 3 times, most recently from 3ddcad0 to 63ed57c Compare October 30, 2024 08:57
@dcdc831

dcdc831 commented Oct 30, 2024

Copy link
Copy Markdown
Contributor Author

I undo the changes to metaserver and keep the msgsource that sends information to devicetwin as metamanager.

@Shelley-BaoYue Shelley-BaoYue left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

/lgtm
CIFuzz error can be ignored in this PR, the viaduct migration caused this error.

@kubeedge-bot kubeedge-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 30, 2024
@Shelley-BaoYue

Copy link
Copy Markdown
Collaborator

/assign @fisherxu @WillardHu @luomengY

@fisherxu

Copy link
Copy Markdown
Member

/approve
Thanks for @luomengY @dcdc831 your great work!

@kubeedge-bot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fisherxu

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

The pull request process is described here

Details 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 30, 2024
@kubeedge-bot kubeedge-bot merged commit e3827d7 into kubeedge:master Oct 30, 2024
@Shelley-BaoYue Shelley-BaoYue added this to the v1.20 milestone Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OSPP] Support the operation of data surface resources in offline scenarios of edge nodes.

7 participants