-
Notifications
You must be signed in to change notification settings - Fork 0
secondary networks for servers #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,6 +100,12 @@ func (p *Provider) CreateMachine(ctx context.Context, req *driver.CreateMachineR | |
| return nil, status.Error(codes.Unavailable, fmt.Sprintf("failed to patch NICs for server: %v", err)) | ||
| } | ||
|
|
||
| if providerSpec.Networking != nil && len(providerSpec.Networking.SecondaryNetworkIDs) > 0 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't this has to happen before patching the networkinterfaces? if this happens after This also means in the All this "waiting" feels a little cumbersome but its just how the create interface is designed. One call to rule em all. |
||
| if err := p.ensureAdditionalNetworks(ctx, projectID, providerSpec.Region, server.ID, providerSpec.Networking, nics); err != nil { | ||
| return nil, status.Error(codes.Unavailable, fmt.Sprintf("failed to ensure additional networks for server: %v", err)) | ||
| } | ||
| } | ||
|
|
||
| // Generate ProviderID in format: stackit://<projectId>/<serverId> | ||
| providerID := fmt.Sprintf("%s://%s/%s", StackitProviderName, projectID, server.ID) | ||
| klog.V(2).Infof("Successfully created server %q with ID %q for machine %q", server.Name, server.ID, req.Machine.Name) | ||
|
|
@@ -111,6 +117,21 @@ func (p *Provider) CreateMachine(ctx context.Context, req *driver.CreateMachineR | |
| }, nil | ||
| } | ||
|
|
||
| func (p *Provider) ensureAdditionalNetworks(ctx context.Context, projectID, region, serverID string, networkingSpec *api.NetworkingSpec, nics []*client.NIC) error { | ||
| for _, networkID := range networkingSpec.SecondaryNetworkIDs { | ||
| exists := slices.ContainsFunc(nics, func(nic *client.NIC) bool { | ||
| return nic.NetworkID == networkID | ||
| }) | ||
| if exists { | ||
| continue | ||
| } | ||
| if err := p.client.AttachServerToNetwork(ctx, projectID, region, networkID, serverID); err != nil { | ||
| return fmt.Errorf("attaching server %s to network %s: %w", serverID, networkID, err) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // nolint: gocyclo // this function is already pretty simple | ||
| func (p *Provider) createServerRequest(req *driver.CreateMachineRequest, providerSpec *api.ProviderSpec) *client.CreateServerRequest { | ||
| // Build labels: merge ProviderSpec labels with MCM-specific labels | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add a check that the list contains unique networkIDs and that they are not equal to the "primary" networkID (if set)