Skip to content

Commit

Permalink
Make the background polling interval configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
kushnaidu committed Nov 8, 2024
1 parent a69870d commit a53309f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ 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=60s \
--background-job-interval=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
1 change: 1 addition & 0 deletions deployments/porch/3-porch-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ spec:
- --secure-port=4443
- --repo-sync-frequency=60s
- --disable-validating-admissions-policy=true
- --background-job-interval=10m

---
apiVersion: v1
Expand Down
17 changes: 10 additions & 7 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type ExtraConfig struct {
DefaultImagePrefix string
RepoSyncFrequency time.Duration
UseGitCaBundle bool
BackgroundJobInterval time.Duration
}

// Config defines the config for the apiserver
Expand All @@ -91,9 +92,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
BackgroundJobInterval time.Duration
}

type completedConfig struct {
Expand Down Expand Up @@ -264,9 +266,10 @@ func (c completedConfig) New() (*PorchServer, error) {
}

s := &PorchServer{
GenericAPIServer: genericServer,
coreClient: coreClient,
cache: memoryCache,
GenericAPIServer: genericServer,
coreClient: coreClient,
cache: memoryCache,
BackgroundJobInterval: c.ExtraConfig.BackgroundJobInterval,
}

// 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.BackgroundJobInterval)

// 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
4 changes: 3 additions & 1 deletion pkg/cmd/server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type PorchServerOptions struct {
UseGitCaBundle bool
DisableValidatingAdmissionPolicy bool
MaxRequestBodySize int64
BackgroundJobInterval time.Duration

SharedInformerFactory informers.SharedInformerFactory
StdOut io.Writer
Expand Down Expand Up @@ -200,6 +201,7 @@ func (o *PorchServerOptions) Config() (*apiserver.Config, error) {
FunctionRunnerAddress: o.FunctionRunnerAddress,
DefaultImagePrefix: o.DefaultImagePrefix,
UseGitCaBundle: o.UseGitCaBundle,
BackgroundJobInterval: o.BackgroundJobInterval,
},
}
return config, nil
Expand Down Expand Up @@ -241,7 +243,7 @@ func (o *PorchServerOptions) AddFlags(fs *pflag.FlagSet) {
"Under the local-debug mode the apiserver will allow all access to its resources without "+
"authorizing the requests, this flag is only intended for debugging in your workstation.")
}

fs.DurationVar(&o.BackgroundJobInterval, "background-job-interval", 10*time.Minute, "Time interval in minutes at which the background job will poll the git repository to maintain the correct state.")
fs.StringVar(&o.FunctionRunnerAddress, "function-runner", "", "Address of the function runner gRPC service.")
fs.StringVar(&o.DefaultImagePrefix, "default-image-prefix", "gcr.io/kpt-fn/", "Default prefix for unqualified function names")
fs.StringVar(&o.CacheDirectory, "cache-directory", "", "Directory where Porch server stores repository and package caches.")
Expand Down
15 changes: 9 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, backgroundJobInterval time.Duration) {
b := background{
coreClient: coreClient,
cache: cache,
coreClient: coreClient,
cache: cache,
backgroundJobInterval: backgroundJobInterval,
}
go b.run(ctx)
}

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

const (
Expand All @@ -50,6 +52,7 @@ const (
// run will run until ctx is done
func (b *background) run(ctx context.Context) {
klog.Infof("Background routine starting ...")
klog.Infof("\n\n\n\n\n------------------- Time-Interval %v -------------\n\n\n\n\n", b.backgroundJobInterval)

// Repository watch.
var events <-chan watch.Event
Expand All @@ -65,7 +68,7 @@ func (b *background) run(ctx context.Context) {
defer reconnect.Stop()

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

loop:
Expand Down

0 comments on commit a53309f

Please sign in to comment.