@Test public void testConditionalStatefulSetEnrichment() throws IOException { final Properties props = new Properties(); props.put("fabric8.enricher.fmp-triggers-annotation.containers", "c2, c3, anotherc"); new Expectations() {{ context.getConfiguration(); result = new Configuration.Builder().properties(props).build(); }}; KubernetesListBuilder builder = new KubernetesListBuilder() .addToItems(new StatefulSetBuilder() .withNewSpec() .withNewTemplate() .withNewSpec() .withContainers(createContainers( "c1", "is1:latest", "c2", "is2:latest", "c3", "is3:latest" )) .endSpec() .endTemplate() .endSpec() .build()); TriggersAnnotationEnricher enricher = new TriggersAnnotationEnricher(context); enricher.enrich(PlatformMode.kubernetes, builder); StatefulSet res = (StatefulSet) builder.build().getItems().get(0); String triggers = res.getMetadata().getAnnotations().get("image.openshift.io/triggers"); assertNotNull(triggers); List<ImageChangeTrigger> triggerList = OBJECT_MAPPER.readValue(triggers, OBJECT_MAPPER.getTypeFactory().constructCollectionType(List.class, ImageChangeTrigger.class)); assertEquals(2, triggerList.size()); ImageChangeTrigger trigger1 = triggerList.get(0); assertEquals("ImageStreamTag", trigger1.getFrom().getKind()); assertEquals("is2:latest", trigger1.getFrom().getName()); assertTrue(trigger1.getAdditionalProperties().containsKey("fieldPath")); ImageChangeTrigger trigger2 = triggerList.get(1); assertEquals("ImageStreamTag", trigger2.getFrom().getKind()); assertEquals("is3:latest", trigger2.getFrom().getName()); assertTrue(trigger2.getAdditionalProperties().containsKey("fieldPath")); }
@Override public void enrich(PlatformMode platformMode, KubernetesListBuilder builder) { builder.accept(new TypedVisitor<StatefulSetBuilder>() { @Override public void visit(StatefulSetBuilder o) { StatefulSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); builder.accept(new TypedVisitor<ReplicaSetBuilder>() { @Override public void visit(ReplicaSetBuilder o) { ReplicaSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); builder.accept(new TypedVisitor<DaemonSetBuilder>() { @Override public void visit(DaemonSetBuilder o) { DaemonSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); }
TriggersAnnotationEnricher extends BaseEnricher { @Override public void enrich(PlatformMode platformMode, KubernetesListBuilder builder) { builder.accept(new TypedVisitor<StatefulSetBuilder>() { @Override public void visit(StatefulSetBuilder o) { StatefulSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); builder.accept(new TypedVisitor<ReplicaSetBuilder>() { @Override public void visit(ReplicaSetBuilder o) { ReplicaSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); builder.accept(new TypedVisitor<DaemonSetBuilder>() { @Override public void visit(DaemonSetBuilder o) { DaemonSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); } }
TriggersAnnotationEnricher extends BaseEnricher { @Override public void enrich(PlatformMode platformMode, KubernetesListBuilder builder) { builder.accept(new TypedVisitor<StatefulSetBuilder>() { @Override public void visit(StatefulSetBuilder o) { StatefulSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); builder.accept(new TypedVisitor<ReplicaSetBuilder>() { @Override public void visit(ReplicaSetBuilder o) { ReplicaSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); builder.accept(new TypedVisitor<DaemonSetBuilder>() { @Override public void visit(DaemonSetBuilder o) { DaemonSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); } TriggersAnnotationEnricher(MavenEnricherContext buildContext); }
TriggersAnnotationEnricher extends BaseEnricher { @Override public void enrich(PlatformMode platformMode, KubernetesListBuilder builder) { builder.accept(new TypedVisitor<StatefulSetBuilder>() { @Override public void visit(StatefulSetBuilder o) { StatefulSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); builder.accept(new TypedVisitor<ReplicaSetBuilder>() { @Override public void visit(ReplicaSetBuilder o) { ReplicaSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); builder.accept(new TypedVisitor<DaemonSetBuilder>() { @Override public void visit(DaemonSetBuilder o) { DaemonSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); } TriggersAnnotationEnricher(MavenEnricherContext buildContext); @Override void enrich(PlatformMode platformMode, KubernetesListBuilder builder); }
TriggersAnnotationEnricher extends BaseEnricher { @Override public void enrich(PlatformMode platformMode, KubernetesListBuilder builder) { builder.accept(new TypedVisitor<StatefulSetBuilder>() { @Override public void visit(StatefulSetBuilder o) { StatefulSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); builder.accept(new TypedVisitor<ReplicaSetBuilder>() { @Override public void visit(ReplicaSetBuilder o) { ReplicaSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); builder.accept(new TypedVisitor<DaemonSetBuilder>() { @Override public void visit(DaemonSetBuilder o) { DaemonSet s = o.build(); if (canWriteTriggers(s)) { o.withMetadata(getMetaEnrichedWithTriggers(s.getMetadata(), o)); } } }); } TriggersAnnotationEnricher(MavenEnricherContext buildContext); @Override void enrich(PlatformMode platformMode, KubernetesListBuilder builder);  }