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