Skip to content

Commit

Permalink
Introduce base linters as pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenmarten committed Jun 16, 2024
1 parent 95c5692 commit 2f6691a
Show file tree
Hide file tree
Showing 25 changed files with 136 additions and 278 deletions.
69 changes: 0 additions & 69 deletions .github/workflows/go.yml

This file was deleted.

74 changes: 0 additions & 74 deletions .github/workflows/main.yml

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/make-test-e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#name: Make run tests e2e
#
#on:
# pull_request:
# types:
# - opened
# - labeled
# - synchronize
#
#jobs:
# test-e2e:
# name: test-e2e on k8s ${{ matrix.k8s.attribute }} version
# # Pull request has label 'ok-to-test' or the author is a member of the organization
# if: contains(github.event.pull_request.labels.*.name, 'ok-to-test') || contains(fromJSON('["COLLABORATOR", "MEMBER", "OWNER"]'), github.event.pull_request.author_association)
# strategy:
# matrix:
# k8s:
# - version: v1.28.0
# attribute: penultimate
# - version: v1.29.0
# attribute: previous
# - version: default
# attribute: latest
# runs-on: ubuntu-22.04
# steps:
# - uses: actions/checkout@v4.1.7
# - uses: actions/setup-go@v5.0.1
# with:
# go-version: 1.22.4
# - uses: docker/setup-buildx-action@v3.3.0
# - uses: tale/kubectl-action@v1.4.0
# with:
# kubectl-version: v1.30.0
# # Empty kubeconfig file
# base64-kube-config: "YXBpVmVyc2lvbjogdjEKa2luZDogQ29uZmlnCnByZWZlcmVuY2VzOiB7fQo="
# - run: |
# if [ "${{ matrix.k8s.version }}" = "default" ]; then
# # For latest version use default from Makefile
# make test-e2e
# else
# K8S_VERSION=${{ matrix.k8s.version }} make test-e2e
# fi
36 changes: 36 additions & 0 deletions .github/workflows/make-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#name: Make run tests
#
#on:
# pull_request:
# types:
# - opened
# - labeled
# - synchronize
#
#jobs:
# test:
# name: test on k8s ${{ matrix.k8s.attribute }} version
# # Pull request has label 'ok-to-test' or the author is a member of the organization
# if: contains(github.event.pull_request.labels.*.name, 'ok-to-test') || contains(fromJSON('["COLLABORATOR", "MEMBER", "OWNER"]'), github.event.pull_request.author_association)
# strategy:
# matrix:
# k8s:
# - version: v1.28.0
# attribute: penultimate
# - version: v1.29.0
# attribute: previous
# - version: default
# attribute: latest
# runs-on: ubuntu-22.04
# steps:
# - uses: actions/checkout@v4.1.7
# - uses: actions/setup-go@v5.0.1
# with:
# go-version: 1.22.4
# - run: |
# if [ "${{ matrix.k8s.version }}" = "default" ]; then
# # For latest version use default from Makefile
# make test
# else
# K8S_VERSION=${{ matrix.k8s.version }} make test
# fi
14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Pre-commit

on:
pull_request:

jobs:
pre-commit:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4.1.7
- uses: actions/setup-go@v5.0.1
with:
go-version: 1.22.4
- uses: pre-commit/action@v3.0.1
35 changes: 0 additions & 35 deletions .github/workflows/verify.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@
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.
limitations under the License.
32 changes: 26 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ endif

all: manager

# Run tests
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate fmt vet manifests
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/master/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
@echo "Check for kubernetes version $(K8S_VERSION_TRIMMED_V) in $(ENVTEST)"
@$(ENVTEST) list | grep -q $(K8S_VERSION_TRIMMED_V)
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(K8S_VERSION_TRIMMED_V) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out

# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
test-e2e:
go test ./test/e2e/ -v -ginkgo.v

# Build manager binary
manager: generate fmt vet
Expand All @@ -54,6 +58,22 @@ fmt:
vet:
go vet ./...

.PHONY: mod-tidy
mod-tidy: ## Run go mod tidy against code.
go mod tidy

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter & yamllint
$(GOLANGCI_LINT) run

.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
$(GOLANGCI_LINT) run --fix

.PHONY: nilaway-lint
nilaway-lint: nilaway
$(NILAWAY_LINT) -include-pkgs=github.com/seaweedfs/seweedfs-operator/api,github.com/seaweedfs/seweedfs-operator/internal,github.com/seaweedfs/seweedfs-operator/test ./...

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ First clone the repository:
git clone https://github.com/seaweedfs/seaweedfs-operator --depth=1
```

To deploy the operator with webhooks enabled, make sure you have installed the `cert-manager`(Installation docs: <https://cert-manager.io/docs/installation/>) in your cluster, then follow the instructions in the `config/default/kustomization.yaml` file to uncomment the components you need.
To deploy the operator with webhooks enabled, make sure you have installed the `cert-manager`(Installation docs: <https://cert-manager.io/docs/installation/>) in your cluster, then follow the instructions in the `config/default/kustomization.yaml` file to uncomment the components you need.
Lastly, change the value of `ENABLE_WEBHOOKS` to `"true"` in `config/manager/manager.yaml`

Manager image must be locally built and published into a registry accessible from your k8s cluster:
Expand Down Expand Up @@ -155,7 +155,7 @@ make redeploy
make install

# run the operator locally outside the Kubernetes cluster
make run ENABLE_WEBHOOKS=false
make run ENABLE_WEBHOOKS=false

# From another terminal in the same directory
kubectl apply -f config/samples/seaweed_v1_seaweed.yaml
Expand Down
2 changes: 1 addition & 1 deletion config/certmanager/certificate.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The following manifests contain a self-signed issuer CR and a certificate CR.
# More document can be found at https://docs.cert-manager.io
# WARNING: Targets CertManager 0.11 check https://docs.cert-manager.io/en/latest/tasks/upgrading/index.html for
# WARNING: Targets CertManager 0.11 check https://docs.cert-manager.io/en/latest/tasks/upgrading/index.html for
# breaking changes
apiVersion: cert-manager.io/v1alpha2
kind: Issuer
Expand Down
2 changes: 1 addition & 1 deletion config/certmanager/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This configuration is for teaching kustomize how to update name ref and var substitution
# This configuration is for teaching kustomize how to update name ref and var substitution
nameReference:
- kind: Issuer
group: cert-manager.io
Expand Down
6 changes: 3 additions & 3 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ bases:
- ../crd
- ../rbac
- ../manager
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
#- ../webhook
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus

patchesStrategicMerge:
Expand All @@ -30,7 +30,7 @@ patchesStrategicMerge:
# endpoint w/o any authn/z, please comment the following line.
- manager_auth_proxy_patch.yaml

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
#- manager_webhook_patch.yaml

Expand Down
Loading

0 comments on commit 2f6691a

Please sign in to comment.