|
1 | 1 | /* |
2 | | -Copyright 2018 The Volcano Authors. |
| 2 | +Copyright 2018 The Kubernetes Authors. |
| 3 | +Copyright 2018-2025 The Volcano Authors. |
3 | 4 |
|
4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 6 | you may not use this file except in compliance with the License. |
@@ -412,3 +413,144 @@ type DependsOn struct { |
412 | 413 | // +optional |
413 | 414 | Iteration Iteration `json:"iteration,omitempty" protobuf:"bytes,2,opt,name=iteration"` |
414 | 415 | } |
| 416 | + |
| 417 | +// ConcurrencyPolicy describes how the job will be handled. |
| 418 | +// Only one of the following concurrent policies may be specified. |
| 419 | +// If none of the following policies is specified, the default one |
| 420 | +// is AllowConcurrent. |
| 421 | +type ConcurrencyPolicy string |
| 422 | + |
| 423 | +const ( |
| 424 | + // AllowConcurrent allows CronJobs to run concurrently. |
| 425 | + AllowConcurrent ConcurrencyPolicy = "Allow" |
| 426 | + |
| 427 | + // ForbidConcurrent forbids concurrent runs, skipping next run if previous |
| 428 | + // hasn't finished yet. |
| 429 | + ForbidConcurrent ConcurrencyPolicy = "Forbid" |
| 430 | + |
| 431 | + // ReplaceConcurrent cancels currently running job and replaces it with a new one. |
| 432 | + ReplaceConcurrent ConcurrencyPolicy = "Replace" |
| 433 | +) |
| 434 | + |
| 435 | +// JobTemplateSpec describes the data a Job should have when created from a template |
| 436 | +type JobTemplateSpec struct { |
| 437 | + // Standard object's metadata of the jobs created from this template. |
| 438 | + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata |
| 439 | + // +optional |
| 440 | + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 441 | + |
| 442 | + // Specification of the desired behavior of the job. |
| 443 | + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status |
| 444 | + // +optional |
| 445 | + Spec JobSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` |
| 446 | +} |
| 447 | + |
| 448 | +// CronJobSpec defines the desired state of Cronjob |
| 449 | +type CronJobSpec struct { |
| 450 | + // The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. |
| 451 | + Schedule string `json:"schedule" protobuf:"bytes,1,opt,name=schedule"` |
| 452 | + |
| 453 | + // The time zone name for the given schedule, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. |
| 454 | + // If not specified, this will default to the time zone of the kube-controller-manager process. |
| 455 | + // The set of valid time zone names and the time zone offset is loaded from the system-wide time zone |
| 456 | + // database by the API server during CronJob validation and the controller manager during execution. |
| 457 | + // If no system-wide time zone database can be found a bundled version of the database is used instead. |
| 458 | + // If the time zone name becomes invalid during the lifetime of a CronJob or due to a change in host |
| 459 | + // configuration, the controller will stop creating new new Jobs and will create a system event with the |
| 460 | + // reason UnknownTimeZone. |
| 461 | + // More information can be found in https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#time-zones |
| 462 | + // +optional |
| 463 | + TimeZone *string `json:"timeZone,omitempty" protobuf:"bytes,2,opt,name=timeZone"` |
| 464 | + |
| 465 | + // Optional deadline in seconds for starting the job if it misses scheduled |
| 466 | + // time for any reason. Missed jobs executions will be counted as failed ones. |
| 467 | + // +kubebuilder:validation:Minimum=0 |
| 468 | + // +optional |
| 469 | + StartingDeadlineSeconds *int64 `json:"startingDeadlineSeconds,omitempty" protobuf:"varint,3,opt,name=startingDeadlineSeconds"` |
| 470 | + |
| 471 | + // Specifies how to treat concurrent executions of a Job. |
| 472 | + // Valid values are: |
| 473 | + // - "Allow" (default): allows CronJobs to run concurrently; |
| 474 | + // - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet; |
| 475 | + // - "Replace": cancels currently running job and replaces it with a new one |
| 476 | + // +kubebuilder:default=Allow |
| 477 | + // +kubebuilder:validation:Enum=Allow;Forbid;Replace |
| 478 | + // +optional |
| 479 | + ConcurrencyPolicy ConcurrencyPolicy `json:"concurrencyPolicy,omitempty" protobuf:"bytes,4,opt,name=concurrencyPolicy,casttype=ConcurrencyPolicy"` |
| 480 | + |
| 481 | + // This flag tells the controller to suspend subsequent executions, it does |
| 482 | + // not apply to already started executions. Defaults to false. |
| 483 | + // +kubebuilder:default=false |
| 484 | + // +optional |
| 485 | + Suspend *bool `json:"suspend,omitempty" protobuf:"varint,5,opt,name=suspend"` |
| 486 | + |
| 487 | + // Specifies the job that will be created when executing a CronJob. |
| 488 | + JobTemplate JobTemplateSpec `json:"jobTemplate" protobuf:"bytes,6,opt,name=jobTemplate"` |
| 489 | + |
| 490 | + // The number of successful finished jobs to retain. |
| 491 | + // This is a pointer to distinguish between explicit zero and not specified. |
| 492 | + // Defaults to 3. |
| 493 | + // +kubebuilder:default=3 |
| 494 | + // +kubebuilder:validation:Minimum=0 |
| 495 | + // +optional |
| 496 | + SuccessfulJobsHistoryLimit *int32 `json:"successfulJobsHistoryLimit,omitempty" protobuf:"varint,7,opt,name=successfulJobsHistoryLimit"` |
| 497 | + |
| 498 | + // The number of failed finished jobs to retain. |
| 499 | + // This is a pointer to distinguish between explicit zero and not specified. |
| 500 | + // Defaults to 3. |
| 501 | + // +kubebuilder:default=1 |
| 502 | + // +kubebuilder:validation:Minimum=0 |
| 503 | + // +optional |
| 504 | + FailedJobsHistoryLimit *int32 `json:"failedJobsHistoryLimit,omitempty" protobuf:"varint,8,opt,name=failedJobsHistoryLimit"` |
| 505 | +} |
| 506 | + |
| 507 | +// CronJobStatus represents the current state of a cron job. |
| 508 | +type CronJobStatus struct { |
| 509 | + // A list of pointers to currently running jobs. |
| 510 | + // +optional |
| 511 | + // +listType=atomic |
| 512 | + Active []v1.ObjectReference `json:"active,omitempty" protobuf:"bytes,1,rep,name=active"` |
| 513 | + |
| 514 | + // Information when was the last time the job was successfully scheduled. |
| 515 | + // +optional |
| 516 | + LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty" protobuf:"bytes,2,opt,name=lastScheduleTime"` |
| 517 | + |
| 518 | + // Information when was the last time the job successfully completed. |
| 519 | + // +optional |
| 520 | + LastSuccessfulTime *metav1.Time `json:"lastSuccessfulTime,omitempty" protobuf:"bytes,3,opt,name=lastSuccessfulTime"` |
| 521 | +} |
| 522 | + |
| 523 | +// +genclient |
| 524 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 525 | +// +kubebuilder:object:root=true |
| 526 | +// +kubebuilder:resource:shortName=cronvcjob;cronvj |
| 527 | +// +kubebuilder:subresource:status |
| 528 | + |
| 529 | +// CronJob is the Schema for the cronjobs API |
| 530 | +type CronJob struct { |
| 531 | + metav1.TypeMeta `json:",inline"` |
| 532 | + // Standard object's metadata. |
| 533 | + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata |
| 534 | + // +optional |
| 535 | + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 536 | + |
| 537 | + // Specification of the desired behavior of a cron job, including the schedule. |
| 538 | + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status |
| 539 | + // +optional |
| 540 | + Spec CronJobSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` |
| 541 | + |
| 542 | + // Current status of a cron job. |
| 543 | + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status |
| 544 | + // +optional |
| 545 | + Status CronJobStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` |
| 546 | +} |
| 547 | + |
| 548 | +// +kubebuilder:object:root=true |
| 549 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 550 | + |
| 551 | +// CronJobList contains a list of Cronjob |
| 552 | +type CronJobList struct { |
| 553 | + metav1.TypeMeta `json:",inline"` |
| 554 | + metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 555 | + Items []CronJob `json:"items" protobuf:"bytes,2,rep,name=items"` |
| 556 | +} |
0 commit comments