Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/lint-config-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Lint Config Checks

on:
push:
paths:
- '.golangci.yml'
- '.github/workflows/lint-config-checks.yaml'
branches: [ main ]
pull_request:
paths:
- '.golangci.yml'
- '.github/workflows/lint-config-checks.yaml'
branches: [ main ]

jobs:
lint-config-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6

- name: Setup Go
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6
with:
go-version-file: 'go.mod'

- name: Verify linter configuration
run: make lint-config
50 changes: 47 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,58 @@
# Configuration for the golangci-lint tool - ensuring that dot imports do not trigger an ST1001 warning.

version: "2"
run:
allow-parallel-runners: true

linters:
default: none
enable:
- copyloopvar
- dupl
- errcheck
- ginkgolinter
- goconst
- gocyclo
- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- revive
- staticcheck
- unconvert
- unparam
- unused
settings:
revive:
rules:
- name: comment-spacings
- name: import-shadowing
exclusions:
generated: lax
rules:
- path: '^integration_tests/|^tests/|[^/]+_test\.go'
linters:
- staticcheck
# exclude dot-imports checks on test-related files
text: "ST1001:"
text: "ST1001:"
- linters:
- lll
path: api/*
- linters:
- dupl
- lll
path: internal/*
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
91 changes: 54 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ endif

# Set the Operator SDK version to use. By default, what is installed on the system is used.
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
OPERATOR_SDK_VERSION ?= v1.37.0
OPM_VERSION ?= v1.23.0
OPERATOR_SDK_VERSION ?= v1.42.0
OPM_VERSION ?= v1.55.0
# Image URL to use all building/pushing image targets
IMG ?= $(IMAGE_TAG_BASE):$(IMAGE_TAG_VERSION)
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.28.0

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -127,7 +125,7 @@ SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

# Source packages outside of tests
PKGS := $(shell go list ./... | grep -vE 'github.com/redhat-developer/rhdh-operator/(tests/|api/v1alpha([1-2]))')
PKGS := $(shell go list ./... | grep -vE 'github.com/redhat-developer/rhdh-operator/(tests/|api/v1alpha([1-9]+))')

.PHONY: all
all: build
Expand Down Expand Up @@ -164,7 +162,7 @@ fmt: goimports ## Format the code using goimports
find . -not -path '*/\.*' -name '*.go' -exec $(GOIMPORTS) -w {} \;

.PHONY: test
test: manifests generate fmt vet envtest $(LOCALBIN) ## Run tests. We need LOCALBIN=$(LOCALBIN) to get correct default-config path
test: manifests generate fmt vet setup-envtest $(LOCALBIN) ## Run tests. We need LOCALBIN=$(LOCALBIN) to get correct default-config path
mkdir -p $(LOCALBIN)/default-config && rm -fr $(LOCALBIN)/default-config/* && cp -r config/profile/$(PROFILE)/default-config/* $(LOCALBIN)/default-config
mkdir -p $(LOCALBIN)/plugin-deps && rm -fr $(LOCALBIN)/plugin-deps/* && cp -r config/profile/$(PROFILE)/plugin-deps/* $(LOCALBIN)/plugin-deps 2>/dev/null || :
LOCALBIN=$(LOCALBIN) KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $(PKGS) -coverprofile cover.out
Expand Down Expand Up @@ -200,7 +198,7 @@ test-e2e-upgrade: ginkgo ## Run end-to-end tests dedicated to the operator upgra
.PHONY: gosec
gosec: addgosec ## run the gosec scanner for non-test files in this repo
# we let the report content trigger a failure using the GitHub Security features.
$(GOSEC) -no-fail -fmt $(GOSEC_FMT) -out $(GOSEC_OUTPUT_FILE) ./...
$(GOSEC) -no-fail -exclude-generated -fmt $(GOSEC_FMT) -out $(GOSEC_OUTPUT_FILE) ./...

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter & yamllint
Expand All @@ -210,6 +208,10 @@ lint: golangci-lint ## Run golangci-lint linter & yamllint
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
$(GOLANGCI_LINT) run --fix --timeout 15m

.PHONY: lint-config
lint-config: golangci-lint ## Verify golangci-lint linter configuration
$(GOLANGCI_LINT) config verify

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
Expand Down Expand Up @@ -463,22 +465,23 @@ $(LOCALBIN):

## Tool Binaries
KUBECTL ?= kubectl
KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
GOIMPORTS ?= $(LOCALBIN)/goimports-$(GOIMPORTS_VERSION)
GOSEC ?= $(LOCALBIN)/gosec-$(GOSEC_VERSION)
GINKGO ?= $(LOCALBIN)/ginkgo-$(GINKGO_VERSION)
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
GOIMPORTS ?= $(LOCALBIN)/goimports
GOSEC ?= $(LOCALBIN)/gosec
GINKGO ?= $(LOCALBIN)/ginkgo

## Tool Versions
KUSTOMIZE_VERSION ?= v5.4.2
CONTROLLER_TOOLS_VERSION ?= v0.14.0
ENVTEST_VERSION ?= release-0.17
KUSTOMIZE_VERSION ?= v5.4.3
CONTROLLER_TOOLS_VERSION ?= v0.18.0
ENVTEST_VERSION := $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
ENVTEST_K8S_VERSION := $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
GOLANGCI_LINT_VERSION ?= v2.6.2
GOIMPORTS_VERSION ?= v0.16.1
GOSEC_VERSION ?= v2.22.8
GINKGO_VERSION ?= v2.22.2
GOIMPORTS_VERSION ?= v0.40.0
GOSEC_VERSION ?= v2.22.11
GINKGO_VERSION ?= v2.27.3

## Gosec options - default format is sarif so we can integrate with Github code scanning
GOSEC_FMT ?= sarif # for other options, see https://github.com/securego/gosec#output-formats
Expand All @@ -494,6 +497,14 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
$(CONTROLLER_GEN): $(LOCALBIN)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))

.PHONY: setup-envtest
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
exit 1; \
}

.PHONY: envtest
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
Expand All @@ -502,62 +513,68 @@ $(ENVTEST): $(LOCALBIN)
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))

.PHONY: goimports
goimports: $(GOIMPORTS) ## Download goimports locally if necessary.
$(GOIMPORTS): $(LOCALBIN)
$(call go-install-tool,$(GOIMPORTS),golang.org/x/tools/cmd/goimports,${GOIMPORTS_VERSION})
$(call go-install-tool,$(GOIMPORTS),golang.org/x/tools/cmd/goimports,$(GOIMPORTS_VERSION))

.PHONY: addgosec
addgosec: $(GOSEC) ## Download gosec locally if necessary.
$(GOSEC): $(LOCALBIN)
$(call go-install-tool,$(GOSEC),github.com/securego/gosec/v2/cmd/gosec,${GOSEC_VERSION})
$(call go-install-tool,$(GOSEC),github.com/securego/gosec/v2/cmd/gosec,$(GOSEC_VERSION))

.PHONY: ginkgo
ginkgo: $(GINKGO) ## Download Ginkgo locally if necessary.
$(GINKGO): $(LOCALBIN)
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo,${GINKGO_VERSION})
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo,$(GINKGO_VERSION))

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f $(1) ] || { \
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef

.PHONY: operator-sdk
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk-$(OPERATOR_SDK_VERSION)
OPERATOR_SDK_WITH_VER ?= $(LOCALBIN)/operator-sdk-$(OPERATOR_SDK_VERSION)
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
operator-sdk: ## Download operator-sdk locally if necessary.
ifeq (,$(wildcard $(OPERATOR_SDK)))
ifeq (,$(wildcard $(OPERATOR_SDK_WITH_VER)))
@{ \
set -e ;\
mkdir -p $(dir $(OPERATOR_SDK)) ;\
mkdir -p $(dir $(OPERATOR_SDK_WITH_VER)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
chmod +x $(OPERATOR_SDK) ;\
curl -sSLo $(OPERATOR_SDK_WITH_VER) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
chmod +x $(OPERATOR_SDK_WITH_VER) ;\
}
endif
ln -sf $(OPERATOR_SDK_WITH_VER) $(OPERATOR_SDK)

.PHONY: opm
OPM ?= $(LOCALBIN)/opm-$(OPM_VERSION)
OPM_WITH_VER ?= $(LOCALBIN)/opm-$(OPM_VERSION)
OPM ?= $(LOCALBIN)/opm
opm: ## Download opm locally if necessary.
ifeq (,$(wildcard $(OPM)))
ifeq (,$(wildcard $(OPM_WITH_VER)))
@{ \
set -e ;\
mkdir -p $(dir $(OPM)) ;\
mkdir -p $(dir $(OPM_WITH_VER)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/$(OPM_VERSION)/$${OS}-$${ARCH}-opm ;\
chmod +x $(OPM) ;\
curl -sSLo $(OPM_WITH_VER) https://github.com/operator-framework/operator-registry/releases/download/$(OPM_VERSION)/$${OS}-$${ARCH}-opm ;\
chmod +x $(OPM_WITH_VER) ;\
}
endif
ln -sf $(OPM_WITH_VER) $(OPM)

##@ Misc.

Expand Down
22 changes: 11 additions & 11 deletions api/v1alpha3/backstage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type RuntimeConfig struct {
type Database struct {
// Control the creation of a local PostgreSQL DB. Set to false if using for example an external Database for Backstage.
// +optional
//+kubebuilder:default=true
// +kubebuilder:default=true
EnableLocalDb *bool `json:"enableLocalDb,omitempty"`

// Name of the secret for database authentication. Optional.
Expand Down Expand Up @@ -99,7 +99,7 @@ type Application struct {
// Number of desired replicas to set in the Backstage Deployment.
// Defaults to 1.
// +optional
//+kubebuilder:default=1
// +kubebuilder:default=1
Replicas *int32 `json:"replicas,omitempty"`

// Custom image to use in all containers (including Init Containers).
Expand Down Expand Up @@ -175,7 +175,7 @@ type ExtraEnvs struct {
type EnvObjectRef struct {
// Name of the object
// We support only ConfigMaps and Secrets.
//+kubebuilder:validation:Required
// +kubebuilder:validation:Required
Name string `json:"name"`

// Key in the object
Expand All @@ -186,7 +186,7 @@ type EnvObjectRef struct {
type FileObjectRef struct {
// Name of the object
// Supported ConfigMaps and Secrets
//+kubebuilder:validation:Required
// +kubebuilder:validation:Required
Name string `json:"name"`

// Key in the object
Expand All @@ -200,7 +200,7 @@ type FileObjectRef struct {

type PvcRef struct {
// Name of the object
//+kubebuilder:validation:Required
// +kubebuilder:validation:Required
Name string `json:"name"`

// Path to mount PVC. If not specified default-path/Name will be used
Expand All @@ -210,11 +210,11 @@ type PvcRef struct {

type Env struct {
// Name of the environment variable
//+kubebuilder:validation:Required
// +kubebuilder:validation:Required
Name string `json:"name"`

// Value of the environment variable
//+kubebuilder:validation:Required
// +kubebuilder:validation:Required
Value string `json:"value"`
}

Expand All @@ -225,8 +225,8 @@ type BackstageStatus struct {
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +operator-sdk:csv:customresourcedefinitions:displayName="Red Hat Developer Hub"

// Backstage is the Schema for the Red Hat Developer Hub backstages API.
Expand All @@ -241,7 +241,7 @@ type Backstage struct {
Status BackstageStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

// BackstageList contains a list of Backstage
type BackstageList struct {
Expand All @@ -255,7 +255,7 @@ type BackstageList struct {
type Route struct {
// Control the creation of a Route on OpenShift.
// +optional
//+kubebuilder:default=true
// +kubebuilder:default=true
Enabled *bool `json:"enabled,omitempty"`

// Host is an alias/DNS that points to the service. Optional.
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading