Skip to content

Support edge nodes report events#5811

Merged
kubeedge-bot merged 12 commits intokubeedge:masterfrom
llmmqq8023:edge_event
Oct 17, 2024
Merged

Support edge nodes report events#5811
kubeedge-bot merged 12 commits intokubeedge:masterfrom
llmmqq8023:edge_event

Conversation

@llmmqq8023
Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind feature

What this PR does / why we need it:

Support edge nodes report events

Proposal: #5722

Issue: #5595

@kubeedge-bot kubeedge-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Aug 20, 2024
@kubeedge-bot kubeedge-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 20, 2024
@llmmqq8023 llmmqq8023 changed the title Edge event Support edge nodes report events Aug 20, 2024
@kubeedge-bot kubeedge-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 20, 2024
Comment thread edge/pkg/edged/edged.go Outdated
Comment thread common/constants/default.go Outdated
Comment thread edge/pkg/edged/kubeclientbridge/typed/core/v1/event_bridge.go Outdated
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
appcorev1 "k8s.io/client-go/applyconfigurations/core/v1"
fakecorev1 "k8s.io/client-go/kubernetes/typed/core/v1/fake"
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 sort these import.

@@ -0,0 +1,95 @@
package client
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.

Add a copyright

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
appcorev1 "k8s.io/client-go/applyconfigurations/core/v1"
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, sort the import.

Comment thread edge/pkg/metamanager/process.go Outdated

func (m *metaManager) process(message model.Message) {
operation := message.GetOperation()
if _, resType, _ := parseResource(&message); resType == model.ResourceTypeEvent {
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.

Could we use processInsert and processUpdate func?

@@ -325,6 +326,8 @@ type EdgeControllerBuffer struct {
type EdgeControllerLoad struct {
// UpdatePodStatusWorkers indicates the load of update pod status workers
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.

You need add a comment for HandleEventWorkers

@@ -252,6 +252,7 @@ type EdgeController struct {
type EdgeControllerBuffer struct {
// UpdatePodStatus indicates the buffer of pod status
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.

You need add a comment for HandleEvent

@Shelley-BaoYue Shelley-BaoYue added this to the v1.19 milestone Aug 27, 2024
@llmmqq8023 llmmqq8023 force-pushed the edge_event branch 3 times, most recently from 4c5fb19 to ebc96e6 Compare August 28, 2024 12:23
@magichan
Copy link
Copy Markdown
Contributor

build fail, @llmmqq8023 you may need fix it before merge
image

Signed-off-by: llmmqq8023 <273337875@qq.com>

cloud

Signed-off-by: llmmqq8023 <273337875@qq.com>

cloud

Signed-off-by: llmmqq8023 <273337875@qq.com>
Signed-off-by: llmmqq8023 <273337875@qq.com>
Signed-off-by: llmmqq8023 <273337875@qq.com>

Modified comments and other content

Signed-off-by: llmmqq8023 <273337875@qq.com>

Revert "不需要推送"

This reverts commit edcf206.

Modified comments and other content

Signed-off-by: llmmqq8023 <273337875@qq.com>
@llmmqq8023
Copy link
Copy Markdown
Contributor Author

build fail, @llmmqq8023 you may need fix it before merge image

Thank you for pointing out the build issue. I have made the necessary fixes, please try it again~

evt := &v1.Event{}
err = json.Unmarshal(data, evt)
if err != nil {
klog.Errorf("Error marshaling createEvent msg content %v", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is Unmarshal action,not marshal action.

You may need to modify the error description to something like this

case msg := <-uc.eventChan:
data, err := msg.GetContentData()
if err != nil {
klog.Errorf("Get event data err: %v", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

printing msg.GetID() in error log is a good practice.

you may need add it in your error log.

}
_, err = uc.kubeClient.CoreV1().Events(evt.Namespace).CreateWithEventNamespace(evt)
if err != nil {
klog.Errorf("CreateWithEventNamespace error, event: %v, err: %v", evt, err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unless you know what you're doing, printing all the information of a structure is a recommended action.

You may need to select the attributes worth printing.

There are several similar issues, if you agree with the review, you may want to check and correct them yourself.

evt := &v1.Event{}
err = json.Unmarshal(data, evt)
if err != nil {
klog.Errorf("Error marshaling updateEvent msg content %v", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don't use %v for err var.

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.

Could you please explain more about why cannot use %v to log err?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

After checking, my comment was wrong,

%v works better for nil.

see https://stackoverflow.com/questions/61283248/format-errors-in-go-s-v-or-w

please close it.

Comment thread common/constants/default.go Outdated
DefaultCertificateSigningRequestWorkers = 4

DefaultUpdatePodStatusBuffer = 1024
DefaultProcessEventBuffer = 1024
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please allow me to be curious,

@wbc6080 Do we need to keep common/constants/default.go and staging/src/github.com/kubeedge/api/apis/common/constants/default.go consistent?

If not, can the unused variables be removed?

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.

Related work have been done in #5844

Comment thread edge/pkg/edged/kubeclientbridge/typed/core/v1/event_bridge.go
}

// Create logs the event creation request.
func (e *EventsBridge) Create(ctx context.Context, event *corev1.Event, opts metav1.CreateOptions) (*corev1.Event, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

about the comment Create logs the event creation request.
I don't think the function is responsible for logging; its responsibility is as a bridge or proxy, forwarding requests to the meta.

Comment thread edge/pkg/metamanager/client/event.go Outdated
}

func (e *events) CreateWithEventNamespace(event *corev1.Event) (*corev1.Event, error) {
resource := fmt.Sprintf("%s/%s/%s", e.namespace, model.ResourceTypeEvent, event.Name)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The same confusion, whether to use NameSpace in Core1.Event within functions ending with WithEventNamespace

But unlike the previous one, which was so certain, the decision on which namespace to use here needs to be made on your own.

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.

Yes, it should be changed to:

Suggested change
resource := fmt.Sprintf("%s/%s/%s", e.namespace, model.ResourceTypeEvent, event.Name)
resource := fmt.Sprintf("%s/%s/%s", event.namespace, model.ResourceTypeEvent, event.Name)

@llmmqq8023

Comment thread edge/pkg/metamanager/client/event.go
Comment thread edge/pkg/metamanager/client/event.go Outdated
return event, nil
}

type PatchInfo struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see the repeat define PatchInfo in MetaManager and EdgeController.

Could you check if it's possible to extract this into the API package to reduce duplication?

}
}

type PatchInfo 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.

Suggested change
type PatchInfo struct {
type EventPatchInfo struct {

evt := &v1.Event{}
err = json.Unmarshal(data, evt)
if err != nil {
klog.Errorf("Error marshaling updateEvent msg content %v", 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.

Could you please explain more about why cannot use %v to log err?

Comment thread edge/pkg/metamanager/client/event.go
Comment thread edge/pkg/metamanager/client/event.go Outdated
}

func (e *events) CreateWithEventNamespace(event *corev1.Event) (*corev1.Event, error) {
resource := fmt.Sprintf("%s/%s/%s", e.namespace, model.ResourceTypeEvent, event.Name)
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.

Yes, it should be changed to:

Suggested change
resource := fmt.Sprintf("%s/%s/%s", e.namespace, model.ResourceTypeEvent, event.Name)
resource := fmt.Sprintf("%s/%s/%s", event.namespace, model.ResourceTypeEvent, event.Name)

@llmmqq8023

@Shelley-BaoYue
Copy link
Copy Markdown
Collaborator

Please solve the error of golint and UT

@llmmqq8023 llmmqq8023 changed the title Support edge nodes report events WIP: Support edge nodes report events Sep 2, 2024
@kubeedge-bot kubeedge-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 2, 2024
Signed-off-by: llmmqq8023 <273337875@qq.com>

solve the error of golint and UT

Signed-off-by: llmmqq8023 <273337875@qq.com>

solve the error of golint and UT

Signed-off-by: llmmqq8023 <273337875@qq.com>
@llmmqq8023 llmmqq8023 changed the title WIP: Support edge nodes report events Support edge nodes report events Sep 4, 2024
@kubeedge-bot kubeedge-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 4, 2024
Copy link
Copy Markdown
Collaborator

@wbc6080 wbc6080 left a comment

Choose a reason for hiding this comment

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

Please make the lint check pass

@kubeedge-bot kubeedge-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 10, 2024
…n "sendEvent".

Signed-off-by: llmmqq8023 <273337875@qq.com>
Signed-off-by: llmmqq8023 <273337875@qq.com>
@kubeedge-bot kubeedge-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 18, 2024
Comment thread common/constants/default.go Outdated
// ImagePrePullController
DefaultImagePrePullJobStatusBuffer = 1024
DefaultImagePrePullJobEventBuffer = 1
DefaultImagePrePullJobWorkers = 1
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.

These contants need to be removed. It seems a misoperation importing these constants when you rebase the master branch

// EdgeControllerLoad indicates the EdgeController load
type EdgeControllerLoad struct {
// HandleEventWorkers indicates the load of handle event workers
// default 1
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.

// SendEvents indicates whether to send events to cloud,
// if set to false, events will not be sent to cloud.
// default true
SendEvent bool `json:"sendEvent"`
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.

In order to allow users to smoothly upgrade and adapt to new versions, I think it is more appropriate to disable this feature by default in the next two release.

@kubeedge-bot kubeedge-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 25, 2024
Signed-off-by: llmmqq8023 <273337875@qq.com>
@kubeedge-bot kubeedge-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 27, 2024
Signed-off-by: llmmqq8023 <273337875@qq.com>
@kubeedge-bot kubeedge-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 28, 2024
Copy link
Copy Markdown
Member

@fisherxu fisherxu left a comment

Choose a reason for hiding this comment

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

Overall looks good.

// SendEvents indicates whether to send events to cloud,
// if set to true, events will be sent to cloud.
// default false
SendEvent bool `json:"sendEvent"`
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.

ReportEvent should be better?

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.

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.

ReportEvent should be better?

+1

Signed-off-by: llmmqq8023 <273337875@qq.com>
Copy link
Copy Markdown
Member

@fisherxu fisherxu left a comment

Choose a reason for hiding this comment

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

Plz fix the lint check error, and you can also run make lint in your local host to check, thanks :) @llmmqq8023

"k8s.io/client-go/kubernetes/fake"
"testing"
"time"
)
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

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
appcorev1 "k8s.io/client-go/applyconfigurations/core/v1"
"testing"
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

// EdgeControllerLoad indicates the EdgeController load
type EdgeControllerLoad struct {
// ProcessEventWorkers indicates the load of process event workers
// default 1
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
// default 1
// default 4

according your code, the default value should be 4

Signed-off-by: llmmqq8023 <273337875@qq.com>

modify imports

Signed-off-by: llmmqq8023 <273337875@qq.com>

change an annotation of "default"

Signed-off-by: llmmqq8023 <273337875@qq.com>
}

func TestEventReport(t *testing.T) {

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 unnecessary blank line

Signed-off-by: llmmqq8023 <273337875@qq.com>

add copyright for _test.go

Signed-off-by: llmmqq8023 <273337875@qq.com>
Copy link
Copy Markdown
Collaborator

@Shelley-BaoYue Shelley-BaoYue left a comment

Choose a reason for hiding this comment

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

@kubeedge-bot kubeedge-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 17, 2024
Copy link
Copy Markdown
Member

@fisherxu fisherxu left a comment

Choose a reason for hiding this comment

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

/approve
Thanks for the 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 17, 2024
@kubeedge-bot kubeedge-bot merged commit 063a213 into kubeedge:master Oct 17, 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/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants