forked from akash-network/provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager_cleanup.go
67 lines (58 loc) · 1.66 KB
/
manager_cleanup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cluster
import (
"context"
"github.com/akash-network/node/manifest/v2beta1"
mtypes "github.com/akash-network/node/x/market/types/v1beta2"
logger "github.com/tendermint/tendermint/libs/log"
)
type purgeIPEntry struct {
serviceName string
port uint32
proto v2beta1.ServiceProtocol
}
type deployCleanupHelper struct {
client Client
log logger.Logger
lease mtypes.LeaseID
hostnamesToPurge []string
ipsToPurge []purgeIPEntry
}
func newDeployCleanupHelper(lease mtypes.LeaseID, client Client, log logger.Logger) *deployCleanupHelper {
return &deployCleanupHelper{
client: client,
log: log,
lease: lease,
}
}
func (dch *deployCleanupHelper) addHostname(hostname string) {
dch.hostnamesToPurge = append(dch.hostnamesToPurge, hostname)
}
func (dch *deployCleanupHelper) addIP(serviceName string, port uint32, proto v2beta1.ServiceProtocol) {
dch.ipsToPurge = append(
dch.ipsToPurge,
purgeIPEntry{
serviceName: serviceName,
port: port,
proto: proto,
})
}
func (dch *deployCleanupHelper) purgeAll(ctx context.Context) {
for _, hostname := range dch.hostnamesToPurge {
err := dch.client.PurgeDeclaredHostname(ctx, dch.lease, hostname)
if err != nil {
dch.log.Error("could not purge hostname",
"lease", dch.lease, "hsotname", hostname, "error", err)
}
}
for _, ipEntry := range dch.ipsToPurge {
err := dch.client.PurgeDeclaredIP(ctx, dch.lease, ipEntry.serviceName, ipEntry.port, ipEntry.proto)
if err != nil {
dch.log.Error("could not purge IP",
"lease", dch.lease,
"serviceName", ipEntry.serviceName,
"port", ipEntry.port,
"proto", ipEntry.proto,
"error", err)
}
}
}