-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Share cleanup job #337
Merged
openshift-merge-bot
merged 3 commits into
openstack-k8s-operators:main
from
fmount:share_cleanup
Oct 7, 2024
Merged
Share cleanup job #337
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
package manila | ||
|
||
import ( | ||
"fmt" | ||
"github.com/openstack-k8s-operators/lib-common/modules/common/env" | ||
manilav1 "github.com/openstack-k8s-operators/manila-operator/api/v1beta1" | ||
batchv1 "k8s.io/api/batch/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// DbSyncJob func | ||
func DbSyncJob(instance *manilav1.Manila, labels map[string]string, annotations map[string]string) *batchv1.Job { | ||
// Job func | ||
func Job( | ||
instance *manilav1.Manila, | ||
labels map[string]string, | ||
annotations map[string]string, | ||
ttl *int32, | ||
jobName string, | ||
jobCommand string, | ||
delay int32, | ||
) *batchv1.Job { | ||
var config0644AccessMode int32 = 0644 | ||
|
||
// Unlike the individual manila services, the DbSyncJob doesn't need a | ||
// secret that contains all of the config snippets required by every | ||
// service, The two snippet files that it does need (DefaultsConfigFileName | ||
// and CustomConfigFileName) can be extracted from the top-level manila | ||
// config-data secret. | ||
dbSyncVolume := []corev1.Volume{ | ||
// Unlike the individual manila services, DbSyncJob or a Job executing a | ||
// manila-manage command doesn't need a secret that contains all of the | ||
// config snippets required by every service, The two snippet files that it | ||
// does need (DefaultsConfigFileName and CustomConfigFileName) can be | ||
// extracted from the top-level manila config-data secret. | ||
manilaJobVolume := []corev1.Volume{ | ||
{ | ||
Name: "db-sync-config-data", | ||
Name: "job-config-data", | ||
VolumeSource: corev1.VolumeSource{ | ||
Secret: &corev1.SecretVolumeSource{ | ||
DefaultMode: &config0644AccessMode, | ||
|
@@ -48,9 +56,9 @@ func DbSyncJob(instance *manilav1.Manila, labels map[string]string, annotations | |
}, | ||
} | ||
|
||
dbSyncMounts := []corev1.VolumeMount{ | ||
manilaJobMounts := []corev1.VolumeMount{ | ||
{ | ||
Name: "db-sync-config-data", | ||
Name: "job-config-data", | ||
MountPath: "/etc/manila/manila.conf.d", | ||
ReadOnly: true, | ||
}, | ||
|
@@ -62,12 +70,13 @@ func DbSyncJob(instance *manilav1.Manila, labels map[string]string, annotations | |
}, | ||
} | ||
|
||
args := []string{"-c", DBSyncCommand} | ||
delayCommand := fmt.Sprintf("sleep %d", delay) | ||
args := []string{"-c", fmt.Sprintf("%s && %s", delayCommand, jobCommand)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gouthampacha the resulting command is the concatenation between the delay and the jobCommand. |
||
|
||
// add CA cert if defined | ||
if instance.Spec.ManilaAPI.TLS.CaBundleSecretName != "" { | ||
dbSyncVolume = append(dbSyncVolume, instance.Spec.ManilaAPI.TLS.CreateVolume()) | ||
dbSyncMounts = append(dbSyncMounts, instance.Spec.ManilaAPI.TLS.CreateVolumeMounts(nil)...) | ||
manilaJobVolume = append(manilaJobVolume, instance.Spec.ManilaAPI.TLS.CreateVolume()) | ||
manilaJobMounts = append(manilaJobMounts, instance.Spec.ManilaAPI.TLS.CreateVolumeMounts(nil)...) | ||
} | ||
|
||
envVars := map[string]env.Setter{} | ||
|
@@ -76,7 +85,7 @@ func DbSyncJob(instance *manilav1.Manila, labels map[string]string, annotations | |
|
||
job := &batchv1.Job{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: instance.Name + "-db-sync", | ||
Name: fmt.Sprintf("%s-%s", instance.Name, jobName), | ||
Namespace: instance.Namespace, | ||
Labels: labels, | ||
}, | ||
|
@@ -90,22 +99,25 @@ func DbSyncJob(instance *manilav1.Manila, labels map[string]string, annotations | |
ServiceAccountName: instance.RbacResourceName(), | ||
Containers: []corev1.Container{ | ||
{ | ||
Name: instance.Name + "-db-sync", | ||
Name: fmt.Sprintf("%s-%s", instance.Name, jobName), | ||
Command: []string{ | ||
"/bin/bash", | ||
}, | ||
Args: args, | ||
Image: instance.Spec.ManilaAPI.ContainerImage, | ||
SecurityContext: manilaDefaultSecurityContext(), | ||
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars), | ||
VolumeMounts: dbSyncMounts, | ||
VolumeMounts: manilaJobMounts, | ||
}, | ||
}, | ||
Volumes: dbSyncVolume, | ||
Volumes: manilaJobVolume, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
if ttl != nil { | ||
// Setting TTL to delete the job after it has completed | ||
job.Spec.TTLSecondsAfterFinished = ttl | ||
} | ||
return job | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gouthampacha we delay according to this parameter.