Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when image in imagerepository Spec.Image.Name is already specified, d… #125

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
mmorhun marked this conversation as resolved.
Show resolved Hide resolved

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
Loading