Merge pull request #993 from micro/k8s-fixes
Add fixes for label selector and skipping things that don't match
This commit is contained in:
commit
7318807dce
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user