diff --git a/runtime/kubernetes/client/api/request.go b/runtime/kubernetes/client/api/request.go index bfb8b117..1b454c00 100644 --- a/runtime/kubernetes/client/api/request.go +++ b/runtime/kubernetes/client/api/request.go @@ -119,7 +119,14 @@ func (r *Request) Body(in interface{}) *Request { // Params isused to set paramters on a request func (r *Request) Params(p *Params) *Request { for k, v := range p.LabelSelector { - r.params.Add("labelSelector", k+"="+v) + // create new key=value pair + value := fmt.Sprintf("%s=%s", k, v) + // check if there's an existing value + if label := r.params.Get("labelSelector"); len(label) > 0 { + value = fmt.Sprintf("%s,%s", label, value) + } + // set and overwrite the value + r.params.Set("labelSelector", value) } return r diff --git a/runtime/kubernetes/client/client.go b/runtime/kubernetes/client/client.go index 6206ea15..4637a9d8 100644 --- a/runtime/kubernetes/client/client.go +++ b/runtime/kubernetes/client/client.go @@ -126,9 +126,9 @@ func (c *client) Update(r *Resource) error { switch r.Kind { case "service": - req.Body(r.Value.(*Service).Spec) + req.Body(r.Value.(*Service)) case "deployment": - req.Body(r.Value.(*Deployment).Spec) + req.Body(r.Value.(*Deployment)) default: return errors.New("unsupported resource") } @@ -151,6 +151,5 @@ func (c *client) List(r *Resource) error { labels := map[string]string{ "micro": "service", } - return c.Get(r, labels) } diff --git a/runtime/kubernetes/kubernetes.go b/runtime/kubernetes/kubernetes.go index 29c90925..7c584eac 100644 --- a/runtime/kubernetes/kubernetes.go +++ b/runtime/kubernetes/kubernetes.go @@ -199,10 +199,13 @@ func (k *kubernetes) run(events <-chan runtime.Event) { continue } + // format the name + name := client.Format(event.Service) + // set the default labels labels := map[string]string{ "micro": "service", - "name": event.Service, + "name": name, } if len(event.Version) > 0 { @@ -225,6 +228,11 @@ func (k *kubernetes) run(events <-chan runtime.Event) { // technically we should not receive multiple versions but hey ho for _, service := range deployed.Items { + // check the name matches + if service.Metadata.Name != name { + continue + } + // update build time annotation if service.Spec.Template.Metadata.Annotations == nil { service.Spec.Template.Metadata.Annotations = make(map[string]string) @@ -242,7 +250,7 @@ func (k *kubernetes) run(events <-chan runtime.Event) { // update the build time service.Spec.Template.Metadata.Annotations["build"] = event.Timestamp.Format(time.RFC3339) - log.Debugf("Runtime updating service: %s", event.Service) + log.Debugf("Runtime updating service: %s deployment: %s", event.Service, service.Metadata.Name) if err := k.client.Update(deploymentResource(&service)); err != nil { log.Debugf("Runtime failed to update service %s: %v", event.Service, err) continue