Skip to content

Commit

Permalink
feat: configure validatorctl (#1)
Browse files Browse the repository at this point in the history
* chore: go mod init

* feat: configure cli commands

* chore: fix up validator command description

* feat: add support for oci plugin

* feat: add support for remaining plugins

* chore: import VsphereCloudAccount from vsphere plugin and remove need for msgError

* chore: use VSphereDriverMock from vsphere plugin

* fix: update vsphere driver interface location

* chore: bump to go 1.22.4 and bump vsphere plugin version to 0.0.23

* feat: add implementation for remaining validator commands

* chore: remove unused functions vars and packages

* test: add unit tests

* ci: setup ci

* ci: address gosec

* test: set up integration tests

* test: fix test deploy interactive

* test: fix test deploy silent

* test: enable all integration tests

* fix: gitleaks

* fix: gitleaks

* chore: remove vmtools

* chore: setup envtest

* chore: fix coverage report

* chore: add gitleaksignore

* chore: remove reference to models dir which doesnt exist

* chore: bump vsphere plugin version to 0.0.24

* chore: remove kuebeconfig from validator.yaml

* chore: add error log lines on integration test failures

* fix: remove subcommands

* chore: remove envtest

* docs: add header links to README

* chore: cleanup unused functions

* chore: cleanup more unused functions

* chore: cleanup Makefile

* chore: go mod tidy

* chore: fix gitleaks
  • Loading branch information
ahmad-ibra authored Jun 11, 2024
1 parent 4051435 commit 34285c6
Show file tree
Hide file tree
Showing 91 changed files with 12,004 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is a comment.
# Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
* @validator-labs/validator
10 changes: 10 additions & 0 deletions .github/workflows/gitleaks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: GitLeaks

on:
pull_request:
workflow_dispatch:

jobs:
call-gitleaks:
uses: validator-labs/workflows/.github/workflows/gitleaks.yaml@main
secrets: inherit
10 changes: 10 additions & 0 deletions .github/workflows/golicences.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: GoLicenses

on:
pull_request:
workflow_dispatch:

jobs:
call-golicenses:
uses: validator-labs/workflows/.github/workflows/golicenses.yaml@main
secrets: inherit
10 changes: 10 additions & 0 deletions .github/workflows/gosec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: GoSec

on:
pull_request:
workflow_dispatch:

jobs:
call-gosec:
uses: validator-labs/workflows/.github/workflows/gosec.yaml@main
secrets: inherit
10 changes: 10 additions & 0 deletions .github/workflows/govulncheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: GoVulnCheck

on:
pull_request:
workflow_dispatch:

jobs:
call-govulncheck:
uses: validator-labs/workflows/.github/workflows/govulncheck.yaml@main
secrets: inherit
17 changes: 17 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Release

on:
push:
branches:
- main
- '[0-9]+.[0-9]+.x'

jobs:
call-release:
uses: validator-labs/workflows/.github/workflows/release.yaml@main
permissions:
contents: write
id-token: write
packages: write
pull-requests: write
secrets: inherit
13 changes: 13 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Test

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
call-test:
uses: validator-labs/workflows/.github/workflows/test.yaml@main
secrets: inherit
45 changes: 45 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test
*cert.pem
*key.pem

# Coverage files
_build/
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# IDE
.idea/installer.iml
.idea/modules.xml
.idea/workspace.xml
.vscode
*__debug_bin*

# Binaries
bin/
!bin/.gitkeep

# Embedded Binaries
pkg/utils/embed/bin/*

# Creds
.netrc

# hack
.validator

# test
tests/unit-test-data/*.tmp
.idea

# os generated files
.DS_Store
6 changes: 6 additions & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
7a35fed25c31e40b59d0b177705f1e774eaf9bc2:tests/integration/_validator/testcases/data/validator.yaml:generic-api-key:474
7e4f6a1c8f4476d44a1befb2535660894d73cef6:tests/integration/_validator/testcases/data/validator.yaml:generic-api-key:474
e7156f3be822e9da88949cd9405e8eedde836e5f:tests/integration/_validator/testcases/data/validator.yaml:generic-api-key:27
e7156f3be822e9da88949cd9405e8eedde836e5f:tests/integration/_validator/testcases/data/validator.yaml:generic-api-key:51
481cdf910c0bc555363ae4278b2f57a66a72ed6b:tests/integration/_validator/testcases/data/validator.yaml:generic-api-key:27
481cdf910c0bc555363ae4278b2f57a66a72ed6b:tests/integration/_validator/testcases/data/validator.yaml:generic-api-key:51
239 changes: 239 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
# If you update this file, please follow:
# https://www.thapaliya.com/en/writings/well-documented-makefiles/

# Meta
.PHONY: docker kind kubectl helm build test
.DEFAULT_GOAL:=help

# Images
IMAGE_TAG ?= latest
CLI_IMG ?= "quay.io/validator-labs/validatorctl:$(IMAGE_TAG)"

# Dependency Versions
BUILDER_GOLANG_VERSION ?= 1.22
DOCKER_VERSION ?= 24.0.6
HELM_VERSION ?= 3.14.0
GOLANGCI_VERSION ?= 1.54.2
KIND_VERSION ?= 0.20.0
KUBECTL_VERSION ?= 1.24.10

# Product Version
VERSION_SUFFIX ?= -dev
VERSION ?= 0.0.1${VERSION_SUFFIX}

# Common vars
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
CURRENT_DIR := $(dir $(MAKEFILE_PATH))
EMBED_BIN := ./pkg/utils/embed/bin
BIN_DIR ?= ./bin

# Go env vars
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

PLATFORM=$(GOOS)
ifeq ("$(GOOS)", "darwin")
PLATFORM=mac
else ifeq ("$(GOOS)", "windows")
PLATFORM=win
endif
TARGETARCH ?= amd64

# Test vars
COVER_DIR=_build/cov
COVER_PKGS=$(shell go list ./... | grep -v /tests/) # omit integration tests

# Integrated Images List
IMAGE_LIST=_build/images/images.list

##@ Help Targets
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[0m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Build Targets
build: binaries ## Build CLI
@echo "Building CLI binary..."
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) GO111MODULE=on go build -ldflags " \
-X github.com/validator-labs/validatorctl/cmd.Version=$(VERSION)" \
-a -o bin/validator validator.go

build-dev: binaries build-cli ## Build CLI & copy validator binary into your PATH
sudo cp bin/validator /usr/local/bin

get-version: ## Get the product version
@echo "$(VERSION)"

##@ Static Analysis Targets
fmt: ## Run go fmt
go fmt ./...

lint: golangci-lint ## Run golangci-lint
$(GOLANGCI_LINT) run

vet: binaries ## Run go vet
go vet ./...

##@ Test Targets
test-unit: ## Run unit tests
@mkdir -p $(COVER_DIR)/unit
rm -rf $(COVER_DIR)/unit/*
IS_TEST=true CLI_VERSION=$(VERSION) go test -v -parallel 6 -timeout 20m \
-covermode=atomic -coverprofile=$(COVER_DIR)/unit/unit.out $(COVER_PKGS)

# For now we can't enable -race for integration tests
# due to https://github.com/spf13/viper/issues/174
test-integration: binaries ## Run integration tests
@mkdir -p $(COVER_DIR)/integration
rm -rf $(COVER_DIR)/integration/*
IS_TEST=true CLI_VERSION=$(VERSION) KUBECONFIG= DISABLE_KIND_CLUSTER_CHECK=true \
go test -v -parallel 6 -timeout 30m \
-covermode=atomic -coverpkg=./... -coverprofile=$(COVER_DIR)/integration/integration.out ./tests/...

.PHONY: test
test: binaries gocovmerge test-unit test-integration ## Run unit tests, integration test
$(GOCOVMERGE) $(COVER_DIR)/unit/*.out $(COVER_DIR)/integration/*.out > $(COVER_DIR)/coverage.out.tmp
# Omit test code from coverage report
cat $(COVER_DIR)/coverage.out.tmp | grep -vE 'tests' > $(COVER_DIR)/coverage.out
go tool cover -func=$(COVER_DIR)/coverage.out -o $(COVER_DIR)/cover.func
go tool cover -html=$(COVER_DIR)/coverage.out -o $(COVER_DIR)/cover.html
go tool cover -func $(COVER_DIR)/coverage.out | grep total
cp $(COVER_DIR)/coverage.out cover.out

coverage: ## Show global test coverage
go tool cover -func $(COVER_DIR)/coverage.out

coverage-html: ## Open global test coverage report in your browser
go tool cover -html $(COVER_DIR)/coverage.out

coverage-unit: ## Show unit test coverage
go tool cover -func $(COVER_DIR)/unit/unit.out

coverage-unit-html: ## Open unit test coverage report in your browser
go tool cover -html $(COVER_DIR)/unit/unit.out

coverage-integration: ## Show integration test coverage
go tool cover -func $(COVER_DIR)/integration/integration.out

coverage-integration-html: ## Open integration test coverage report in your browser
go tool cover -html $(COVER_DIR)/integration/integration.out

##@ Image Targets

BUILD_ARGS = --build-arg CLI_VERSION=${VERSION} --build-arg BUILDER_GOLANG_VERSION=${BUILDER_GOLANG_VERSION}

docker-all: docker-cli docker-push ## Builds & pushes Docker images to container registry

docker-cli: binaries
docker buildx build ${BUILD_ARGS} --platform linux/${TARGETARCH} --load -f build/docker/cli.Dockerfile . -t ${CLI_IMG}

docker-compose: binaries ## Rebuild images and restart docker-compose
docker compose build
docker compose up

docker-push: ## Pushes Docker images to container registry
docker push ${CLI_IMG}
echo cli,core,${CLI_IMG} >> ${IMAGE_LIST}

docker-rmi: ## Remove Docker images from local Docker engine
docker rmi -f ${CLI_IMG}

create-images-list: ## Create the image list for CICD
mkdir -p _build/images
touch $(IMAGE_LIST)


##@ Tools Targets
binaries: docker helm kind kubectl

clean-binaries: ## Clean embedded binaries
@echo "Cleaning embedded binaries..."
rm -rf $(EMBED_BIN)/docker
rm -rf $(EMBED_BIN)/helm
rm -rf $(EMBED_BIN)/kind
rm -rf $(EMBED_BIN)/kubectl

truncate-binaries:
@echo "Truncating embedded binaries..."
: > $(EMBED_BIN)/docker
: > $(EMBED_BIN)/helm
: > $(EMBED_BIN)/kind
: > $(EMBED_BIN)/kubectl

docker:
ifeq ("$(wildcard $(EMBED_BIN)/docker)", "")
if [[ "$(GOOS)" == "windows" ]]; then \
curl -L https://download.docker.com/$(PLATFORM)/static/stable/x86_64/docker-$(DOCKER_VERSION).zip -o docker.zip; \
unzip docker.zip; \
rm -f docker.zip; \
mv docker/docker.exe $(EMBED_BIN)/docker; \
else \
curl -L https://download.docker.com/$(PLATFORM)/static/stable/x86_64/docker-$(DOCKER_VERSION).tgz | tar xz docker/docker; \
mv docker/docker $(EMBED_BIN)/docker; \
fi
chmod +x $(EMBED_BIN)/docker
rm -rf ./docker
endif

kind:
ifeq ("$(wildcard $(EMBED_BIN)/kind)", "")
curl -Lo $(EMBED_BIN)/kind https://github.com/kubernetes-sigs/kind/releases/download/v$(KIND_VERSION)/kind-$(GOOS)-$(GOARCH)
chmod +x $(EMBED_BIN)/kind
endif

kubectl:
ifeq ("$(wildcard $(EMBED_BIN)/kubectl)", "")
if [[ "$(GOOS)" == "windows" ]]; then \
curl -Lo $(EMBED_BIN)/kubectl https://dl.k8s.io/release/v$(KUBECTL_VERSION)/bin/$(GOOS)/$(GOARCH)/kubectl.exe; \
else \
curl -Lo $(EMBED_BIN)/kubectl https://dl.k8s.io/release/v$(KUBECTL_VERSION)/bin/$(GOOS)/$(GOARCH)/kubectl; \
fi
chmod +x $(EMBED_BIN)/kubectl
endif

helm:
ifeq ("$(wildcard $(EMBED_BIN)/helm)", "")
if [[ "$(GOOS)" == "windows" ]]; then \
curl -L https://get.helm.sh/helm-v$(HELM_VERSION)-$(GOOS)-$(GOARCH).zip -o helm.zip; \
unzip helm.zip; \
rm -f helm.zip; \
mv windows-amd64/helm.exe $(EMBED_BIN)/helm; \
rm -rf ./windows-amd64; \
else \
curl -L https://get.helm.sh/helm-v$(HELM_VERSION)-$(GOOS)-$(GOARCH).tar.gz | tar xz; \
mv $(GOOS)-$(GOARCH)/helm $(EMBED_BIN)/helm; \
rm -rf ./$(GOOS)-$(GOARCH); \
fi
chmod +x $(EMBED_BIN)/helm
endif

golangci-lint:
if ! test -f $(BIN_DIR)/golangci-lint-linux-amd64; then \
curl -LOs https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_VERSION)/golangci-lint-$(GOLANGCI_VERSION)-linux-amd64.tar.gz; \
tar -zxf golangci-lint-$(GOLANGCI_VERSION)-linux-amd64.tar.gz; \
mv golangci-lint-$(GOLANGCI_VERSION)-*/golangci-lint $(BIN_DIR)/golangci-lint-linux-amd64; \
chmod +x $(BIN_DIR)/golangci-lint-linux-amd64; \
rm -rf ./golangci-lint-$(GOLANGCI_VERSION)-linux-amd64*; \
fi
if ! test -f $(BIN_DIR)/golangci-lint-$(GOOS)-$(GOARCH); then \
curl -LOs https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_VERSION)/golangci-lint-$(GOLANGCI_VERSION)-$(GOOS)-$(GOARCH).tar.gz; \
tar -zxf golangci-lint-$(GOLANGCI_VERSION)-$(GOOS)-$(GOARCH).tar.gz; \
mv golangci-lint-$(GOLANGCI_VERSION)-*/golangci-lint $(BIN_DIR)/golangci-lint-$(GOOS)-$(GOARCH); \
chmod +x $(BIN_DIR)/golangci-lint-$(GOOS)-$(GOARCH); \
rm -rf ./golangci-lint-$(GOLANGCI_VERSION)-$(GOOS)-$(GOARCH)*; \
fi
GOLANGCI_LINT=$(BIN_DIR)/golangci-lint-$(GOOS)-$(GOARCH)

gocovmerge:
ifeq (, $(shell which gocovmerge))
go version
go install github.com/wadey/gocovmerge@latest
go mod tidy
GOCOVMERGE=$(GOBIN)/gocovmerge
else
GOCOVMERGE=$(shell which gocovmerge)
endif
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
[![Contributions Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/validator-labs/validatorctl/issues)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
![Test](https://github.com/validator-labs/validatorctl/actions/workflows/test.yaml/badge.svg)
[![Go Report Card](https://goreportcard.com/badge/github.com/validator-labs/validatorctl)](https://goreportcard.com/report/github.com/validator-labs/validatorctl)
[![codecov](https://codecov.io/gh/validator-labs/validatorctl/graph/badge.svg?token=GVZ4LZ5SOY)](https://codecov.io/gh/validator-labs/validatorctl)
[![Go Reference](https://pkg.go.dev/badge/github.com/validator-labs/validatorctl.svg)](https://pkg.go.dev/github.com/validator-labs/validatorctl)

# validatorctl
A CLI tool for the validator ecosystem

Loading

0 comments on commit 34285c6

Please sign in to comment.