@Test void shouldHandleCrdSubresources() { KubernetesAttributesExtractor extractor = new KubernetesAttributesExtractor(); String[] subresources = new String[]{"status", "scale"}; String basePath = "/apis/test.com/v1/namespaces/myns/crds/mycrd/"; for (String subresource : subresources) { AttributeSet attributes = extractor.extract(basePath + subresource); AttributeSet expected = new AttributeSet(); expected = expected.add(new Attribute("kind", "crd")); expected = expected.add(new Attribute("namespace", "myns")); expected = expected.add(new Attribute("name", "mycrd")); assertTrue(attributes.matches(expected), "extracted attributes match for " + subresource + " expectation: " + expected); } AttributeSet attributes = extractor.extract(basePath + "somethingRandom"); assertTrue(attributes.matches(new AttributeSet()), "should extract nothing from an unsupported crd subresource"); }
@Override public AttributeSet extract(String s) { if (s == null || s.isEmpty()) { return new AttributeSet(); } HasMetadata h = toKubernetesResource(s); if (h != null) { return extract(h); } return fromPath(s); }
KubernetesAttributesExtractor implements AttributeExtractor<HasMetadata> { @Override public AttributeSet extract(String s) { if (s == null || s.isEmpty()) { return new AttributeSet(); } HasMetadata h = toKubernetesResource(s); if (h != null) { return extract(h); } return fromPath(s); } }
KubernetesAttributesExtractor implements AttributeExtractor<HasMetadata> { @Override public AttributeSet extract(String s) { if (s == null || s.isEmpty()) { return new AttributeSet(); } HasMetadata h = toKubernetesResource(s); if (h != null) { return extract(h); } return fromPath(s); } KubernetesAttributesExtractor();  KubernetesAttributesExtractor(List<CustomResourceDefinitionContext> crdContexts); }
KubernetesAttributesExtractor implements AttributeExtractor<HasMetadata> { @Override public AttributeSet extract(String s) { if (s == null || s.isEmpty()) { return new AttributeSet(); } HasMetadata h = toKubernetesResource(s); if (h != null) { return extract(h); } return fromPath(s); } KubernetesAttributesExtractor();  KubernetesAttributesExtractor(List<CustomResourceDefinitionContext> crdContexts); @Override AttributeSet fromPath(String s); @Override AttributeSet fromResource(String s); @Override AttributeSet extract(String s); @Override AttributeSet extract(HasMetadata o); }
KubernetesAttributesExtractor implements AttributeExtractor<HasMetadata> { @Override public AttributeSet extract(String s) { if (s == null || s.isEmpty()) { return new AttributeSet(); } HasMetadata h = toKubernetesResource(s); if (h != null) { return extract(h); } return fromPath(s); } KubernetesAttributesExtractor();  KubernetesAttributesExtractor(List<CustomResourceDefinitionContext> crdContexts); @Override AttributeSet fromPath(String s); @Override AttributeSet fromResource(String s); @Override AttributeSet extract(String s); @Override AttributeSet extract(HasMetadata o); static final String KEY; static final String KIND; static final String NAME; static final String NAMESPACE; static final String VALUE; }