mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
refactor: move StopGracePeriod from ServiceSpec to ContainerSpec
This commit is contained in:
+3
-3
@@ -69,9 +69,6 @@ type ServiceSpec struct {
|
|||||||
Ports []PortSpec
|
Ports []PortSpec
|
||||||
// Replicas is the number of containers to run for the service. Only valid for a replicated service.
|
// Replicas is the number of containers to run for the service. Only valid for a replicated service.
|
||||||
Replicas uint `json:",omitempty"`
|
Replicas uint `json:",omitempty"`
|
||||||
// StopGracePeriod is how long to wait after SIGTERM before sending SIGKILL when stopping a container.
|
|
||||||
// Default is 10 seconds if not specified.
|
|
||||||
StopGracePeriod *time.Duration `json:",omitempty"`
|
|
||||||
// UpdateConfig configures how the service is updated during a deployment.
|
// UpdateConfig configures how the service is updated during a deployment.
|
||||||
UpdateConfig UpdateConfig
|
UpdateConfig UpdateConfig
|
||||||
// Volumes is list of data volumes that can be mounted into the container.
|
// Volumes is list of data volumes that can be mounted into the container.
|
||||||
@@ -265,6 +262,9 @@ type ContainerSpec struct {
|
|||||||
PullPolicy string
|
PullPolicy string
|
||||||
// Resource allocation for the container.
|
// Resource allocation for the container.
|
||||||
Resources ContainerResources
|
Resources ContainerResources
|
||||||
|
// StopGracePeriod is how long to wait after SIGTERM before sending SIGKILL when stopping the container.
|
||||||
|
// Default is 10 seconds if not specified.
|
||||||
|
StopGracePeriod *time.Duration `json:",omitempty"`
|
||||||
// Namespaced kernel parameters to be set in the container.
|
// Namespaced kernel parameters to be set in the container.
|
||||||
Sysctls map[string]string
|
Sysctls map[string]string
|
||||||
// User overrides the default user of the image used to run the container. Format: user|UID[:group|GID].
|
// User overrides the default user of the image used to run the container. Format: user|UID[:group|GID].
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ func ServiceSpecFromCompose(project *types.Project, serviceName string) (api.Ser
|
|||||||
|
|
||||||
if service.StopGracePeriod != nil {
|
if service.StopGracePeriod != nil {
|
||||||
d := time.Duration(*service.StopGracePeriod)
|
d := time.Duration(*service.StopGracePeriod)
|
||||||
spec.StopGracePeriod = &d
|
spec.Container.StopGracePeriod = &d
|
||||||
}
|
}
|
||||||
|
|
||||||
if service.Scale != nil {
|
if service.Scale != nil {
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ func TestServiceSpecFromCompose(t *testing.T) {
|
|||||||
{Count: -1, Capabilities: [][]string{{"gpu"}}},
|
{Count: -1, Capabilities: [][]string{{"gpu"}}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
StopGracePeriod: new(30 * time.Second),
|
||||||
Sysctls: map[string]string{
|
Sysctls: map[string]string{
|
||||||
"net.ipv4.ip_forward": "1",
|
"net.ipv4.ip_forward": "1",
|
||||||
},
|
},
|
||||||
@@ -207,8 +208,7 @@ func TestServiceSpecFromCompose(t *testing.T) {
|
|||||||
Placement: api.Placement{
|
Placement: api.Placement{
|
||||||
Machines: []string{"machine-1", "machine-2"},
|
Machines: []string{"machine-1", "machine-2"},
|
||||||
},
|
},
|
||||||
Replicas: 3,
|
Replicas: 3,
|
||||||
StopGracePeriod: api.AsPtr(30 * time.Second),
|
|
||||||
UpdateConfig: api.UpdateConfig{
|
UpdateConfig: api.UpdateConfig{
|
||||||
Order: api.UpdateOrderStopFirst,
|
Order: api.UpdateOrderStopFirst,
|
||||||
MonitorPeriod: &api.DefaultHealthMonitorPeriod,
|
MonitorPeriod: &api.DefaultHealthMonitorPeriod,
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ func (s *RollingStrategy) planReplicated(svc *api.Service, spec api.ServiceSpec)
|
|||||||
OldContainer: ctr,
|
OldContainer: ctr,
|
||||||
Order: order,
|
Order: order,
|
||||||
SkipHealthMonitor: s.SkipHealthMonitor,
|
SkipHealthMonitor: s.SkipHealthMonitor,
|
||||||
StopGracePeriod: spec.StopGracePeriod,
|
StopGracePeriod: spec.Container.StopGracePeriod,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ func (s *RollingStrategy) planReplicated(svc *api.Service, spec api.ServiceSpec)
|
|||||||
MachineID: mid,
|
MachineID: mid,
|
||||||
MachineName: machineNames[mid],
|
MachineName: machineNames[mid],
|
||||||
Container: c,
|
Container: c,
|
||||||
StopGracePeriod: spec.StopGracePeriod,
|
StopGracePeriod: spec.Container.StopGracePeriod,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,7 +260,7 @@ func (s *RollingStrategy) planGlobal(svc *api.Service, spec api.ServiceSpec) (Se
|
|||||||
MachineID: c.MachineID,
|
MachineID: c.MachineID,
|
||||||
MachineName: machineNames[c.MachineID],
|
MachineName: machineNames[c.MachineID],
|
||||||
Container: c.Container,
|
Container: c.Container,
|
||||||
StopGracePeriod: spec.StopGracePeriod,
|
StopGracePeriod: spec.Container.StopGracePeriod,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,7 +318,7 @@ func reconcileGlobalContainer(
|
|||||||
MachineID: old.MachineID,
|
MachineID: old.MachineID,
|
||||||
MachineName: machine.Name,
|
MachineName: machine.Name,
|
||||||
Container: old.Container,
|
Container: old.Container,
|
||||||
StopGracePeriod: spec.StopGracePeriod,
|
StopGracePeriod: spec.Container.StopGracePeriod,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -354,7 +354,7 @@ func reconcileGlobalContainer(
|
|||||||
ContainerID: c.Container.ID,
|
ContainerID: c.Container.ID,
|
||||||
MachineID: machine.Id,
|
MachineID: machine.Id,
|
||||||
MachineName: machine.Name,
|
MachineName: machine.Name,
|
||||||
StopGracePeriod: spec.StopGracePeriod,
|
StopGracePeriod: spec.Container.StopGracePeriod,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -369,7 +369,7 @@ func reconcileGlobalContainer(
|
|||||||
OldContainer: containerToReplace.Container,
|
OldContainer: containerToReplace.Container,
|
||||||
Order: order,
|
Order: order,
|
||||||
SkipHealthMonitor: skipHealthCheck,
|
SkipHealthMonitor: skipHealthCheck,
|
||||||
StopGracePeriod: spec.StopGracePeriod,
|
StopGracePeriod: spec.Container.StopGracePeriod,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Remove any other containers (there shouldn't be any in normal operation).
|
// Remove any other containers (there shouldn't be any in normal operation).
|
||||||
@@ -381,7 +381,7 @@ func reconcileGlobalContainer(
|
|||||||
MachineID: c.MachineID,
|
MachineID: c.MachineID,
|
||||||
MachineName: machine.Name,
|
MachineName: machine.Name,
|
||||||
Container: c.Container,
|
Container: c.Container,
|
||||||
StopGracePeriod: spec.StopGracePeriod,
|
StopGracePeriod: spec.Container.StopGracePeriod,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -398,7 +398,7 @@ func reconcileGlobalContainer(
|
|||||||
MachineID: c.MachineID,
|
MachineID: c.MachineID,
|
||||||
MachineName: machine.Name,
|
MachineName: machine.Name,
|
||||||
Container: c.Container,
|
Container: c.Container,
|
||||||
StopGracePeriod: spec.StopGracePeriod,
|
StopGracePeriod: spec.Container.StopGracePeriod,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user