Skip to content
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

feat: Advanced Workload pre-download image support attach metadata in ImagePullJob #1246

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/controller/cloneset/cloneset_predownload_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,18 @@ func (r *ReconcileCloneSet) createImagePullJobsForInPlaceUpdate(cs *appsv1alpha1
}
labelMap[history.ControllerRevisionHashLabel] = updateRevision.Labels[history.ControllerRevisionHashLabel]

annotationMap := make(map[string]string)
for k, v := range cs.Spec.Template.Annotations {
annotationMap[k] = v
}

containerImages := diffImagesBetweenRevisions(currentRevision, updateRevision)
klog.V(3).Infof("CloneSet %s/%s begin to create ImagePullJobs for revision %s -> %s: %v",
cs.Namespace, cs.Name, currentRevision.Name, updateRevision.Name, containerImages)
for name, image := range containerImages {
// job name is revision name + container name, it can not be more than 255 characters
jobName := fmt.Sprintf("%s-%s", updateRevision.Name, name)
err := imagejobutilfunc.CreateJobForWorkload(r.Client, cs, clonesetutils.ControllerKind, jobName, image, labelMap, *selector, pullSecrets)
err := imagejobutilfunc.CreateJobForWorkload(r.Client, cs, clonesetutils.ControllerKind, jobName, image, labelMap, annotationMap, *selector, pullSecrets)
if err != nil {
if !errors.IsAlreadyExists(err) {
klog.Errorf("CloneSet %s/%s failed to create ImagePullJob %s: %v", cs.Namespace, cs.Name, jobName, err)
Expand Down
7 changes: 6 additions & 1 deletion pkg/controller/daemonset/daemonset_predownload_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ func (dsc *ReconcileDaemonSet) createImagePullJobsForInPlaceUpdate(ds *appsv1alp
}
labelMap[history.ControllerRevisionHashLabel] = updateRevision.Labels[history.ControllerRevisionHashLabel]

annotationMap := make(map[string]string)
for k, v := range ds.Spec.Template.Annotations {
annotationMap[k] = v
}

containerImages := diffImagesBetweenRevisions(oldRevisions, updateRevision)
klog.V(3).Infof("DaemonSet %s/%s begin to create ImagePullJobs for revision %s: %v",
ds.Namespace, ds.Name, updateRevision.Name, containerImages)
for name, image := range containerImages {
// job name is revision name + container name, it can not be more than 255 characters
jobName := fmt.Sprintf("%s-%s", updateRevision.Name, name)
err := imagejobutilfunc.CreateJobForWorkload(dsc.Client, ds, controllerKind, jobName, image, labelMap, *selector, pullSecrets)
err := imagejobutilfunc.CreateJobForWorkload(dsc.Client, ds, controllerKind, jobName, image, labelMap, annotationMap, *selector, pullSecrets)
if err != nil {
if !errors.IsAlreadyExists(err) {
klog.Errorf("DaemonSet %s/%s failed to create ImagePullJob %s: %v", ds.Namespace, ds.Name, jobName, err)
Expand Down
7 changes: 6 additions & 1 deletion pkg/controller/statefulset/statefulset_predownload_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,18 @@ func (dss *defaultStatefulSetControl) createImagePullJobsForInPlaceUpdate(sts *a
}
labelMap[history.ControllerRevisionHashLabel] = updateRevision.Labels[history.ControllerRevisionHashLabel]

annotationMap := make(map[string]string)
for k, v := range sts.Spec.Template.Annotations {
annotationMap[k] = v
}

containerImages := diffImagesBetweenRevisions(currentRevision, updateRevision)
klog.V(3).Infof("Statefulset %s/%s begin to create ImagePullJobs for revision %s -> %s: %v",
sts.Namespace, sts.Name, currentRevision.Name, updateRevision.Name, containerImages)
for name, image := range containerImages {
// job name is revision name + container name, it can not be more than 255 characters
jobName := fmt.Sprintf("%s-%s", updateRevision.Name, name)
err := imagejobutilfunc.CreateJobForWorkload(sigsruntimeClient, sts, controllerKind, jobName, image, labelMap, *selector, pullSecrets)
err := imagejobutilfunc.CreateJobForWorkload(sigsruntimeClient, sts, controllerKind, jobName, image, labelMap, annotationMap, *selector, pullSecrets)
if err != nil {
if !errors.IsAlreadyExists(err) {
klog.Errorf("Statefulset %s/%s failed to create ImagePullJob %s: %v", sts.Namespace, sts.Name, jobName, err)
Expand Down
6 changes: 5 additions & 1 deletion pkg/util/imagejob/utilfunction/imagejob_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

func CreateJobForWorkload(c client.Client, owner metav1.Object, gvk schema.GroupVersionKind, name, image string, labels map[string]string, podSelector metav1.LabelSelector, pullSecrets []string) error {
func CreateJobForWorkload(c client.Client, owner metav1.Object, gvk schema.GroupVersionKind, name, image string, labels map[string]string, annotations map[string]string, podSelector metav1.LabelSelector, pullSecrets []string) error {
var pullTimeoutSeconds int32 = 300
if str, ok := owner.GetAnnotations()[appsv1alpha1.ImagePreDownloadTimeoutSecondsKey]; ok {
if i, err := strconv.Atoi(str); err == nil {
Expand Down Expand Up @@ -61,6 +61,10 @@ func CreateJobForWorkload(c client.Client, owner metav1.Object, gvk schema.Group
Type: appsv1alpha1.Always,
TTLSecondsAfterFinished: utilpointer.Int32Ptr(600),
},
SandboxConfig: &appsv1alpha1.SandboxConfig{
Annotations: annotations,
Labels: labels,
},
},
}

Expand Down