fix: resolve missing restrict resources namespace

This commit is contained in:
2025-03-04 23:55:28 +03:30
parent 75d0557286
commit 346f69100c
4 changed files with 15 additions and 10 deletions

View File

@@ -21,23 +21,28 @@ func (crd Crd) watchFlinkJobs() rxgo.Observable {
go func() {
pkg.Logger.Debug("[crd] starting watch")
watcher, err := crd.client.Namespace(os.Getenv("NAMESPACE")).Watch(context.Background(), metaV1.ListOptions{})
watcher, err := crd.client.Watch(context.Background(), metaV1.ListOptions{})
if err != nil {
panic(err)
}
defer watcher.Stop()
namespace := os.Getenv("NAMESPACE")
pkg.Logger.Debug("[crd] [watch]", zap.String("namespace", namespace))
for event := range watcher.ResultChan() {
unstructuredJob := event.Object.(*unstructured.Unstructured)
unstructuredMap, _, err := unstructured.NestedMap(unstructuredJob.Object)
if err != nil {
pkg.Logger.Error("cannot create unstructured map", zap.Error(err))
pkg.Logger.Error("[crd] [watch]cannot create unstructured map", zap.Error(err))
continue
}
job := &v1alpha1.FlinkJob{}
err = runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredMap, job)
if err != nil {
pkg.Logger.Error("cannot convert unstructured to structured", zap.Error(err))
pkg.Logger.Error("[crd] [watch]cannot convert unstructured to structured", zap.Error(err))
continue
}
if job.Namespace != namespace {
continue
}