-
Notifications
You must be signed in to change notification settings - Fork 4
Description
As with the others, focused on both Typing and backwards compat:
#199
Before (MapBuilder API)
.WithDeploy(deploy => deploy
.WithReplicas(2)
.WithUpdateConfig(c => c.WithProperty("delay", "30s"))
.WithRestartPolicy(c => c
.WithProperty("delay", "30s")
.WithProperty("max_attempts", 10)
.WithProperty("window", "120s")
)
.WithPlacement(c => c
.WithProperty("constraints", new[] { "node.role == worker" })
.WithProperty("preferences", new[] { new PlacementPreferences { Spread = "node.labels.zone" } })
)
.WithResources(c => c.WithProperty("limits", new Dictionary<string, string>
{
["memory"] = "1600m",
}))
)
After (Typed API)
.WithDeploy(deploy => deploy
.WithReplicas(2)
.WithUpdateConfig(c => c.WithDelay("30s"))
.WithRestartPolicy(c => c
.WithDelay("30s")
.WithMaxAttempts(10)
.WithWindow("120s")
)
.WithPlacement(c => c
.WithConstraints("node.role == worker")
.WithPreference("node.labels.zone")
)
.WithResources(c => c.WithLimits(l => l.WithMemory("1600m")))
)
Benefits
- IntelliSense/autocomplete - Discover available options without docs
- Compile-time safety - Typos like "max_attempt" caught at build time
- Enum support - WithCondition(ERestartCondition.OnFailure) instead of magic strings
- Cleaner syntax - No WithProperty() or new Dictionary<> boilerplate
Both produce identical YAML output, and the old API still works for backwards compatibility.