Skip to content

Commit

Permalink
Merge pull request nephio-project#134 from Nordix/background-poll-int…
Browse files Browse the repository at this point in the history
…erval

Fix hardcoded background job periodic poll interval
  • Loading branch information
radoslawc authored Nov 15, 2024
2 parents 31ee5d5 + 766b576 commit d7bd755
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ run-local: porch
--kubeconfig="$(CURDIR)/deployments/local/kubeconfig" \
--cache-directory="$(CACHEDIR)" \
--function-runner 192.168.8.202:9445 \
--repo-sync-frequency=60s
--repo-sync-frequency=10m

.PHONY: run-jaeger
run-jaeger:
Expand Down
1 change: 1 addition & 0 deletions cmd/porchctl/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func hideFlags(cmd *cobra.Command) {
"password",
"token",
"username",
"request-timeout",
}
for _, f := range flags {
_ = cmd.PersistentFlags().MarkHidden(f)
Expand Down
2 changes: 1 addition & 1 deletion deployments/porch/3-porch-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ spec:
- --cache-directory=/cache
- --cert-dir=/tmp/certs
- --secure-port=4443
- --repo-sync-frequency=60s
- --repo-sync-frequency=10m
- --disable-validating-admissions-policy=true

---
Expand Down
11 changes: 7 additions & 4 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ type Config struct {

// PorchServer contains state for a Kubernetes cluster master/api server.
type PorchServer struct {
GenericAPIServer *genericapiserver.GenericAPIServer
coreClient client.WithWatch
cache cache.Cache
GenericAPIServer *genericapiserver.GenericAPIServer
coreClient client.WithWatch
cache cache.Cache
PeriodicRepoSyncFrequency time.Duration
}

type completedConfig struct {
Expand Down Expand Up @@ -267,6 +268,8 @@ func (c completedConfig) New() (*PorchServer, error) {
GenericAPIServer: genericServer,
coreClient: coreClient,
cache: memoryCache,
// Set background job periodic frequency the same as repo sync frequency.
PeriodicRepoSyncFrequency: c.ExtraConfig.RepoSyncFrequency,
}

// Install the groups.
Expand All @@ -278,7 +281,7 @@ func (c completedConfig) New() (*PorchServer, error) {
}

func (s *PorchServer) Run(ctx context.Context) error {
porch.RunBackground(ctx, s.coreClient, s.cache)
porch.RunBackground(ctx, s.coreClient, s.cache, s.PeriodicRepoSyncFrequency)

// TODO: Reconsider if the existence of CERT_STORAGE_DIR was a good inidcator for webhook setup,
// but for now we keep backward compatiblity
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,5 @@ func (o *PorchServerOptions) AddFlags(fs *pflag.FlagSet) {
fs.Int64Var(&o.MaxRequestBodySize, "max-request-body-size", 6*1024*1024, "Maximum size of the request body in bytes.")
fs.BoolVar(&o.UseGitCaBundle, "use-git-cabundle", false, "Determine whether to use a user-defined CaBundle for TLS towards git.")
fs.BoolVar(&o.DisableValidatingAdmissionPolicy, "disable-validating-admissions-policy", true, "Determine whether to (dis|en)able the Validating Admission Policy, which requires k8s version >= v1.30")
fs.DurationVar(&o.RepoSyncFrequency, "repo-sync-frequency", 60*time.Second, "Frequency in seconds at which registered repositories will be synced.")
fs.DurationVar(&o.RepoSyncFrequency, "repo-sync-frequency", 10*time.Minute, "Frequency in seconds at which registered repositories will be synced and the background job repository refresh runs.")
}
9 changes: 5 additions & 4 deletions pkg/cmd/server/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
package server

import (
"testing"
"time"

porchv1alpha1 "github.com/nephio-project/porch/api/porch/v1alpha1"
"github.com/nephio-project/porch/pkg/apiserver"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime/schema"
genericoptions "k8s.io/apiserver/pkg/server/options"
"testing"
"time"
)

func TestAddFlags(t *testing.T) {
Expand All @@ -35,7 +36,7 @@ func TestAddFlags(t *testing.T) {
),
}
o.AddFlags(&pflag.FlagSet{})
if o.RepoSyncFrequency < 30*time.Second {
t.Fatalf("AddFlags(): repo-sync-frequency cannot be less that 30 seconds.")
if o.RepoSyncFrequency < 5*time.Minute {
t.Fatalf("AddFlags(): repo-sync-frequency cannot be less that 5 minutes.")
}
}
14 changes: 8 additions & 6 deletions pkg/registry/porch/background.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

func RunBackground(ctx context.Context, coreClient client.WithWatch, cache cache.Cache) {
func RunBackground(ctx context.Context, coreClient client.WithWatch, cache cache.Cache, PeriodicRepoSyncFrequency time.Duration) {
b := background{
coreClient: coreClient,
cache: cache,
coreClient: coreClient,
cache: cache,
PeriodicRepoSyncFrequency: PeriodicRepoSyncFrequency,
}
go b.run(ctx)
}

// background manages background tasks
type background struct {
coreClient client.WithWatch
cache cache.Cache
coreClient client.WithWatch
cache cache.Cache
PeriodicRepoSyncFrequency time.Duration
}

const (
Expand All @@ -65,7 +67,7 @@ func (b *background) run(ctx context.Context) {
defer reconnect.Stop()

// Start ticker
ticker := time.NewTicker(1 * time.Minute)
ticker := time.NewTicker(b.PeriodicRepoSyncFrequency)
defer ticker.Stop()

loop:
Expand Down

0 comments on commit d7bd755

Please sign in to comment.