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 41c19ae
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
44 changes: 44 additions & 0 deletions pkg/builder/jib.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package builder

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

arch, err := t.GetControllerArchitecture(ctx)
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 +152,37 @@ func (t *jibTask) Do(ctx context.Context) v1.BuildStatus {

return status
}

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

// Create a Kubernetes client using in-cluster configuration
config, err := rest.InClusterConfig()
if err != nil {
return "", err
}

c, err := client.NewClientWithConfig(false, config)
if err != nil {
return "", err
}

// Retrieve pod name and namespace from environment variables
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 41c19ae

Please sign in to comment.