Skip to content

Commit

Permalink
Use the platform for all image related operations (#2759)
Browse files Browse the repository at this point in the history
  • Loading branch information
0sewa0 committed Feb 19, 2024
1 parent 73fa7e5 commit 91d92e3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
9 changes: 8 additions & 1 deletion cmd/troubleshoot/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"

dynatracev1beta1 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta1/dynakube"
"github.com/Dynatrace/dynatrace-operator/pkg/arch"
"github.com/go-logr/logr"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -87,7 +88,13 @@ func tryImagePull(ctx context.Context, keychain authn.Keychain, transport *http.
return err
}

_, err = remote.Get(imageReference, remote.WithContext(ctx), remote.WithAuthFromKeychain(keychain), remote.WithTransport(transport))
_, err = remote.Get(
imageReference,
remote.WithContext(ctx),
remote.WithAuthFromKeychain(keychain),
remote.WithTransport(transport),
remote.WithPlatform(arch.ImagePlatform),
)
if err != nil {
return err
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/arch/consts.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package arch

import containerv1 "github.com/google/go-containerregistry/pkg/v1"

const (
FlavorDefault = "default"
FlavorMultidistro = "multidistro"

// These architectures are for the DynatraceAPI

ArchX86 = "x86"
ArchARM = "arm"
ArchPPCLE = "ppcle"
ArchS390 = "s390"

// These architectures are for the Image Registry

AMDImageArch = "amd64"
ARMImageArch = "arm64"

DefaultImageOS = "linux"
)

var (
ImagePlatform = containerv1.Platform{
OS: DefaultImageOS,
Architecture: ImageArch,
}
)
9 changes: 1 addition & 8 deletions pkg/injection/codemodule/installer/image/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import (
"github.com/pkg/errors"
)

const (
defaultOS = "linux"
)

type imagePullInfo struct {
imageCacheDir string
targetDir string
Expand Down Expand Up @@ -52,10 +48,7 @@ func (installer Installer) pullImageInfo(imageName string) (*containerv1.Image,
image, err := remote.Image(ref, remote.WithContext(context.TODO()),
remote.WithAuthFromKeychain(installer.keychain),
remote.WithTransport(installer.transport),
remote.WithPlatform(containerv1.Platform{
OS: defaultOS,
Architecture: arch.ImageArch,
}),
remote.WithPlatform(arch.ImagePlatform),
)
if err != nil {
return nil, errors.WithMessagef(err, "getting image %q", imageName)
Expand Down
9 changes: 8 additions & 1 deletion pkg/oci/registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"

dynatracev1beta1 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta1/dynakube"
"github.com/Dynatrace/dynatrace-operator/pkg/arch"
"github.com/Dynatrace/dynatrace-operator/pkg/oci/dockerkeychain"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -105,6 +106,7 @@ func (c *Client) GetImageVersion(ctx context.Context, imageName string) (ImageVe
options := []remote.Option{
remote.WithContext(ctx),
remote.WithTransport(c.transport),
remote.WithPlatform(arch.ImagePlatform),
}
if c.keychain != nil {
options = append(options, remote.WithAuthFromKeychain(c.keychain))
Expand Down Expand Up @@ -153,7 +155,12 @@ func (c *Client) PullImageInfo(ctx context.Context, imageName string) (*containe
return nil, errors.WithMessagef(err, "parsing reference %q:", imageName)
}

image, err := remote.Image(ref, remote.WithContext(ctx), remote.WithAuthFromKeychain(c.keychain), remote.WithTransport(c.transport))
image, err := remote.Image(ref,
remote.WithContext(ctx),
remote.WithAuthFromKeychain(c.keychain),
remote.WithTransport(c.transport),
remote.WithPlatform(arch.ImagePlatform),
)
if err != nil {
return nil, errors.WithMessagef(err, "getting image %q", imageName)
}
Expand Down

0 comments on commit 91d92e3

Please sign in to comment.