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

Add quay webhook #118

Merged
merged 2 commits into from
Jan 15, 2021
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
3 changes: 2 additions & 1 deletion api/v1beta1/receiver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
type ReceiverSpec struct {
// Type of webhook sender, used to determine
// the validation procedure and payload deserialization.
// +kubebuilder:validation:Enum=generic;github;gitlab;bitbucket;harbor;dockerhub
// +kubebuilder:validation:Enum=generic;github;gitlab;bitbucket;harbor;dockerhub;quay
// +required
Type string `json:"type"`

Expand Down Expand Up @@ -69,6 +69,7 @@ const (
BitbucketReceiver string = "bitbucket"
HarborReceiver string = "harbor"
DockerHubReceiver string = "dockerhub"
QuayReceiver string = "quay"
)

func ReceiverReady(receiver Receiver, reason, message, url string) Receiver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ spec:
- bitbucket
- harbor
- dockerhub
- quay
type: string
required:
- resources
Expand Down
2 changes: 1 addition & 1 deletion docs/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ with an exponential backoff of maximum 30 seconds.
The notification controller handles webhook requests on a dedicated port.
This port can be used to create a Kubernetes LoadBalancer Service or
Ingress to expose the receiver endpoint outside the cluster
to be accessed by GitHub, GitLab, Bitbucket, Harbor, DockerHub, Jenkins, etc.
to be accessed by GitHub, GitLab, Bitbucket, Harbor, DockerHub, Jenkins, Quay, etc.

Receiver API:

Expand Down
20 changes: 19 additions & 1 deletion docs/spec/v1beta1/receiver.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ reconciliation for a group of resources.
type ReceiverSpec struct {
// Type of webhook sender, used to determine
// the validation procedure and payload deserialization.
// +kubebuilder:validation:Enum=generic;github;gitlab;harbor;dockerhub
// +kubebuilder:validation:Enum=generic;github;gitlab;harbor;dockerhub;quay
// +required
Type string `json:"type"`

Expand Down Expand Up @@ -44,6 +44,7 @@ const (
BitbucketReceiver string = "bitbucket"
HarborReceiver string = "harbor"
DockerHubReceiver string = "dockerhub"
QuayReceiver string = "quay"
)
```

Expand Down Expand Up @@ -181,6 +182,23 @@ spec:
name: webapp
```

### Quay receiver

```yaml
apiVersion: notification.toolkit.fluxcd.io/v1beta1
kind: Receiver
metadata:
name: quay-receiver
namespace: default
spec:
type: quay
secretRef:
name: webhook-token
resources:
- kind: ImageRepository
name: webapp
```

### Generic receiver

```yaml
Expand Down
15 changes: 15 additions & 0 deletions internal/server/receiver_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ func (s *ReceiverServer) validate(ctx context.Context, receiver v1beta1.Receiver

s.logger.Info("handling Bitbucket server event: "+event, "receiver", receiver.Name)
return nil
case v1beta1.QuayReceiver:
type payload struct {
DockerUrl string `json:"docker_url"`
UpdatedTags []string `json:"updated_tags"`
}

var p payload
if err := json.NewDecoder(r.Body).Decode(&p); err != nil {
return fmt.Errorf("cannot decode Quay webhook payload")
}

s.logger.Info(
fmt.Sprintf("handling event from %s", p.DockerUrl),
"receiver", receiver.Name)
return nil
case v1beta1.HarborReceiver:
if r.Header.Get("Authorization") != token {
return fmt.Errorf("the Harbor Authorization header value does not match the receiver token")
Expand Down