Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions v2v-helper/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,25 +233,47 @@ func (r *Reporter) GetCutoverLabel() (string, error) {

func (r *Reporter) WatchPodLabels(ctx context.Context, ch chan<- string) {
go func() {
fmt.Printf("Info: WatchPodLabels goroutine started for pod %s in namespace %s\n", r.PodName, r.PodNamespace)
timeoutSeconds := int64(86400) // Set to 24 hours
watch, err := r.Clientset.CoreV1().Pods(r.PodNamespace).Watch(ctx, metav1.ListOptions{
FieldSelector: fmt.Sprintf("metadata.name=%s", r.PodName),
FieldSelector: fmt.Sprintf("metadata.name=%s", r.PodName),
TimeoutSeconds: &timeoutSeconds,
})
if err != nil {
fmt.Printf("Failed to watch pod labels: %v\n", err)
fmt.Printf("Error: Failed to start watch for pod %s: %v\n", r.PodName, err)
return
}
fmt.Printf("Info: Watch established for pod %s with timeout %d seconds\n", r.PodName, timeoutSeconds)
defer watch.Stop()
originalStartCutover := "no"
fmt.Printf("Info: Entering event loop for pod %s\n", r.PodName)
for event := range watch.ResultChan() {
fmt.Printf("Info: Received event for pod %s: type=%v\n", r.PodName, event.Type)
pod, ok := event.Object.(*corev1.Pod)
if !ok {
fmt.Printf("Error: Received non-pod event for pod %s: %v\n", r.PodName, event.Object)
continue
}
if cutover, ok := pod.Labels["startCutover"]; ok {
if cutover != originalStartCutover {
ch <- cutover
fmt.Printf("Info: Label changed for pod %s: %s -> %s\n", r.PodName, originalStartCutover, cutover)
select {
case ch <- cutover:
fmt.Printf("Info: Sent label %s for pod %s to channel\n", cutover, r.PodName)
default:
fmt.Printf("Error: Channel blocked when sending label %s for pod %s\n", cutover, r.PodName)
}
originalStartCutover = cutover
}
}
}
fmt.Printf("Info: Watch channel closed for pod %s after ~%d seconds\n", r.PodName, timeoutSeconds)
select {
case <-ctx.Done():
fmt.Printf("Error: Context canceled for pod %s: %v\n", r.PodName, ctx.Err())
default:
fmt.Printf("Info: Watch stopped for pod %s, no context cancellation\n", r.PodName)
}
fmt.Printf("Info: WatchPodLabels goroutine exiting for pod %s\n", r.PodName)
}()
}
Loading