Skip to content

Commit

Permalink
update service cache when receiving update service event
Browse files Browse the repository at this point in the history
  • Loading branch information
dxGuan committed Dec 10, 2021
1 parent b4659b1 commit 30f3b2c
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,20 @@ public void onAdd(V1Service service) {
}

@Override
public void onUpdate(V1Service oldObj, V1Service newObj) {
public void onUpdate(V1Service oldSvc, V1Service newSvc) {
if (newSvc.getMetadata() != null && newSvc.getSpec() != null &&
newSvc.getSpec().getPorts() != null) {
String svcName = newSvc.getMetadata().getName();
String ip = newSvc.getSpec().getClusterIP();
for (V1ServicePort port : newSvc.getSpec().getPorts()) {
String portName = port.getName();
K8sServiceMetaData metaData = new K8sServiceMetaData(svcName, portName);
cache.put(metaData, new CerberusService.Builder(Object.class)
.metaData(metaData).host(ip).port(port.getPort())
.build());
LOGGER.debug("update svc, meta-data:{} with ip:{}, port:{}", metaData, ip, port.getPort());
}
}
}

@Override
Expand Down

0 comments on commit 30f3b2c

Please sign in to comment.