Skip to content

Commit

Permalink
Honor config-file options (#85)
Browse files Browse the repository at this point in the history
* Improve logging
* Remove default CLI argument values
If the default values are set, then the config file does not
oeverride them. Because there is no way to know whether the flag value
was provided via command-line by user, or it was taken from the default.
  • Loading branch information
rustycl0ck authored Jun 3, 2022
1 parent 6a6fed0 commit 2cbbddc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 10 additions & 6 deletions controllers/spannerautoscaler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (r *SpannerAutoscalerReconciler) Reconcile(ctx context.Context, req ctrlrec
return ctrlreconcile.Result{}, err
}

log.Info("replaced syncer", "namespaced name", sa)
log.Info("replaced syncer", "namespacedName", sa)
return ctrlreconcile.Result{}, nil
}

Expand Down Expand Up @@ -482,22 +482,26 @@ func (r *SpannerAutoscalerReconciler) needUpdateProcessingUnits(log logr.Logger,

switch {
case desiredProcessingUnits == currentProcessingUnits:
log.Info("no need to scale", "current-processing-units", currentProcessingUnits, "current-cpu", sa.Status.CurrentHighPriorityCPUUtilization)
log.Info("no need to scale", "currentPU", currentProcessingUnits, "currentCPU", sa.Status.CurrentHighPriorityCPUUtilization)
return false

case desiredProcessingUnits > currentProcessingUnits && r.clock.Now().Before(sa.Status.LastScaleTime.Time.Add(10*time.Second)):
log.Info("too short to scale up since last scale-up event",
"time gap", now.Sub(sa.Status.LastScaleTime.Time),
"timeGap", now.Sub(sa.Status.LastScaleTime.Time).String(),
"now", now.String(),
"last scale time", sa.Status.LastScaleTime,
"lastScaleTime", sa.Status.LastScaleTime,
"currentPU", currentProcessingUnits,
"desiredPU", desiredProcessingUnits,
)
return false

case desiredProcessingUnits < currentProcessingUnits && r.clock.Now().Before(sa.Status.LastScaleTime.Time.Add(r.scaleDownInterval)):
log.Info("too short to scale down since last scale-up event",
"time gap", now.Sub(sa.Status.LastScaleTime.Time),
"timeGap", now.Sub(sa.Status.LastScaleTime.Time).String(),
"now", now.String(),
"last scale time", sa.Status.LastScaleTime,
"lastScaleTime", sa.Status.LastScaleTime,
"currentPU", currentProcessingUnits,
"desiredPU", desiredProcessingUnits,
)
return false

Expand Down
18 changes: 7 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,19 @@ func init() {
}

var (
metricsAddr = flag.String("metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
probeAddr = flag.String("health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
metricsAddr = flag.String("metrics-bind-address", "", "The address the metric endpoint binds to.")
probeAddr = flag.String("health-probe-bind-address", "", "The address the probe endpoint binds to.")
enableLeaderElection = flag.Bool("leader-elect", false, "Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
leaderElectionID = flag.String("leader-elect-id", "", "Lease name for leader election.")
scaleDownInterval = flag.Duration("scale-down-interval", 55*time.Minute, "The scale down interval.")
configFile = flag.String("config", "", "The controller will load its initial configuration from this file. "+
"Omit this flag to use the default configuration values. Command-line flags override configuration from this file.")
)

const (
exitCode = 1
leaderElectionID = "spanner-autoscaler-leader-election"
healthzEndpoint = "/healthz"
readyzEndpoint = "/readyz"
healthzName = "healthz"
readyzName = "readyz"
exitCode = 1
healthzName = "healthz"
readyzName = "readyz"
)

func main() {
Expand Down Expand Up @@ -100,11 +98,9 @@ func main() {
options := ctrlmanager.Options{
Scheme: scheme,
LeaderElection: *enableLeaderElection,
LeaderElectionID: leaderElectionID,
LeaderElectionID: *leaderElectionID,
MetricsBindAddress: *metricsAddr,
HealthProbeBindAddress: *probeAddr,
ReadinessEndpointName: readyzEndpoint,
LivenessEndpointName: healthzEndpoint,

// TODO: remove this when `v1beta1` is stable and tested
// Only for development
Expand Down

0 comments on commit 2cbbddc

Please sign in to comment.