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 (#125)

add namespace if it is already there

STONEBLD-2530

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

Please sign in to comment.