Skip to content

Commit

Permalink
chore: remove master refs & improve CI (#489)
Browse files Browse the repository at this point in the history
* chore: remove lingering 'master' refs

Signed-off-by: Tyler Gillson <[email protected]>

* ci: tidy workflows; ensure reviewable and run tests

Signed-off-by: Tyler Gillson <[email protected]>

* ci: add go generate to reviewability checks

Signed-off-by: Tyler Gillson <[email protected]>

* chore: remove lingering 'master' refs

Signed-off-by: Tyler Gillson <[email protected]>

---------

Signed-off-by: Tyler Gillson <[email protected]>
  • Loading branch information
TylerGillson authored Jul 25, 2024
1 parent 5d29b0a commit 2436178
Show file tree
Hide file tree
Showing 28 changed files with 183 additions and 233 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Unshallow
run: git fetch --prune --unshallow

- name: Configure git for private modules
env:
TOKEN: ${{ secrets.SPECTRO_TOKEN }}
USER: ${{ secrets.SPECTRO_USER }}
run: git config --global url."https://${USER}:${TOKEN}@github.com".insteadOf "https://github.com"

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21
- name: Vet
run: make vet
- name: Lint
run: make lint
- name: Test
go-version-file: go.mod

- name: Ensure reviewable
run: make check-diff

- name: Run acceptance tests
run: make testacc
27 changes: 14 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,41 @@
# in `goreleaser` to indicate this is being used in a non-interactive mode.
#
name: release

on:
push:
tags:
- 'v*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
- name: Checkout
uses: actions/checkout@v3
-
name: Unshallow

- name: Unshallow
run: git fetch --prune --unshallow
-
name: Configure git for private modules

- name: Configure git for private modules
env:
TOKEN: ${{ secrets.SPECTRO_TOKEN }}
USER: ${{ secrets.SPECTRO_USER }}
run: git config --global url."https://${USER}:${TOKEN}@github.com".insteadOf "https://github.com"
-
name: Set up Go

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21
-
name: Import GPG key
go-version-file: go.mod

- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
-
name: Run GoReleaser

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
Expand Down
108 changes: 9 additions & 99 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
## golangci-lint v1.46.2

# References:
# - https://golangci-lint.run/usage/linters/
# - https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322

run:
timeout: 10m # default 1m

linters-settings:
gosimple:
go: "1.18" # default 1.13
govet:
enable-all: true
disable:
- fieldalignment # too strict
- shadow # too strict
staticcheck:
go: "1.18" # default 1.13

# Non-default
cyclop:
Expand All @@ -36,98 +29,15 @@ linters-settings:
linters:
disable-all: true
enable:
## enabled by default
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- gosimple # Linter for Go source code that specializes in simplifying a code
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # Detects when assignments to existing variables are not used
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
- unused # Checks Go code for unused constants, variables, functions and types
## disabled by default
- cyclop # checks function and package cyclomatic complexity
- gocognit # Computes and checks the cognitive complexity of functions
## disabled
#- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
#- bidichk # Checks for dangerous unicode character sequences
#- bodyclose # checks whether HTTP response body is closed successfully
#- containedctx # containedctx is a linter that detects struct contained context.Context field
#- contextcheck # check the function whether use a non-inherited context
#- decorder # check declaration order and count of types, constants, variables and functions
#- depguard # [replaced by gomodguard] Go linter that checks if package imports are in a list of acceptable packages
#- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
#- dupl # Tool for code clone detection
#- durationcheck # check for two durations multiplied together
#- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted.
#- errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error.
#- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
#- execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds
#- exhaustive # check exhaustiveness of enum switch statements
#- exhaustivestruct # [deprecated, replaced by exhaustruct] Checks if all struct's fields are initialized
#- exhaustruct # [can be enabled, but have to be configured] Checks if all structure fields are initialized
#- exportloopref # checks for pointers to enclosing loop variables
#- forbidigo # Forbids identifiers
#- forcetypeassert # [replaced by errcheck] finds forced type assertions
#- funlen # Tool for detection of long functions
#- gci # Gci controls golang package import order and makes it always deterministic.
#- gocyclo # Computes and checks the cyclomatic complexity of functions
#- godox # Tool for detection of FIXME, TODO and other comment keywords
#- goerr113 # [too strict] Golang linter to check the errors handling expressions
#- gofmt # [replaced by goimports] Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
#- gofumpt # [replaced by goimports, gofumports is not available yet] Gofumpt checks whether code was gofumpt-ed.
#- goheader # Checks is file header matches to pattern
#- golint # [deprecated, replaced by revive] Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
#- grouper # An analyzer to analyze expression groups.
#- gochecknoglobals # check that no global variables exist
#- gochecknoinits # Checks that no init functions are present in Go code
#- goconst # Finds repeated strings that could be replaced by a constant
#- gocritic # Provides diagnostics that check for bugs, performance and style issues.
#- godot # Check if comments end in a period
#- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt.
#- gomnd # An analyzer to detect magic numbers.
#- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
#- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
#- goprintffuncname # Checks that printf-like functions are named with f at the end
#- gosec # Inspects source code for security problems
#- ifshort # Checks that your code uses short syntax for if-statements whenever possible
#- importas # Enforces consistent import aliases
#- interfacer # [deprecated] Linter that suggests narrower interface types
#- ireturn # [good, but too strict] Accept Interfaces, Return Concrete Types
#- lll # Reports long lines
#- maintidx # maintidx measures the maintainability index of each function.
#- makezero # Finds slice declarations with non-zero initial length
#- maligned # [deprecated, replaced by govet fieldalignment] Tool to detect Go structs that would take less memory if their fields were sorted
#- misspell # [useless] Finds commonly misspelled English words in comments
#- nakedret # Finds naked returns in functions greater than a specified function length
#- nestif # Reports deeply nested if statements
#- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
#- nilnil # Checks that there is no simultaneous return of nil error and an invalid value.
#- nlreturn # [too strict and mostly code is not more readable] nlreturn checks for a new line before return and branch statements to increase code clarity
#- noctx # noctx finds sending http request without context.Context
#- nolintlint # Reports ill-formed or insufficient nolint directives
#- nonamedreturns # Reports all named returns
#- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL.
#- paralleltest # [too many false positives] paralleltest detects missing usage of t.Parallel() method in your Go test
#- prealloc # Finds slice declarations that could potentially be preallocated
#- predeclared # find code that shadows one of Go's predeclared identifiers
#- promlinter # Check Prometheus metrics naming via promlint
#- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
#- rowserrcheck # checks whether Err of rows is checked successfully
#- scopelint # [deprecated, replaced by exportloopref] Scopelint checks for unpinned variables in go programs
#- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
#- stylecheck # Stylecheck is a replacement for golint
#- tagliatelle # Checks the struct tags.
#- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
#- testpackage # linter that makes you use a separate _test package
#- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
#- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
#- unconvert # Remove unnecessary type conversions
#- unparam # Reports unused function parameters
#- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope
#- wastedassign # wastedassign finds wasted assignment statements.
#- whitespace # Tool for detection of leading and trailing whitespace
#- wrapcheck # [too strict] Checks that errors returned from external packages are wrapped
#- wsl # [too strict and mostly code is not more readable] Whitespace Linter - Forces you to use empty lines!
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
- cyclop
- gocognit

issues:
max-issues-per-linter: 0
Expand Down
38 changes: 31 additions & 7 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,63 @@

.DEFAULT_GOAL:=help

DEV_PROVIDER_VERSION=100.100.100
GOLANGCI_VERSION ?= 1.55.2

BIN_DIR ?= ./bin
# Go variables
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)

# Output
TIME = `date +%H:%M:%S`
GREEN := $(shell printf "\033[32m")
RED := $(shell printf "\033[31m")
CNone := $(shell printf "\033[0m")
OK = echo ${TIME} ${GREEN}[ OK ]${CNone}
ERR = echo ${TIME} ${RED}[ ERR ]${CNone} "error:"

##@ 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)

bin-dir:
test -d $(BIN_DIR) || mkdir $(BIN_DIR)

##@ Static Analysis Targets

check-diff: reviewable ## Execute branch is clean
git --no-pager diff
git diff --quiet || ($(ERR) please run 'make reviewable' to include all changes && false)
@$(OK) branch is clean

reviewable: fmt vet lint generate ## Ensure code is ready for review
git submodule update --remote
go mod tidy

fmt: ## Run go fmt against code
go fmt ./...

vet: ## Run go vet against code
go vet ./...

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

generate:
go generate ./...

##@ Test Targets
.PHONY: testacc
testacc: ## Run acceptance tests
TF_ACC=1 go test -v $(TESTARGS) -covermode=atomic -coverpkg=./... -coverprofile=profile.cov ./... -timeout 120m

##@ Development Targets

DEV_PROVIDER_VERSION=100.100.100
dev-provider: ## Generate dev provider
bash generate_dev_provider.sh $(DEV_PROVIDER_VERSION)

# Tools Section

BIN_DIR ?= ./bin
bin-dir:
test -d $(BIN_DIR) || mkdir $(BIN_DIR)

GOLANGCI_VERSION ?= 1.54.2
golangci-lint: bin-dir
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; \
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/cluster_custom_cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ description: |-
}
control_plane = true
control_plane_as_worker = true
node_pool_config = templatefile("config_templates/master_pool_config.yaml", local.node_pool_config_variables)
node_pool_config = templatefile("config_templates/cp_pool_config.yaml", local.node_pool_config_variables)
}
machine_pool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ spec:
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
name: "master-pool"
name: "cp-pool"
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: NutanixCluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
metadata:
name: ${MASTER_NODE_POOL_NAME}
name: ${CP_NODE_POOL_NAME}
spec:
kubeadmConfigSpec:
clusterConfiguration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ locals {
}
# Node Pool config variables
node_pool_config_variables = {
MASTER_NODE_POOL_NAME = "master-pool"
CP_NODE_POOL_NAME = "cp-pool"
CLUSTER_NAME = local.cloud_config_override_variables["CLUSTER_NAME"]
CONTROL_PLANE_ENDPOINT_IP = local.cloud_config_override_variables["CONTROL_PLANE_ENDPOINT_IP"]
NUTANIX_SSH_AUTHORIZED_KEY = "ssh -a test-test"
Expand Down Expand Up @@ -71,7 +71,7 @@ resource "spectrocloud_cluster_custom_cloud" "cluster_nutanix" {
machine_pool {
control_plane = true
control_plane_as_worker = true
node_pool_config = templatefile("config_templates/master_pool_config.yaml", local.node_pool_config_variables)
node_pool_config = templatefile("config_templates/cp_pool_config.yaml", local.node_pool_config_variables)
}

machine_pool {
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/spectrocloud_cluster_tke/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ resource "spectrocloud_cluster_tke" "cluster" {
ssh_key_name = var.tke_ssh_key_name
region = var.tke_region
vpc_id = var.tke_vpc_id
az_subnets = var.master_tke_subnets_map
az_subnets = var.cp_tke_subnets_map
}

machine_pool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sc_trace = false
tke_ssh_key_name = "{enter Spectro Cloud ssh key for tke}"
tke_region = "{enter region name for tke cluster}"
tke_vpc_id = "{enter tke vpc id}"
master_tke_subnets_map = {
cp_tke_subnets_map = {
"{enter subnet key}" : "{enter subnet id}"
}
worker_tke_subnets_map = {
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/spectrocloud_cluster_tke/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ variable "sc_trace" {}
variable "tke_ssh_key_name" {}
variable "tke_region" {}
variable "tke_vpc_id" {}
variable "master_tke_subnets_map" {}
variable "cp_tke_subnets_map" {}
variable "worker_tke_subnets_map" {}
2 changes: 1 addition & 1 deletion spectrocloud/cluster_common_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func resourceMachinePoolEksHash(v interface{}) int {
func resourceMachinePoolGkeHash(v interface{}) int {
m := v.(map[string]interface{})
buf := CommonHash(m)
if _, ok := m["disk_size_gb"]; ok {
if _, ok := m["disk_size_gb"]; ok {
buf.WriteString(fmt.Sprintf("%d-", m["disk_size_gb"].(int)))
}
buf.WriteString(fmt.Sprintf("%s-", m["instance_type"].(string)))
Expand Down
4 changes: 2 additions & 2 deletions spectrocloud/data_source_cloud_account_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ func dataSourceCloudAccountAws() *schema.Resource {
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Description: "ID of the AWS cloud account registered in Palette.",
Description: "ID of the AWS cloud account registered in Palette.",
Optional: true,
Computed: true,
ExactlyOneOf: []string{"id", "name"},
},
"name": {
Type: schema.TypeString,
Description: "Name of the AWS cloud account registered in Palette.",
Description: "Name of the AWS cloud account registered in Palette.",
Optional: true,
Computed: true,
ExactlyOneOf: []string{"id", "name"},
Expand Down
Loading

0 comments on commit 2436178

Please sign in to comment.