package crd import ( "context" "fmt" "gitea.com/logicamp/lc" "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/watch" ) func (crd Crd) watchFlinkJobs() { lc.Logger.Debug("[crd] starting watch") watcher, err := crd.client.Watch(context.Background(), metav1.ListOptions{}) if err != nil { panic(err) } defer watcher.Stop() for event := range watcher.ResultChan() { lc.Logger.Debug("[crd] event received") switch event.Type { case watch.Added: job := event.Object.(*unstructured.Unstructured) fmt.Printf("New FlinkJob created: %s\n", job.GetName()) // Handle the new FlinkJob handleNewFlinkJob(job) } } } func handleNewFlinkJob(job *unstructured.Unstructured) { // Extract job details name := job.GetName() namespace := job.GetNamespace() // Get specific fields using unstructured.Unstructured methods spec, found, err := unstructured.NestedMap(job.Object, "spec") if err != nil || !found { fmt.Printf("Error getting spec for job %s: %v\n", name, err) return } // Process job specification fmt.Printf("Processing FlinkJob %s in namespace %s\n", name, namespace) lc.Logger.Debug("[crd] [watch]", zap.Any("spec", spec)) // Add your custom logic here }