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

chore: merge the same kbagent events #8044

Closed
wants to merge 14 commits into from
Closed

Conversation

Ursasi
Copy link
Contributor

@Ursasi Ursasi commented Aug 28, 2024

No description provided.

@github-actions github-actions bot added the size/L Denotes a PR that changes 100-499 lines. label Aug 28, 2024
Copy link

codecov bot commented Aug 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.51%. Comparing base (abf4a83) to head (54463b0).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8044      +/-   ##
==========================================
+ Coverage   62.38%   62.51%   +0.12%     
==========================================
  Files         334      334              
  Lines       40745    40745              
==========================================
+ Hits        25419    25470      +51     
+ Misses      13054    13000      -54     
- Partials     2272     2275       +3     
Flag Coverage Δ
unittests 62.51% <ø> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Ursasi Ursasi requested a review from leon-inf August 29, 2024 00:49
@@ -44,7 +44,7 @@ type EventReconciler struct {
}

// events API only allows ready-only, create, patch
// +kubebuilder:rbac:groups=core,resources=events,verbs=get;list;watch;create;patch
// +kubebuilder:rbac:groups=core,resources=events,verbs=get;list;watch;create;patch;update;
Copy link
Contributor

Choose a reason for hiding this comment

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

The controller has no need to the update permission.

"time"

"github.com/apecloud/kubeblocks/pkg/constant"
Copy link
Contributor

Choose a reason for hiding this comment

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

Check the import orders.

if !errors.IsNotFound(err) {
return fmt.Errorf("error getting event: %v", err)
}
event = createEvent(reason, message, eventName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename these functions like: createEvent -> newEvent, sendEvent -> createEvent.

event, err := clientSet.CoreV1().Events(baseInfo.namespace).Get(context.TODO(), eventName, metav1.GetOptions{})
if err != nil {
if !errors.IsNotFound(err) {
return fmt.Errorf("error getting event: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should back-off to create a new Event, or the event may be lost.

namespace := os.Getenv(constant.KBEnvNamespace)
func sendOrUpdateEvent(reason string, message string) error {
suffix := hashReasonNMessage(reason, message)
eventName := fmt.Sprintf("%s.%s.%s", baseInfo.podName, baseInfo.podUID, suffix)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a little weird that kinds of event with same reason and message will have an unique Event object.

event = createEvent(reason, message, eventName)
return sendEvent(clientSet, event)
}
return updateEvent(clientSet, event)
Copy link
Contributor

@leon-inf leon-inf Aug 30, 2024

Choose a reason for hiding this comment

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

Should there be some other conditions to determine whether to update the exist Event or create a new Event? For example, the time interval between events, or consecutive events of the same type, etc., rather than just depending on the existence of the Event.

event := createEvent(reason, message)
err := sendEvent(event)
once.Do(func() {
baseInfo = eventBaseInfo{
Copy link
Contributor

Choose a reason for hiding this comment

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

The eventBaseInfo struct is not necessary.

podUID := os.Getenv(constant.KBEnvPodUID)
nodeName := os.Getenv(constant.KBEnvNodeName)
namespace := os.Getenv(constant.KBEnvNamespace)
func sendOrUpdateEvent(reason string, message string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should add some test cases for different behaviors.

@Ursasi Ursasi requested a review from a team as a code owner September 23, 2024 15:15
@@ -44,7 +44,7 @@ type EventReconciler struct {
}

// events API only allows ready-only, create, patch
// +kubebuilder:rbac:groups=core,resources=events,verbs=get;list;watch;create;patch
// +kubebuilder:rbac:groups=core,resources=events,verbs=get;list;watch;create;patch;update;
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary change.

@@ -22,94 +22,115 @@ package util
import (
"context"
"fmt"
"github.com/apecloud/kubeblocks/pkg/constant"
Copy link
Contributor

Choose a reason for hiding this comment

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

Adjust the import order, move to last.

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/rand"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

metav1

@Ursasi Ursasi marked this pull request as draft September 30, 2024 02:46
@github-actions github-actions bot removed the size/L Denotes a PR that changes 100-499 lines. label Oct 29, 2024
@github-actions github-actions bot added the size/XXL Denotes a PR that changes 1000+ lines. label Oct 29, 2024
@Ursasi Ursasi closed this Oct 29, 2024
@github-actions github-actions bot added this to the Release 0.9.2 milestone Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XXL Denotes a PR that changes 1000+ lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants