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

Support schedule configuration like CronJob #30

Closed
tjun opened this issue Jul 21, 2021 · 5 comments · Fixed by #78
Closed

Support schedule configuration like CronJob #30

tjun opened this issue Jul 21, 2021 · 5 comments · Fixed by #78
Labels
enhancement New feature or request

Comments

@tjun
Copy link
Member

tjun commented Jul 21, 2021

What you want to add

Add schedule node count schedule configuration like this

spec:
  scaleTargetRef:
    projectId: your-gcp-project-id
    instanceId: your-spanner-instance-id
  minNodes: 1
  maxNodes: 4
  cron:
    schedule: "*/1 * * * *"
    period: 1H
    minNodes: 4

Why this is needed

We sometimes want to increase node num before starting a batch job.

@tjun tjun added the enhancement New feature or request label Jul 21, 2021
@apstndb
Copy link
Contributor

apstndb commented Aug 27, 2021

Possible requirements:

  • Supports multiple CRON schedules per SpannerAutoscaler resource.
  • Supports on-demand constraints for on-demand tasks beside CRON schedules.
    • It should be configured without modifying SpannerAutoscaler resource.

@apstndb
Copy link
Contributor

apstndb commented Sep 1, 2021

Precedents:

@apstndb
Copy link
Contributor

apstndb commented Sep 22, 2021

Currently, SpannerAutoscaler CRD has two responsibility.

  • Scale
    • scale compute capacity of Cloud Spanner instance from concrete value(PU/node count)
    • analogous to ReplicaSet/Deployment
  • Autoscaler
    • compute and modify current desired scale within the scale config
    • analogous to HorizontalPodAutoscaler

We want to add a new functionality.

  • Schedule
    • individual schedule
      • time spec
        • fixed(start time/end time or duration)
        • recurring(cron with duration)
        • (We want TZ support)
      • scale constraints within the period
        • If their periods are overlapped, we can use most strong one for the period(e.g. use max resource of them)
    • analogous to Schedule of d-kuro/scheduled-pod-autoscaler

Considerations

  • Should each Schedule be separated from Autoscaler?
    • If Schedule is separated CRD, non IoC-style on-demand schedules may be possible.
      • Should we do garbage collection?
      • end time or duration deterministic is not deterministic so on-demand "done" is needed.
        • delete the resource?
        • patch some field?
          • end time or some flag
  • How to link the Autoscaler and the Schedule?
    • Use another CRD
    • Doesn't use another CRD(Schedule directly references the Autoscaler)
      • Current scale config is not represented as concrete resource
        • Use status?
      • Autoscaler controller will be complicated

(For reference) Relationships in d-kuro/scheduled-pod-autoscaler

  • Schedule
    • .spec.scaleTargetRef references to ScheduledPodAutoscaler
  • ScheduledPodAutoscaler
    • .spec.horizontalPodAutoscalerSpec.scaleTargetRef references to HorizontalPodAutoscaler
  • HorizontalPodAutoscaler
    • It is generated and updated by the autoscaler
  • Deployment/ReplicaSet
    • It is not touched by the autoscaler

@apstndb
Copy link
Contributor

apstndb commented Sep 27, 2021

Draft schema

Written in CUE to express disjunctions.

import "time"

#ScheduledSpannerAutoscaler: {
	apiVersion: "spanner.mercari.com/v1alpha1"
	kind:       "ScheduledSpannerAutoscaler"
	metadata: {
		name:      string
		namespace: string
	}
	spec: {
		// SpannerAutoscaler without {min,max}{Nodes,ProcessingUnits}
		spannerAutoscalerTemplate: {
			scaleTargetRef: {
				projectId:  string
				instanceId: string
			}
			{
				serviceAccountSecretRef: {
					namespace: string
					name:      string
					key:       string
				}
			} | {
				impersonateConfig: targetServiceAccount: string
			}
			maxScaleDownNodes: int
			targetCPUUtilization: {
				highPriority: int
			}
		}
		defaultScaleConfig: #ScaleConfig
	}
}

#Schedule: {
	apiVersion: "spanner.mercari.com/v1alpha1"
	kind:       "Schedule"
	metadata: {
		name:      string
		namespace: string
	}
	spec: {
		// References in same namespace
		ScheduledSpannerAutoscalerRef: {
			name: string
		}
		scaleConfig: #ScaleConfig
		{
			manual: {
				// RFC3339
				startTime: time.Time
				// RFC3339
				endTime?: time.Time
			}
		} | {
			cron: {
				// in github.com/robfig/cron compatible format
				spec:      string
				duration:  time.Duration
				timeZone?: string | *"UTC"
			}
		}
	}
}

#ScaleConfig: {
	// Only supports processing units
	min: int
	max: int
}

@apstndb
Copy link
Contributor

apstndb commented Oct 6, 2021

Missing use case

Schedule last day of month

  1. Some CRON implementation have L(last) notation. robfig/cron doesn't yet support it.
    Run Cron last Monday of month robfig/cron#319
  2. First day of month with advanced offset can be last day of month.
    Example) 2022-01-01T00:30:00+10:00 = 2021-12-31T23:30:00+09:00

IMHO, 2 is realistic approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants