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

Change Sync Config Duration Type #42

Merged
merged 5 commits into from
Feb 23, 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
6 changes: 5 additions & 1 deletion charts/beskar-ostree/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,8 @@ configData:
gcs:
bucket: beskar-ostree
azure:
container: beskar-ostree
container: beskar-ostree

sync:
timeout: 3600s # 1 hour
max_worker_count: 10
22 changes: 15 additions & 7 deletions internal/pkg/config/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,35 @@

package config

import "time"
import (
"time"

"google.golang.org/protobuf/types/known/durationpb"
)

const (
DefaultSyncTimeout = time.Hour
DefaultSyncMaxWorkerCount = 10
)

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 == nil {
return DefaultSyncTimeout
}

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
}
Expand Down
4 changes: 2 additions & 2 deletions internal/plugins/ostree/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ gossip:
- 127.0.0.1:5102

sync:
timeout: 3600 # 1 hour
timeout: 3600s # 1 hour
max_worker_count: 10
2 changes: 1 addition & 1 deletion internal/plugins/ostree/pkg/ostreerepository/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions pkg/plugins/ostree/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ package apiv1
import (
"context"
"regexp"
"time"

"google.golang.org/protobuf/types/known/durationpb"
)

const (
Expand Down Expand Up @@ -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.
Expand Down
Loading