@@ -25,17 +25,15 @@ public class PodWatcher implements Watcher<Pod> {
2525 private Boolean debug ;
2626 private KubernetesClient client ;
2727 private String namespace ;
28- private Boolean hostport ;
2928
3029 PodWatcher (ProxyServer proxyServer , Logger logger , Configuration configuration , KubernetesClient client ,
31- String namespace , Boolean hostport ) {
30+ String namespace ) {
3231 this .proxyServer = proxyServer ;
3332 this .logger = logger ;
3433 this .configuration = configuration ;
3534 this .debug = configuration .getBoolean ("debug" );
3635 this .client = client ;
3736 this .namespace = namespace ;
38- this .hostport = hostport ;
3937 }
4038
4139 @ Override
@@ -51,6 +49,7 @@ public void eventReceived(Action action, Pod resource) {
5149 }
5250
5351 Map <String , String > labels = resource .getMetadata ().getLabels ();
52+ Map <String , String > annotations = resource .getMetadata ().getAnnotations ();
5453 if (labels != null ) {
5554 if (this .debug ) {
5655 logger .info ("[Kubernetes Container Inspector] labels: " + labels .toString ());
@@ -75,8 +74,8 @@ public void eventReceived(Action action, Pod resource) {
7574 Map <String , String > environmentVariables = new HashMap <>();
7675 for (EnvVar i : resource .getSpec ().getContainers ().get (0 ).getEnv ())
7776 environmentVariables .put (i .getName (), i .getValue ());
78- containerEvent . setEnvironmentVariables ( environmentVariables );
79- if ( hostport ) {
77+ if ( annotations . toString (). contains ( "dynamic-hostports.k8s" )) {
78+ environmentVariables . remove ( "SERVER_PORT" );
8079 String nodeName = resource .getSpec ().getNodeName ();
8180 if (nodeName == null )
8281 return ;
@@ -90,7 +89,7 @@ public void eventReceived(Action action, Pod resource) {
9089 ip = nodeExternalAddresses .get (0 ).getAddress ();
9190 else
9291 ip = nodeInternalAddresses .get (0 ).getAddress ();
93- String port = resource . getMetadata (). getAnnotations () .get ("dynamic-hostports.k8s/25565" );
92+ String port = annotations .get ("dynamic-hostports.k8s/25565" );
9493 if (this .debug ) {
9594 logger .info ("[Kubernetes Container Inspector] env:" + environmentVariables );
9695 logger .info ("[Kubernetes Container Inspector] port: " + port );
@@ -115,6 +114,7 @@ public void eventReceived(Action action, Pod resource) {
115114 containerEvent .setPort (Integer .parseInt (environmentVariables .get ("SERVER_PORT" )));
116115 containerEvent .setIp (InetAddress .getByName (resource .getStatus ().getPodIP ()));
117116 }
117+ containerEvent .setEnvironmentVariables (environmentVariables );
118118 if (!dockerAction .equals ("nothing" ))
119119 this .proxyServer .getPluginManager ().callEvent (containerEvent );
120120 } catch (java .net .UnknownHostException ex ) {
@@ -128,6 +128,6 @@ public void onClose(KubernetesClientException cause) {
128128 logger .warning ("[Kubernetes Container Inspector] Watcher close due to " + cause );
129129 logger .warning ("[Kubernetes Container Inspector] Rewatching resources..." );
130130 client .pods ().inNamespace (namespace )
131- .watch (new PodWatcher (proxyServer , logger , configuration , client , namespace , hostport ));
131+ .watch (new PodWatcher (proxyServer , logger , configuration , client , namespace ));
132132 }
133133}
0 commit comments