Skip to content

Commit

Permalink
Support External Networks
Browse files Browse the repository at this point in the history
Damnit CAPO!!!!  It does infer the external network, and when I say
"the" I mean only one, or it has a hissy fit, so we need to arbitrarily
choose one for it.
  • Loading branch information
spjmurray committed Jun 10, 2024
1 parent 242270d commit 9d5f042
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 87 deletions.
4 changes: 2 additions & 2 deletions charts/region/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Helm chart for deploying Unikorn's Region Controller

type: application

version: v0.1.2
appVersion: v0.1.2
version: v0.1.3
appVersion: v0.1.3

icon: https://raw.githubusercontent.com/unikorn-cloud/unikorn/main/icons/default.png
48 changes: 47 additions & 1 deletion pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ func convertCloudConfig(identity *unikornv1.Identity, in *providers.CloudConfig)
return out
}

func generateClusterInfo(in *openapi.IdentityWrite) *providers.ClusterInfo {
out := &providers.ClusterInfo{
OrganizationID: in.OrganizationId,
ProjectID: in.ProjectId,
ClusterID: in.ClusterId,
}

return out
}

func (h *Handler) PostApiV1RegionsRegionIDIdentities(w http.ResponseWriter, r *http.Request, regionID openapi.RegionIDParameter) {
request := &openapi.IdentityWrite{}

Expand All @@ -234,7 +244,7 @@ func (h *Handler) PostApiV1RegionsRegionIDIdentities(w http.ResponseWriter, r *h
return
}

identity, cloudconfig, err := provider.CreateIdentity(r.Context(), &providers.ClusterInfo{})
identity, cloudconfig, err := provider.CreateIdentity(r.Context(), generateClusterInfo(request))
if err != nil {
errors.HandleError(w, r, err)
return
Expand All @@ -246,3 +256,39 @@ func (h *Handler) PostApiV1RegionsRegionIDIdentities(w http.ResponseWriter, r *h

func (h *Handler) DeleteApiV1RegionsRegionIDIdentitiesIdentityID(w http.ResponseWriter, r *http.Request, regionID openapi.RegionIDParameter, identityID openapi.IdentityIDParameter) {
}

func convertExternalNetwork(in providers.ExternalNetwork) openapi.ExternalNetwork {
out := openapi.ExternalNetwork{
Id: in.ID,
Name: in.Name,
}

return out
}

func convertExternalNetworks(in providers.ExternalNetworks) openapi.ExternalNetworks {
out := make(openapi.ExternalNetworks, len(in))

for i := range in {
out[i] = convertExternalNetwork(in[i])
}

return out
}

func (h *Handler) GetApiV1RegionsRegionIDExternalnetworks(w http.ResponseWriter, r *http.Request, regionID openapi.RegionIDParameter) {
provider, err := region.NewClient(h.client, h.namespace).Provider(r.Context(), regionID)
if err != nil {
errors.HandleError(w, r, err)
return
}

result, err := provider.ListExternalNetworks(r.Context())
if err != nil {
errors.HandleError(w, r, err)
return
}

h.setCacheable(w)
util.WriteJSONResponse(w, r, http.StatusOK, convertExternalNetworks(result))
}
141 changes: 141 additions & 0 deletions pkg/openapi/client.go

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

39 changes: 39 additions & 0 deletions pkg/openapi/router.go

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

Loading

0 comments on commit 9d5f042

Please sign in to comment.