Skip to content

Commit cf0bdcb

Browse files
committed
Add ORC API linter to enforce API design philosophy
Add a custom golangci-lint plugin that flags OpenStack ID references in spec structs, enforcing ORC's API design philosophy that spec fields should only reference ORC Kubernetes objects, not OpenStack resources directly by UUID. The noopenstackidref linter flags fields like 'ProjectID *string' in spec/filter structs and suggests using '*KubernetesNameRef' with a 'Ref' suffix instead (e.g., 'ProjectRef *KubernetesNameRef'). Status structs are exempt, as they are expected to report OpenStack UUIDs. See: https://k-orc.cloud/development/architecture/#api-design-philosophy
1 parent 0ff2b62 commit cf0bdcb

30 files changed

Lines changed: 511 additions & 25 deletions

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ linters:
6262
- statusoptional
6363
- statussubresource
6464
- uniquemarkers
65+
- noopenstackidref
6566
lintersConfig:
6667
conditions:
6768
isFirstField: Warn

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ lint: golangci-kal ## Run golangci-kal linter
139139
$(GOLANGCI_KAL) run
140140

141141
.PHONY: lint-fix
142-
lint-fix: golangci-kal ## Run golangci-lint linter and perform fixes
142+
lint-fix: golangci-kal ## Run golangci-kal linter and perform fixes
143143
$(GOLANGCI_KAL) run --fix
144144

145145
##@ Build
@@ -315,7 +315,6 @@ KUSTOMIZE_VERSION ?= v5.6.0
315315
CONTROLLER_TOOLS_VERSION ?= v0.17.1
316316
ENVTEST_VERSION ?= release-0.22
317317
GOLANGCI_LINT_VERSION ?= v2.7.2
318-
KAL_VERSION ?= v0.0.0-20260205134631-d65d24a9df89
319318
MOCKGEN_VERSION ?= v0.5.0
320319
KUTTL_VERSION ?= v0.24.0
321320
GOVULNCHECK_VERSION ?= v1.1.4
@@ -346,8 +345,8 @@ version: $(GOLANGCI_LINT_VERSION)
346345
name: golangci-kube-api-linter
347346
destination: $(LOCALBIN)
348347
plugins:
349-
- module: 'sigs.k8s.io/kube-api-linter'
350-
version: $(KAL_VERSION)
348+
- module: 'github.com/k-orc/openstack-resource-controller/v2/tools/orc-api-linter'
349+
path: ./tools/orc-api-linter
351350
endef
352351
export custom-gcl
353352

@@ -357,6 +356,7 @@ CUSTOM_GCL_FILE ?= $(shell pwd)/.custom-gcl.yml
357356
golangci-kal: $(GOLANGCI_KAL)
358357
$(GOLANGCI_KAL): $(LOCALBIN) $(GOLANGCI_LINT)
359358
$(file >$(CUSTOM_GCL_FILE),$(custom-gcl))
359+
cd tools/orc-api-linter && go mod tidy
360360
$(GOLANGCI_LINT) custom
361361

362362
.PHONY: mockgen

api/v1alpha1/zz_generated.domain-resource.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/zz_generated.flavor-resource.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/zz_generated.floatingip-resource.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/zz_generated.group-resource.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/zz_generated.image-resource.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/zz_generated.keypair-resource.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/zz_generated.network-resource.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/zz_generated.port-resource.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)