Skip to content

Commit

Permalink
GH actions - PR tests and code coverage (#20)
Browse files Browse the repository at this point in the history
* GH actions - PR tests

* Add code owners
  • Loading branch information
jayanthvn committed Aug 21, 2023
1 parent 8f255a4 commit 8d5c893
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 9 deletions.
35 changes: 35 additions & 0 deletions .github/.codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# To validate:
# cat codecov.yml | curl --data-binary @- https://codecov.io/validate

codecov:
# Avoid "Missing base report"
# https://docs.codecov.io/docs/comparing-commits
allow_coverage_offsets: true
notify:
require_ci_to_pass: yes

coverage:
precision: 2
round: down
range: "50...75"

status:
project:
default:
threshold: 1
unittest:
threshold: 1
only_pulls: true
flags:
- "unittest"
# Disable patch since it is noisy and not correct
patch:
default:
enabled: no
if_not_found: success

comment: false

ignore:
- "api/v1alpha1/**/*"
- "hack/**/*"
7 changes: 7 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#package-ecosystem
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "monthly"
51 changes: 51 additions & 0 deletions .github/workflows/pr-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Automatic Pull Request test

on:
pull_request:
branches:
- "main"

permissions:
contents: read

jobs:
unit-test:
name: Unit test
runs-on: ubuntu-latest
steps:
- name: Checkout latest commit in the PR
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.20"
- name: Set up tools
run: |
go install golang.org/x/lint/golint@latest
go install golang.org/x/tools/cmd/goimports@latest
- name: Run code checks
run: |
make check-format
make vet
- name: Build
run: make build
- name: Unit test
run: make test
- name: Upload code coverage
uses: codecov/codecov-action@v3
docker-build:
name: Build Docker images
runs-on: ubuntu-latest
steps:
- name: Checkout latest commit in the PR
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.20"
- name: Build Network Policy Controller images
run: make docker-buildx
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @aws/eks-networking
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,14 @@ GO_RUNNER_IMAGE=public.ecr.aws/eks-distro/kubernetes/go-runner:v0.15.0-eks-1-27-
.PHONY: docker-buildx
docker-buildx: test
docker buildx build --platform=$(PLATFORMS) -t $(IMG)-$(GOARCH) --build-arg BASE_IMAGE=$(BASE_IMAGE) --build-arg BUILD_IMAGE=$(BUILD_IMAGE) --build-arg $(GOARCH) --load .

# Check formatting of source code files without modification.
check-format: FORMAT_FLAGS = -l
check-format: format

format: ## Format all Go source code files.
@command -v goimports >/dev/null || { echo "ERROR: goimports not installed"; exit 1; }
@exit $(shell find ./* \
-type f \
-name '*.go' \
-print0 | sort -z | xargs -0 -- goimports $(or $(FORMAT_FLAGS),-w) | wc -l | bc)
2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/eventhandlers/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eventhandlers

import (
"context"

"github.com/aws/amazon-network-policy-controller-k8s/pkg/k8s"
"github.com/aws/amazon-network-policy-controller-k8s/pkg/resolvers"

Expand Down
3 changes: 2 additions & 1 deletion internal/eventhandlers/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package eventhandlers

import (
"context"
"github.com/aws/amazon-network-policy-controller-k8s/pkg/resolvers"
"time"

"github.com/aws/amazon-network-policy-controller-k8s/pkg/resolvers"

"github.com/aws/amazon-network-policy-controller-k8s/pkg/k8s"
"github.com/go-logr/logr"
networking "k8s.io/api/networking/v1"
Expand Down
1 change: 1 addition & 0 deletions internal/eventhandlers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package eventhandlers

import (
"context"

"github.com/aws/amazon-network-policy-controller-k8s/pkg/k8s"
"github.com/aws/amazon-network-policy-controller-k8s/pkg/resolvers"
"github.com/go-logr/logr"
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/runtime_config.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package config

import (
"time"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
ctrl "sigs.k8s.io/controller-runtime"
"time"

"github.com/spf13/pflag"
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/k8s/pod_utils_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package k8s

import (
"testing"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"testing"
)

func Test_GetPodIP(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/k8s/service_utils_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package k8s

import (
"testing"

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"testing"
)

func Test_LookupServicePort(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/k8s/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package k8s

import (
"sigs.k8s.io/controller-runtime/pkg/client"
"testing"

"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/stretchr/testify/assert"
networking "k8s.io/api/networking/v1"
rbac "k8s.io/api/rbac/v1"
Expand Down
3 changes: 2 additions & 1 deletion pkg/policyendpoints/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
"golang.org/x/exp/maps"
"strconv"

"golang.org/x/exp/maps"

"github.com/go-logr/logr"
"github.com/pkg/errors"
"github.com/samber/lo"
Expand Down
1 change: 1 addition & 0 deletions pkg/resolvers/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resolvers

import (
"context"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
networking "k8s.io/api/networking/v1"
Expand Down
1 change: 1 addition & 0 deletions pkg/resolvers/policies_for_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resolvers

import (
"context"

"github.com/aws/amazon-network-policy-controller-k8s/pkg/k8s"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
Expand Down
5 changes: 3 additions & 2 deletions pkg/resolvers/policies_for_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package resolvers

import (
"context"
"sort"
"testing"

mock_client "github.com/aws/amazon-network-policy-controller-k8s/mocks/controller-runtime/client"
"github.com/go-logr/logr"
"github.com/golang/mock/gomock"
Expand All @@ -12,8 +15,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"sort"
"testing"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down

0 comments on commit 8d5c893

Please sign in to comment.