Skip to content

Commit 7a9426b

Browse files
authored
OMNI-496: update RegisterCluster API model (#672)
1 parent b1a2ce4 commit 7a9426b

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
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: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ type omniClusterResource struct {
2424
}
2525

2626
type omniClusterModel struct {
27-
ID types.String `tfsdk:"id"`
28-
OrganizationID types.String `tfsdk:"organization_id"`
29-
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+
Status *omniClusterStatusModel `tfsdk:"status"`
31+
}
32+
33+
type omniClusterStatusModel struct {
34+
OmniAgentVersion types.String `tfsdk:"omni_agent_version"`
35+
PodCIDR types.String `tfsdk:"pod_cidr"`
3036
}
3137

3238
func newOmniClusterResource() resource.Resource {
@@ -62,6 +68,26 @@ func (r *omniClusterResource) Schema(_ context.Context, _ resource.SchemaRequest
6268
stringplanmodifier.RequiresReplace(),
6369
},
6470
},
71+
"status": schema.SingleNestedAttribute{
72+
Optional: true,
73+
Description: "Current status of the cluster to report on registration.",
74+
Attributes: map[string]schema.Attribute{
75+
"omni_agent_version": schema.StringAttribute{
76+
Required: true,
77+
Description: "Version of the omni agent running on the cluster.",
78+
PlanModifiers: []planmodifier.String{
79+
stringplanmodifier.RequiresReplace(),
80+
},
81+
},
82+
"pod_cidr": schema.StringAttribute{
83+
Required: true,
84+
Description: "Pod CIDR of the cluster.",
85+
PlanModifiers: []planmodifier.String{
86+
stringplanmodifier.RequiresReplace(),
87+
},
88+
},
89+
},
90+
},
6591
},
6692
}
6793
}
@@ -91,11 +117,19 @@ func (r *omniClusterResource) Create(ctx context.Context, req resource.CreateReq
91117
return
92118
}
93119

120+
body := omni.RegisteredCluster{}
121+
if plan.Status != nil {
122+
body.Status = &omni.RegisteredClusterStatus{
123+
OmniAgentVersion: plan.Status.OmniAgentVersion.ValueString(),
124+
PodCidr: plan.Status.PodCIDR.ValueString(),
125+
}
126+
}
127+
94128
client := r.client.omniAPI
95129
organizationID := plan.OrganizationID.ValueString()
96130
clusterID := plan.ClusterID.ValueString()
97131

98-
apiResp, err := client.ClustersAPIRegisterClusterWithResponse(ctx, organizationID, clusterID, omni.ClustersAPIRegisterClusterJSONRequestBody{})
132+
apiResp, err := client.ClustersAPIRegisterClusterWithResponse(ctx, organizationID, clusterID, body)
99133
if err != nil {
100134
resp.Diagnostics.AddError("Failed to register omni cluster", err.Error())
101135
return

docs/resources/omni_cluster.md

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

0 commit comments

Comments
 (0)