diff --git a/Makefile b/Makefile index 72195ca3..065981c8 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/cmd/porchctl/run/run.go b/cmd/porchctl/run/run.go index 7b2299e9..9a97fbe8 100644 --- a/cmd/porchctl/run/run.go +++ b/cmd/porchctl/run/run.go @@ -213,6 +213,7 @@ func hideFlags(cmd *cobra.Command) { "password", "token", "username", + "request-timeout", } for _, f := range flags { _ = cmd.PersistentFlags().MarkHidden(f) diff --git a/deployments/porch/3-porch-server.yaml b/deployments/porch/3-porch-server.yaml index 4c01ac95..54a1e3dd 100644 --- a/deployments/porch/3-porch-server.yaml +++ b/deployments/porch/3-porch-server.yaml @@ -77,6 +77,7 @@ spec: - --secure-port=4443 - --repo-sync-frequency=60s - --disable-validating-admissions-policy=true + - --background-job-interval=10m --- apiVersion: v1 diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index f109ee24..97363cbe 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -81,6 +81,7 @@ type ExtraConfig struct { DefaultImagePrefix string RepoSyncFrequency time.Duration UseGitCaBundle bool + BackgroundJobInterval time.Duration } // Config defines the config for the apiserver @@ -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 { @@ -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. @@ -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 diff --git a/pkg/cmd/server/start.go b/pkg/cmd/server/start.go index 0d1b93b9..be9c8fd7 100644 --- a/pkg/cmd/server/start.go +++ b/pkg/cmd/server/start.go @@ -59,6 +59,7 @@ type PorchServerOptions struct { UseGitCaBundle bool DisableValidatingAdmissionPolicy bool MaxRequestBodySize int64 + BackgroundJobInterval time.Duration SharedInformerFactory informers.SharedInformerFactory StdOut io.Writer @@ -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 @@ -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.") diff --git a/pkg/registry/porch/background.go b/pkg/registry/porch/background.go index 688e9280..c0d9f030 100644 --- a/pkg/registry/porch/background.go +++ b/pkg/registry/porch/background.go @@ -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 ( @@ -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 @@ -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: