updateSvc updates the cache with the given retina service.
(svc *common.RetinaSvc)
| 258 | |
| 259 | // updateSvc updates the cache with the given retina service. |
| 260 | func (c *Cache) updateSvc(svc *common.RetinaSvc) error { |
| 261 | // TODO check if a service already exists here |
| 262 | ip, err := svc.GetPrimaryIP() |
| 263 | if err != nil { |
| 264 | c.l.Error("updateSvc: error getting primary IP for service", zap.String("service", svc.Key()), zap.Error(err)) |
| 265 | return err |
| 266 | } |
| 267 | |
| 268 | // delete if any existing object is using this IP |
| 269 | // send a delete event for the existing object |
| 270 | err = c.deleteByIP(ip, svc.Key()) |
| 271 | if err != nil { |
| 272 | c.l.Error("updateSvc: error deleting existing object for IP", |
| 273 | zap.String("svc", svc.Key()), |
| 274 | zap.String("ip", ip), |
| 275 | zap.Error(err), |
| 276 | ) |
| 277 | return err |
| 278 | } |
| 279 | |
| 280 | c.ipToSvcKey[ip] = svc.Key() |
| 281 | c.svcMap[svc.Key()] = svc |
| 282 | |
| 283 | // notify pubsub |
| 284 | c.publish(EventTypeSvcAdded, svc) |
| 285 | |
| 286 | return nil |
| 287 | } |
| 288 | |
| 289 | // UpdateRetinaNode updates the cache with the given retina node. |
| 290 | func (c *Cache) UpdateRetinaNode(node *common.RetinaNode) error { |
no test coverage detected