From 9830cb6a398465d26c89560ee33f47ce4aad6851 Mon Sep 17 00:00:00 2001 From: kishie Date: Mon, 12 Feb 2024 16:13:22 -0500 Subject: [PATCH 1/5] updates sync config to use protobuf duration type to allow for friendlier API --- charts/beskar-ostree/values.yaml | 6 +++++- internal/pkg/config/sync.go | 18 +++++++++++------- .../pkg/config/default/beskar-ostree.yaml | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/charts/beskar-ostree/values.yaml b/charts/beskar-ostree/values.yaml index 223c957..9c19d10 100644 --- a/charts/beskar-ostree/values.yaml +++ b/charts/beskar-ostree/values.yaml @@ -127,4 +127,8 @@ configData: gcs: bucket: beskar-ostree azure: - container: beskar-ostree \ No newline at end of file + container: beskar-ostree + + sync: + timeout: 3600s # 1 hour + max_worker_count: 10 \ No newline at end of file diff --git a/internal/pkg/config/sync.go b/internal/pkg/config/sync.go index 378dfac..be25c62 100644 --- a/internal/pkg/config/sync.go +++ b/internal/pkg/config/sync.go @@ -3,7 +3,11 @@ package config -import "time" +import ( + "time" + + "google.golang.org/protobuf/types/known/durationpb" +) const ( DefaultSyncTimeout = time.Hour @@ -11,19 +15,19 @@ const ( ) type SyncConfig struct { - Timeout time.Duration `yaml:"timeout"` - MaxWorkerCount int `yaml:"max_worker_count"` + Timeout durationpb.Duration `yaml:"timeout"` + MaxWorkerCount int `yaml:"max_worker_count"` } -func (sc SyncConfig) GetTimeout() time.Duration { - if sc.Timeout <= 0 { +func (sc *SyncConfig) GetTimeout() time.Duration { + if !sc.Timeout.IsValid() || sc.Timeout.GetSeconds() <= 0 { return DefaultSyncTimeout } - return sc.Timeout + return sc.Timeout.AsDuration() } -func (sc SyncConfig) GetMaxWorkerCount() int { +func (sc *SyncConfig) GetMaxWorkerCount() int { if sc.MaxWorkerCount <= 0 { return DefaultSyncMaxWorkerCount } diff --git a/internal/plugins/ostree/pkg/config/default/beskar-ostree.yaml b/internal/plugins/ostree/pkg/config/default/beskar-ostree.yaml index 0dd0160..a1f01d8 100644 --- a/internal/plugins/ostree/pkg/config/default/beskar-ostree.yaml +++ b/internal/plugins/ostree/pkg/config/default/beskar-ostree.yaml @@ -16,5 +16,5 @@ gossip: - 127.0.0.1:5102 sync: - timeout: 3600 # 1 hour + timeout: 3600s # 1 hour max_worker_count: 10 \ No newline at end of file From f9772e29dd0820a203f2972186f9cc4109197f26 Mon Sep 17 00:00:00 2001 From: Kyle Ishie Date: Mon, 12 Feb 2024 16:25:14 -0500 Subject: [PATCH 2/5] Update internal/pkg/config/sync.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- internal/pkg/config/sync.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/config/sync.go b/internal/pkg/config/sync.go index be25c62..c530795 100644 --- a/internal/pkg/config/sync.go +++ b/internal/pkg/config/sync.go @@ -15,7 +15,7 @@ const ( ) type SyncConfig struct { - Timeout durationpb.Duration `yaml:"timeout"` + Timeout *durationpb.Duration `yaml:"timeout"` MaxWorkerCount int `yaml:"max_worker_count"` } From 41246e9634ec2f2e55087e85f45f3aaa8ae00515 Mon Sep 17 00:00:00 2001 From: kishie Date: Mon, 12 Feb 2024 16:26:26 -0500 Subject: [PATCH 3/5] updates sync config to use protobuf duration type to allow for friendlier API --- internal/pkg/config/sync.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/pkg/config/sync.go b/internal/pkg/config/sync.go index c530795..ecc5e4c 100644 --- a/internal/pkg/config/sync.go +++ b/internal/pkg/config/sync.go @@ -16,10 +16,14 @@ const ( type SyncConfig struct { Timeout *durationpb.Duration `yaml:"timeout"` - MaxWorkerCount int `yaml:"max_worker_count"` + MaxWorkerCount int `yaml:"max_worker_count"` } func (sc *SyncConfig) GetTimeout() time.Duration { + if sc.Timeout == nil { + return DefaultSyncTimeout + } + if !sc.Timeout.IsValid() || sc.Timeout.GetSeconds() <= 0 { return DefaultSyncTimeout } From 627a9612e222cdb4de589cb8daa0680474ac4f2d Mon Sep 17 00:00:00 2001 From: kishie Date: Mon, 12 Feb 2024 16:33:39 -0500 Subject: [PATCH 4/5] updates sync config to use protobuf duration type to allow for friendlier API --- pkg/plugins/ostree/api/v1/api.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/plugins/ostree/api/v1/api.go b/pkg/plugins/ostree/api/v1/api.go index edfc237..fc3c41f 100644 --- a/pkg/plugins/ostree/api/v1/api.go +++ b/pkg/plugins/ostree/api/v1/api.go @@ -6,7 +6,8 @@ package apiv1 import ( "context" "regexp" - "time" + + "google.golang.org/protobuf/types/known/durationpb" ) const ( @@ -64,8 +65,8 @@ type OSTreeRepositorySyncRequest struct { // Depth - The depth of the mirror. Defaults is 0, -1 means infinite. Depth int `json:"depth"` - // Timeout - The timeout for the sync in seconds. Default is 20 minutes. - Timeout time.Duration `json:"timeout"` + // Timeout - The timeout for the sync in seconds. Default is 1 hour. + Timeout durationpb.Duration `json:"timeout"` } // Mirror sync status. From bd1fc71d9d9fb02e7d168b856fb91ccee690aa2b Mon Sep 17 00:00:00 2001 From: kishie Date: Mon, 12 Feb 2024 16:51:07 -0500 Subject: [PATCH 5/5] updates sync config to use protobuf duration type to allow for friendlier API --- internal/plugins/ostree/api.go | 4 ++-- internal/plugins/ostree/pkg/ostreerepository/api.go | 2 +- pkg/plugins/ostree/api/v1/api.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/plugins/ostree/api.go b/internal/plugins/ostree/api.go index 2e99c00..bb4e6f7 100644 --- a/internal/plugins/ostree/api.go +++ b/internal/plugins/ostree/api.go @@ -72,8 +72,8 @@ func (p *Plugin) SyncRepository(ctx context.Context, repository string, properti return err } - if properties.Timeout <= 0 { - properties.Timeout = p.beskarOSTreeConfig.Sync.GetTimeout() + if properties.Timeout == nil || !properties.Timeout.IsValid() || properties.Timeout.GetSeconds() <= 0 { + properties.Timeout = p.beskarOSTreeConfig.Sync.Timeout } return p.repositoryManager.Get(ctx, repository).SyncRepository(ctx, properties) diff --git a/internal/plugins/ostree/pkg/ostreerepository/api.go b/internal/plugins/ostree/pkg/ostreerepository/api.go index 0484b06..7dddda3 100644 --- a/internal/plugins/ostree/pkg/ostreerepository/api.go +++ b/internal/plugins/ostree/pkg/ostreerepository/api.go @@ -273,7 +273,7 @@ func (h *Handler) SyncRepository(_ context.Context, properties *apiv1.OSTreeRepo h.clearState() }() - ctx, cancel := context.WithTimeout(context.Background(), properties.Timeout) + ctx, cancel := context.WithTimeout(context.Background(), properties.Timeout.AsDuration()) defer cancel() err = h.BeginLocalRepoTransaction(ctx, func(ctx context.Context, repo *libostree.Repo) (commit bool, transactionFnErr error) { diff --git a/pkg/plugins/ostree/api/v1/api.go b/pkg/plugins/ostree/api/v1/api.go index fc3c41f..2b32b88 100644 --- a/pkg/plugins/ostree/api/v1/api.go +++ b/pkg/plugins/ostree/api/v1/api.go @@ -66,7 +66,7 @@ type OSTreeRepositorySyncRequest struct { Depth int `json:"depth"` // Timeout - The timeout for the sync in seconds. Default is 1 hour. - Timeout durationpb.Duration `json:"timeout"` + Timeout *durationpb.Duration `json:"timeout"` } // Mirror sync status.