Skip to content

Commit

Permalink
Revert "imageDigest only for ecr"
Browse files Browse the repository at this point in the history
This reverts commit af54b2f.
  • Loading branch information
sparrc committed Feb 16, 2023
1 parent 81034b1 commit 699e9ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 53 deletions.
29 changes: 11 additions & 18 deletions agent/engine/docker_image_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,27 +165,20 @@ func (imageManager *dockerImageManager) RecordContainerReference(container *apic
return nil
}

// check whether image pull from ECR
func (imageManager *dockerImageManager) isImagePullFromECR(container *apicontainer.Container) bool {
return container.RegistryAuthentication != nil && container.RegistryAuthentication.ECRAuthData != nil && container.RegistryAuthentication.Type == apicontainer.AuthTypeECR
}

// The helper function to fetch the RepoImageDigest when inspect the image
func (imageManager *dockerImageManager) fetchRepoDigest(imageInspected *types.ImageInspect, container *apicontainer.Container) string {
imageRepoDigests := imageInspected.RepoDigests
resultRepoDigest := ""
if imageManager.isImagePullFromECR(container) {
imageRepoDigests := imageInspected.RepoDigests
imagePrefix := strings.Split(container.Image, "/")[0]
for _, imageRepoDigest := range imageRepoDigests {
if strings.HasPrefix(imageRepoDigest, imagePrefix) {
repoDigestSplitList := strings.Split(imageRepoDigest, "@")
if len(repoDigestSplitList) > 1 {
resultRepoDigest = repoDigestSplitList[1]
return resultRepoDigest
} else {
seelog.Warnf("ImageRepoDigest doesn't have the right format: %v", imageRepoDigest)
return ""
}
imagePrefix := strings.Split(container.Image, ":")[0]
for _, imageRepoDigest := range imageRepoDigests {
if strings.HasPrefix(imageRepoDigest, imagePrefix) {
repoDigestSplitList := strings.Split(imageRepoDigest, "@")
if len(repoDigestSplitList) > 1 {
resultRepoDigest = repoDigestSplitList[1]
return resultRepoDigest
} else {
seelog.Warnf("ImageRepoDigest doesn't have the right format: %v", imageRepoDigest)
return ""
}
}
}
Expand Down
38 changes: 3 additions & 35 deletions agent/engine/docker_image_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func TestFetchRepoDigest(t *testing.T) {
container: &apicontainer.Container{
Name: "testContainer1",
Image: "repo1",
ImageDigest: "",
ImageDigest: "digest1",
},
imageInspected: &types.ImageInspect{
RepoDigests: []string{"repo1@digest1", "repo2@digest2", "repo3@digest3"},
Expand All @@ -317,7 +317,7 @@ func TestFetchRepoDigest(t *testing.T) {
container: &apicontainer.Container{
Name: "testContainer2",
Image: "repo1:latest",
ImageDigest: "",
ImageDigest: "digest1",
},
imageInspected: &types.ImageInspect{
RepoDigests: []string{"repo1@digest1", "repo2@digest2", "repo3@digest3"},
Expand All @@ -327,7 +327,7 @@ func TestFetchRepoDigest(t *testing.T) {
container: &apicontainer.Container{
Name: "testContainer3",
Image: "repo1@sha256:12345",
ImageDigest: "",
ImageDigest: "sha256:12345",
},
imageInspected: &types.ImageInspect{
RepoDigests: []string{"repo1@sha256:12345", "repo2@digest2", "repo3"},
Expand All @@ -353,38 +353,6 @@ func TestFetchRepoDigest(t *testing.T) {
RepoDigests: []string{"mysql", "repo2@digest2"},
},
},
{
container: &apicontainer.Container{
Name: "testContainer6",
Image: "123456781234.dkr.ecr.us-west-2.amazonaws.com/test-rci@sha256:d1c14fcf2e9476ed58ebc4251b211f403f271e96b6c3d9ada0f1c5454ca4d230",
ImageDigest: "sha256:d1c14fcf2e9476ed58ebc4251b211f403f271e96b6c3d9ada0f1c5454ca4d230",
RegistryAuthentication: &apicontainer.RegistryAuthenticationData{
Type: "ecr",
ECRAuthData: &apicontainer.ECRAuthData{
RegistryID: "123456781234",
},
},
},
imageInspected: &types.ImageInspect{
RepoDigests: []string{"repo1@digest1", "repo2@digest2", "123456781234.dkr.ecr.us-west-2.amazonaws.com/test-rci@sha256:d1c14fcf2e9476ed58ebc4251b211f403f271e96b6c3d9ada0f1c5454ca4d230"},
},
},
{
container: &apicontainer.Container{
Name: "testContainer7",
Image: "123456781234.dkr.ecr.us-west-2.amazonaws.com/ubuntu:trusty",
ImageDigest: "sha256:2feffff9eeca4e736f9f8e57813a97fe930554f474f7795ffa5a9261adeaaf44",
RegistryAuthentication: &apicontainer.RegistryAuthenticationData{
Type: "ecr",
ECRAuthData: &apicontainer.ECRAuthData{
RegistryID: "123456781234",
},
},
},
imageInspected: &types.ImageInspect{
RepoDigests: []string{"repo1@digest1", "repo2@digest2", "", "123456781234.dkr.ecr.us-west-2.amazonaws.com/ubuntu@sha256:2feffff9eeca4e736f9f8e57813a97fe930554f474f7795ffa5a9261adeaaf44"},
},
},
}

for i, test := range testCases {
Expand Down

0 comments on commit 699e9ef

Please sign in to comment.