Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Satyam Bhardwaj <[email protected]>

rh-pre-commit.version: 2.1.0
rh-pre-commit.check-secrets: ENABLED
  • Loading branch information
Satyam Bhardwaj committed Feb 12, 2024
1 parent 19d73a4 commit 52aafe7
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions pkg/watcher/reconciler/dynamic/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ func (r *Reconciler) streamLogs(ctx context.Context, o results.Object, logType,

// logctx is derived from ctx. Therefore, if ctx is cancelled (either explicitly through a call to its cancel
// function or when it reaches its deadline), logctx will be cancelled automatically.
// TODO: Implement configurable timeout based on user feedback analysis.
logctx, _ := context.WithTimeout(ctx, 10*time.Minute)

go func(ctx context.Context, echan <-chan error, o metav1.Object) {
Expand All @@ -413,24 +414,23 @@ func (r *Reconciler) streamLogs(ctx context.Context, o results.Object, logType,
)
case writeErr := <-echan:
errChanRepeater <- writeErr
var gofuncerr error
_, gofuncerr = writer.Flush()
if gofuncerr != nil {
logger.Error(gofuncerr)
}
if gofuncerr = logsClient.CloseSend(); gofuncerr != nil {
logger.Error(gofuncerr)
}
logger.Debugw("Flush in streamLogs done",
zap.String("namespace", o.GetNamespace()),
zap.String("name", o.GetName()),
)
}
logger.Debugw("Gofunc in streamLogs done",
var gofuncerr error
_, gofuncerr = writer.Flush()
if gofuncerr != nil {
logger.Error(gofuncerr)
}
logger.Info("Flush in streamLogs done",
zap.String("namespace", o.GetNamespace()),
zap.String("name", o.GetName()),
)
if err = logsClient.CloseSend(); err != nil {
logger.Error(err)
}
logger.Info("Gofunc in streamLogs done",
zap.String("namespace", o.GetNamespace()),
zap.String("name", o.GetName()),
)

err = r.RemoveFinalizer(ctx, o)
if err != nil {
logger.Errorw("Error removing finalizer",
Expand All @@ -441,7 +441,7 @@ func (r *Reconciler) streamLogs(ctx context.Context, o results.Object, logType,
return
}

logger.Debugw("Finalizer removed successfully",
logger.Info("Finalizer removed successfully",
zap.String("namespace", o.GetNamespace()),
zap.String("name", o.GetName()),
)
Expand All @@ -453,8 +453,8 @@ func (r *Reconciler) streamLogs(ctx context.Context, o results.Object, logType,
zap.String("name", o.GetName()),
zap.Error(err),
)

}

}(logctx, errChan, o)

// errChanRepeater receives stderr from the TaskRun containers.
Expand All @@ -465,14 +465,22 @@ func (r *Reconciler) streamLogs(ctx context.Context, o results.Object, logType,
Err: writer,
}, logChan, errChanRepeater)

logger.Debugw("Exiting streaming logs",
logger.Info("Exiting streaming logs",
zap.String("namespace", o.GetNamespace()),
zap.String("name", o.GetName()),
)
return nil
}

func (r *Reconciler) AddFinalizer(ctx context.Context, o metav1.Object) error {
if ownerReferences := o.GetOwnerReferences(); len(ownerReferences) > 0 {
// do not add finalizer if the object is owned by a PipelineRun object
for _, or := range ownerReferences {
if or.Kind == "PipelineRun" {
return nil
}
}
}
finalizers := o.GetFinalizers()
for _, f := range finalizers {
if f == LogFinalizer {
Expand All @@ -481,7 +489,7 @@ func (r *Reconciler) AddFinalizer(ctx context.Context, o metav1.Object) error {
}
finalizers = append(finalizers, LogFinalizer)

patch, err := finalizerPatch(o, finalizers)
patch, err := finalizerPatch(finalizers)
if err != nil {
return fmt.Errorf("error adding results log finalizer: %w", err)
}
Expand All @@ -497,7 +505,7 @@ func (r *Reconciler) RemoveFinalizer(ctx context.Context, o metav1.Object) error
for i, f := range finalizers {
if f == LogFinalizer {
finalizers = append(finalizers[:i], finalizers[i+1:]...)
patch, err := finalizerPatch(o, finalizers)
patch, err := finalizerPatch(finalizers)
if err != nil {
return fmt.Errorf("error removing results log finalizer: %w", err)
}
Expand Down Expand Up @@ -530,7 +538,7 @@ type metadata struct {
Finalizer []string `json:"finalizers"`
}

func finalizerPatch(object metav1.Object, finalizers []string) ([]byte, error) {
func finalizerPatch(finalizers []string) ([]byte, error) {
data := mergePatch{
Metadata: metadata{
Finalizer: []string{},
Expand Down

0 comments on commit 52aafe7

Please sign in to comment.