Browse Source

lables and annotations

tags/0.0.7
Vladimir Smagin 1 month ago
parent
commit
9afb79972c
5 changed files with 24 additions and 6 deletions
  1. +1
    -1
      VERSION
  2. +1
    -1
      deploy/operator.yaml
  3. +2
    -1
      pkg/apis/blindage/v1alpha1/cronop_types.go
  4. +19
    -2
      pkg/controller/cronop/cronjob.go
  5. +1
    -1
      version/version.go

+ 1
- 1
VERSION View File

@@ -1 +1 @@
0.0.6
0.0.7

+ 1
- 1
deploy/operator.yaml View File

@@ -15,7 +15,7 @@ spec:
serviceAccountName: cron-operator
containers:
- name: cron-operator
image: iam21h/cron-operator:0.0.5.1
image: iam21h/cron-operator:0.0.7
command:
- cron-operator
imagePullPolicy: Always


+ 2
- 1
pkg/apis/blindage/v1alpha1/cronop_types.go View File

@@ -30,7 +30,8 @@ type CronTask struct {
}

type CronOpSpec struct {
Image string `json:"image,omitempty"` // default busybox
Annotations map[string]string `json:"annotations,omitempty"` // annotations for pod
Image string `json:"image,omitempty"` // default busybox

RestartPolicy *corev1.RestartPolicy `json:"restartPolicy,omitempty"` // default OnFailure, global
ConcurrencyPolicy *batchv1beta1.ConcurrencyPolicy `json:"concurrencyPolicy,omitempty"` // default Allow, global


+ 19
- 2
pkg/controller/cronop/cronjob.go View File

@@ -9,9 +9,19 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func mergeMaps(itermaps ...map[string]string) map[string]string {
result := make(map[string]string)
for _, rv := range itermaps {
for k, v := range rv {
result[k] = v
}
}
return result
}

// generate one cronjob for specific task
func generateCronjob(reqLogger logr.Logger, cr *blindagev1alpha1.CronOp, jobSpec blindagev1alpha1.CronTask) batchv1beta1.CronJob {
labels := map[string]string{
baseLabels := map[string]string{
"operator": "cron-operator",
"cronop": cr.Name,
}
@@ -26,11 +36,18 @@ func generateCronjob(reqLogger logr.Logger, cr *blindagev1alpha1.CronOp, jobSpec
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name + "-" + jobSpec.Name,
Namespace: cr.Namespace,
Labels: labels,
Labels: mergeMaps(baseLabels, cr.ObjectMeta.Labels),
},
Spec: batchv1beta1.CronJobSpec{},
}

// job and pod needs labels too
cronjob.Spec.JobTemplate.ObjectMeta.Labels = mergeMaps(baseLabels, cr.ObjectMeta.Labels)
cronjob.Spec.JobTemplate.Spec.Template.ObjectMeta.Labels = mergeMaps(baseLabels, cr.ObjectMeta.Labels)

// set annotation for template
cronjob.Spec.JobTemplate.Spec.Template.ObjectMeta.Annotations = cr.Spec.Annotations

cronjob.Spec.Schedule = "0 * * * *"
if jobSpec.Schedule != "" {
cronjob.Spec.Schedule = jobSpec.Schedule


+ 1
- 1
version/version.go View File

@@ -1,5 +1,5 @@
package version

var (
Version = "0.0.6"
Version = "0.0.7"
)

Loading…
Cancel
Save