Skip to content

Commit

Permalink
when image in imagerepository Spec.Image.Name is already specified, d…
Browse files Browse the repository at this point in the history
…on't

add namespace if it is already there

STONEBLD-2530

Signed-off-by: Robert Cerven <[email protected]>
  • Loading branch information
rcerven committed Jun 17, 2024
1 parent eee407f commit 6fd237a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
6 changes: 5 additions & 1 deletion controllers/imagerepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ func (r *ImageRepositoryReconciler) ProvisionImageRepository(ctx context.Context
imageRepositoryName = imageRepository.Namespace + "/" + imageRepository.Name
}
} else {
imageRepositoryName = imageRepository.Namespace + "/" + imageRepository.Spec.Image.Name
if strings.HasPrefix(imageRepository.Spec.Image.Name, "/"+imageRepository.Namespace+"/") || strings.HasPrefix(imageRepository.Spec.Image.Name, imageRepository.Namespace+"/") {
imageRepositoryName = imageRepository.Spec.Image.Name
} else {
imageRepositoryName = imageRepository.Namespace + "/" + imageRepository.Spec.Image.Name
}
}
imageRepository.Spec.Image.Name = imageRepositoryName

Expand Down
33 changes: 31 additions & 2 deletions controllers/imagerepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ var _ = Describe("Image repository controller", func() {
expectedImage string
)

BeforeEach(func() {
createNamespace(defaultNamespace)
})

Context("Image repository provision", func() {

BeforeEach(func() {
quay.ResetTestQuayClientToFails()
})

It("should prepare environment", func() {
createNamespace(defaultNamespace)

pushToken = "push-token1234"
expectedImageName = fmt.Sprintf("%s/%s", defaultNamespace, defaultImageRepositoryName)
expectedImage = fmt.Sprintf("quay.io/%s/%s", quay.TestQuayOrg, expectedImageName)
Expand Down Expand Up @@ -563,6 +565,33 @@ var _ = Describe("Image repository controller", func() {
imageRepository := getImageRepository(resourceKey)
Expect(imageRepository.Spec.Image.Name).To(Equal(expectedImageName))
})

It("should create image repository with requested name, includes already namespace", func() {
customImageName := defaultNamespace + "/" + "my-image-with-namespace"
expectedImageName = customImageName

isCreateRepositoryInvoked := false
quay.CreateRepositoryFunc = func(repository quay.RepositoryRequest) (*quay.Repository, error) {
defer GinkgoRecover()
isCreateRepositoryInvoked = true
Expect(repository.Repository).To(Equal(expectedImageName))
Expect(repository.Namespace).To(Equal(quay.TestQuayOrg))
Expect(repository.Visibility).To(Equal("public"))
Expect(repository.Description).ToNot(BeEmpty())
return &quay.Repository{Name: expectedImageName}, nil
}

createImageRepository(imageRepositoryConfig{ImageName: customImageName})
defer deleteImageRepository(resourceKey)

Eventually(func() bool { return isCreateRepositoryInvoked }, timeout, interval).Should(BeTrue())

waitImageRepositoryFinalizerOnImageRepository(resourceKey)

imageRepository := getImageRepository(resourceKey)
Expect(imageRepository.Spec.Image.Name).To(Equal(expectedImageName))
})

})

Context("Image repository error scenarios", func() {
Expand Down

0 comments on commit 6fd237a

Please sign in to comment.