Skip to content

Commit

Permalink
Update github actions and add local test tools
Browse files Browse the repository at this point in the history
This commit adds make targets to install testing tools locally
and run various tests as github actions can not be used locally.
Local tools and github actions share configurations as much as
possible to ensure identical test criteria.

Signed-off-by: Umanga Chapagain <[email protected]>
  • Loading branch information
umangachapagain committed Aug 9, 2021
1 parent 5f4f030 commit 8d9fdde
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 101 deletions.
4 changes: 0 additions & 4 deletions .github/.kube-lint-config.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions .github/workflows/docker-build.yaml

This file was deleted.

38 changes: 0 additions & 38 deletions .github/workflows/golangci-lint.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions .github/workflows/integration-test.yaml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/kube-lint.yaml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Lint Codebase

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'

defaults:
run:
shell: bash

jobs:
golangci-lint:
strategy:
matrix:
go-version: [1.16.x]

name: Go
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.41.1
only-new-issues: true

kube-linter:
name: Kube YAML
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Lint
uses: stackrox/[email protected]
with:
directory: config/
config: .kube-linter-config.yaml
110 changes: 110 additions & 0 deletions .github/workflows/test-and-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Tests & Builds

on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]

env:
GO_VERSION: "1.16"

defaults:
run:
shell: bash

jobs:
clean-workdir:
name: Ensure Clean Workdir
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Scan for uncommitted changes
run: make ensure-clean-workdir

unit-test:
name: Unit Tests
needs: clean-workdir
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Run unit tests
run: make unit-test

integration-test:
name: Integration Tests
needs: clean-workdir
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Run integration tests
run: make test

build-operator:
name: Build Operator Image
needs: [unit-test,integration-test]
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Build
run: make docker-build

validate-bundle:
name: Validate Operator Bundle
needs: clean-workdir
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Validate
run: make bundle

build-bundle:
name: Build Bundle Image
needs: validate-bundle
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Build
run: make bundle-build
43 changes: 43 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This file contains golangci-lint configurations

# options for analysis running
run:
timeout: 5m
modules-download-mode: readonly

linters-settings:
errcheck:
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: true
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: true
gocognit:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 15
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 15
goheader:
template: |
Copyright 2021 Red Hat OpenShift Data Foundation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
misspell:
locale: US

# output configuration options
output:
print-issued-lines: true
sort-results: false
16 changes: 16 additions & 0 deletions .kube-linter-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
checks:
include:
- "cluster-admin-role-binding"
- "exposed-services"
- "privileged-ports"
- "writable-host-mount"
exclude:
- "dangling-service"
- "default-service-account"
- "mismatching-selector"
- "no-read-only-root-fs"
- "non-existent-service-account"
- "run-as-non-root"
- "unset-cpu-requirements"
- "unset-memory-requirements"
- "latest-tag"
24 changes: 19 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

golanci-lint: ## Run golangci-lint against code.
$(GOLANGCI_BIN) run ./...

kube-linter: ## Run kube-linter against YAML files
$(KUBELINTER_BIN) lint ./ --config ./.kube-linter-config.yaml

unit-test: ## Run unit tests
go test ./... -v -tags unit -coverprofile unit-cover.out

Expand All @@ -60,7 +66,7 @@ build: generate fmt vet ## Build manager binary.
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go

docker-build: test ## Build docker image with the manager.
docker-build: generate fmt vet ## Build docker image with the manager.
docker build -t ${IMG} .

docker-push: ## Push docker image with the manager.
Expand All @@ -82,11 +88,11 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
$(KUSTOMIZE) build config/default | kubectl delete -f -

.PHONY: bundle
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
$(OSDK) generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle
$(KUSTOMIZE) build config/manifests | $(OSDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
$(OSDK) bundle validate ./bundle

.PHONY: bundle-build
bundle-build: ## Build the bundle image.
Expand All @@ -103,3 +109,11 @@ catalog-build: opm ## Build a catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

##@ Actions

ensure-clean-workdir: ## Ensure all required changes are generated and committed
go mod tidy
$(MAKE) manifests generate fmt vet
git --no-pager diff
git status --porcelain 2>&1 | tee /dev/stderr | (! read)
Loading

0 comments on commit 8d9fdde

Please sign in to comment.