mirror of
https://github.com/lukaszraczylo/jobs-manager-operator.git
synced 2026-10-12 05:32:52 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75393e791a
|
||
|
|
c99558314c | ||
|
|
56edfc8d8c
|
||
|
|
5c92083161
|
||
|
|
60cb552179
|
@@ -145,6 +145,43 @@ In this case - result for the first job will look like this:
|
||||
status: succeeded
|
||||
```
|
||||
|
||||
### Available params
|
||||
|
||||
There's quite a lot of of flexibility with parameters. On every level where params are allowed, you can define:
|
||||
|
||||
```yaml
|
||||
params:
|
||||
fromEnv:
|
||||
- configMapRef:
|
||||
name: "configmap-name"
|
||||
key: "key-name"
|
||||
env:
|
||||
- name: "FOO"
|
||||
value: "bar"
|
||||
volumes:
|
||||
- name: secrets-store-api
|
||||
csi:
|
||||
driver: secrets-store.csi.k8s.io
|
||||
readOnly: true
|
||||
volumeAttributes:
|
||||
secretProviderClass: api-secrets-provider
|
||||
volumeMount:
|
||||
- name: secrets-store-api
|
||||
mountPath: "/mnt/secrets-api"
|
||||
readOnly: true
|
||||
serviceAccount: "service-account-name"
|
||||
restartPolicy: "Never"
|
||||
imagePullSecrets:
|
||||
- "ghcr-token"
|
||||
imagePullPolicy:
|
||||
- "Always"
|
||||
labels:
|
||||
this/works: "true"
|
||||
annotations:
|
||||
this/works/aswell: "true"
|
||||
```
|
||||
|
||||
|
||||
### Kustomization and references
|
||||
|
||||
In case of any issues with `configmapGenerator` or `secretGenerator`, please add following to your `kustomization.yaml`:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.19
|
||||
version: 0.0.24
|
||||
# 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.19"
|
||||
appVersion: "0.0.24"
|
||||
keywords:
|
||||
- operator
|
||||
- jobs
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,6 +5,18 @@ metadata:
|
||||
labels:
|
||||
{{- include "chart.labels" . | nindent 4 }}
|
||||
rules:
|
||||
- apiGroups:
|
||||
- batch
|
||||
resources:
|
||||
- jobs
|
||||
verbs:
|
||||
- create
|
||||
- delete
|
||||
- get
|
||||
- list
|
||||
- patch
|
||||
- update
|
||||
- watch
|
||||
- apiGroups:
|
||||
- jobsmanager.raczylo.com
|
||||
resources:
|
||||
@@ -31,28 +43,6 @@ rules:
|
||||
- get
|
||||
- patch
|
||||
- update
|
||||
# Add ability to manage jobs
|
||||
- apiGroups:
|
||||
- batch
|
||||
resources:
|
||||
- jobs
|
||||
verbs:
|
||||
- create
|
||||
- delete
|
||||
- get
|
||||
- list
|
||||
- patch
|
||||
- update
|
||||
- watch
|
||||
# Add access to events
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- events
|
||||
verbs:
|
||||
- create
|
||||
- patch
|
||||
- update
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRoleBinding
|
||||
|
||||
@@ -12,8 +12,8 @@ controllerManager:
|
||||
memory: 64Mi
|
||||
manager:
|
||||
image:
|
||||
repository: ghcr.io/lukaszraczylo/jobs-manager-operator
|
||||
tag: 0.0.19
|
||||
repository: controller
|
||||
tag: latest
|
||||
resources:
|
||||
limits:
|
||||
cpu: 500m
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
resources:
|
||||
- manager.yaml
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
|
||||
@@ -5,6 +5,18 @@ metadata:
|
||||
creationTimestamp: null
|
||||
name: manager-role
|
||||
rules:
|
||||
- apiGroups:
|
||||
- batch
|
||||
resources:
|
||||
- jobs
|
||||
verbs:
|
||||
- create
|
||||
- delete
|
||||
- get
|
||||
- list
|
||||
- patch
|
||||
- update
|
||||
- watch
|
||||
- apiGroups:
|
||||
- jobsmanager.raczylo.com
|
||||
resources:
|
||||
|
||||
@@ -118,6 +118,7 @@ func (cp *connPackage) generateDependencyTree() {
|
||||
groupTree := mainTree.Add(group.Name)
|
||||
for _, job := range group.Jobs {
|
||||
jobTree := groupTree.Add(job.Name)
|
||||
job.CompiledParams = cp.compileParameters(cp.mj.Spec.Params, group.Params, job.Params)
|
||||
if job.Parallel {
|
||||
continue
|
||||
} else {
|
||||
@@ -130,7 +131,6 @@ func (cp *connPackage) generateDependencyTree() {
|
||||
jobTree.Add("Depends on: " + generatedJobName)
|
||||
if !cp.checkIfPresentInDependencies(job.Dependencies, generatedJobName) {
|
||||
job.Dependencies = append(job.Dependencies, &jobsmanagerv1beta1.ManagedJobDependencies{Name: generatedJobName, Status: ExecutionStatusPending})
|
||||
job.CompiledParams = cp.compileParameters(cp.mj.Spec.Params, group.Params, job.Params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
@@ -52,10 +53,17 @@ func (cp *connPackage) compileParameters(params ...jobsmanagerv1beta1.ManagedJob
|
||||
cparams.ImagePullSecrets = append(cparams.ImagePullSecrets, params.ImagePullSecrets...)
|
||||
}
|
||||
if params.Labels != nil {
|
||||
cparams.Labels = make(map[string]string)
|
||||
for k, v := range params.Labels {
|
||||
cparams.Labels[k] = v
|
||||
}
|
||||
}
|
||||
if params.Annotations != nil {
|
||||
cparams.Annotations = make(map[string]string)
|
||||
for k, v := range params.Annotations {
|
||||
cparams.Annotations[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return cparams
|
||||
@@ -242,6 +250,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 +264,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,
|
||||
|
||||
@@ -40,6 +40,7 @@ type ManagedJobReconciler struct {
|
||||
//+kubebuilder:rbac:groups=jobsmanager.raczylo.com,resources=managedjobs,verbs=get;list;watch;create;update;patch;delete
|
||||
//+kubebuilder:rbac:groups=jobsmanager.raczylo.com,resources=managedjobs/status,verbs=get;update;patch
|
||||
//+kubebuilder:rbac:groups=jobsmanager.raczylo.com,resources=managedjobs/finalizers,verbs=update
|
||||
//+kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;update;patch;delete
|
||||
|
||||
func (r *ManagedJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||
_ = log.FromContext(ctx)
|
||||
@@ -63,6 +64,7 @@ func (r *ManagedJobReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
||||
_, theSame, _ := pandati.CompareStructsReplaced(originalMainJobDefinition, cp.mj)
|
||||
if !theSame {
|
||||
cp.updateCRDStatusDirectly()
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
originalMainJobDefinition = cp.mj.DeepCopy()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user