From 56edfc8d8c896e58753629106ba9708f81548a1c Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Thu, 16 Mar 2023 11:18:44 +0000 Subject: [PATCH] Add annotations support. --- api/v1beta1/managedjob_types.go | 2 ++ api/v1beta1/zz_generated.deepcopy.go | 7 +++++++ charts/jobs-manager-operator/Chart.yaml | 4 ++-- .../templates/managedjob-crd.yaml | 16 ++++++++++++++++ .../jobsmanager.raczylo.com_managedjobs.yaml | 16 ++++++++++++++++ controllers/crd_scrapper.go | 19 ++++++++++++++++--- 6 files changed, 59 insertions(+), 5 deletions(-) diff --git a/api/v1beta1/managedjob_types.go b/api/v1beta1/managedjob_types.go index e01fb68..8669802 100644 --- a/api/v1beta1/managedjob_types.go +++ b/api/v1beta1/managedjob_types.go @@ -94,6 +94,8 @@ type ManagedJobParameters struct { ImagePullPolicy string `json:"imagePullPolicy,omitempty"` // +kubebuilder:validation:Optional Labels map[string]string `json:"labels,omitempty"` + // +kubebuilder:validation:Optional + Annotations map[string]string `json:"annotations,omitempty"` } // ManagedJobSpec defines the desired state of ManagedJob diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 7ab6f02..fd4a2b6 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -213,6 +213,13 @@ func (in *ManagedJobParameters) DeepCopyInto(out *ManagedJobParameters) { (*out)[key] = val } } + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManagedJobParameters. diff --git a/charts/jobs-manager-operator/Chart.yaml b/charts/jobs-manager-operator/Chart.yaml index 6f3f891..5a68004 100644 --- a/charts/jobs-manager-operator/Chart.yaml +++ b/charts/jobs-manager-operator/Chart.yaml @@ -13,12 +13,12 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.0.20 +version: 0.0.21 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "0.0.20" +appVersion: "0.0.21" keywords: - operator - jobs diff --git a/charts/jobs-manager-operator/templates/managedjob-crd.yaml b/charts/jobs-manager-operator/templates/managedjob-crd.yaml index 2ba14b6..0202f7f 100644 --- a/charts/jobs-manager-operator/templates/managedjob-crd.yaml +++ b/charts/jobs-manager-operator/templates/managedjob-crd.yaml @@ -59,6 +59,10 @@ spec: type: array compiledParams: properties: + annotations: + additionalProperties: + type: string + type: object env: items: description: EnvVar represents an environment variable @@ -2135,6 +2139,10 @@ spec: type: boolean params: properties: + annotations: + additionalProperties: + type: string + type: object env: items: description: EnvVar represents an environment variable @@ -4205,6 +4213,10 @@ spec: type: boolean params: properties: + annotations: + additionalProperties: + type: string + type: object env: items: description: EnvVar represents an environment variable present @@ -6131,6 +6143,10 @@ spec: type: array params: properties: + annotations: + additionalProperties: + type: string + type: object env: items: description: EnvVar represents an environment variable present diff --git a/config/crd/bases/jobsmanager.raczylo.com_managedjobs.yaml b/config/crd/bases/jobsmanager.raczylo.com_managedjobs.yaml index 1f8b97f..eefae17 100644 --- a/config/crd/bases/jobsmanager.raczylo.com_managedjobs.yaml +++ b/config/crd/bases/jobsmanager.raczylo.com_managedjobs.yaml @@ -59,6 +59,10 @@ spec: type: array compiledParams: properties: + annotations: + additionalProperties: + type: string + type: object env: items: description: EnvVar represents an environment variable @@ -2205,6 +2209,10 @@ spec: type: boolean params: properties: + annotations: + additionalProperties: + type: string + type: object env: items: description: EnvVar represents an environment variable @@ -4345,6 +4353,10 @@ spec: type: boolean params: properties: + annotations: + additionalProperties: + type: string + type: object env: items: description: EnvVar represents an environment variable @@ -6317,6 +6329,10 @@ spec: type: array params: properties: + annotations: + additionalProperties: + type: string + type: object env: items: description: EnvVar represents an environment variable present diff --git a/controllers/crd_scrapper.go b/controllers/crd_scrapper.go index c4e7072..630d709 100644 --- a/controllers/crd_scrapper.go +++ b/controllers/crd_scrapper.go @@ -24,6 +24,7 @@ type compiledParams struct { ImagePullSecrets []corev1.LocalObjectReference ImagePullPolicy string Labels map[string]string + Annotations map[string]string } func (cp *connPackage) compileParameters(params ...jobsmanagerv1beta1.ManagedJobParameters) jobsmanagerv1beta1.ManagedJobParameters { @@ -56,6 +57,11 @@ func (cp *connPackage) compileParameters(params ...jobsmanagerv1beta1.ManagedJob cparams.Labels[k] = v } } + if params.Annotations != nil { + for k, v := range params.Annotations { + cparams.Annotations[k] = v + } + } } } return cparams @@ -242,6 +248,12 @@ func (cp *connPackage) executeJob(j *jobsmanagerv1beta1.ManagedJobDefinition, g labels[k] = v } + annotations := map[string]string{} + + for k, v := range j.CompiledParams.Annotations { + annotations[k] = v + } + job_handler := kbatch.Job{ ObjectMeta: metav1.ObjectMeta{ Name: generatedJobName, @@ -250,9 +262,10 @@ func (cp *connPackage) executeJob(j *jobsmanagerv1beta1.ManagedJobDefinition, g Spec: kbatch.JobSpec{ Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ - Name: generatedJobName, - Namespace: cp.mj.Namespace, - Labels: labels, + Name: generatedJobName, + Namespace: cp.mj.Namespace, + Labels: labels, + Annotations: annotations, }, Spec: corev1.PodSpec{ Volumes: j.CompiledParams.Volumes,