From 61dbc7ef28b73447961ac368e4759835b5a82091 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Mon, 8 Jan 2018 20:15:46 +0100 Subject: [PATCH 1/7] Add some logging to mock server --- kubernetes-server-mock/pom.xml | 7 +++ .../mock/KubernetesAttributesExtractor.java | 60 +++++++------------ .../server/mock/KubernetesCrudDispatcher.java | 5 ++ 3 files changed, 34 insertions(+), 38 deletions(-) diff --git a/kubernetes-server-mock/pom.xml b/kubernetes-server-mock/pom.xml index ce17236b2df..01ded81d7da 100644 --- a/kubernetes-server-mock/pom.xml +++ b/kubernetes-server-mock/pom.xml @@ -52,6 +52,13 @@ junit ${junit.version} + + + org.slf4j + slf4j-simple + ${slf4j.version} + test + diff --git a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java index d521637fb38..462b97bf5dd 100644 --- a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java +++ b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java @@ -28,8 +28,13 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class KubernetesAttributesExtractor implements AttributeExtractor { + private static final Logger LOGGER = LoggerFactory.getLogger(KubernetesAttributesExtractor.class); + public static final String KIND = "kind"; public static final String NAME = "name"; public static final String NAMESPACE = "namespace"; @@ -45,6 +50,8 @@ public class KubernetesAttributesExtractor implements AttributeExtractor entry : map.entrySet()) { if (entry.getKey().matches(query)) { + LOGGER.debug("Entry found for query {} : {}", query, entry); items.add(entry.getValue()); } } From 29e2080b2ccf9b470cdb13d7acf353eb4ee52ae3 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Mon, 8 Jan 2018 20:12:25 +0100 Subject: [PATCH 2/7] KubernetesAttributesExtractor is not testing anything expected.add does not modify object Parse correctly urls without namespace --- .../mock/KubernetesAttributesExtractor.java | 8 +++---- .../KubernetesAttributesExtractorTest.java | 22 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java index 462b97bf5dd..fffd8d0da14 100644 --- a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java +++ b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java @@ -39,15 +39,15 @@ public class KubernetesAttributesExtractor implements AttributeExtractor Date: Mon, 8 Jan 2018 21:45:26 +0100 Subject: [PATCH 3/7] Parse ingresses correctly --- .../mock/KubernetesAttributesExtractor.java | 4 +++- .../mock/KubernetesAttributesExtractorTest.java | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java index fffd8d0da14..47f3c2a22da 100644 --- a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java +++ b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java @@ -134,7 +134,9 @@ private static AttributeSet extract(Matcher m) { if (!Strings.isNullOrEmpty(kind)) { //Poor mans to singular. - if (kind.endsWith("s")) { + if (kind.endsWith("ses")) { + kind = kind.substring(0, kind.length() - 2); + } else if (kind.endsWith("s")) { kind = kind.substring(0, kind.length() - 1); } attributes = attributes.add(new Attribute(KIND, kind)); diff --git a/kubernetes-server-mock/src/test/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractorTest.java b/kubernetes-server-mock/src/test/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractorTest.java index 93bae7b50f6..d71a0b59729 100644 --- a/kubernetes-server-mock/src/test/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractorTest.java +++ b/kubernetes-server-mock/src/test/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractorTest.java @@ -17,6 +17,8 @@ import io.fabric8.kubernetes.api.model.Pod; import io.fabric8.kubernetes.api.model.PodBuilder; +import io.fabric8.kubernetes.api.model.extensions.Ingress; +import io.fabric8.kubernetes.api.model.extensions.IngressBuilder; import io.fabric8.mockwebserver.crud.Attribute; import io.fabric8.mockwebserver.crud.AttributeSet; import org.junit.Assert; @@ -64,4 +66,18 @@ public void shouldHandleResource() { Assert.assertTrue("Expected " + attributes + " to match " + expected, attributes.matches(expected)); } + + @Test + public void shouldHandleIngress() { + KubernetesAttributesExtractor extractor = new KubernetesAttributesExtractor(); + Ingress ingress = new IngressBuilder().withNewMetadata().withName("myingress").withNamespace("myns").endMetadata().build(); + + AttributeSet attributes = extractor.extract(ingress); + + AttributeSet expected = new AttributeSet(); + expected = expected.add(new Attribute("kind", "ingress")); + expected = expected.add(new Attribute("namespace", "myns")); + expected = expected.add(new Attribute("name", "myingress")); + Assert.assertTrue("Expected " + attributes + " to match " + expected, attributes.matches(expected)); + } } From cce4b6617ffb0eeeb0dbc01cfa4c38a0acb73832 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Mon, 8 Jan 2018 21:59:38 +0100 Subject: [PATCH 4/7] Handle /apis/extensions/* urls --- .../server/mock/KubernetesAttributesExtractor.java | 9 +++++---- .../server/mock/KubernetesAttributesExtractorTest.java | 4 +--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java index 47f3c2a22da..4dc1442b2e4 100644 --- a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java +++ b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java @@ -39,16 +39,17 @@ public class KubernetesAttributesExtractor implements AttributeExtractor Date: Tue, 9 Jan 2018 10:24:21 +0100 Subject: [PATCH 5/7] KubernetesAttributesExtractor, handle ingresses root url --- .../server/mock/KubernetesAttributesExtractor.java | 9 +++++---- .../mock/KubernetesAttributesExtractorTest.java | 11 +++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java index 4dc1442b2e4..3fc1beda0f8 100644 --- a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java +++ b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java @@ -44,12 +44,13 @@ public class KubernetesAttributesExtractor implements AttributeExtractor Date: Tue, 9 Jan 2018 10:33:25 +0100 Subject: [PATCH 6/7] KubernetesAttributesExtractor, handle path with parameters --- .../mock/KubernetesAttributesExtractor.java | 4 ++-- .../KubernetesAttributesExtractorTest.java | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java index 3fc1beda0f8..239fb4200d9 100644 --- a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java +++ b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java @@ -41,8 +41,8 @@ public class KubernetesAttributesExtractor implements AttributeExtractor Date: Tue, 9 Jan 2018 12:08:52 +0100 Subject: [PATCH 7/7] Simplify regex in KubernetesAttributesExtractor --- .../mock/KubernetesAttributesExtractor.java | 42 +++++++------------ .../KubernetesAttributesExtractorTest.java | 22 +++++++++- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java index 239fb4200d9..5b277dc20fe 100644 --- a/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java +++ b/kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java @@ -39,20 +39,14 @@ public class KubernetesAttributesExtractor implements AttributeExtractor