Skip to content

Commit

Permalink
Report integration (F5Networks#3506)
Browse files Browse the repository at this point in the history
* Adding support for ignore coverage

* Adding support for coverage and unit test case reports
  • Loading branch information
vklohiya authored Aug 6, 2024
1 parent c200ed8 commit 9a08de1
Show file tree
Hide file tree
Showing 438 changed files with 41,110 additions and 16,591 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ debian/*.substvars
*.rel
coverage.out
coverage.html
report.xml
python/.cache
/venv.local
*.coverprofile
Expand Down
31 changes: 28 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ all: local-build

test: local-go-test

coverage: local-go-coverage

create-coverage-report: create-coverage-report

prod: prod-build

verify: fmt vet
Expand Down Expand Up @@ -55,8 +59,29 @@ info:
# Disable builtin implicit rules
.SUFFIXES:

local-go-test: local-build check-gopath
ginkgo ./pkg/... ./cmd/...
local-go-coverage:
go install github.com/Azure/gocover@latest
$(GOPATH)/bin/gocover test --repository-path=. --coverage-mode full --executor-mode go --excludes "**/config/**,**/vlogger/**,**/test/**,**/prometheus/**,**/mockmanager/**" --outputdir ./
awk "!/\/config\/|vlogger|prometheus|mockmanager|\/test\/test/" coverage.out >coverage-new.out
mv coverage-new.out coverage.out
grep "Coverage (with ignorance)" coverage.html | head -1 | awk 'END { print "Total coverage:", $$4, "of statements" }'
#go tool cover -func=coverage.out | grep "^total:" | awk 'END { print "Total coverage:", $$3, "of statements" }'
@if [ $(COVERALLS_TOKEN) ]; then \
go install github.com/mattn/goveralls@latest; \
echo "Pushing coverage data to coveralls"; \
$(GOPATH)/bin/goveralls -coverprofile=./coverage.out -service=azure; \
fi

local-go-test:
go install github.com/onsi/ginkgo/v2/ginkgo
go install github.com/onsi/gomega
$(GOPATH)/bin/ginkgo -r --procs=4 --compilers=1 --randomize-all --randomize-suites --fail-on-pending --keep-going --trace --junit-report=report.xml --timeout=300s --flake-attempts=3 --succinct

create-coverage-report: local-go-coverage
go install github.com/axw/gocov/gocov@latest
go install github.com/AlekSi/gocov-xml@latest
$(GOPATH)/bin/gocov convert coverage.out > coverage.json
$(GOPATH)/bin/gocov-xml < coverage.json > coverage.xml

local-build: check-gopath
GOBIN=$(GOBIN) go install $(GO_BUILD_FLAGS) ./pkg/... ./cmd/...
Expand Down Expand Up @@ -152,4 +177,4 @@ endif

crd-code-gen:
docker run --platform linux/amd64 --name crdcodegen -v $(PWD):/go/src/github.com/F5Networks/k8s-bigip-ctlr/v3 quay.io/f5networks/ciscrdcodegen:v1
docker rm crdcodegen
docker rm crdcodegen
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


F5 BIG-IP Container Ingress Services for Kubernetes & OpenShift
========================================================
===============================================================

The F5 BIG-IP Container Ingress Services for [Kubernetes](https://kubernetes.io/) and [OpenShift](https://www.openshift.com/) makes F5 [BIG-IP](https://www.f5.com/products/big-ip-services) services available to applications running in Kubernetes and OpenShift.

Expand Down
58 changes: 51 additions & 7 deletions azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,69 @@ variables:
operatorImageName: 'f5networks/f5-cis-operator-devel'
operatorBundleImageName: 'f5networks/f5-cis-operator-bundle-devel'
operatorIndexImage: 'f5networks/f5-cis-operator-index-devel'
goVersion: 1.21.4
goVersion: 1.22.3

stages:
- stage: PreCheck
- stage: VerifyFormatting
dependsOn: []
jobs:
- job: Preverification
- job: VerifyFormatting
steps:
- task: GoTool@0
inputs:
version: $(goVersion)
displayName: Install Go 1.21.4
displayName: Install Go
- task: CmdLine@2
displayName: Check Go format and Suspicious constructs
inputs:
script: 'make verify'
- stage: RunUnitTests
dependsOn: []
jobs:
- job: RunUnitTests
steps:
- task: CmdLine@2
displayName: Check for unit tests
inputs:
script: |
docker run -t -v $(System.DefaultWorkingDirectory):/go/src/github.com/F5Networks/k8s-bigip-ctlr -w /go/src/github.com/F5Networks/k8s-bigip-ctlr --rm golang:$(goVersion) make test
- task: PublishTestResults@2
displayName: Publish Test Results
inputs:
testRunner: JUnit
testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml
- stage: RunCoverage
dependsOn: []
jobs:
- job: RunCoverage
steps:
- task: CmdLine@2
displayName: Check for Coverage
inputs:
script: |
docker run -t -v $(System.DefaultWorkingDirectory):/go/src/github.com/F5Networks/k8s-bigip-ctlr -w /go/src/github.com/F5Networks/k8s-bigip-ctlr --rm golang:$(goVersion) make create-coverage-report
mkdir -p $(System.DefaultWorkingDirectory)/coverage
cp -r coverage.html $(System.DefaultWorkingDirectory)/coverage
- task: PublishCodeCoverageResults@2
displayName: Publish Code Coverage Results
inputs:
pathToSources: $(System.DefaultWorkingDirectory)
summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml
failIfCoverageEmpty: true
- stage: CheckDocumentation
dependsOn: []
jobs:
- job: CheckDocumentation
steps:
- task: CmdLine@2
displayName: Check documentation
inputs:
script: 'make docs'
- stage: ContainerImage
dependsOn: PreCheck
dependsOn:
- VerifyFormatting
- RunUnitTests
- RunCoverage
jobs:
- job: BuildContainerImage
steps:
Expand Down Expand Up @@ -93,7 +135,7 @@ stages:
Dockerfile: build-tools/Dockerfile.ubi
buildContext: .
tags: "$(BUILD_VERSION)-$(Build.SourceVersion)"
arguments: "--build-arg BUILD_INFO=azure-$(Build.BuildId)-$(Build.SourceVersion) --build-arg BUILD_VERSION=$(BUILD_VERSION) --build-arg RUN_TESTS=$(RUN_TESTS) --build-arg COVERALLS_TOKEN=$(COVERALLS_TOKEN)"
arguments: "--build-arg BUILD_INFO=azure-$(Build.BuildId)-$(Build.SourceVersion) --build-arg BUILD_VERSION=$(BUILD_VERSION)"
- task: Docker@2
displayName: Push image to Quay
inputs:
Expand Down Expand Up @@ -124,8 +166,10 @@ stages:
docker push $(docker_repo):$(BUILD_VERSION)
displayName: 'Push image to DockerHub'
condition: startsWith(variables['build.sourceBranch'], 'refs/tags/')
- stage: ScanContainerImage
dependsOn: ContainerImage
jobs:
- job: ScanContainerImage
dependsOn: BuildContainerImage
steps:
- script: |
FILE_VALUE=$(cat next-version.txt)
Expand Down
2 changes: 0 additions & 2 deletions build-tools/Dockerfile.ubi
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
FROM golang:1.21 as builder

ARG REPOPATH=$GOPATH/src/github.com/F5Networks/k8s-bigip-ctlr
ARG RUN_TESTS
ARG COVERALLS_TOKEN
ARG BUILD_VERSION
ARG BUILD_INFO

Expand Down
50 changes: 0 additions & 50 deletions build-tools/_build-lib.sh

This file was deleted.

30 changes: 9 additions & 21 deletions build-tools/rel-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,18 @@

set -ex

if [[ $BUILD_VERSION == "" ]]; then
echo "Must set BUILD_VERSION"
false
fi
if [[ $BUILD_INFO == "" ]]; then
echo "Must set BUILD_INFO"
false
fi

go mod download

CGO_ENABLED=0
GOOS=linux
GOARCH=amd64
go build -v -ldflags "-extldflags \"-static\" -X main.version=${BUILD_VERSION} -X main.buildInfo=${BUILD_INFO}" -o /bin/k8s-bigip-ctlr $REPOPATH/cmd/k8s-bigip-ctlr

RUN_TESTS=${RUN_TESTS:-1}

. $REPOPATH/build-tools/_build-lib.sh

if [ $RUN_TESTS -eq 1 ]; then
go get github.com/onsi/ginkgo/[email protected]
go get github.com/onsi/[email protected]
go install github.com/onsi/ginkgo/[email protected]
go install github.com/quantumcycle/go-ignore-cov@latest
GO111MODULE=off
go get github.com/wadey/gocovmerge
go get github.com/mattn/goveralls
echo "Gathering unit test code coverage for 'release' build..."
ginkgo_test_with_coverage
# push coverage data to coveralls if F5 repo or if configured for fork.
if [ "$COVERALLS_TOKEN" ]; then
echo "Pushing coverage data to coveralls"
goveralls -coverprofile=./coverage.out -service=azure
fi
fi
2 changes: 1 addition & 1 deletion cmd/k8s-bigip-ctlr/k8s_bigip_ctlr_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"testing"
Expand Down
44 changes: 23 additions & 21 deletions cmd/k8s-bigip-ctlr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,15 @@ func getCredentials() error {
}

func main() {
//coverage:ignore
defer func() {
if r := recover(); r != nil {
return
{ // +gocover:ignore:block as main function can not be run in unit tests
defer func() {
if r := recover(); r != nil {
return
}
}()
if err := run(os.Args, flags.Parse); err != nil {
os.Exit(1)
}
}()
if err := run(os.Args, flags.Parse); err != nil {
os.Exit(1)
}
}

Expand Down Expand Up @@ -347,21 +348,23 @@ func run(args []string, parseFunc func([]string) error) error {
}

err = initClientSets(config, kubernetes.NewForConfig, versioned.NewForConfig, routeclient.NewForConfig)
if err != nil {
if err != nil { // +gocover:ignore:block ignore coverage for error handling
log.Errorf("[INIT] error connecting to the client: %v", err)
return err
}
userAgentInfo = getUserAgentInfo(clientSets.KubeClient.Discovery().RESTClient())
ctlr := initController(config)

// TODO initialize and add support for teems data
initTeems(ctlr)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigs
ctlr.Stop()
log.Debugf("Exiting - signal %v\n", sig)
return nil
{ // +gocover:ignore:block ignore coverage
userAgentInfo = getUserAgentInfo(clientSets.KubeClient.Discovery().RESTClient())
ctlr := initController(config)

// TODO initialize and add support for teems data
initTeems(ctlr)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigs
ctlr.Stop()
log.Debugf("Exiting - signal %v\n", sig)
return nil
}
}

func initClientSets(
Expand Down Expand Up @@ -399,8 +402,7 @@ func initClientSets(

func initController(
config *rest.Config,
) *controller.Controller {
//coverage:ignore
) *controller.Controller { //+gocover:ignore:block run controller function can not be run in unit tests
ctlr := controller.RunController(
controller.Params{
Config: config,
Expand Down
5 changes: 1 addition & 4 deletions cmd/k8s-bigip-ctlr/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"fmt"
"github.com/F5Networks/k8s-bigip-ctlr/v3/config/client/clientset/versioned"
"github.com/F5Networks/k8s-bigip-ctlr/v3/pkg/controller"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
routeclient "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -567,9 +567,6 @@ var _ = Describe("Run", func() {
})

Context("when getCredentials returns an error", func() {
BeforeEach(func() {

})

It("should return an error", func() {
defer _init()
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.. include:: RELEASE-NOTES.rst
.. include:: ./cis-3.x/RELEASE-NOTES.rst

.. include:: ../README.md
Loading

0 comments on commit 9a08de1

Please sign in to comment.