Skip to content

Commit

Permalink
Merge pull request #330 from suleymanakbas91/verify
Browse files Browse the repository at this point in the history
OCPVE-334: Add verify target to check go formatting and generated files
  • Loading branch information
suleymanakbas91 authored Apr 25, 2023
2 parents 1e9be13 + c7c6ac8 commit 1bc3cca
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

verify: ## Verify go formatting and generated files
hack/verify-gofmt.sh
hack/verify-deps.sh
hack/verify-bundle.sh
hack/verify-generated.sh

godeps-update: ## Run go mod tidy and go mod vendor.
go mod tidy && go mod vendor

Expand Down
25 changes: 25 additions & 0 deletions config/default/manager_custom_env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: operator
namespace: system
annotations:
target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}'
spec:
template:
spec:
containers:
- name: manager
env:
- name: TOPOLVM_CSI_IMAGE
value: quay.io/lvms_dev/topolvm:latest
- name: CSI_LIVENESSPROBE_IMAGE
value: k8s.gcr.io/sig-storage/livenessprobe:v2.8.0
- name: CSI_PROVISIONER_IMAGE
value: k8s.gcr.io/sig-storage/csi-provisioner:v3.3.0
- name: CSI_REGISTRAR_IMAGE
value: k8s.gcr.io/sig-storage/csi-node-driver-registrar:v2.6.2
- name: CSI_RESIZER_IMAGE
value: k8s.gcr.io/sig-storage/csi-resizer:v1.6.0
- name: CSI_SNAPSHOTTER_IMAGE
value: k8s.gcr.io/sig-storage/csi-snapshotter:v6.1.0
7 changes: 7 additions & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ resources:

generatorOptions:
disableNameSuffixHash: true
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: quay.io/lvms_dev/lvms-operator
newTag: latest
namePrefix: lvms-
17 changes: 17 additions & 0 deletions hack/verify-bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -euo pipefail

function print_failure {
echo "There are unexpected changes to the tree when running 'make bundle'. Please"
echo "run these commands locally and double-check the Git repository for unexpected changes which may"
echo "need to be committed."
exit 1
}

if [ "${OPENSHIFT_CI:-false}" = true ]; then
echo "> generating the OLM bundle"
make bundle

test -z "$(git status --porcelain | \grep -v '^??')" || print_failure
echo "> verified generated bundle and deep copy"
fi
17 changes: 17 additions & 0 deletions hack/verify-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -euo pipefail

function print_failure {
echo "There are unexpected changes to the vendor tree following 'go mod vendor' and 'go mod tidy'. Please"
echo "run these commands locally and double-check the Git repository for unexpected changes which may"
echo "need to be committed."
exit 1
}

if [ "${OPENSHIFT_CI:-false}" = true ]; then
go mod vendor
go mod tidy

test -z "$(git status --porcelain)" || print_failure
echo "verified Go modules"
fi
17 changes: 17 additions & 0 deletions hack/verify-generated.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -euo pipefail

function print_failure {
echo "There are unexpected changes to the tree when running 'make generate' and 'make manifests'. Please"
echo "run these commands locally and double-check the Git repository for unexpected changes which may"
echo "need to be committed."
exit 1
}

if [ "${OPENSHIFT_CI:-false}" = true ]; then
make generate
make manifests

test -z "$(git status --porcelain | \grep -v '^??')" || print_failure
echo "verified generated manifests and deep copy"
fi
10 changes: 10 additions & 0 deletions hack/verify-gofmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

go_files=$( find . -name '*.go' -not -path './vendor/*' -print )
bad_files=$(gofmt -s -l ${go_files})
if [[ -n "${bad_files}" ]]; then
(>&2 echo "!!! gofmt needs to be run on the listed files")
echo "${bad_files}"
(>&2 echo "Try running 'gofmt -s -d [path]' or autocorrect with 'hack/verify-gofmt.sh | xargs -n 1 gofmt -s -w'")
exit 1
fi

0 comments on commit 1bc3cca

Please sign in to comment.