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

aviold event duplicates #45

Merged
merged 2 commits into from
Aug 19, 2024
Merged

aviold event duplicates #45

merged 2 commits into from
Aug 19, 2024

Conversation

apesternikov
Copy link
Contributor

All events are displayed in a test log every 30 seconds, which is misleading. We would like to see only new events.

Comment on lines 131 to 133
func listenForEvents(ctx context.Context, clientset *kubernetes.Clientset, onFailure func(*v1.Event)) {

kubeInformerFactory := informers.NewFilteredSharedInformerFactory(clientset, time.Second*30, *namespace, nil)
kubeInformerFactory := informers.NewSharedInformerFactoryWithOptions(clientset, 0, informers.WithNamespace(*namespace))

Choose a reason for hiding this comment

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

The listenForEvents function does not handle the case where the namespace variable might be nil or an empty string. This could lead to unexpected behavior or runtime errors.

Recommended Solution:
Add a check to ensure that the namespace variable is not nil or empty before proceeding with the creation of the SharedInformerFactory. If it is, handle the error appropriately, possibly by logging an error message and returning early from the function.

Comment on lines 277 to 283
var wg sync.WaitGroup
wg.Add(len(ports))
for _, port := range ports {
ep, err := clientset.CoreV1().Endpoints(*namespace).Get(ctx, serviceName, meta_v1.GetOptions{})
ep, err := clientset.CoreV1().Endpoints(namespace).Get(ctx, serviceName, meta_v1.GetOptions{})
if err != nil {
return fmt.Errorf("error listing endpoints for service %s: %v", serviceName, err)
}

Choose a reason for hiding this comment

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

The Get call to retrieve endpoints for a service is made inside a loop without any rate limiting or retries. This can lead to throttling by the Kubernetes API server if there are many ports, causing potential failures.

Recommended Solution:
Implement rate limiting and retries for the Get call to ensure that the function can handle cases where the API server throttles requests. Use a backoff strategy to retry the request in case of transient errors.

Comment on lines 373 to 379
clientset = kubernetes.NewForConfigOrDie(config)

go func() {
err := stern.Run(ctx, *namespace, clientset, allowErrors, disablePodLogs)
err := stern.Run(ctx, namespace, clientset, allowErrors, disablePodLogs)
if err != nil {
log.Print(err)
}

Choose a reason for hiding this comment

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

The error handling in the goroutine that runs stern.Run is insufficient. If stern.Run returns an error, it is only logged, and no further action is taken. This can lead to silent failures where the main program continues running without the necessary sidecar functionality.

Recommended Solution:
Enhance the error handling by implementing a mechanism to signal the main program to terminate or take corrective action if stern.Run fails. This could involve canceling the context or sending a signal to a monitoring channel.

@apesternikov apesternikov merged commit 0f0562b into main Aug 19, 2024
1 of 2 checks passed
@apesternikov apesternikov deleted the ap/no-event-dupes branch August 30, 2024 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants