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

Quay notification support for ImageRepository #112

Merged
merged 1 commit into from
May 29, 2024

Conversation

Allda
Copy link
Contributor

@Allda Allda commented May 17, 2024

The ImageRepository CR is extended to allow defining a Quay notifications. The notification schema is based on Quay API schema and supports webhook and email configuration.

Quay notification is created using the rest API client and added to a CR status field.

JIRA: ISV-4756

Example:

apiVersion: appstudio.redhat.com/v1alpha1
kind: ImageRepository
metadata:
  name: imagerepository-sample
  namespace: image-controller-system
spec:
  notifications:
    - title: MyNotif
      event: repo_push
      method: webhook 
      config: 
        url: https://foo.com

Update CR after a notification was set:

apiVersion: appstudio.redhat.com/v1alpha1
kind: ImageRepository
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"appstudio.redhat.com/v1alpha1","kind":"ImageRepository","metadata":{"annotations":{},"name":"imagerepository-sample-10","namespace":"image-controller-system"},"spec":{"notifications":[{"config":{"url":"https://foo.com"},"event":"repo_push","method":"webhook","title":"MyNofif"}]}}
  resourceVersion: '1822153325'
  name: imagerepository-sample-10
  uid: cc5e5c92-de44-4661-aceb-f4c5389037d3
  creationTimestamp: '2024-05-16T12:21:55Z'
  generation: 3
  namespace: image-controller-system
  finalizers:
    - appstudio.openshift.io/image-repository
spec:
  image:
    name: image-controller-system/imagerepository-sample-10
    visibility: public
  notifications:
    - config:
        url: 'https://foo.com'
      event: repo_push
      method: webhook
      title: MyNofif
    - config:
        url: 'https://examples.com'
      event: repo_push
      method: webhook
      title: MyNofif-2
status:
  credentials:
    generationTimestamp: '2024-05-16T12:21:56Z'
    push-remote-secret: imagerepository-sample-10-image-push
    push-robot-account: image_controller_system_imagerepository_sample_10_8d83bb7277
    push-secret: imagerepository-sample-10-image-push
  image:
    url: quay.io/isv_org_123/image-controller-system/imagerepository-sample-10
    visibility: public
  notifications:
    - title: MyNofif
      uuid: 68eaeac8-c0f8-46c1-8a86-8641c19a0ccd
  state: ready

@openshift-ci openshift-ci bot requested review from mmorhun and psturc May 17, 2024 11:14
@Allda Allda marked this pull request as draft May 17, 2024 11:14
Copy link

openshift-ci bot commented May 17, 2024

Hi @Allda. Thanks for your PR.

I'm waiting for a konflux-ci member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@Allda Allda marked this pull request as ready for review May 20, 2024 11:04
Copy link
Collaborator

@mmorhun mmorhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation is missing removal of the notifications. As a user I can edit the CR and add/remove the notifications.
Will quay automatically cleanup notifications on the image repository deletion?

@@ -1,6 +1,8 @@
module github.com/redhat-appstudio/image-controller

go 1.20
go 1.21
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to do the update?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to run in locally with the previous version and since the new version was already available I bumped it up.

api/v1alpha1/imagerepository_types.go Show resolved Hide resolved
controllers/imagerepository_controller.go Outdated Show resolved Hide resolved
controllers/imagerepository_controller.go Outdated Show resolved Hide resolved

for _, notification := range imageRepository.Spec.Notifications {
log.Info("Creating notification in Quay", "Title", notification.Title, "Event", notification.Event, "Method", notification.Method)
quayNotification, err := r.QuayClient.CreateNotification(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will return an error if this function is called second time.
See how, for example, CreateRobotAccount is implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated code to not create a duplicated entries if a notification already exists.

@Allda
Copy link
Contributor Author

Allda commented May 22, 2024

The implementation is missing removal of the notifications. As a user I can edit the CR and add/remove the notifications. Will quay automatically cleanup notifications on the image repository deletion?

We currently don't have a planned workflow for the removal event. But yeah once the repo is removed all notifications are removed as well.

pkg/quay/quay_debug_test.go Outdated Show resolved Hide resolved
func (r *ImageRepositoryReconciler) AddNotifications(ctx context.Context, imageRepository *imagerepositoryv1alpha1.ImageRepository) ([]imagerepositoryv1alpha1.NotificationStatus, error) {
log := ctrllog.FromContext(ctx).WithName("ConfigureNotifications")

if imageRepository.Spec.Notifications == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check it before calling this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check what?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imageRepository.Spec.Notifications?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aha, I didn't want to add extra complexity to the parent function and instead return early from this one in case notifications are not set.

controllers/imagerepository_controller.go Outdated Show resolved Hide resolved
@@ -319,6 +364,11 @@ func (r *ImageRepositoryReconciler) ProvisionImageRepository(ctx context.Context
}
}

var notificationStatus []imagerepositoryv1alpha1.NotificationStatus
if notificationStatus, err = r.AddNotifications(ctx, imageRepository); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add the notifications on image repository creation only or at any point?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the current usecase that we have it is fine to create a notification on CR creation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to be implemented in follow up PR.

@mmorhun
Copy link
Collaborator

mmorhun commented May 27, 2024

/retest

Copy link
Collaborator

@mmorhun mmorhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To have a complete feature we have to implement editing and removing of the notifications.
But to not to block the functionality die date, we can merge this and improve later.

You can ignore EC failure, it's not related to the changes in this PR.

controllers/suite_util_test.go Outdated Show resolved Hide resolved
The ImageRepository CR is extended to allow defining a Quay
notifications. The notification schema is based on Quay API schema and
supports webhook and email configuration.

Quay notification is created using the rest API client and added to a CR
status field.

JIRA: ISV-4756

Example:

apiVersion: appstudio.redhat.com/v1alpha1
kind: ImageRepository
metadata:
  name: imagerepository-sample
  namespace: image-controller-system
spec:
  notifications:
    - title: MyNotif
      event: repo_push
      method: webhook
      config:
        url: https://foo.com

Signed-off-by: Ales Raszka <[email protected]>
@openshift-ci openshift-ci bot added the lgtm label May 29, 2024
@mmorhun
Copy link
Collaborator

mmorhun commented May 29, 2024

/ok-to-test

@mmorhun mmorhun merged commit 4577b7f into konflux-ci:main May 29, 2024
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants