Skip to content

Commit a3c85f3

Browse files
committed
fixup! OMNI-496: update RegisterCluster API model
1 parent 3df6db4 commit a3c85f3

File tree

3 files changed

+68
-33
lines changed

3 files changed

+68
-33
lines changed

castai/resource_omni_cluster.go

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ 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 {
3034
OmniAgentVersion types.String `tfsdk:"omni_agent_version"`
3135
PodCIDR types.String `tfsdk:"pod_cidr"`
3236
}
@@ -64,18 +68,24 @@ func (r *omniClusterResource) Schema(_ context.Context, _ resource.SchemaRequest
6468
stringplanmodifier.RequiresReplace(),
6569
},
6670
},
67-
"omni_agent_version": schema.StringAttribute{
71+
"status": schema.SingleNestedAttribute{
6872
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(),
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+
},
7989
},
8090
},
8191
},
@@ -107,23 +117,11 @@ func (r *omniClusterResource) Create(ctx context.Context, req resource.CreateReq
107117
return
108118
}
109119

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-
122120
body := omni.RegisteredCluster{}
123-
if agentVersion != "" {
121+
if plan.Status != nil {
124122
body.Status = &omni.RegisteredClusterStatus{
125-
OmniAgentVersion: agentVersion,
126-
PodCidr: podCIDR,
123+
OmniAgentVersion: plan.Status.OmniAgentVersion.ValueString(),
124+
PodCidr: plan.Status.PodCIDR.ValueString(),
127125
}
128126
}
129127

castai/sdk/api.gen.go

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

docs/resources/omni_cluster.md

Lines changed: 5 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)