Skip to content
......@@ -31,8 +31,8 @@ func (in *Container) DeepCopyInto(out *Container) {
*out = new(ContainerSpec)
(*in).DeepCopyInto(*out)
}
if in.ConfigSpec != nil {
in, out := &in.ConfigSpec, &out.ConfigSpec
if in.SettingsSpec != nil {
in, out := &in.SettingsSpec, &out.SettingsSpec
*out = (*in).DeepCopy()
}
}
......@@ -50,6 +50,11 @@ func (in *Container) DeepCopy() *Container {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ContainerSpec) DeepCopyInto(out *ContainerSpec) {
*out = *in
if in.Command != nil {
in, out := &in.Command, &out.Command
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.Args != nil {
in, out := &in.Args, &out.Args
*out = make([]string, len(*in))
......
/*
Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.gnu.org/licenses/agpl-3.0.html
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cronjob
import (
"errors"
batchv1beta1 "k8s.io/api/batch/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.libre.sh/interfaces"
"k8s.libre.sh/meta"
"k8s.libre.sh/objects/job"
)
// +kubebuilder:object:generate=true
type CronJob struct {
// Standard object metadata.
// +optional
*meta.ObjectMeta `json:"meta,omitempty"`
// Specification of the desired behavior of the Job.
// +optional
*CronJobSpec `json:",inline"`
}
// +kubebuilder:object:generate=true
type CronJobSpec struct {
// The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
Schedule string `json:"schedule" protobuf:"bytes,1,opt,name=schedule"`
// Optional deadline in seconds for starting the job if it misses scheduled
// time for any reason. Missed jobs executions will be counted as failed ones.
// +optional
StartingDeadlineSeconds *int64 `json:"startingDeadlineSeconds,omitempty" protobuf:"varint,2,opt,name=startingDeadlineSeconds"`
// Specifies how to treat concurrent executions of a Job.
// Valid values are:
// - "Allow" (default): allows CronJobs to run concurrently;
// - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet;
// - "Replace": cancels currently running job and replaces it with a new one
// +optional
ConcurrencyPolicy batchv1beta1.ConcurrencyPolicy `json:"concurrencyPolicy,omitempty" protobuf:"bytes,3,opt,name=concurrencyPolicy,casttype=ConcurrencyPolicy"`
// This flag tells the controller to suspend subsequent executions, it does
// not apply to already started executions. Defaults to false.
// +optional
Suspend *bool `json:"suspend,omitempty" protobuf:"varint,4,opt,name=suspend"`
// The number of successful finished jobs to retain.
// This is a pointer to distinguish between explicit zero and not specified.
// Defaults to 3.
// +optional
SuccessfulJobsHistoryLimit *int32 `json:"successfulJobsHistoryLimit,omitempty" protobuf:"varint,6,opt,name=successfulJobsHistoryLimit"`
// The number of failed finished jobs to retain.
// This is a pointer to distinguish between explicit zero and not specified.
// Defaults to 1.
// +optional
FailedJobsHistoryLimit *int32 `json:"failedJobsHistoryLimit,omitempty" protobuf:"varint,7,opt,name=failedJobsHistoryLimit"`
// Job describes the pod that will be created.
*job.Job `json:",inline"`
}
func (spec *CronJobSpec) GetSuccessfulJobsHistoryLimit() *int32 {
return spec.SuccessfulJobsHistoryLimit
}
func (spec *CronJobSpec) GetFailedJobsHistoryLimit() *int32 {
return spec.FailedJobsHistoryLimit
}
func (spec *CronJobSpec) GetConcurrencyPolicy() batchv1beta1.ConcurrencyPolicy {
return spec.ConcurrencyPolicy
}
func (spec *CronJobSpec) GetStartingDeadlineSeconds() *int64 {
return spec.StartingDeadlineSeconds
}
func (spec *CronJobSpec) GetSchedule() string {
return spec.Schedule
}
func (o *CronJob) GetObject() interfaces.Object {
obj := &batchv1beta1.CronJob{
TypeMeta: metav1.TypeMeta{
Kind: "CronJob",
APIVersion: "batch/v1beta1",
},
}
obj.SetName(o.GetName())
obj.SetNamespace(o.GetNamespace())
return obj
}
func (o *CronJob) Mutate(obj interfaces.Object) error {
cron, ok := obj.(*batchv1beta1.CronJob)
if !ok {
return errors.New("object is not a CronJob")
}
// TODO TO FIX merge meta
o.Pod.ObjectMeta = o.ObjectMeta
err := MutateCronJob(o, cron)
if err != nil {
return err
}
err = meta.MutateMeta(o.ObjectMeta, obj)
if err != nil {
return err
}
cron.Spec.JobTemplate.ObjectMeta.Name = cron.ObjectMeta.Name
cron.Spec.JobTemplate.ObjectMeta.Labels = o.ObjectMeta.Labels
return nil
}
func (o *CronJob) Init() {
if o.ObjectMeta == nil {
o.ObjectMeta = &meta.ObjectMeta{}
}
if o.ObjectMeta.Labels == nil {
o.ObjectMeta.Labels = make(map[string]string)
}
if o.CronJobSpec == nil {
o.CronJobSpec = &CronJobSpec{}
}
if o.Job == nil {
o.Job = &job.Job{}
}
o.Job.Init()
}
func (o *CronJob) GetObjectKind() string { return "CronJob" }
func (o *CronJob) GetObjectGroup() string { return "batchv1beta1" }
/*
Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.gnu.org/licenses/agpl-3.0.html
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cronjob
import (
batchv1beta1 "k8s.io/api/batch/v1beta1"
"k8s.libre.sh/objects/job"
)
type Mutate interface {
GetSuccessfulJobsHistoryLimit() *int32
GetConcurrencyPolicy() batchv1beta1.ConcurrencyPolicy
GetStartingDeadlineSeconds() *int64
GetSchedule() string
GetFailedJobsHistoryLimit() *int32
job.Mutate
}
func MutateCronJob(i Mutate, obj *batchv1beta1.CronJob) error {
obj.Spec.SuccessfulJobsHistoryLimit = i.GetSuccessfulJobsHistoryLimit()
obj.Spec.ConcurrencyPolicy = i.GetConcurrencyPolicy()
obj.Spec.StartingDeadlineSeconds = i.GetStartingDeadlineSeconds()
obj.Spec.FailedJobsHistoryLimit = i.GetFailedJobsHistoryLimit()
obj.Spec.Schedule = i.GetSchedule()
err := job.MutateJob(i, &obj.Spec.JobTemplate.Spec)
if err != nil {
return err
}
return nil
}
This diff is collapsed.
This diff is collapsed.
......@@ -58,9 +58,9 @@ func (in *DeploymentSpec) DeepCopyInto(out *DeploymentSpec) {
**out = **in
}
in.Strategy.DeepCopyInto(&out.Strategy)
if in.PodSpec != nil {
in, out := &in.PodSpec, &out.PodSpec
*out = new(pod.PodSpec)
if in.Pod != nil {
in, out := &in.Pod, &out.Pod
*out = new(pod.Pod)
(*in).DeepCopyInto(*out)
}
}
......
......@@ -31,6 +31,16 @@ type Ingress struct {
*networkingv1beta1.IngressSpec `json:",inline"`
}
func (obj *Ingress) Init() {
if obj.ObjectMeta == nil {
obj.ObjectMeta = &meta.ObjectMeta{}
}
if obj.ObjectMeta.Labels == nil {
obj.ObjectMeta.Labels = make(map[string]string)
}
}
func (r *Ingress) GetIngressRules() []networkingv1beta1.IngressRule { return r.Rules }
func (r *Ingress) GetIngressTLS() []networkingv1beta1.IngressTLS { return r.TLS }
func (r *Ingress) GetIngressClassName() *string { return r.IngressClassName }
......@@ -45,3 +55,6 @@ func (o *Ingress) Mutate(obj interfaces.Object) error {
func (o *Ingress) GetObject() interfaces.Object {
return &networkingv1beta1.Ingress{}
}
func (o *Ingress) GetObjectKind() string { return "Ingress" }
func (o *Ingress) GetObjectGroup() string { return "network" }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.