Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add endpoint port protocol to the k8s metadata #407

Merged
merged 2 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ public enum KubernetesMetadataKey implements MetadataKey {
/**
* The key to access the kubernates namespace
*/
META_K8S_NAMESPACE("k8s-namespace");
META_K8S_NAMESPACE("k8s-namespace"),

/**
* The key to access the port protocol
*/
META_K8S_PORT_PROTOCOL("k8s-port-protocol");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.smallrye.stork.servicediscovery.kubernetes;

import static io.smallrye.stork.servicediscovery.kubernetes.KubernetesMetadataKey.META_K8S_NAMESPACE;
import static io.smallrye.stork.servicediscovery.kubernetes.KubernetesMetadataKey.META_K8S_PORT_PROTOCOL;
import static io.smallrye.stork.servicediscovery.kubernetes.KubernetesMetadataKey.META_K8S_SERVICE_ID;

import java.util.ArrayList;
Expand Down Expand Up @@ -182,8 +183,10 @@ private List<ServiceInstance> toStorkServiceInstances(Map<Endpoints, List<Pod>>
}
List<EndpointPort> endpointPorts = subset.getPorts();
Integer port = 0;
String protocol = "";
if (endpointPorts.size() == 1) {
port = endpointPorts.get(0).getPort();
protocol = endpointPorts.get(0).getProtocol();
}

ServiceInstance matching = ServiceInstanceUtils.findMatching(previousInstances, hostname, port);
Expand All @@ -208,7 +211,8 @@ private List<ServiceInstance> toStorkServiceInstances(Map<Endpoints, List<Pod>>
Metadata<KubernetesMetadataKey> k8sMetadata = Metadata.of(KubernetesMetadataKey.class);
serviceInstances.add(new DefaultServiceInstance(ServiceInstanceIds.next(), hostname, port, secure,
labels,
k8sMetadata.with(META_K8S_SERVICE_ID, hostname).with(META_K8S_NAMESPACE, podNamespace)));
k8sMetadata.with(META_K8S_SERVICE_ID, hostname).with(META_K8S_NAMESPACE, podNamespace)
.with(META_K8S_PORT_PROTOCOL, protocol)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ private Endpoints buildAndRegisterKubernetesService(String serviceName, String n
Endpoints endpoint = new EndpointsBuilder()
.withNewMetadata().withName(serviceName).withLabels(serviceLabels).endMetadata()
.addToSubsets(new EndpointSubsetBuilder().withAddresses(endpointAddresses)
.addToPorts(new EndpointPortBuilder().withPort(8080).build())
.addToPorts(new EndpointPortBuilder().withPort(8080).withProtocol("TCP").build())
.build())
.build();

Expand Down