Extract k8s run error
This commit is contained in:
parent
65df711b01
commit
39d7938405
@ -266,6 +266,11 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er
|
||||
o(&options)
|
||||
}
|
||||
|
||||
// hackish
|
||||
if len(options.Type) == 0 {
|
||||
options.Type = k.options.Type
|
||||
}
|
||||
|
||||
// quickly prevalidate the name and version
|
||||
name := s.Name
|
||||
if len(s.Version) > 0 {
|
||||
|
@ -1,10 +1,12 @@
|
||||
package kubernetes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/micro/go-micro/runtime"
|
||||
"github.com/micro/go-micro/util/kubernetes/api"
|
||||
"github.com/micro/go-micro/util/kubernetes/client"
|
||||
"github.com/micro/go-micro/util/log"
|
||||
)
|
||||
@ -18,6 +20,12 @@ type service struct {
|
||||
kdeploy *client.Deployment
|
||||
}
|
||||
|
||||
func parseError(err error) *api.Status {
|
||||
status := new(api.Status)
|
||||
json.Unmarshal([]byte(err.Error()), &status)
|
||||
return status
|
||||
}
|
||||
|
||||
func newService(s *runtime.Service, c runtime.CreateOptions) *service {
|
||||
// use pre-formatted name/version
|
||||
name := client.Format(s.Name)
|
||||
@ -90,12 +98,20 @@ func (s *service) Start(k client.Client) error {
|
||||
if err := k.Create(deploymentResource(s.kdeploy)); err != nil {
|
||||
log.Debugf("Runtime failed to create deployment: %v", err)
|
||||
s.Status("error", err)
|
||||
v := parseError(err)
|
||||
if v.Reason == "AlreadyExists" {
|
||||
return runtime.ErrAlreadyExists
|
||||
}
|
||||
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)
|
||||
v := parseError(err)
|
||||
if v.Reason == "AlreadyExists" {
|
||||
return runtime.ErrAlreadyExists
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,18 @@
|
||||
// Package runtime is a service runtime manager
|
||||
package runtime
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultRuntime is default micro runtime
|
||||
DefaultRuntime Runtime = NewRuntime()
|
||||
// DefaultName is default runtime service name
|
||||
DefaultName = "go.micro.runtime"
|
||||
|
||||
ErrAlreadyExists = errors.New("already exists")
|
||||
)
|
||||
|
||||
// Runtime is a service runtime manager
|
||||
|
Loading…
x
Reference in New Issue
Block a user