feat(cli): Added output of diff when updating outboundConnections in the desired manifest

This commit is contained in:
Richard Robert Reitz 2025-10-06 16:45:53 +02:00
parent 51ce4ed111
commit 36934e8abf
2 changed files with 43 additions and 25 deletions

View file

@ -384,17 +384,20 @@ func (p *EdgeConnectPlanner) compareAppStates(current, desired *AppState) ([]str
} }
// Compare outbound connections // Compare outbound connections
if !p.compareOutboundConnections(current.OutboundConnections, desired.OutboundConnections) { outboundChanges := p.compareOutboundConnections(current.OutboundConnections, desired.OutboundConnections)
changes = append(changes, "Outbound connections changed") if len(outboundChanges) > 0 {
changes = append(changes, "Outbound connections changed:")
changes = append(changes, outboundChanges...)
} }
return changes, manifestChanged return changes, manifestChanged
} }
// compareOutboundConnections compares two sets of outbound connections for equality // compareOutboundConnections compares two sets of outbound connections for equality
func (p *EdgeConnectPlanner) compareOutboundConnections(current, desired []SecurityRule) bool { func (p *EdgeConnectPlanner) compareOutboundConnections(current, desired []SecurityRule) []string {
makeMap := func(rules []SecurityRule) map[string]struct{} { var changes []string
m := make(map[string]struct{}, len(rules)) makeMap := func(rules []SecurityRule) map[string]SecurityRule {
m := make(map[string]SecurityRule, len(rules))
for _, r := range rules { for _, r := range rules {
key := fmt.Sprintf("%s:%d-%d:%s", key := fmt.Sprintf("%s:%d-%d:%s",
strings.ToLower(r.Protocol), strings.ToLower(r.Protocol),
@ -402,7 +405,7 @@ func (p *EdgeConnectPlanner) compareOutboundConnections(current, desired []Secur
r.PortRangeMax, r.PortRangeMax,
r.RemoteCIDR, r.RemoteCIDR,
) )
m[key] = struct{}{} m[key] = r
} }
return m return m
} }
@ -410,17 +413,21 @@ func (p *EdgeConnectPlanner) compareOutboundConnections(current, desired []Secur
currentMap := makeMap(current) currentMap := makeMap(current)
desiredMap := makeMap(desired) desiredMap := makeMap(desired)
if len(currentMap) != len(desiredMap) { // Find added and modified rules
return false for key, rule := range desiredMap {
} if _, exists := currentMap[key]; !exists {
changes = append(changes, fmt.Sprintf(" - Added outbound connection: %s %d-%d to %s", rule.Protocol, rule.PortRangeMin, rule.PortRangeMax, rule.RemoteCIDR))
for k := range currentMap {
if _, exists := desiredMap[k]; !exists {
return false
} }
} }
return true // Find removed rules
for key, rule := range currentMap {
if _, exists := desiredMap[key]; !exists {
changes = append(changes, fmt.Sprintf(" - Removed outbound connection: %s %d-%d to %s", rule.Protocol, rule.PortRangeMin, rule.PortRangeMax, rule.RemoteCIDR))
}
}
return changes
} }
// compareInstanceStates compares current and desired instance states and returns changes // compareInstanceStates compares current and desired instance states and returns changes

View file

@ -4,6 +4,7 @@ package apply
import ( import (
"fmt" "fmt"
"strings"
"time" "time"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/config" "edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/config"
@ -353,40 +354,50 @@ func (dp *DeploymentPlan) GenerateSummary() string {
return "No changes required - configuration matches current state" return "No changes required - configuration matches current state"
} }
summary := fmt.Sprintf("Deployment plan for '%s':\n", dp.ConfigName) var sb strings.Builder
sb.WriteString(fmt.Sprintf("Deployment plan for '%s':\n", dp.ConfigName))
// App actions // App actions
if dp.AppAction.Type != ActionNone { if dp.AppAction.Type != ActionNone {
summary += fmt.Sprintf("- %s application '%s'\n", dp.AppAction.Type, dp.AppAction.Desired.Name) sb.WriteString(fmt.Sprintf("- %s application '%s'\n", dp.AppAction.Type, dp.AppAction.Desired.Name))
if len(dp.AppAction.Changes) > 0 { if len(dp.AppAction.Changes) > 0 {
for _, change := range dp.AppAction.Changes { for _, change := range dp.AppAction.Changes {
summary += fmt.Sprintf(" - %s\n", change) sb.WriteString(fmt.Sprintf(" - %s\n", change))
} }
} }
} }
// Instance actions // Instance actions
createCount := 0 createCount := 0
updateCount := 0 updateActions := []InstanceAction{}
for _, action := range dp.InstanceActions { for _, action := range dp.InstanceActions {
switch action.Type { switch action.Type {
case ActionCreate: case ActionCreate:
createCount++ createCount++
case ActionUpdate: case ActionUpdate:
updateCount++ updateActions = append(updateActions, action)
} }
} }
if createCount > 0 { if createCount > 0 {
summary += fmt.Sprintf("- CREATE %d instance(s) across %d cloudlet(s)\n", createCount, len(dp.GetTargetCloudlets())) sb.WriteString(fmt.Sprintf("- CREATE %d instance(s) across %d cloudlet(s)\n", createCount, len(dp.GetTargetCloudlets())))
}
if updateCount > 0 {
summary += fmt.Sprintf("- UPDATE %d instance(s)\n", updateCount)
} }
summary += fmt.Sprintf("Estimated duration: %s", dp.EstimatedDuration.String()) if len(updateActions) > 0 {
sb.WriteString(fmt.Sprintf("- UPDATE %d instance(s)\n", len(updateActions)))
for _, action := range updateActions {
if len(action.Changes) > 0 {
sb.WriteString(fmt.Sprintf(" - Instance '%s':\n", action.InstanceName))
for _, change := range action.Changes {
sb.WriteString(fmt.Sprintf(" - %s\n", change))
}
}
}
}
return summary sb.WriteString(fmt.Sprintf("Estimated duration: %s", dp.EstimatedDuration.String()))
return sb.String()
} }
// Validate checks if the deployment plan is valid and safe to execute // Validate checks if the deployment plan is valid and safe to execute