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

Add cluster ip for Kubernetes Nat Manager #1156

Merged
merged 9 commits into from
Jul 1, 2020

Conversation

matkt
Copy link
Contributor

@matkt matkt commented Jun 26, 2020

Signed-off-by: Karim TAAM karim.t2am@gmail.com

PR description

Kubernetes nat manager could work with LoadBalancer services. This PR add compatibility with ClusterIP services.
A code refactor was made in order to facilitate the addition of new services thereafter such as the NodePort

Sample of ClusterIP service :

---
apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: besu
    app.kubernetes.io/release: "1.0.0"
  name: besu
spec:
  ports:
  - name: "json-rpc"
    port: 8546
    targetPort: 8545
  - name: "rlpx"
    port: 30303
    targetPort: 30303
  selector:
    app.kubernetes.io/name: besu
    app.kubernetes.io/release: "1.0.0"
  type: ClusterIP

You can find the IP that will be used by BESU by launching the following command

kubectl describe services besu

Name:              besu
Namespace:         default
Labels:            app.kubernetes.io/name=besu
                   app.kubernetes.io/release=1.0.0
Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                     {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app.kubernetes.io/name":"besu","app.kubernetes.io/release":"1....
Selector:          app.kubernetes.io/name=besu,app.kubernetes.io/release=1.0.0
Type:              ClusterIP
IP:                **<IP USED BY KUBERNETES NAT MANAGER>**
Port:              json-rpc  8546/TCP
TargetPort:        8545/TCP
Endpoints:         <none>
Port:              rlpx  30303/TCP
TargetPort:        30303/TCP
Endpoints:         <none>
Session Affinity:  None
Events:            <none>

Update of the fallback mechanism

  • If the nat-method is equal to AUTO (default). A bad configuration (invalid service, ingress not found, etc.) will cause a switch to the NONE mode.

  • If the nat-method is equal to KUBERNETES and Xnat-method-fallback-enabled is equal to true. A bad configuration will cause a switch to the NONE mode.

  • If the nat-method is equal to KUBERNETES and Xnat-method-fallback-enabledis equal to false. A bad configuration will cause a stop of BESU in order to indicate to him that the automatic configuration has failed

New error message added

If you are trying to use not implemented service you will now have an issue :

Failed update information using pod metadata : NodePort is not implemented.

Tested

Test Result expected
Deploy with a ClusterIP Work OK
Deploy with a LoadBalancer Work OK
Deploy with a NodePort (AUTO) Throw an exception and switch to NONE OK
Deploy with a Missing service (AUTO) Throw an exception and switch to NONE OK
Deploy without fallback (KUBERNETES and fallback=false) Stop besu with an exception OK
Deploy without fallback (KUBERNETES and fallback=true) Throw an exception and switch to NONE OK

Fixed Issue(s)

matkt added 2 commits June 26, 2020 16:08
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
@matkt matkt marked this pull request as ready for review June 26, 2020 15:17
Copy link
Contributor

@AbdelStark AbdelStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested

+ e.getMessage()
+ ". NONE mode will be used");
disableNatManager();
String.format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use String.format, use standard logging placeholder instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


import io.kubernetes.client.models.V1Service;

public class ClusterIpBasedDetector implements IpDetector {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not worth creating a class for such a simple implementation IMO. You can inject the code as a lambda directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

final String serviceType = v1Service.getSpec().getType();
switch (KubernetesServiceType.fromName(serviceType)) {
case CLUSTER_IP:
return new ClusterIpBasedDetector(v1Service);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return a lambda instead IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -197,6 +197,24 @@ public void assertThatManagerSwitchToNoneForInvalidNatEnvironment()
assertThat(natService.queryLocalIPAddress(fallbackLocalIp)).isEqualTo(fallbackLocalIp);
}

@Test(expected = RuntimeException.class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use assertThatThrownBy instead.
Example here:

assertThatThrownBy(() -> exporter.exportBlocks(outputPath, Optional.of(-1L), Optional.empty()))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -61,7 +63,14 @@ public void assertThatExternalIPIsEqualToRemoteHost()
@Test
public void assertThatExternalIPIsEqualToDefaultHostIfIpDetectorCannotRetrieveIP()
throws ExecutionException, InterruptedException {
when(hostBasedIpDetector.detectExternalIp()).thenReturn(Optional.empty());
NatManager natManager =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You right . Done

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Copy link
Contributor

@AbdelStark AbdelStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
@matkt matkt self-assigned this Jun 29, 2020
@timbeiko timbeiko added this to the Chupacabra Sprint 68 milestone Jun 30, 2020
matkt added 2 commits July 1, 2020 14:16
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Copy link
Contributor

@AbdelStark AbdelStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

matkt added 2 commits July 1, 2020 14:41
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
Copy link
Contributor

@AbdelStark AbdelStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
@matkt matkt merged commit 50db46f into hyperledger:master Jul 1, 2020
@matkt matkt added the doc-change-required Indicates an issue or PR that requires doc to be updated label Jul 1, 2020
@AbdelStark AbdelStark removed the doc-change-required Indicates an issue or PR that requires doc to be updated label Jul 1, 2020
@matkt matkt added the doc-change-required Indicates an issue or PR that requires doc to be updated label Jul 24, 2020
matkt added a commit that referenced this pull request Jul 24, 2020
Add  #1156 and #1149

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>

Co-authored-by: Ratan (Rai) Sur <ratan.r.sur@gmail.com>
shemnon pushed a commit to shemnon/besu that referenced this pull request Jul 28, 2020
Add  hyperledger#1156 and hyperledger#1149

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>

Co-authored-by: Ratan (Rai) Sur <ratan.r.sur@gmail.com>
(cherry picked from commit baa11a2)
Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
shemnon pushed a commit that referenced this pull request Jul 28, 2020
Add  #1156 and #1149

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>

Co-authored-by: Ratan (Rai) Sur <ratan.r.sur@gmail.com>
(cherry picked from commit baa11a2)
Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
@bgravenorst bgravenorst removed the doc-change-required Indicates an issue or PR that requires doc to be updated label Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants