Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"; \
Expand Down
42 changes: 38 additions & 4 deletions castai/resource_omni_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
},
},
},
},
},
}
}
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions docs/resources/omni_cluster.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading