fix: resolve missing restrict resources namespace
This commit is contained in:
parent
75d0557286
commit
346f69100c
@ -2,6 +2,7 @@ package crd
|
||||
|
||||
import (
|
||||
"flink-kube-operator/internal/crd/v1alpha1"
|
||||
"os"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/client-go/dynamic"
|
||||
@ -12,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
type Crd struct {
|
||||
client dynamic.NamespaceableResourceInterface
|
||||
client dynamic.ResourceInterface
|
||||
runtimeClient client.Client
|
||||
}
|
||||
|
||||
@ -32,12 +33,12 @@ func New() *Crd {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
shema := runtime.NewScheme()
|
||||
v1alpha1.AddKnownTypes(shema)
|
||||
scheme := runtime.NewScheme()
|
||||
v1alpha1.AddKnownTypes(scheme)
|
||||
// Get FlinkJob resource interface
|
||||
flinkJobClient := dynamicClient.Resource(v1alpha1.FlinkJobGVR)
|
||||
flinkJobClient := dynamicClient.Resource(v1alpha1.FlinkJobGVR).Namespace(os.Getenv("NAMESPACE"))
|
||||
runtimeClient, err := client.New(config.GetConfigOrDie(), client.Options{
|
||||
Scheme: shema,
|
||||
Scheme: scheme,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@ -23,7 +23,6 @@ func (crd *Crd) Patch(jobUid types.UID, patchData map[string]interface{}) error
|
||||
|
||||
// Patch the status sub-resource
|
||||
unstructuredJob, err := crd.client.
|
||||
Namespace(job.GetNamespace()).
|
||||
Patch(
|
||||
context.Background(),
|
||||
job.GetName(),
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -51,5 +51,5 @@ func (job *ManagedJob) Cycle() {
|
||||
// return
|
||||
// }
|
||||
|
||||
pkg.Logger.Warn("[managed-job] [cycle] unhanded job status", zap.String("name", job.def.Name), zap.String("status", string(job.def.Status.JobStatus)))
|
||||
pkg.Logger.Warn("[managed-job] [cycle] unhandled job status", zap.String("name", job.def.Name), zap.String("status", string(job.def.Status.JobStatus)), zap.String("namespace", job.def.Namespace))
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user