1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-12 22:07:47 +02:00

Runtime hacks (#1344)

* Add Args/Image to runtime

* remove the hacks
This commit is contained in:
Asim Aslam
2020-03-13 18:39:59 +00:00
committed by GitHub
parent 3543b275e0
commit e803fb0855
12 changed files with 166 additions and 102 deletions

View File

@ -2,8 +2,6 @@
package kubernetes
import (
"fmt"
"strings"
"sync"
"time"
@ -250,11 +248,6 @@ func (k *kubernetes) Init(opts ...runtime.Option) error {
o(&k.options)
}
// trim the source prefix if its a git url
if strings.HasPrefix(k.options.Source, "github.com") {
k.options.Source = strings.TrimPrefix(k.options.Source, "github.com/")
}
return nil
}
@ -270,14 +263,20 @@ func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) er
o(&options)
}
// hackish
// default type if it doesn't exist
if len(options.Type) == 0 {
options.Type = k.options.Type
}
// determine the full source for this service
options.Source = k.sourceForService(s.Name)
// default the source if it doesn't exist
if len(s.Source) == 0 {
s.Source = k.options.Source
}
// determine the image from the source and options
options.Image = k.getImage(s, options)
// create new service
service := newService(s, options)
// start the service
@ -334,10 +333,15 @@ func (k *kubernetes) List() ([]*runtime.Service, error) {
// Update the service in place
func (k *kubernetes) Update(s *runtime.Service) error {
// create new kubernetes micro service
service := newService(s, runtime.CreateOptions{
Type: k.options.Type,
Source: k.sourceForService(s.Name),
})
opts := runtime.CreateOptions{
Type: k.options.Type,
}
// set image
opts.Image = k.getImage(s, opts)
// new pseudo service
service := newService(s, opts)
// update build time annotation
service.kdeploy.Spec.Template.Metadata.Annotations["build"] = time.Now().Format(time.RFC3339)
@ -442,14 +446,15 @@ func NewRuntime(opts ...runtime.Option) runtime.Runtime {
}
}
// sourceForService determines the nested package name for github
// e.g src: docker.pkg.github.com/micro/services an srv: users/api
// would become docker.pkg.github.com/micro/services/users-api
func (k *kubernetes) sourceForService(name string) string {
if !strings.HasPrefix(k.options.Source, "docker.pkg.github.com") {
return k.options.Source
func (k *kubernetes) getImage(s *runtime.Service, options runtime.CreateOptions) string {
// use the image when its specified
if len(options.Image) > 0 {
return options.Image
}
formattedName := strings.ReplaceAll(name, "/", "-")
return fmt.Sprintf("%v/%v", k.options.Source, formattedName)
if len(k.options.Image) > 0 {
return k.options.Image
}
return ""
}