diff --git a/Makefile b/Makefile index 3e98ab8e..e06ef1ff 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,9 @@ 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 \ + 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 @@ -16,17 +18,25 @@ default: build format-tf: terraform fmt -recursive -list=false -.PHONY: generate-sdk -generate-sdk: generate-sdk-new +.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 $(SDK_SPECS); do \ + @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"; \ diff --git a/castai/resource_omni_cluster.go b/castai/resource_omni_cluster.go index d6ffcbf3..1db9f1e6 100644 --- a/castai/resource_omni_cluster.go +++ b/castai/resource_omni_cluster.go @@ -24,9 +24,15 @@ type omniClusterResource struct { } type omniClusterModel struct { - ID types.String `tfsdk:"id"` - OrganizationID types.String `tfsdk:"organization_id"` - ClusterID types.String `tfsdk:"cluster_id"` + ID types.String `tfsdk:"id"` + OrganizationID types.String `tfsdk:"organization_id"` + ClusterID types.String `tfsdk:"cluster_id"` + Status *omniClusterStatusModel `tfsdk:"status"` +} + +type omniClusterStatusModel struct { + OmniAgentVersion types.String `tfsdk:"omni_agent_version"` + PodCIDR types.String `tfsdk:"pod_cidr"` } func newOmniClusterResource() resource.Resource { @@ -62,6 +68,26 @@ func (r *omniClusterResource) Schema(_ context.Context, _ resource.SchemaRequest stringplanmodifier.RequiresReplace(), }, }, + "status": schema.SingleNestedAttribute{ + Optional: true, + Description: "Current status of the cluster to report on registration.", + Attributes: map[string]schema.Attribute{ + "omni_agent_version": schema.StringAttribute{ + Required: true, + Description: "Version of the omni agent running on the cluster.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "pod_cidr": schema.StringAttribute{ + Required: true, + Description: "Pod CIDR of the cluster.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + }, + }, }, } } @@ -91,11 +117,19 @@ func (r *omniClusterResource) Create(ctx context.Context, req resource.CreateReq return } + body := omni.RegisteredCluster{} + if plan.Status != nil { + body.Status = &omni.RegisteredClusterStatus{ + OmniAgentVersion: plan.Status.OmniAgentVersion.ValueString(), + PodCidr: plan.Status.PodCIDR.ValueString(), + } + } + client := r.client.omniAPI organizationID := plan.OrganizationID.ValueString() clusterID := plan.ClusterID.ValueString() - apiResp, err := client.ClustersAPIRegisterClusterWithResponse(ctx, organizationID, clusterID, omni.ClustersAPIRegisterClusterJSONRequestBody{}) + apiResp, err := client.ClustersAPIRegisterClusterWithResponse(ctx, organizationID, clusterID, body) if err != nil { resp.Diagnostics.AddError("Failed to register omni cluster", err.Error()) return diff --git a/docs/resources/omni_cluster.md b/docs/resources/omni_cluster.md index 3a065859..9ea39dd7 100644 --- a/docs/resources/omni_cluster.md +++ b/docs/resources/omni_cluster.md @@ -20,8 +20,20 @@ Omni cluster resource allows registering a cluster with CAST AI Omni provider. - `cluster_id` (String) CAST AI cluster ID to register - `organization_id` (String) CAST AI organization ID +### Optional + +- `status` (Attributes) Current status of the cluster to report on registration. (see [below for nested schema](#nestedatt--status)) + ### Read-Only - `id` (String) Resource ID (same as cluster_id) + +### Nested Schema for `status` + +Required: + +- `omni_agent_version` (String) Version of the omni agent running on the cluster. +- `pod_cidr` (String) Pod CIDR of the cluster. +