Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from kubearchive/github-ci
Browse files Browse the repository at this point in the history
feat: CI via GitHub Actions
  • Loading branch information
adambkaplan committed Dec 13, 2023
2 parents 6bbfba7 + 50fa38a commit ca505c5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ci/github

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]

permissions:
contents: read

jobs:
unit:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
cache: true
check-latest: true
- name: Lint
run: make lint
- name: Build
run: make build
- name: Test
run: make test
3 changes: 2 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func main() {
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&eventsSource, "events-source-uri-ref", "locahost", "Source of the CloudEvent as a URI reference. The source plus ID of a CloudEvent should be uniquely identifiable.")
flag.StringVar(&eventsSource, "events-source-uri-ref", "locahost",
"Source of the CloudEvent as a URI reference. The source plus ID of a CloudEvent should be uniquely identifiable.")
flag.StringVar(&eventsTargetAddr, "events-target-address", ":8082", "The target address to send CloudEvents to.")
opts := &zap.Options{
Development: true,
Expand Down
12 changes: 8 additions & 4 deletions internal/controller/job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func (r *JobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
eventCtx := cloudevents.ContextWithTarget(ctx, r.EventsTarget)

job := &batchv1.Job{}
event := r.newEvent(req.NamespacedName)
event, err := r.newEvent(req.NamespacedName)
if err != nil {
log.Error(err, "failed to create event")
return ctrl.Result{}, err
}
if err := r.Get(ctx, req.NamespacedName, job); err != nil {
// If not found, return error for requeue
if !errors.IsNotFound(err) {
Expand All @@ -76,17 +80,17 @@ func (r *JobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
return ctrl.Result{}, nil
}

func (r *JobReconciler) newEvent(key types.NamespacedName) cloudevents.Event {
func (r *JobReconciler) newEvent(key types.NamespacedName) (cloudevents.Event, error) {
event := cloudevents.NewEvent()
event.SetSource(r.EventsSource)
event.SetType("dynowatch.kubearchive.dev")
event.SetData(cloudevents.ApplicationJSON, map[string]string{
err := event.SetData(cloudevents.ApplicationJSON, map[string]string{
"kind": "Job",
"apiVersion": "batch/v1",
"namespace": key.Namespace,
"name": key.Name,
})
return event
return event, err
}

// SetupWithManager sets up the controller with the Manager.
Expand Down

0 comments on commit ca505c5

Please sign in to comment.