Move service instance to commons#1399
Move service instance to commons#1399ryanjbaxter merged 29 commits intospring-cloud:3.0.xfrom wind57:move-service-instance-to-commons
Conversation
| Assertions.assertEquals(hostNames, List.of("one", "three", "two")); | ||
| } | ||
|
|
||
| @Test |
There was a problem hiding this comment.
tests were moved to commons, not deleted
| } | ||
| } | ||
|
|
||
| public static ServiceInstance serviceInstance(@Nullable ServicePortSecureResolver servicePortSecureResolver, |
There was a problem hiding this comment.
this method has changed from the way it used to exist in fabric8 implementation. For example it takes as input a Supplier<InstanceIdHostPodName>, where:
/**
* computes instanceId, host and podName. All needed when calculating ServiceInstance.
* @author wind57
*/
public record InstanceIdHostPodName(String instanceId, String host, String podName) {
}
instanceId, host and podName are computed based on specific fabric8 EndpointAddress/Service:
final class Fabric8InstanceIdHostPodNameSupplier implements Supplier<InstanceIdHostPodName> {
private final EndpointAddress endpointAddress;
private final Service service;
Fabric8InstanceIdHostPodNameSupplier(EndpointAddress endpointAddress, Service service) {
this.endpointAddress = endpointAddress;
this.service = service;
}
@Override
public InstanceIdHostPodName get() {
return new InstanceIdHostPodName(instanceId(), host(), podName());
}
// instanceId is usually the pod-uid as seen in the .metadata.uid
private String instanceId() {
return Optional.ofNullable(endpointAddress).map(EndpointAddress::getTargetRef).map(ObjectReference::getUid)
.orElseGet(() -> service.getMetadata().getUid());
}
private String host() {
return Optional.ofNullable(endpointAddress).map(EndpointAddress::getIp)
.orElseGet(() -> service.getSpec().getExternalName());
}
private String podName() {
return Optional.ofNullable(endpointAddress).map(EndpointAddress::getTargetRef)
.filter(objectReference -> "Pod".equals(objectReference.getKind())).map(ObjectReference::getName)
.orElse(null);
}
}
The logic is exactly the same as it used to be, but a Supplier/Function is needed so that I can pass into this method from commons both fabric8 and in the nearest future: k8s code.
|
Last PR before I start working on k8s integration with all these moved methods |
| return primaryPortName; | ||
| } | ||
|
|
||
| static Map<String, Map<String, String>> podMetadata(String podName, Map<String, String> serviceMetadata, |
There was a problem hiding this comment.
exactly the same logic is preserved, tests ensure this
|
@ryanjbaxter ready to be looked at. This is a bit more involved, but in essence it does not change anything "business related". It just makes sure that instead of passing fabric8 specific stuff to
it now expects a Another example would be that
from a
This is needed so that commons does not care what client we use, thus I can delegate to the same common code. |
No description provided.