Skip to content

Commit 3df6db4

Browse files
committed
OMNI-496: update RegisterCluster API model
1 parent 9ba13f6 commit 3df6db4

File tree

5 files changed

+208
-32
lines changed

5 files changed

+208
-32
lines changed

Makefile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ export SWAGGER_LOCATION ?= https://$(API_HOST)/v1/spec/openapi.json
77
# To add a new SDK, add a line here in the format: package_name:ApiTagName:spec_location
88
SDK_SPECS := \
99
cluster_autoscaler:HibernationSchedulesAPI:https://$(API_HOST)/spec/cluster-autoscaler/openapi.yaml \
10-
organization_management:EnterpriseAPI:https://$(API_HOST)/spec/organization-management/openapi.yaml \
10+
organization_management:EnterpriseAPI:https://$(API_HOST)/spec/organization-management/openapi.yaml
11+
12+
OMNI_SDK_SPECS := \
1113
omni:EdgeLocationsAPI,ClustersAPI:https://$(API_HOST)/spec/omni/openapi.yaml
1214

1315
default: build
@@ -16,17 +18,25 @@ default: build
1618
format-tf:
1719
terraform fmt -recursive -list=false
1820

19-
.PHONY: generate-sdk
20-
generate-sdk: generate-sdk-new
21+
.PHONY: generate-sdk
22+
generate-sdk:
2123
@echo "==> Generating main sdk client"
24+
$(MAKE) generate-sdk-new SPECS="$(SDK_SPECS)"
2225
go generate castai/sdk/generate.go
2326

27+
.PHONY: generate-omni-sdk
28+
generate-omni-sdk:
29+
@echo "==> Generating omni sdk client"
30+
$(MAKE) generate-sdk-new SPECS="$(OMNI_SDK_SPECS)"
31+
2432
.PHONY: generate-sdk-new
33+
# Internal target: run oapi-codegen for the given SPECS variable.
34+
# Not meant to be called directly; use generate-sdk or generate-omni-sdk.
2535
generate-sdk-new:
2636
@echo "==> Generating api sdk clients"
2737
@go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.4.1
2838
@go install github.com/golang/mock/mockgen
29-
@cd castai/sdk && for spec in $(SDK_SPECS); do \
39+
@cd castai/sdk && for spec in $(SPECS); do \
3040
IFS=':' read -r pkg tag loc <<< "$$spec"; \
3141
[ -z "$$pkg" ] && continue; \
3242
echo "generating sdk for: $$tag from $$loc"; \

castai/resource_omni_cluster.go

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1111
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1212
"github.com/hashicorp/terraform-plugin-framework/types"
13+
14+
"github.com/castai/terraform-provider-castai/castai/sdk/omni"
1315
)
1416

1517
var (
@@ -22,9 +24,11 @@ type omniClusterResource struct {
2224
}
2325

2426
type omniClusterModel struct {
25-
ID types.String `tfsdk:"id"`
26-
OrganizationID types.String `tfsdk:"organization_id"`
27-
ClusterID types.String `tfsdk:"cluster_id"`
27+
ID types.String `tfsdk:"id"`
28+
OrganizationID types.String `tfsdk:"organization_id"`
29+
ClusterID types.String `tfsdk:"cluster_id"`
30+
OmniAgentVersion types.String `tfsdk:"omni_agent_version"`
31+
PodCIDR types.String `tfsdk:"pod_cidr"`
2832
}
2933

3034
func newOmniClusterResource() resource.Resource {
@@ -60,6 +64,20 @@ func (r *omniClusterResource) Schema(_ context.Context, _ resource.SchemaRequest
6064
stringplanmodifier.RequiresReplace(),
6165
},
6266
},
67+
"omni_agent_version": schema.StringAttribute{
68+
Optional: true,
69+
Description: "Version of the omni agent running on the cluster",
70+
PlanModifiers: []planmodifier.String{
71+
stringplanmodifier.RequiresReplace(),
72+
},
73+
},
74+
"pod_cidr": schema.StringAttribute{
75+
Optional: true,
76+
Description: "Pod CIDR of the cluster",
77+
PlanModifiers: []planmodifier.String{
78+
stringplanmodifier.RequiresReplace(),
79+
},
80+
},
6381
},
6482
}
6583
}
@@ -89,11 +107,31 @@ func (r *omniClusterResource) Create(ctx context.Context, req resource.CreateReq
89107
return
90108
}
91109

110+
agentVersion := plan.OmniAgentVersion.ValueString()
111+
podCIDR := plan.PodCIDR.ValueString()
112+
113+
// Both fields must be set or both must be empty
114+
if (agentVersion == "") != (podCIDR == "") {
115+
resp.Diagnostics.AddError(
116+
"Invalid configuration",
117+
"all cluster status fields (omni_agent_version and pod_cidr) must be set",
118+
)
119+
return
120+
}
121+
122+
body := omni.RegisteredCluster{}
123+
if agentVersion != "" {
124+
body.Status = &omni.RegisteredClusterStatus{
125+
OmniAgentVersion: agentVersion,
126+
PodCidr: podCIDR,
127+
}
128+
}
129+
92130
client := r.client.omniAPI
93131
organizationID := plan.OrganizationID.ValueString()
94132
clusterID := plan.ClusterID.ValueString()
95133

96-
apiResp, err := client.ClustersAPIRegisterClusterWithResponse(ctx, organizationID, clusterID)
134+
apiResp, err := client.ClustersAPIRegisterClusterWithResponse(ctx, organizationID, clusterID, body)
97135
if err != nil {
98136
resp.Diagnostics.AddError("Failed to register omni cluster", err.Error())
99137
return

castai/sdk/omni/api.gen.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

castai/sdk/omni/client.gen.go

Lines changed: 49 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)