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

(fix#5280): Basic integration fails on ARM64 #5286

Closed
wants to merge 1 commit into from
Closed
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
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
Loading