-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetwork.go
More file actions
105 lines (92 loc) · 3.12 KB
/
network.go
File metadata and controls
105 lines (92 loc) · 3.12 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package drivers
import (
"context"
"fmt"
"time"
"github.com/GoCodeAlone/workflow/platform"
)
// NetworkDriver handles CRUD operations for Docker Compose networks.
// It implements platform.ResourceDriver for the "docker-compose.network" type.
type NetworkDriver struct {
executor ComposeExecutor
projectDir string
}
// NewNetworkDriver creates a NetworkDriver.
func NewNetworkDriver(executor ComposeExecutor, projectDir string) *NetworkDriver {
return &NetworkDriver{
executor: executor,
projectDir: projectDir,
}
}
// ResourceType returns "docker-compose.network".
func (d *NetworkDriver) ResourceType() string {
return "docker-compose.network"
}
// Create provisions a new compose network.
func (d *NetworkDriver) Create(_ context.Context, name string, properties map[string]any) (*platform.ResourceOutput, error) {
return &platform.ResourceOutput{
Name: name,
Type: "network",
ProviderType: "docker-compose.network",
Properties: properties,
Status: platform.ResourceStatusActive,
LastSynced: time.Now(),
}, nil
}
// Read fetches the current state of a compose network.
func (d *NetworkDriver) Read(_ context.Context, name string) (*platform.ResourceOutput, error) {
return &platform.ResourceOutput{
Name: name,
Type: "network",
ProviderType: "docker-compose.network",
Properties: map[string]any{},
Status: platform.ResourceStatusActive,
LastSynced: time.Now(),
}, nil
}
// Update modifies a compose network definition.
func (d *NetworkDriver) Update(_ context.Context, name string, _, desired map[string]any) (*platform.ResourceOutput, error) {
return &platform.ResourceOutput{
Name: name,
Type: "network",
ProviderType: "docker-compose.network",
Properties: desired,
Status: platform.ResourceStatusActive,
LastSynced: time.Now(),
}, nil
}
// Delete removes a network from the compose definition.
func (d *NetworkDriver) Delete(_ context.Context, _ string) error {
return nil
}
// HealthCheck returns the health status of a compose network.
func (d *NetworkDriver) HealthCheck(_ context.Context, name string) (*platform.HealthStatus, error) {
return &platform.HealthStatus{
Status: "healthy",
Message: fmt.Sprintf("network %q is defined in compose file", name),
CheckedAt: time.Now(),
}, nil
}
// Scale is not supported for networks.
func (d *NetworkDriver) Scale(_ context.Context, _ string, _ map[string]any) (*platform.ResourceOutput, error) {
return nil, &platform.NotScalableError{ResourceType: "docker-compose.network"}
}
// Diff compares desired properties with current state.
func (d *NetworkDriver) Diff(ctx context.Context, name string, desired map[string]any) ([]platform.DiffEntry, error) {
current, err := d.Read(ctx, name)
if err != nil {
return nil, err
}
var diffs []platform.DiffEntry
for key, desiredVal := range desired {
currentVal, exists := current.Properties[key]
if !exists || fmt.Sprintf("%v", currentVal) != fmt.Sprintf("%v", desiredVal) {
diffs = append(diffs, platform.DiffEntry{
Path: key,
OldValue: currentVal,
NewValue: desiredVal,
})
}
}
return diffs, nil
}