From ed201a72ef28d6712a7f6fee1dfd7c6258f28f6c Mon Sep 17 00:00:00 2001 From: Dimitris Karakasilis Date: Tue, 20 Dec 2022 10:26:10 +0200 Subject: [PATCH 1/3] Always produce an importable tar from the image and name it after the artifact Fixes https://github.com/kairos-io/kairos/issues/514 Signed-off-by: Dimitris Karakasilis --- api/v1alpha1/osartifact_types.go | 3 ++- controllers/job.go | 19 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/api/v1alpha1/osartifact_types.go b/api/v1alpha1/osartifact_types.go index a2ff806..b4a26e5 100644 --- a/api/v1alpha1/osartifact_types.go +++ b/api/v1alpha1/osartifact_types.go @@ -49,7 +49,8 @@ type OSArtifactSpec struct { Bundles []string `json:"bundles,omitempty"` PullOptions Pull `json:"pull,omitempty"` OSRelease string `json:"osRelease,omitempty"` - PushOptions Push `json:"push,omitempty"` + // TODO: Currently not used. Reseved to be used when we have a way to push to registries. + PushOptions Push `json:"push,omitempty"` } type Push struct { diff --git a/controllers/job.go b/controllers/job.go index 411418a..c63ca20 100644 --- a/controllers/job.go +++ b/controllers/job.go @@ -65,7 +65,11 @@ func unpackContainer(id, containerImage, pullImage string, pullOptions buildv1al } } -func createImageContainer(containerImage string, pushOptions buildv1alpha1.Push) v1.Container { +func createImageContainer(containerImage string, artifact buildv1alpha1.OSArtifact) v1.Container { + imageName := "dontpush" // No image was defined, use a dummy one to let luet work + if artifact.Spec.PushOptions.ImageName != "" { + imageName = artifact.Spec.PushOptions.ImageName + } return v1.Container{ ImagePullPolicy: v1.PullAlways, Name: "create-image", @@ -73,8 +77,9 @@ func createImageContainer(containerImage string, pushOptions buildv1alpha1.Push) Command: []string{"/bin/bash", "-cxe"}, Args: []string{ fmt.Sprintf( - "tar -czvpf test.tar -C /rootfs . && luet util pack %s test.tar image.tar && mv image.tar /artifacts", - pushOptions.ImageName, + "tar -czvpf test.tar -C /rootfs . && luet util pack %[1]s test.tar %[2]s.tar && chmod +r %[2]s.tar && mv %[2]s.tar /artifacts", + imageName, + artifact.Name, ), }, VolumeMounts: []v1.VolumeMount{ @@ -139,8 +144,6 @@ func osReleaseContainer(containerImage string) v1.Container { func (r *OSArtifactReconciler) genJob(artifact buildv1alpha1.OSArtifact) *batchv1.Job { objMeta := genObjectMeta(artifact) - pushImage := artifact.Spec.PushOptions.Push - privileged := false serviceAccount := true @@ -326,11 +329,7 @@ func (r *OSArtifactReconciler) genJob(artifact buildv1alpha1.OSArtifact) *batchv pod.InitContainers = append(pod.InitContainers, buildGCECloudImageContainer) } - // TODO: Does it make sense to build the image and not push it? Maybe remove - // this flag? - if pushImage { - pod.InitContainers = append(pod.InitContainers, createImageContainer(r.ToolImage, artifact.Spec.PushOptions)) - } + pod.InitContainers = append(pod.InitContainers, createImageContainer(r.ToolImage, artifact)) pod.Containers = []v1.Container{ createPushToServerImageContainer(r.CopierImage, r.ArtifactPodInfo), From 4c8f1dd0f09bb4258f0e5bdf025583c411987576 Mon Sep 17 00:00:00 2001 From: Dimitris Karakasilis Date: Wed, 21 Dec 2022 15:29:10 +0200 Subject: [PATCH 2/3] Fix typo Signed-off-by: Dimitris Karakasilis --- api/v1alpha1/osartifact_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v1alpha1/osartifact_types.go b/api/v1alpha1/osartifact_types.go index b4a26e5..0e3894b 100644 --- a/api/v1alpha1/osartifact_types.go +++ b/api/v1alpha1/osartifact_types.go @@ -49,7 +49,7 @@ type OSArtifactSpec struct { Bundles []string `json:"bundles,omitempty"` PullOptions Pull `json:"pull,omitempty"` OSRelease string `json:"osRelease,omitempty"` - // TODO: Currently not used. Reseved to be used when we have a way to push to registries. + // TODO: Currently not used. Reserved to be used when we have a way to push to registries. PushOptions Push `json:"push,omitempty"` } From 04d46465a7a6f4807a3a1deebc9374f4bf6cfa53 Mon Sep 17 00:00:00 2001 From: Dimitris Karakasilis Date: Mon, 9 Jan 2023 13:25:04 +0200 Subject: [PATCH 3/3] Fallback to the spec name when a push image name is not provided Signed-off-by: Dimitris Karakasilis --- controllers/job.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/controllers/job.go b/controllers/job.go index c63ca20..fe0248e 100644 --- a/controllers/job.go +++ b/controllers/job.go @@ -65,11 +65,17 @@ func unpackContainer(id, containerImage, pullImage string, pullOptions buildv1al } } -func createImageContainer(containerImage string, artifact buildv1alpha1.OSArtifact) v1.Container { - imageName := "dontpush" // No image was defined, use a dummy one to let luet work - if artifact.Spec.PushOptions.ImageName != "" { - imageName = artifact.Spec.PushOptions.ImageName +func pushImageName(artifact buildv1alpha1.OSArtifact) string { + pushName := artifact.Spec.PushOptions.ImageName + if pushName != "" { + return pushName } + return artifact.Name +} + +func createImageContainer(containerImage string, artifact buildv1alpha1.OSArtifact) v1.Container { + imageName := pushImageName(artifact) + return v1.Container{ ImagePullPolicy: v1.PullAlways, Name: "create-image",