Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
5be7a32
refactor(cloud): extract public IPs service in CAPG style
LSchu Oct 19, 2026
235e129
fix: add legacy event api permssion to controller role
LSchu Oct 28, 2026
36f9f8b
feat: create bastion host in a single availability zone and not metro
LSchu Oct 28, 2026
1f76439
docs: removed comments
LSchu Oct 29, 2026
84012bf
feat: refactor security groups
LSchu Oct 30, 2026
2d595d2
refactor: public ip service (#35)
LSchu Nov 10, 2026
018954c
Merge branch 'feat/refactor-service-implementations' into feat/refact…
LSchu Nov 11, 2026
254dd8b
refactor: fix merge
LSchu Nov 11, 2026
2fddb3a
feat: refactor loadbalancer service
LSchu Nov 10, 2026
f6ae98b
feat: refactor server service
LSchu Nov 12, 2026
2651d71
feat: refactor publicip, network, and availabilityzone services
LSchu Nov 12, 2026
86ad4a9
refactor: remove cloud middle-man wrappers and deduplicate service he…
LSchu Nov 12, 2026
4c07314
refactor: deduplicate bastion teardown and server ID lookup by tags
LSchu Nov 12, 2026
cdda171
refactor: remove unused interfaces, functions, and struct fields
LSchu Nov 12, 2026
36df058
refactor: remove leftover pre-HTTP-transport helpers and dead state i…
LSchu Nov 12, 2026
4ff52c6
refactor: consolidate service ClientScope aliases and FindByTags in s…
LSchu Nov 12, 2026
735a265
fix: resolve spec.ID on reconcile in loadbalancer/securitygroup and u…
LSchu Nov 12, 2026
0f1b477
fix: adjusted logmessages
LSchu Nov 12, 2026
a43f547
refactor: unexport internal methods and fields in scope and cloud ser…
LSchu Nov 12, 2026
1c84b16
refactor: use service Delete in CleanupByTags and unexport service cl…
LSchu Nov 13, 2026
dbab6b9
fix: continue on partial delete errors and delete servers before secu…
LSchu Nov 13, 2026
eb45e5b
refactor: defer NIC lookup in server listByTags until single server i…
LSchu Nov 13, 2026
a0953b5
fix: preserve bastion CloudInitHash on tag adoption and gate bastion …
LSchu Nov 13, 2026
26af476
fix: include AdditionalLabels in nodeSSHSecurityGroupSpec ServerSelector
LSchu Nov 13, 2026
157dff0
refactor: move bastion enablement guard into MachineScope.SecurityGro…
LSchu Nov 13, 2026
b248891
refactor: deduplicate resource lookup and deletion in server and load…
LSchu Nov 13, 2026
cfd074f
refactor: replace hardcoded bootstrap target IP and protocol literals…
LSchu Nov 13, 2026
b14ce80
refactor: remove duplicated STACKIT SDK helpers from e2e tests
LSchu Nov 13, 2026
c521528
docs: remove comments
LSchu Nov 13, 2026
cab79ba
refactor: remove unused return fields on ParseProviderID
LSchu Nov 13, 2026
2c74147
refactor: remove unused receiver from deleteBastionResources
LSchu Nov 13, 2026
dbccb0c
fix: treat missing tag-referenced remote security group as transient …
LSchu Nov 13, 2026
4273372
fix: avoid dual sentinel wrapping on missing remote security group
LSchu Nov 13, 2026
5c7a847
refactor: remove unused ParseProviderID function
LSchu Nov 13, 2026
623188f
refactor: remove redundant ClearBastionStatus after bastion service d…
LSchu Nov 13, 2026
1dc195d
refactor: deduplicate bastion deletion event handling and move HasBas…
LSchu Nov 13, 2026
21f94e0
fix: only delete bastion server when recreating on cloud-init change
LSchu Nov 13, 2026
92acb63
refactor: use shared.DeleteByIDOrTags in publicip.Delete
LSchu Nov 13, 2026
90caba1
refactor: remove redundant client struct across cloud services
LSchu Nov 16, 2026
9a07200
refactor: move bastion SSH key and CIDR validation into server and se…
LSchu Nov 16, 2026
77c32eb
refactor: remove duplicate port range check
LSchu Nov 16, 2026
40bc54b
refactor: extract generic shared.ListIDsByTags helper
LSchu Nov 16, 2026
2deb8d5
fix: require ingress rule source and set target port on pool update
LSchu Nov 16, 2026
0f25312
test: cover RequireSSHKey in scope ServerSpec and use DirectionIngres…
LSchu Nov 16, 2026
ee506cb
refactor: use shared.DeleteByIDOrTags in securitygroup.deleteSecurity…
LSchu Nov 16, 2026
95d85c1
refactor: align securitygroup deleteByID with other cloud services
LSchu Nov 16, 2026
1babd52
refactor: remove redundant empty ID check in cleanupAndDeleteByID
LSchu Nov 16, 2026
688cd3f
fix: log no-op SDK calls in attachToServer and detachFromServer
LSchu Nov 16, 2026
f1e1a9d
refactor: move CloudFailureResult and CredentialFailureResult onto Cl…
LSchu Nov 16, 2026
80e1ea1
docs: update architecture.md to reflect scope and service packages
LSchu Nov 17, 2026
f5f44aa
docs: refine architecture.md formatting and spec struct name
LSchu Nov 17, 2026
85d4a30
refactor: unify state clearing callbacks across server and loadbalanc…
LSchu Nov 17, 2026
639a463
refactor: use scope condition and credential failure helpers across c…
LSchu Nov 17, 2026
983690b
refactor: align deletion order for bastion resources
LSchu Nov 17, 2026
08efbfa
refactor: combine LoadBalancerSpec SetID and SetAddress into SetLoadB…
LSchu Nov 17, 2026
36dbda0
refactor: unify PublicIPSpec and SecurityGroupSpec callbacks to pass …
LSchu Nov 17, 2026
bcdb367
refactor: extract shared.ListByTags for tag-filtered SDK listing
LSchu Nov 17, 2026
e81734e
refactor: remove single-use shared helpers and update cloud.Client doc
LSchu Nov 17, 2026
6d1db2f
refactor: unify MapContains with labelsContainTags and use ListByTags…
LSchu Nov 17, 2026
da2f18e
Merge remote-tracking branch 'origin' into refactor/service-implement…
tuunit Nov 18, 2026
d88ae61
refactor: infrastructure into controllers and server state into servi…
tuunit Nov 18, 2026
f4e036e
chore: cleanup unnecessary providerid file
tuunit Nov 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 64 additions & 40 deletions cloud/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,86 @@ package cloud

import (
"context"
"errors"
"fmt"
"maps"
"strings"

"github.com/stackitcloud/cluster-api-provider-stackit/cloud/services/loadbalancer"
"github.com/stackitcloud/cluster-api-provider-stackit/cloud/services/network"
"github.com/stackitcloud/cluster-api-provider-stackit/cloud/services/publicip"
"github.com/stackitcloud/cluster-api-provider-stackit/cloud/services/securitygroup"
"github.com/stackitcloud/cluster-api-provider-stackit/cloud/services/server"
"github.com/stackitcloud/cluster-api-provider-stackit/cloud/services/shared"
)

type cleanupScope struct {
Client
tags map[string]string
}

// CleanupByTags deletes provider-managed cloud resources matching tags without
// relying on Kubernetes objects. Load balancers are deleted before servers so
// server deletion is not blocked by target attachments.
// server deletion is not blocked by target attachments, servers are deleted
// before security groups so attached servers do not block security group
// deletion if server detachment fails or lags, and networks are deleted last.
func CleanupByTags(ctx context.Context, client Client, tags map[string]string) error {
if len(tags) == 0 {
return fmt.Errorf("%w: empty cleanup tag selector", ErrInvalidInput)
return fmt.Errorf("%w: empty cleanup tag selector", shared.ErrInvalidInput)
}

var errs []string
bastionTags := make(map[string]string, len(tags)+1)
maps.Copy(bastionTags, tags)
bastionTags["cluster-api-provider-stackit/resource-role"] = "bastion"
if err := client.DeleteBastion(ctx, BastionInput{Tags: bastionTags}, Bastion{}); err != nil && !IsNotFound(err) {
errs = append(errs, fmt.Sprintf("delete bastion resources: %v", err))
scope := &cleanupScope{
Client: client,
tags: tags,
}

loadBalancers, err := client.ListAPIServerLoadBalancersByTags(ctx, tags)
if err != nil {
errs = append(errs, err.Error())
} else {
for _, loadBalancer := range loadBalancers {
if err := client.DeleteAPIServerLoadBalancer(ctx, loadBalancer.ID); err != nil && !IsNotFound(err) {
errs = append(errs, fmt.Sprintf("delete load balancer %q: %v", loadBalancer.ID, err))
}
var errs []error
for _, deleteFn := range []func(context.Context) error{
publicip.New(scope).Delete,
loadbalancer.New(scope).Delete,
server.New(scope).Delete,
securitygroup.New(scope).Delete,
network.New(scope).Delete,
} {
if err := deleteFn(ctx); err != nil {
errs = append(errs, err)
}
}

servers, err := client.ListServersByTags(ctx, tags)
if err != nil {
errs = append(errs, err.Error())
} else {
for _, server := range servers {
if err := client.DeleteServer(ctx, server.ID); err != nil && !IsNotFound(err) {
errs = append(errs, fmt.Sprintf("delete server %q: %v", server.ID, err))
}
}
if len(errs) > 0 {
return fmt.Errorf("%w: %w", shared.ErrTransient, errors.Join(errs...))
}
return nil
}

networks, err := client.ListNetworksByTags(ctx, tags)
if err != nil {
errs = append(errs, err.Error())
} else {
for _, net := range networks {
if err := client.DeleteNetwork(ctx, net.ID); err != nil && !IsNotFound(err) {
errs = append(errs, fmt.Sprintf("delete network %q: %v", net.ID, err))
}
}
func (s *cleanupScope) PublicIPSpec() publicip.PublicIPSpec {
return publicip.PublicIPSpec{
Tags: s.tags,
ServerSelector: s.tags,
}
}

if len(errs) > 0 {
return fmt.Errorf("%w: %s", ErrTransient, strings.Join(errs, "; "))
func (s *cleanupScope) LoadBalancerSpec() loadbalancer.LoadBalancerSpec {
return loadbalancer.LoadBalancerSpec{
Tags: s.tags,
}
}

func (s *cleanupScope) ServerSpec() server.ServerSpec {
return server.ServerSpec{
Tags: s.tags,
}
}

func (s *cleanupScope) SecurityGroupSpecs() []securitygroup.SecurityGroupSpec {
return []securitygroup.SecurityGroupSpec{
{
Tags: s.tags,
ServerSelector: s.tags,
},
}
}

func (s *cleanupScope) NetworkSpec() network.NetworkSpec {
return network.NetworkSpec{
Tags: s.tags,
Managed: true,
}
return nil
}
Loading
Loading