From 8da1f91ad9a913d5c88cb39d81e4426ea5007874 Mon Sep 17 00:00:00 2001 From: EKS Distro PR Bot <75336432+eks-distro-pr-bot@users.noreply.github.com> Date: Sun, 17 Nov 2024 19:56:38 -0500 Subject: [PATCH] Use ECR Public source client for image checks in prod bundle release (#9016) Co-authored-by: Abhay Krishna Arunachalam --- release/cli/pkg/images/images.go | 18 ++++++++++++++---- release/cli/pkg/operations/upload.go | 7 ++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/release/cli/pkg/images/images.go b/release/cli/pkg/images/images.go index c73cc152a258..4517aada973b 100644 --- a/release/cli/pkg/images/images.go +++ b/release/cli/pkg/images/images.go @@ -388,14 +388,24 @@ func ComputeImageDigestFromManifest(ecrPublicClient *ecrpublicsdk.ECRPublic, reg return fmt.Sprintf("%x", digest), nil } -func CheckRepositoryImagesAndTagsCountLimit(sourceImageUri, releaseImageUri, sourceContainerRegistry, releaseContainerRegistry string, ecrClient *ecrsdk.ECR, ecrPublicClient *ecrpublicsdk.ECRPublic) error { +func CheckRepositoryImagesAndTagsCountLimit(sourceImageUri, releaseImageUri, sourceContainerRegistry, releaseContainerRegistry string, ecrClient interface{}, ecrPublicClient *ecrpublicsdk.ECRPublic) error { repository, _ := artifactutils.SplitImageUri(releaseImageUri, releaseContainerRegistry) fmt.Printf("Checking if image %s can be pushed to repository %s\n", releaseImageUri, repository) - sourceImageDigest, err := ecr.GetImageDigest(sourceImageUri, sourceContainerRegistry, ecrClient) - if err != nil { - return errors.Cause(err) + var sourceImageDigest string + var err error + switch ecrClient.(type) { + case *ecrsdk.ECR: + sourceImageDigest, err = ecr.GetImageDigest(sourceImageUri, sourceContainerRegistry, ecrClient.(*ecrsdk.ECR)) + if err != nil { + return errors.Cause(err) + } + case *ecrpublicsdk.ECRPublic: + sourceImageDigest, err = ecrpublic.GetImageDigest(sourceImageUri, sourceContainerRegistry, ecrClient.(*ecrpublicsdk.ECRPublic)) + if err != nil { + return errors.Cause(err) + } } allImagesCount, err := ecrpublic.GetAllImagesCount(repository, ecrPublicClient) diff --git a/release/cli/pkg/operations/upload.go b/release/cli/pkg/operations/upload.go index caa48040488c..f50a831ae1f8 100644 --- a/release/cli/pkg/operations/upload.go +++ b/release/cli/pkg/operations/upload.go @@ -163,7 +163,12 @@ func handleImageUpload(_ context.Context, r *releasetypes.ReleaseConfig, package releaseImageUri := artifact.Image.ReleaseImageURI sourceEcrAuthConfig := defaultSourceEcrAuthConfig sourceContainerRegistry := r.SourceContainerRegistry - sourceEcrClient := r.SourceClients.ECR.EcrClient + var sourceEcrClient interface{} + if r.ReleaseEnvironment == "production" && r.BundleRelease { + sourceEcrClient = r.SourceClients.ECR.EcrPublicClient + } else { + sourceEcrClient = r.SourceClients.ECR.EcrClient + } if packagesutils.NeedsPackagesAccountArtifacts(r) && (strings.Contains(sourceImageUri, "eks-anywhere-packages") || strings.Contains(sourceImageUri, "ecr-token-refresher") || strings.Contains(sourceImageUri, "credential-provider-package")) { sourceEcrAuthConfig = packagesSourceEcrAuthConfig sourceContainerRegistry = r.PackagesSourceContainerRegistry