diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index fc8873771..ebfcd4a30 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "os" + "time" scannerreports "kubeops.dev/scanner/apis/reports" scannerreportsapi "kubeops.dev/scanner/apis/reports/v1alpha1" @@ -98,6 +99,7 @@ import ( rsapi "kmodules.xyz/resource-metadata/apis/meta/v1alpha1" uiinstall "kmodules.xyz/resource-metadata/apis/ui/install" uiapi "kmodules.xyz/resource-metadata/apis/ui/v1alpha1" + "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/manager" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" @@ -200,6 +202,7 @@ func (c completedConfig) New(ctx context.Context) (*UIServer, error) { setupLog := log.Log.WithName("setup") cfg := c.ExtraConfig.ClientConfig + syncPeriod := 1 * time.Hour mgr, err := manager.New(cfg, manager.Options{ Scheme: Scheme, Metrics: metricsserver.Options{BindAddress: ""}, @@ -210,7 +213,9 @@ func (c completedConfig) New(ctx context.Context) (*UIServer, error) { // &core.Pod{}, //}, NewClient: cu.NewClient, - // Default SyncPeriod is 10 Hours + Cache: cache.Options{ + SyncPeriod: &syncPeriod, // Default SyncPeriod is 10 Hours + }, }) if err != nil { return nil, fmt.Errorf("unable to start manager, reason: %v", err) diff --git a/pkg/graph/reconciler.go b/pkg/graph/reconciler.go index 7ad9877d0..bfb9ee92a 100644 --- a/pkg/graph/reconciler.go +++ b/pkg/graph/reconciler.go @@ -18,7 +18,9 @@ package graph import ( "context" + "time" + core "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" kmapi "kmodules.xyz/client-go/api/v1" @@ -36,6 +38,8 @@ type Reconciler struct { Scheme *runtime.Scheme } +var gvkService = core.SchemeGroupVersion.WithKind("Service") + func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { log := logger.FromContext(ctx).WithValues("name", req.NamespacedName.Name) gvk := r.R.GroupVersionKind() @@ -60,6 +64,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco // requeue (we'll need to wait for a new notification), and we can get them // on deleted requests. return reconcile.Result{}, client.IgnoreNotFound(err) + } else if gvk == gvkService && result[kmapi.EdgeLabelExposedBy].Len() == 0 { + return reconcile.Result{RequeueAfter: 2 * time.Minute}, nil } else { objGraph.Update(kmapi.NewObjectID(&obj).OID(), result) }