refactor: handle CreateContainer server-side

This commit is contained in:
Pavel Sviderski
2025-03-28 19:01:19 +10:00
parent 3893005866
commit 1cba1eef0a
10 changed files with 423 additions and 182 deletions
+17 -1
View File
@@ -44,7 +44,21 @@ type ServiceSpec struct {
// Ports defines what service ports to publish to make the service accessible outside the cluster.
Ports []PortSpec
// Replicas is the number of containers to run for the service. Only valid for a replicated service.
Replicas uint
Replicas uint `json:",omitempty"`
}
func (s *ServiceSpec) ApplyDefaults() {
if s.Mode == "" {
s.Mode = ServiceModeReplicated
}
// Ensure the replicated service has at least one replica.
if s.Mode == ServiceModeReplicated && s.Replicas == 0 {
s.Replicas = 1
}
if s.Container.PullPolicy == "" {
s.Container.PullPolicy = PullPolicyMissing
}
}
func (s *ServiceSpec) Validate() error {
@@ -58,6 +72,8 @@ func (s *ServiceSpec) Validate() error {
return fmt.Errorf("invalid mode: %q", s.Mode)
}
// TODO: validate the service name is a valid DNS label.
for _, p := range s.Ports {
if (p.Mode == "" || p.Mode == PortModeIngress) &&
p.Protocol != ProtocolHTTP && p.Protocol != ProtocolHTTPS {