gitlab

package
v0.17.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2020 License: Apache-2.0 Imports: 0 Imported by: 0

README

GitLab Event Source for Knative

GitLab Source example shows how to wire GitLab events for consumption by a Knative Service.

Deploy the GitLab source controller

We recommend to use ko tool to deploy GitLab source:

ko apply -f gitlab/config/

Check that the manager is running:

kubectl -n knative-sources get pods gitlab-controller-manager-0

With the controller running you can now move on to a user persona and setup a GitLab webhook as well as a function that will consume GitLab events.

Using the GitLab Event Source

You are now ready to use the Event Source and trigger functions based on GitLab projects events.

We will:

  • Create a Knative service which will receive the events. To keep things simple this service will simply dump the events to stdout, this is the so-called: event_display
  • Create a GitLab access token and a random secret token used to secure the webhooks
  • Create the event source by posting a GitLab source object manifest to Kubernetes
Create a Knative Service

Create a simple Knative service that dumps incoming messages to its log. The event-display.yaml file defines this basic service which will receive the configured GitLab event from the GitLabSource object.

kubectl -n default apply -f samples/event-display.yaml
Create GitLab Tokens
  1. Create a personal access token which the GitLab source will use to register webhooks with the GitLab API. The token must have an "api" access scope in order to create repository webhooks. Also decide on a secret token that your code will use to authenticate the incoming webhooks from GitLab.

  2. Update a secret defined in secret.yaml:

    accessToken is the personal access token created in step 1 and secretToken is any token of your choosing.

    Hint: you can generate a random secretToken with:

    head -c 8 /dev/urandom | base64
    
  3. Apply the gitlabsecret using kubectl.

    kubectl -n default apply -f samples/secret.yaml
    
Create Event Source for GitLab Events
  1. In order to receive GitLab events, you have to create a concrete Event Source for a specific namespace. Replace the projectUrl value in the file gitlabsource.yaml with your GitLab username and project name. For example, if your repo URL is https://gitlab.com/knative-examples/functions then use it as the value for projectUrl.

  2. Apply the yaml file using kubectl:

    kubectl -n default apply -f samples/gitlabsource.yaml
    
Verify

Verify the GitLab webhook was created by looking at the list of webhooks under Settings >> Integrations in your GitLab project. A hook should be listed that points to your Knative cluster.

Create a push event and check the logs of the Pod backing the gitlab-event-display knative service. You will see the GitLab event:

☁️  cloudevents.Event
Validation: valid
Context Attributes,
  specversion: 0.3
  type: dev.knative.sources.gitlabsource.Push Hook
  source: https://gitlab.com/<user>/<project>
  id: f83c080f-c2af-48ff-8d8b-fd5b21c5938e
  time: 2020-03-12T11:08:41.414572482Z
  datacontenttype: application/json
Data,
  {
   <Event payload>
  }

Documentation

Index

Constants

View Source
const (
	AccessTokenKey = "accessToken"
	VolumeName     = "gitlab-binding"
	MountPath      = "/var/bindings/gitlab"
)

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd
Package config is a placeholder that allows us to pull in config files via go mod vendor.
Package config is a placeholder that allows us to pull in config files via go mod vendor.
pkg
apis
Package apis contains Kubernetes API groups.
Package apis contains Kubernetes API groups.
apis/bindings/v1alpha1
Package v1alpha1 contains API Schema definitions for the sources v1alpha1 API group +k8s:openapi-gen=true +k8s:deepcopy-gen=package,register +k8s:defaulter-gen=TypeMeta +groupName=bindings.knative.dev
Package v1alpha1 contains API Schema definitions for the sources v1alpha1 API group +k8s:openapi-gen=true +k8s:deepcopy-gen=package,register +k8s:defaulter-gen=TypeMeta +groupName=bindings.knative.dev
apis/sources
Package sources contains sources API versions
Package sources contains sources API versions
apis/sources/v1alpha1
Package v1alpha1 contains API Schema definitions for the sources v1alpha1 API group +k8s:openapi-gen=true +k8s:deepcopy-gen=package,register +k8s:conversion-gen=knative.dev/eventing-contrib/gitlab/pkg/apis/sources +k8s:defaulter-gen=TypeMeta +groupName=sources.knative.dev Package v1alpha1 contains API Schema definitions for the sources v1alpha1 API group +k8s:openapi-gen=true +k8s:deepcopy-gen=package,register +k8s:conversion-gen=knative.dev/eventing-contrib/gitlab/pkg/apis/sources +k8s:defaulter-gen=TypeMeta +groupName=sources.knative.dev
Package v1alpha1 contains API Schema definitions for the sources v1alpha1 API group +k8s:openapi-gen=true +k8s:deepcopy-gen=package,register +k8s:conversion-gen=knative.dev/eventing-contrib/gitlab/pkg/apis/sources +k8s:defaulter-gen=TypeMeta +groupName=sources.knative.dev Package v1alpha1 contains API Schema definitions for the sources v1alpha1 API group +k8s:openapi-gen=true +k8s:deepcopy-gen=package,register +k8s:conversion-gen=knative.dev/eventing-contrib/gitlab/pkg/apis/sources +k8s:defaulter-gen=TypeMeta +groupName=sources.knative.dev
client/clientset/versioned
This package has the automatically generated clientset.
This package has the automatically generated clientset.
client/clientset/versioned/fake
This package has the automatically generated fake clientset.
This package has the automatically generated fake clientset.
client/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
This package contains the scheme of the automatically generated clientset.
client/clientset/versioned/typed/bindings/v1alpha1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
client/clientset/versioned/typed/bindings/v1alpha1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.
client/clientset/versioned/typed/sources/v1alpha1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
client/clientset/versioned/typed/sources/v1alpha1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL