Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requeue service objects if pods not created yet #282

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"os"
"time"

scannerreports "kubeops.dev/scanner/apis/reports"
scannerreportsapi "kubeops.dev/scanner/apis/reports/v1alpha1"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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: ""},
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions pkg/graph/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
Expand All @@ -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)
}
Expand Down
Loading