32 lines
745 B
Go
32 lines
745 B
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
schedulev1 "github.com/baschno/tdset-operator/api/v1"
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
"sigs.k8s.io/controller-runtime/pkg/log"
|
|
)
|
|
|
|
func (r *TDSetReconciler) GetExpectedReplica(ctx context.Context, req ctrl.Request, tdSet *schedulev1.TDSet) (int32, error) {
|
|
|
|
log := log.FromContext(ctx)
|
|
|
|
if len(tdSet.Spec.SchedulingConfig) != 0 {
|
|
now := time.Now()
|
|
hour := now.Hour()
|
|
|
|
log.Info("Current server", hour, "time", now)
|
|
|
|
for _, config := range tdSet.Spec.SchedulingConfig {
|
|
if hour >= config.StartTime && hour < config.EndTime {
|
|
return int32(config.Replicas), nil
|
|
}
|
|
}
|
|
|
|
}
|
|
log.Info("Default replicas is not set. Using 1 replica")
|
|
return tdSet.Spec.DefaultReplicas, nil
|
|
}
|