From 20d0dbf9658ef83c8829fcbf84b176fd2963dd71 Mon Sep 17 00:00:00 2001 From: Shinae Woo Date: Tue, 7 May 2024 16:39:38 -0700 Subject: [PATCH 1/2] Add a git workflow for golang linters, test, build Signed-off-by: Shinae Woo --- .github/workflows/go.yml | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..92f2eeb --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,68 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go + +on: + pull_request: + types: + - opened + - synchronize + - reopened + branches: + - main + push: + branches: + - main + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: Lint + uses: golangci/golangci-lint-action@v5 + with: + version: 'v1.58.0' + args: -v --timeout 5m + skip-cache: true + + - name: vet + run: + make vet + + - name: fmt + run: + test -z "$(go fmt ./...)" + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: Test + run: go test -v ./... + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: Build + run: make build From 29b9a9dc6d917eda85402add563e643afc7b63be Mon Sep 17 00:00:00 2001 From: Shinae Woo Date: Wed, 8 May 2024 11:20:10 -0700 Subject: [PATCH 2/2] Fix linter issue Signed-off-by: Shinae Woo --- pkg/engine/check_object_task.go | 5 ++++- pkg/engine/submit_object_task.go | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/engine/check_object_task.go b/pkg/engine/check_object_task.go index a4303ea..8e744f9 100644 --- a/pkg/engine/check_object_task.go +++ b/pkg/engine/check_object_task.go @@ -89,7 +89,7 @@ func (task *CheckObjTask) Exec(ctx context.Context) error { done := make(chan struct{}) defer close(done) - informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ + _, err = informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { resource := obj.(*unstructured.Unstructured) task.log.V(4).Info("Informer added", "resource", info.GVR.Resource, "name", resource.GetName()) @@ -101,6 +101,9 @@ func (task *CheckObjTask) Exec(ctx context.Context) error { task.checkStateAsync(ctx, resource.GetName(), info, nameMap, done) }, }) + if err != nil { + return err + } stopCh := make(chan struct{}) go informer.Run(stopCh) diff --git a/pkg/engine/submit_object_task.go b/pkg/engine/submit_object_task.go index f0f35e1..8ab50ce 100644 --- a/pkg/engine/submit_object_task.go +++ b/pkg/engine/submit_object_task.go @@ -207,10 +207,8 @@ func (task *SubmitObjTask) Exec(ctx context.Context) error { } } - task.setter.SetObjInfo(task.taskID, + return task.setter.SetObjInfo(task.taskID, NewObjInfo([]string{task.obj[0].Metadata.Name}, task.obj[0].Metadata.Namespace, gvr, task.Pods.Names()...)) - - return nil } func (obj *GenericObject) UnmarshalYAML(unmarshal func(interface{}) error) error {