-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathMakefile
More file actions
106 lines (87 loc) · 3.78 KB
/
Makefile
File metadata and controls
106 lines (87 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
SHELL := /bin/bash
export API_HOST ?= api.cast.ai
export API_TAGS ?= ExternalClusterAPI,PoliciesAPI,NodeConfigurationAPI,NodeTemplatesAPI,AuthTokenAPI,ScheduledRebalancingAPI,InventoryAPI,UsersAPI,OperationsAPI,EvictorAPI,SSOAPI,CommitmentsAPI,WorkloadOptimizationAPI,ServiceAccountsAPI,RbacServiceAPI,RuntimeSecurityAPI,AllocationGroupAPI,DboAPI
export SWAGGER_LOCATION ?= https://$(API_HOST)/v1/spec/openapi.json
# To add a new SDK, add a line here in the format: package_name:ApiTagName:spec_location
SDK_SPECS := \
cluster_autoscaler:HibernationSchedulesAPI:https://$(API_HOST)/spec/cluster-autoscaler/openapi.yaml \
organization_management:EnterpriseAPI:https://$(API_HOST)/spec/organization-management/openapi.yaml
OMNI_SDK_SPECS := \
omni:EdgeLocationsAPI,ClustersAPI:https://$(API_HOST)/spec/omni/openapi.yaml
default: build
.PHONY: format-tf
format-tf:
terraform fmt -recursive -list=false
.PHONY: generate-sdk
generate-sdk:
@echo "==> Generating main sdk client"
$(MAKE) generate-sdk-new SPECS="$(SDK_SPECS)"
go generate castai/sdk/generate.go
.PHONY: generate-omni-sdk
generate-omni-sdk:
@echo "==> Generating omni sdk client"
$(MAKE) generate-sdk-new SPECS="$(OMNI_SDK_SPECS)"
.PHONY: generate-sdk-new
# Internal target: run oapi-codegen for the given SPECS variable.
# Not meant to be called directly; use generate-sdk or generate-omni-sdk.
generate-sdk-new:
@echo "==> Generating api sdk clients"
@go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.4.1
@go install github.com/golang/mock/mockgen
@cd castai/sdk && for spec in $(SPECS); do \
IFS=':' read -r pkg tag loc <<< "$$spec"; \
[ -z "$$pkg" ] && continue; \
echo "generating sdk for: $$tag from $$loc"; \
mkdir -p $$pkg/mock && \
oapi-codegen -o $$pkg/api.gen.go --old-config-style -generate types -include-tags $$tag -package $$pkg $$loc && \
oapi-codegen -o $$pkg/client.gen.go --old-config-style -templates codegen/templates -generate client -include-tags $$tag -package $$pkg $$loc && \
mockgen -source $$pkg/client.gen.go -destination $$pkg/mock/client.go . ClientInterface; \
done
# The following command also rewrites existing documentation
.PHONY: generate-docs
generate-docs:
go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@v0.14.1
tfplugindocs generate --rendered-provider-name "CAST AI" --ignore-deprecated --provider-name terraform-provider-castai
.PHONY: generate-all
generate-all: generate-sdk generate-docs
.PHONY: build
build: generate-sdk
build: generate-docs
build:
@echo "==> Building terraform-provider-castai"
go build
.PHONY: lint
lint:
@echo "==> Running lint"
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run
.PHONY: test
test: build
@echo "==> Running tests"
go test $$(go list ./... | grep -v vendor/ | grep -v e2e) -timeout=1m -parallel=4
.PHONY: testacc-eks
testacc-eks: build
@echo "==> Running EKS acceptance tests"
TF_ACC=1 go test ./castai/... '-run=^TestAccEKS_' -v -timeout 50m
.PHONY: testacc-gke
testacc-gke: build
@echo "==> Running GKE acceptance tests"
TF_ACC=1 go test ./castai/... '-run=^TestAccGKE_' -v -timeout 50m
.PHONY: testacc-aks
testacc-aks: build
@echo "==> Running AKS acceptance tests"
TF_ACC=1 go test ./castai/... '-run=^TestAccAKS_' -v -timeout 50m
.PHONY: testacc-cloud-agnostic
testacc-cloud-agnostic: build
@echo "==> Running cloud agnostic acceptance tests"
TF_ACC=1 go test ./castai/... '-run=^TestAccCloudAgnostic_' -v -timeout 50m
.PHONY: validate-terraform-examples
validate-terraform-examples:
@.ci/scripts/validate-examples.sh
.PHONY: plan-terraform-example
plan-terraform-example:
@if [ -z "$(EXAMPLE_DIR)" ]; then \
echo "Error: EXAMPLE_DIR is required. Usage: make plan-terraform-example EXAMPLE_DIR=examples/.../..."; \
exit 1; \
fi
@.ci/scripts/plan-example.sh "$(EXAMPLE_DIR)"