Skip to content

Commit

Permalink
Make Provisioning Work Fully
Browse files Browse the repository at this point in the history
We need a network for every cluster, not just those that may require
one.
  • Loading branch information
spjmurray committed Dec 6, 2024
1 parent 4cc0deb commit c36ab21
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,10 @@ spec:
hostname:
description: Hostname of the machine.
type: string
privateIP:
privateIp:
description: PrivateIP is the private IP address.
type: string
publicIP:
publicIp:
description: PublicIP is the public IP address if requested.
type: string
required:
Expand Down
44 changes: 4 additions & 40 deletions pkg/server/handler/cluster/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,30 +193,6 @@ func (c *Client) createNetworkOpenstack(ctx context.Context, organizationID, pro
return resp.JSON201, nil
}

func (c *Client) getRegion(ctx context.Context, organizationID, regionID string) (*regionapi.RegionRead, error) {
// TODO: Need a straight get interface rather than a list.
resp, err := c.region.GetApiV1OrganizationsOrganizationIDRegionsWithResponse(ctx, organizationID)
if err != nil {
return nil, errors.OAuth2ServerError("unable to get region").WithError(err)
}

if resp.StatusCode() != http.StatusOK {
return nil, errors.OAuth2ServerError("unable to get region")
}

results := *resp.JSON200

index := slices.IndexFunc(results, func(region regionapi.RegionRead) bool {
return region.Metadata.Id == regionID
})

if index < 0 {
return nil, errors.OAuth2ServerError("unable to get region")
}

return &results[index], nil
}

func (c *Client) applyCloudSpecificConfiguration(ctx context.Context, organizationID, projectID, regionID string, identity *regionapi.IdentityRead, cluster *unikornv1.ComputeCluster) error {

Check failure on line 196 in pkg/server/handler/cluster/client.go

View workflow job for this annotation

GitHub Actions / Runtime

`(*Client).applyCloudSpecificConfiguration` - `regionID` is unused (unparam)
// Save the identity ID for later cleanup.
if cluster.Annotations == nil {
Expand All @@ -225,25 +201,13 @@ func (c *Client) applyCloudSpecificConfiguration(ctx context.Context, organizati

cluster.Annotations[constants.IdentityAnnotation] = identity.Metadata.Id

// Apply any region specific configuration based on feature flags.
region, err := c.getRegion(ctx, organizationID, regionID)
// Provision a network for nodes to attach to.
network, err := c.createNetworkOpenstack(ctx, organizationID, projectID, cluster, identity)
if err != nil {
return err
return errors.OAuth2ServerError("failed to create physical network").WithError(err)
}

// Provision a vlan physical network for bare-metal nodes to attach to.
// For now, do this for everything, given you may start with a VM only cluster
// and suddely want some compute nodes. CAPO won't allow you to change
// networks, so play it safe. Please note that the cluster controller will
// automatically discover the physical network, so we don't need an annotation.
if region.Spec.Features.PhysicalNetworks {
network, err := c.createNetworkOpenstack(ctx, organizationID, projectID, cluster, identity)
if err != nil {
return errors.OAuth2ServerError("failed to create physical network").WithError(err)
}

cluster.Annotations[constants.PhysicalNetworkAnnotation] = network.Metadata.Id
}
cluster.Annotations[constants.PhysicalNetworkAnnotation] = network.Metadata.Id

return nil
}
Expand Down

0 comments on commit c36ab21

Please sign in to comment.