Skip to content

Commit

Permalink
Merge pull request #3 from mikenairn/add_gh_workflows_and_local_setup
Browse files Browse the repository at this point in the history
Add local-setup and CI GH Workflow
  • Loading branch information
mikenairn authored Feb 2, 2024
2 parents 8d61efa + abb1ebd commit b81ed4b
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 3 deletions.
111 changes: 111 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: CI

on:
push:
branches:
- main
- "release-*"
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
paths-ignore:
- '**.adoc'
- '**.md'
- 'samples/**'
- 'LICENSE'
pull_request:
branches:
- main
- "release-*"
paths-ignore:
- '**.adoc'
- '**.md'
- 'samples/**'
- 'LICENSE'

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: v1.21.x
cache: false
- uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
only-new-issues: true
args: --timeout=5m
verify-code:
name: Verify code
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.21.x
uses: actions/setup-go@v4
with:
go-version: 1.21.x
cache: false
id: go
- name: Check out code
uses: actions/checkout@v4
- name: Run make verify-code
run: |
make verify-code
verify-manifests:
name: Verify manifests
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.21.x
uses: actions/setup-go@v4
with:
go-version: 1.21.x
cache: false
id: go
- name: Check out code
uses: actions/checkout@v4
- name: Run make verify-manifests
run: |
make verify-manifests
verify-bundle:
name: Verify bundle
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.21.x
uses: actions/setup-go@v4
with:
go-version: 1.21.x
cache: false
id: go
- name: Check out code
uses: actions/checkout@v4
- name: Run make verify-bundle
run: |
make verify-bundle
verify-imports:
name: Verify imports
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.21.x
uses: actions/setup-go@v4
with:
go-version: 1.21.x
cache: false
id: go
- name: Check out code
uses: actions/checkout@v4
- name: Run make verify-manifests
run: |
make verify-imports
unit_test_suite:
name: Unit Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: v1.21
cache: false
- name: Run suite
run: |
make test
5 changes: 5 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# https://golangci-lint.run/usage/linters/
linters:
enable:
- gofmt
- misspell
28 changes: 25 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

.PHONY: lint
lint: ## Run golangci-lint against code.
golangci-lint run ./...

.PHONY: imports
imports: openshift-goimports ## Run openshift goimports against code.
$(OPENSHIFT_GOIMPORTS) -m github.com/kuadrant/kuadrant-dns-operator -i github.com/kuadrant/kuadrant-operator
Expand All @@ -119,6 +123,14 @@ imports: openshift-goimports ## Run openshift goimports against code.
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

.PHONY: local-setup
local-setup: $(KIND) ## Setup local development kind cluster and dependencies
$(MAKE) kind-delete-cluster
$(MAKE) kind-create-cluster

.PHONY: local-deploy
local-deploy: docker-build kind-load-image deploy ## Deploy the dns operator into local kind cluster from the current code

##@ Build

.PHONY: build
Expand Down Expand Up @@ -174,11 +186,11 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
$(KUSTOMIZE) build config/deploy/local | $(KUBECTL) apply -f -

.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
$(KUSTOMIZE) build config/deploy/local | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -

##@ Build Dependencies

Expand All @@ -193,11 +205,13 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
OPENSHIFT_GOIMPORTS ?= $(LOCALBIN)/openshift-goimports
KIND = $(LOCALBIN)/kind

## Tool Versions
KUSTOMIZE_VERSION ?= v5.0.1
CONTROLLER_TOOLS_VERSION ?= v0.12.0
OPENSHIFT_GOIMPORTS_VERSION ?= c70783e636f2213cac683f6865d88c5edace3157
KIND_VERSION = v0.20.0

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
Expand Down Expand Up @@ -238,9 +252,14 @@ endif

.PHONY: openshift-goimports
openshift-goimports: $(OPENSHIFT_GOIMPORTS) ## Download openshift-goimports locally if necessary
$(OPENSHIFT_GOIMPORTS):
$(OPENSHIFT_GOIMPORTS): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install github.com/openshift-eng/openshift-goimports@$(OPENSHIFT_GOIMPORTS_VERSION)

.PHONY: kind
kind: $(KIND) ## Download kind locally if necessary.
$(KIND): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/kind@$(KIND_VERSION)

.PHONY: bundle
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
$(OPERATOR_SDK) generate kustomize manifests -q
Expand Down Expand Up @@ -296,3 +315,6 @@ catalog-build: opm ## Build a catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

# Include last to avoid changing MAKEFILE_LIST used above
include ./make/*.mk
10 changes: 10 additions & 0 deletions config/deploy/local/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Local deployment overlay.
#
# Set the deployment imagePullPolicy to IfNotPresent. This is required if you are using a local image loaded into kind i.e. make kind-load-image
#

resources:
- ../../default

patchesStrategicMerge:
- manager_config_patch.yaml
11 changes: 11 additions & 0 deletions config/deploy/local/manager_config_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: manager
imagePullPolicy: IfNotPresent
6 changes: 6 additions & 0 deletions hack/kind-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: kindest/node:v1.27.3
18 changes: 18 additions & 0 deletions make/kind.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

##@ Kind

## Targets to help install and use kind for development https://kind.sigs.k8s.io

KIND_CLUSTER_NAME ?= kuadrant-dns-local

.PHONY: kind-create-cluster
kind-create-cluster: kind ## Create the "kuadrant-dns-local" kind cluster.
$(KIND) create cluster --name $(KIND_CLUSTER_NAME) --config hack/kind-cluster.yaml

.PHONY: kind-delete-cluster
kind-delete-cluster: kind ## Delete the "kuadrant-dns-local" kind cluster.
- $(KIND) delete cluster --name $(KIND_CLUSTER_NAME)

.PHONY: kind-load-image
kind-load-image: kind ## Load image to "kuadrant-dns-local" kind cluster.
$(KIND) load docker-image $(IMG) --name $(KIND_CLUSTER_NAME)
22 changes: 22 additions & 0 deletions make/verify.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

##@ Verify

## Targets to verify actions that generate/modify code have been executed and output committed

.PHONY: verify-code
verify-code: vet ## Verify code formatting
@diff -u <(echo -n) <(gofmt -s -d `find . -type f -name '*.go' -not -path "./vendor/*"`)

.PHONY: verify-manifests
verify-manifests: manifests ## Verify manifests update.
git diff --exit-code ./config
[ -z "$$(git ls-files --other --exclude-standard --directory --no-empty-directory ./config)" ]

.PHONY: verify-bundle
verify-bundle: bundle ## Verify bundle update.
git diff --exit-code ./bundle
[ -z "$$(git ls-files --other --exclude-standard --directory --no-empty-directory ./bundle)" ]

.PHONY: verify-imports
verify-imports: ## Verify go imports are sorted and grouped correctly.
hack/verify-imports.sh

0 comments on commit b81ed4b

Please sign in to comment.