@@ -81,6 +81,17 @@ func (s *Service) Reconcile(ctx context.Context) (err error) {
81
81
}
82
82
}
83
83
84
+ if len (network .Subnets ) > 1 {
85
+ conditions .MarkFalse (
86
+ s .scope .HetznerCluster ,
87
+ infrav1 .NetworkReadyCondition ,
88
+ infrav1 .MultipleSubnetsExistReason ,
89
+ clusterv1 .ConditionSeverityWarning ,
90
+ "multiple subnets not allowed" ,
91
+ )
92
+ return nil
93
+ }
94
+
84
95
conditions .MarkTrue (s .scope .HetznerCluster , infrav1 .NetworkReadyCondition )
85
96
s .scope .HetznerCluster .Status .Network = statusFromHCloudNetwork (network )
86
97
@@ -137,25 +148,33 @@ func (s *Service) createOpts() (hcloud.NetworkCreateOpts, error) {
137
148
138
149
// Delete implements deletion of the network.
139
150
func (s * Service ) Delete (ctx context.Context ) error {
140
- if s .scope .HetznerCluster .Status .Network == nil {
151
+ hetznerCluster := s .scope .HetznerCluster
152
+
153
+ if hetznerCluster .Status .Network == nil {
141
154
// nothing to delete
142
155
return nil
143
156
}
144
157
145
- id := s .scope .HetznerCluster .Status .Network .ID
158
+ // only delete the network if it is owned by us
159
+ if hetznerCluster .Status .Network .Labels [hetznerCluster .ClusterTagKey ()] != string (infrav1 .ResourceLifecycleOwned ) {
160
+ s .scope .V (1 ).Info ("network is not owned by us" , "id" , hetznerCluster .Status .Network .ID , "labels" , hetznerCluster .Status .Network .Labels )
161
+ return nil
162
+ }
163
+
164
+ id := hetznerCluster .Status .Network .ID
146
165
147
166
if err := s .scope .HCloudClient .DeleteNetwork (ctx , & hcloud.Network {ID : id }); err != nil {
148
- hcloudutil .HandleRateLimitExceeded (s . scope . HetznerCluster , err , "DeleteNetwork" )
167
+ hcloudutil .HandleRateLimitExceeded (hetznerCluster , err , "DeleteNetwork" )
149
168
// if resource has been deleted already then do nothing
150
169
if hcloud .IsError (err , hcloud .ErrorCodeNotFound ) {
151
170
s .scope .V (1 ).Info ("deleting network failed - not found" , "id" , id )
152
171
return nil
153
172
}
154
- record .Warnf (s . scope . HetznerCluster , "NetworkDeleteFailed" , "Failed to delete network with ID %v" , id )
173
+ record .Warnf (hetznerCluster , "NetworkDeleteFailed" , "Failed to delete network with ID %v" , id )
155
174
return fmt .Errorf ("failed to delete network: %w" , err )
156
175
}
157
176
158
- record .Eventf (s . scope . HetznerCluster , "NetworkDeleted" , "Deleted network with ID %v" , id )
177
+ record .Eventf (hetznerCluster , "NetworkDeleted" , "Deleted network with ID %v" , id )
159
178
return nil
160
179
}
161
180
@@ -170,9 +189,6 @@ func (s *Service) findNetwork(ctx context.Context) (*hcloud.Network, error) {
170
189
}
171
190
172
191
if network != nil {
173
- if len (network .Subnets ) > 1 {
174
- return nil , fmt .Errorf ("multiple subnets not allowed" )
175
- }
176
192
s .scope .V (1 ).Info ("found network" , "id" , network .ID , "name" , network .Name , "labels" , network .Labels )
177
193
return network , nil
178
194
}
0 commit comments