Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 2 additions & 23 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,25 +487,7 @@ func main() {
monitor := reservations.NewMonitor(multiclusterClient)
metrics.Registry.MustRegister(&monitor)
commitmentsConfig := conf.GetConfigOrDie[commitments.Config]()
commitmentsDefaults := commitments.DefaultConfig()
if commitmentsConfig.RequeueIntervalActive == 0 {
commitmentsConfig.RequeueIntervalActive = commitmentsDefaults.RequeueIntervalActive
}
if commitmentsConfig.RequeueIntervalRetry == 0 {
commitmentsConfig.RequeueIntervalRetry = commitmentsDefaults.RequeueIntervalRetry
}
if commitmentsConfig.PipelineDefault == "" {
commitmentsConfig.PipelineDefault = commitmentsDefaults.PipelineDefault
}
if commitmentsConfig.SchedulerURL == "" {
commitmentsConfig.SchedulerURL = commitmentsDefaults.SchedulerURL
}
if commitmentsConfig.ChangeAPIWatchReservationsTimeout == 0 {
commitmentsConfig.ChangeAPIWatchReservationsTimeout = commitmentsDefaults.ChangeAPIWatchReservationsTimeout
}
if commitmentsConfig.ChangeAPIWatchReservationsPollInterval == 0 {
commitmentsConfig.ChangeAPIWatchReservationsPollInterval = commitmentsDefaults.ChangeAPIWatchReservationsPollInterval
}
commitmentsConfig.ApplyDefaults()

if err := (&commitments.CommitmentReservationController{
Client: multiclusterClient,
Expand Down Expand Up @@ -673,10 +655,7 @@ func main() {
must.Succeed(metrics.Registry.Register(syncerMonitor))
syncer := commitments.NewSyncer(multiclusterClient, syncerMonitor)
syncerConfig := conf.GetConfigOrDie[commitments.SyncerConfig]()
syncerDefaults := commitments.DefaultSyncerConfig()
if syncerConfig.SyncInterval == 0 {
syncerConfig.SyncInterval = syncerDefaults.SyncInterval
}
syncerConfig.ApplyDefaults()
if err := (&task.Runner{
Client: multiclusterClient,
Interval: syncerConfig.SyncInterval,
Expand Down
25 changes: 25 additions & 0 deletions internal/scheduling/reservations/commitments/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ type Config struct {
EnableReportCapacityAPI bool `json:"committedResourceEnableReportCapacityAPI"`
}

// ApplyDefaults fills in any unset values with defaults.
func (c *Config) ApplyDefaults() {
defaults := DefaultConfig()
if c.RequeueIntervalActive == 0 {
c.RequeueIntervalActive = defaults.RequeueIntervalActive
}
if c.RequeueIntervalRetry == 0 {
c.RequeueIntervalRetry = defaults.RequeueIntervalRetry
}
if c.PipelineDefault == "" {
c.PipelineDefault = defaults.PipelineDefault
}
if c.SchedulerURL == "" {
c.SchedulerURL = defaults.SchedulerURL
}
if c.ChangeAPIWatchReservationsTimeout == 0 {
c.ChangeAPIWatchReservationsTimeout = defaults.ChangeAPIWatchReservationsTimeout
}
if c.ChangeAPIWatchReservationsPollInterval == 0 {
c.ChangeAPIWatchReservationsPollInterval = defaults.ChangeAPIWatchReservationsPollInterval
}
// Note: EnableChangeCommitmentsAPI, EnableReportUsageAPI, EnableReportCapacityAPI
// are booleans where false is a valid value, so we don't apply defaults for them
}

func DefaultConfig() Config {
return Config{
RequeueIntervalActive: 5 * time.Minute,
Expand Down
14 changes: 13 additions & 1 deletion internal/scheduling/reservations/commitments/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,24 @@ func DefaultSyncerConfig() SyncerConfig {
}
}

// ApplyDefaults fills in any unset values with defaults.
func (c *SyncerConfig) ApplyDefaults() {
defaults := DefaultSyncerConfig()
if c.SyncInterval == 0 {
c.SyncInterval = defaults.SyncInterval
}
// Note: KeystoneSecretRef and SSOSecretRef are not defaulted as they require explicit configuration
}

type Syncer struct {
// Client to fetch commitments from Limes
CommitmentsClient
// Kubernetes client for CRD operations
client.Client
// Monitor for metrics
monitor *SyncerMonitor
// SyncInterval is stored for logging purposes (actual interval managed by task.Runner)
syncInterval time.Duration
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

func NewSyncer(k8sClient client.Client, monitor *SyncerMonitor) *Syncer {
Expand All @@ -54,6 +65,7 @@ func NewSyncer(k8sClient client.Client, monitor *SyncerMonitor) *Syncer {
}

func (s *Syncer) Init(ctx context.Context, config SyncerConfig) error {
s.syncInterval = config.SyncInterval
if err := s.CommitmentsClient.Init(ctx, s.Client, config); err != nil {
return err
}
Expand Down Expand Up @@ -191,7 +203,7 @@ func (s *Syncer) SyncReservations(ctx context.Context) error {
ctx = WithNewGlobalRequestID(ctx)
logger := LoggerFromContext(ctx).WithValues("component", "syncer", "runID", runID)

logger.Info("starting commitment sync with sync interval", "interval", DefaultSyncerConfig().SyncInterval)
logger.Info("starting commitment sync", "syncInterval", s.syncInterval)

// Record sync run
if s.monitor != nil {
Expand Down
Loading