normalise runtime service status
This commit is contained in:
parent
61dd2b8489
commit
e1e6199743
@ -114,7 +114,18 @@ func (k *kubernetes) getService(labels map[string]string) ([]*runtime.Service, e
|
||||
|
||||
// parse out deployment status and inject into service metadata
|
||||
if len(kdep.Status.Conditions) > 0 {
|
||||
status := kdep.Status.Conditions[0].Type
|
||||
var status string
|
||||
switch kdep.Status.Conditions[0].Type {
|
||||
case "Available":
|
||||
status = "running"
|
||||
delete(svc.Metadata, "error")
|
||||
case "Progressing":
|
||||
status = "starting"
|
||||
delete(svc.Metadata, "error")
|
||||
default:
|
||||
status = "error"
|
||||
svc.Metadata["error"] = kdep.Status.Conditions[0].Message
|
||||
}
|
||||
// pick the last known condition type and mark the service status with it
|
||||
log.Debugf("Runtime setting %s service deployment status: %v", name, status)
|
||||
svc.Metadata["status"] = status
|
||||
|
@ -89,14 +89,18 @@ func (s *service) Start(k client.Client) error {
|
||||
// create deployment first; if we fail, we dont create service
|
||||
if err := k.Create(deploymentResource(s.kdeploy)); err != nil {
|
||||
log.Debugf("Runtime failed to create deployment: %v", err)
|
||||
s.Status("error", err)
|
||||
return err
|
||||
}
|
||||
// create service now that the deployment has been created
|
||||
if err := k.Create(serviceResource(s.kservice)); err != nil {
|
||||
log.Debugf("Runtime failed to create service: %v", err)
|
||||
s.Status("error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
s.Status("started", nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -104,20 +108,25 @@ func (s *service) Stop(k client.Client) error {
|
||||
// first attempt to delete service
|
||||
if err := k.Delete(serviceResource(s.kservice)); err != nil {
|
||||
log.Debugf("Runtime failed to delete service: %v", err)
|
||||
s.Status("error", err)
|
||||
return err
|
||||
}
|
||||
// delete deployment once the service has been deleted
|
||||
if err := k.Delete(deploymentResource(s.kdeploy)); err != nil {
|
||||
log.Debugf("Runtime failed to delete deployment: %v", err)
|
||||
s.Status("error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
s.Status("stopped", nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) Update(k client.Client) error {
|
||||
if err := k.Update(deploymentResource(s.kdeploy)); err != nil {
|
||||
log.Debugf("Runtime failed to update deployment: %v", err)
|
||||
s.Status("error", err)
|
||||
return err
|
||||
}
|
||||
if err := k.Update(serviceResource(s.kservice)); err != nil {
|
||||
@ -127,3 +136,12 @@ func (s *service) Update(k client.Client) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) Status(status string, err error) {
|
||||
if err == nil {
|
||||
s.Metadata["status"] = status
|
||||
return
|
||||
}
|
||||
s.Metadata["status"] = "error"
|
||||
s.Metadata["error"] = err.Error()
|
||||
}
|
||||
|
@ -86,10 +86,20 @@ func (s *service) Start() error {
|
||||
s.err = nil
|
||||
s.closed = make(chan bool)
|
||||
|
||||
if s.Metadata == nil {
|
||||
s.Metadata = make(map[string]string)
|
||||
}
|
||||
|
||||
s.Metadata["status"] = "starting"
|
||||
// delete any existing error
|
||||
delete(s.Metadata, "error")
|
||||
|
||||
// TODO: pull source & build binary
|
||||
log.Debugf("Runtime service %s forking new process", s.Service.Name)
|
||||
p, err := s.Process.Fork(s.Exec)
|
||||
if err != nil {
|
||||
s.Metadata["status"] = "error"
|
||||
s.Metadata["error"] = err.Error()
|
||||
return err
|
||||
}
|
||||
|
||||
@ -97,6 +107,8 @@ func (s *service) Start() error {
|
||||
s.PID = p
|
||||
// set to running
|
||||
s.running = true
|
||||
// set status
|
||||
s.Metadata["status"] = "running"
|
||||
|
||||
if s.output != nil {
|
||||
s.streamOutput()
|
||||
@ -122,10 +134,18 @@ func (s *service) Stop() error {
|
||||
if s.PID == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// set status
|
||||
s.Metadata["status"] = "stopping"
|
||||
|
||||
// kill the process
|
||||
err := s.Process.Kill(s.PID)
|
||||
// wait for it to exit
|
||||
s.Process.Wait(s.PID)
|
||||
|
||||
// set status
|
||||
s.Metadata["status"] = "stopped"
|
||||
|
||||
// return the kill error
|
||||
return err
|
||||
}
|
||||
@ -148,6 +168,8 @@ func (s *service) Wait() {
|
||||
|
||||
// save the error
|
||||
if err != nil {
|
||||
s.Metadata["status"] = "error"
|
||||
s.Metadata["error"] = err.Error()
|
||||
s.err = err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user