Skip to content

Commit

Permalink
(fix#5280): Basic integration fails on ARM64
Browse files Browse the repository at this point in the history
  • Loading branch information
tdiesler committed Mar 26, 2024
1 parent ef5b562 commit 16dbb67
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 31 additions & 0 deletions pkg/builder/jib.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package builder

import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -107,12 +108,20 @@ func (t *jibTask) Do(ctx context.Context) v1.BuildStatus {
return status.Failed(err)
}

arch, err := t.GetControllerArchitecture(ctx, t.c)
if err != nil {
return status.Failed(err)
}

mavenArgs := make([]string, 0)
mavenArgs = append(mavenArgs, jib.JibMavenGoal)
mavenArgs = append(mavenArgs, strings.Split(string(mavenCommand), " ")...)
mavenArgs = append(mavenArgs, "-P", "jib")
mavenArgs = append(mavenArgs, jib.JibMavenToImageParam+t.task.Image)
mavenArgs = append(mavenArgs, jib.JibMavenFromImageParam+baseImage)
if arch == "amd64" || arch == "arm64" {
mavenArgs = append(mavenArgs, jib.JibMavenFromPlatforms+"linux/"+arch)
}
if t.task.Registry.Insecure {
mavenArgs = append(mavenArgs, jib.JibMavenInsecureRegistries+"true")
}
Expand Down Expand Up @@ -142,3 +151,25 @@ func (t *jibTask) Do(ctx context.Context) v1.BuildStatus {

return status
}

func (t *jibTask) GetControllerArchitecture(ctx context.Context, c client.Client) (string, error) {

podName := os.Getenv("POD_NAME")
namespace, _ := c.GetCurrentNamespace("")
log.Infof("Fetching image architecture for pod %s in namespace %s", podName, namespace)

// Get the pod by name
pod, err := c.CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{})
if err != nil {
panic(err.Error())
}

// Note, it might be better to inspect the image metadata
// by querying the registry with the image id
image := pod.Spec.Containers[0].Image
if strings.HasSuffix(image, "-amd64") || strings.HasSuffix(image, "-arm64") {
return image[len(image)-5:], nil
}

return "", nil
}
3 changes: 2 additions & 1 deletion pkg/util/jib/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ import (
const JibMavenGoal = "jib:build"
const JibMavenToImageParam = "-Djib.to.image="
const JibMavenFromImageParam = "-Djib.from.image="
const JibMavenFromPlatforms = "-Djib.from.platforms="
const JibMavenInsecureRegistries = "-Djib.allowInsecureRegistries="
const JibDigestFile = "target/jib-image.digest"
const JibMavenPluginVersionDefault = "3.3.2"
const JibMavenPluginVersionDefault = "3.4.1"
const JibLayerFilterExtensionMavenVersionDefault = "0.3.0"

type JibBuild struct {
Expand Down

0 comments on commit 16dbb67

Please sign in to comment.