RevisionHistoryEnricher extends BaseEnricher { @Override public void create(PlatformMode platformMode, KubernetesListBuilder builder) { final Integer maxRevisionHistories = Configs.asInt(getConfig(Config.limit)); log.info("Adding revision history limit to %s", maxRevisionHistories); if(platformMode == PlatformMode.kubernetes) { builder.accept(new TypedVisitor<io.fabric8.kubernetes.api.model.apps.DeploymentBuilder>() { @Override public void visit(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder item) { item.editOrNewSpec() .withRevisionHistoryLimit(maxRevisionHistories) .endSpec(); } }); builder.accept(new TypedVisitor<io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder>() { @Override public void visit(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder item) { item.editOrNewSpec() .withRevisionHistoryLimit(maxRevisionHistories) .endSpec(); } }); } else { builder.accept(new TypedVisitor<DeploymentConfigBuilder>() { @Override public void visit(DeploymentConfigBuilder item) { item.editOrNewSpec() .withRevisionHistoryLimit(maxRevisionHistories) .endSpec(); } }); } } RevisionHistoryEnricher(MavenEnricherContext buildContext); @Override void create(PlatformMode platformMode, KubernetesListBuilder builder); static final String DEFAULT_NAME; }
@Test public void testDefaultRevisionHistoryLimit() throws JsonProcessingException { KubernetesListBuilder builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().build()); RevisionHistoryEnricher enricher = new RevisionHistoryEnricher(context); enricher.create(PlatformMode.kubernetes, builder); assertRevisionHistory(builder.build(), Configs.asInt(RevisionHistoryEnricher.Config.limit.def())); }
@Test public void testCustomRevisionHistoryLimit() throws JsonProcessingException { final String revisionNumber = "10"; new Expectations() {{ Configuration config = new Configuration.Builder().processorConfig(prepareEnricherConfig(revisionNumber)).build(); context.getConfiguration(); result = config; }}; KubernetesListBuilder builder = new KubernetesListBuilder().withItems(new DeploymentBuilder().build()); RevisionHistoryEnricher enricher = new RevisionHistoryEnricher(context); enricher.create(PlatformMode.kubernetes, builder); assertRevisionHistory(builder.build(), Integer.parseInt(revisionNumber)); }