-
Notifications
You must be signed in to change notification settings - Fork 1k
add pod metadata and annotations as part of the service discovery response #1254
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
Changes from 6 commits
032014e
c3d0ad2
10889fd
8f0375a
96ebf42
db8403e
90a5345
b041c00
9580444
a34ac47
6613f78
1b3eae9
48ba4cb
ff026e8
845eff0
146d191
cc278e1
f26d4aa
80b49a8
6f8e59d
0c595d6
a2a0af1
4275382
618f25a
100a9cd
5d3d2a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,8 +35,8 @@ | |
| * @param cluster the cluster the service resides in. | ||
| */ | ||
| public record DefaultKubernetesServiceInstance(String instanceId, String serviceId, String host, int port, | ||
| Map<String, String> metadata, boolean secure, String namespace, | ||
| String cluster) implements KubernetesServiceInstance { | ||
| Map<String, String> metadata, boolean secure, String namespace, String cluster, Map<String, String> podLabels, | ||
| Map<String, String> podAnnotations) implements KubernetesServiceInstance { | ||
|
|
||
| /** | ||
| * @param instanceId the id of the instance. | ||
|
|
@@ -48,7 +48,12 @@ public record DefaultKubernetesServiceInstance(String instanceId, String service | |
| */ | ||
| public DefaultKubernetesServiceInstance(String instanceId, String serviceId, String host, int port, | ||
| Map<String, String> metadata, boolean secure) { | ||
| this(instanceId, serviceId, host, port, metadata, secure, null, null); | ||
| this(instanceId, serviceId, host, port, metadata, secure, null, null, Map.of(), Map.of()); | ||
| } | ||
|
|
||
| public DefaultKubernetesServiceInstance(String instanceId, String serviceId, String host, int port, | ||
| Map<String, String> metadata, boolean secure, String namespace, String cluster) { | ||
| this(instanceId, serviceId, host, port, metadata, secure, namespace, cluster, Map.of(), Map.of()); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -101,6 +106,16 @@ public String getCluster() { | |
| return this.cluster; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> podLabels() { | ||
|
||
| return podLabels; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> podAnnotations() { | ||
| return podAnnotations; | ||
| } | ||
|
|
||
| private URI createUri(String scheme, String host, int port) { | ||
| // assume ExternalName type of service | ||
| if (port == -1) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,15 +92,30 @@ public KubernetesDiscoveryProperties(@DefaultValue("true") boolean enabled, bool | |
| * @param annotationsPrefix prefix for the annotations | ||
| * @param addPorts include ports as metadata | ||
| * @param portsPrefix prefix for the ports, by default it is "port." | ||
| * @param addPodLabels add pod labels as part of the response. | ||
| * @param addPodAnnotations add pod annotations as part of the response. | ||
| */ | ||
| public record Metadata(@DefaultValue("true") boolean addLabels, String labelsPrefix, | ||
| @DefaultValue("true") boolean addAnnotations, String annotationsPrefix, | ||
| @DefaultValue("true") boolean addPorts, @DefaultValue("port.") String portsPrefix) { | ||
| @DefaultValue("true") boolean addPorts, @DefaultValue("port.") String portsPrefix, boolean addPodLabels, | ||
| boolean addPodAnnotations) { | ||
|
|
||
| @ConstructorBinding | ||
| public Metadata { | ||
|
|
||
| } | ||
|
|
||
| public Metadata(@DefaultValue("true") boolean addLabels, String labelsPrefix, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a new constructor not to break the public existing one |
||
| @DefaultValue("true") boolean addAnnotations, String annotationsPrefix, | ||
| @DefaultValue("true") boolean addPorts, @DefaultValue("port.") String portsPrefix) { | ||
|
|
||
| this(addLabels, labelsPrefix, addAnnotations, annotationsPrefix, addPorts, portsPrefix, false, false); | ||
| } | ||
|
|
||
| /** | ||
| * Default instance. | ||
| */ | ||
| public static final Metadata DEFAULT = new Metadata(true, null, true, null, true, "port."); | ||
| public static final Metadata DEFAULT = new Metadata(true, null, true, null, true, "port.", false, false); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright 2013-2023 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.cloud.kubernetes.commons.discovery; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * @author wind57 | ||
| */ | ||
| public record PodMetadata(Map<String, String> podLabels, Map<String, String> podAnnotations) { | ||
|
|
||
| /** | ||
| * pod labels and annotations are empty. | ||
| */ | ||
| public static PodMetadata EMPTY = new PodMetadata(Map.of(), Map.of()); | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep the previous constructor intact and introduce a new one