Repository navigation
feat(api): make network.id optional and implement network creation - #34
fabian-schmitt wants to merge 15 commits into
Conversation
| stackitCluster := clusterScope.StackitCluster | ||
| input := bastionservice.Input(stackitCluster, nil) | ||
| input := bastionservice.Input(stackitCluster, clusterScope.NetworkID(), nil) |
There was a problem hiding this comment.
i think we should rather provide the cluster scope to the bastion input and call clusterScope.NetworkID() inside of the input method
| ) | ||
|
|
||
| func Input(stackitCluster *infrav1.StackitCluster, cloudInit []byte) cloud.BastionInput { | ||
| func Input(stackitCluster *infrav1.StackitCluster, networkID string, cloudInit []byte) cloud.BastionInput { |
There was a problem hiding this comment.
as in my comment further below we should change this method signature to use the clusterScope as an input
pseudo code:
| func Input(stackitCluster *infrav1.StackitCluster, networkID string, cloudInit []byte) cloud.BastionInput { | |
| func Input(cluster *scope.ClusterScope, cloudInit []byte) cloud.BastionInput { |
| func APIServerInput( | ||
| stackitCluster *infrav1.StackitCluster, | ||
| networkID string, | ||
| targets []cloud.LoadBalancerTargetInput, |
There was a problem hiding this comment.
same as for the bastion input, provide the cluster scope instead of extending the parameters of the method signature
| loadBalancer, err := cloudClient.EnsureAPIServerLoadBalancer( | ||
| ctx, | ||
| loadbalancerservice.APIServerInput(stackitCluster, seed), | ||
| loadbalancerservice.APIServerInput(stackitCluster, clusterScope.NetworkID(), seed), |
There was a problem hiding this comment.
use clusterScope as input instead of the stackitCluster and networkid
| return ctrl.Result{}, err | ||
| } | ||
| if err := cloudClient.DeleteBastion(ctx, bastionservice.Input(stackitCluster, nil), cloud.Bastion{ | ||
| if err := cloudClient.DeleteBastion(ctx, bastionservice.Input(stackitCluster, clusterScope.NetworkID(), nil), cloud.Bastion{ |
There was a problem hiding this comment.
use clusterScope as input instead of the stackitCluster and networkid
| networkID := machineScope.NetworkID() | ||
| if networkID == "" { | ||
| return nil, false, fmt.Errorf("%w: cluster network ID is not yet available", cloud.ErrTransient) | ||
| } |
There was a problem hiding this comment.
can this realistically even happen? i don't think the reconiliation for a machine can start if the cluster isn't reconcilled
| AvailabilityZone: machineScope.AvailabilityZone(), | ||
| SSHKeyName: stackitMachine.Spec.SSHKeyName, | ||
| NetworkID: stackitMachine.Spec.Network.ID, | ||
| NetworkID: networkID, |
There was a problem hiding this comment.
so most likely it is sufficient to use machineScope.NetworkID() here and it shouldn't case any issues
| if s.StackitMachine != nil && s.StackitMachine.Spec.Network.ID != "" { | ||
| return s.StackitMachine.Spec.Network.ID | ||
| } | ||
| if s.StackitCluster != nil { |
There was a problem hiding this comment.
i tried the most defensive approach and existing availabilityZone() is doing this too. I am not sure tho, open to change that...
Co-authored-by: Jan Larwig <jan.larwig@digits.schwarz>
Co-authored-by: Jan Larwig <jan.larwig@digits.schwarz>
Description
This PR implements support for managed network creation in
StackitCluster, resolving #9.Previously,
StackitClusterandStackitMachinerequired a pre-existing STACKIT network ID (.spec.network.id). This PR makes.spec.network.idoptional, introducing two operational modes:Managed Mode (omitted
spec.network.id):/24STACKIT network named<cluster-name>-network.cluster.x-k8s.io/cluster-name,managed-by, etc.).{ id: "<uuid>", managed: true }instatus.network.NetworkInUsecondition and warning event. If status was lost during deletion, falls back to tag-based discovery.Bring-Your-Own (BYO) Mode (provided
spec.network.id):{ id: "<uuid>", managed: false }instatus.network.Key Changes
API & CRDs (
api/v1alpha1/,config/crd/):.spec.networkand.spec.network.idoptional inStackitCluster,StackitMachine, and their templates.Status.Network(StackitNetworkStatus{ id, managed }) toStackitClusterStatus.kubectlprintcolumn forNetwork IDto read from.status.network.id(works for both BYO and managed clusters).Webhook Validation (
webhook/v1alpha1/):.spec.network.idor switching between managed and BYO after creation.Cloud Client & Abstraction (
cloud/):CreateNetworkInput{ Name, IPv4Prefix, Tags }.CreateNetwork,DeleteNetwork,FindNetworkByTags, andListNetworksByTagstocloud.Client,SDKClient, andcloudfake.Client.CreateNetworkto avoid duplicate networks across reconcile retries.cloud.CleanupByTagsto clean up managed networks in E2E environments.Scope & Service Layer (
scope/,cloud/services/):cloud/services/network/network.gofor network input assembly and tag generation.MachineScope.NetworkID()andClusterScope.NetworkID()for encapsulated fallback resolution (Machine Spec -> Cluster Spec -> Cluster Status).networkID.Reconciliation & Teardown (
controller/):reconcileNormalto provision or adopt managed networks and setClusterNetworkReadyCondition.reconcileDeleteto delete managed networks, handling 409 Conflict requeues gracefully.Tests & Documentation (
*_test.go,docs/):docs/src/getting-started/cloud-resources.md.Testing
make testToDo or at least to discuss
Cluster-template changes: Should we now default to empty network?
LoadBalancer NetworkID:
@ templates/cluster-template.yaml#L288-294
How to handle the STACKIT_NETWORK_ID in the cloud.yaml in the generated secret?
Should a controller patch or generate the value after the network is generated?