|
| 1 | +/** |
| 2 | + * Copyright (2022, ) Institute of Software, Chinese Academy of Sciences |
| 3 | + */ |
| 4 | +package io.github.kubesys.client.install.stack; |
| 5 | + |
| 6 | + |
| 7 | +import io.github.kubesys.client.writers.ConfigMapWriter; |
| 8 | +import io.github.kubesys.client.writers.DaemonSetWriter; |
| 9 | +import io.github.kubesys.client.writers.PVCWriter; |
| 10 | +import io.github.kubesys.client.writers.PVWriter; |
| 11 | +import io.github.kubesys.client.writers.ServiceWriter; |
| 12 | +import io.github.kubesys.client.writers.WorkloadWriter.Container; |
| 13 | +import io.github.kubesys.client.writers.WorkloadWriter.Port; |
| 14 | +import io.github.kubesys.client.writers.WorkloadWriter.VolumeMount; |
| 15 | + |
| 16 | +/** |
| 17 | + * @author wuheng@iscas.ac.cn |
| 18 | + * @since 2023/08/02 |
| 19 | + * @version 1.0.3 |
| 20 | + * |
| 21 | + * get real Url from <code>KubernetesRuleBase</code> |
| 22 | + * |
| 23 | + */ |
| 24 | +public class KubeLoggerTest { |
| 25 | + |
| 26 | + static final String NAME = "kube-logger"; |
| 27 | + |
| 28 | + static final String LOGGER = "logger"; |
| 29 | + |
| 30 | + static final String LOGGER_IMAGE = "grafana/loki:2.8.3"; |
| 31 | + |
| 32 | + static final String CONFIG_YML = "loki.yml"; |
| 33 | + |
| 34 | + static final String YML_PATH = "configs/loki.yml"; |
| 35 | + |
| 36 | + public static void main(String[] args) throws Exception { |
| 37 | + |
| 38 | + ConfigMapWriter cm = new ConfigMapWriter(NAME, StackCommon.NAMESPACE); |
| 39 | + cm.withYamlData(CONFIG_YML, StackCommon.read(YML_PATH)).stream(System.out); |
| 40 | + |
| 41 | + PVWriter pv = new PVWriter(NAME); |
| 42 | + pv.withCapacity("20").withPath(StackCommon.PATH + LOGGER).withPVC(NAME, StackCommon.NAMESPACE).stream(System.out); |
| 43 | + |
| 44 | + PVCWriter pvc = new PVCWriter(NAME, StackCommon.NAMESPACE); |
| 45 | + pvc.withCapacity("20").stream(System.out); |
| 46 | + |
| 47 | + DaemonSetWriter ds = new DaemonSetWriter(NAME, StackCommon.NAMESPACE); |
| 48 | + |
| 49 | + ds.withMasterEnbale() |
| 50 | + .withContainer(new Container(LOGGER, LOGGER_IMAGE, |
| 51 | + new String[] { |
| 52 | + "-config.file=/etc/loki/loki.yml", |
| 53 | + }, |
| 54 | + null, |
| 55 | + new Port[] { |
| 56 | + new Port(9093) |
| 57 | + }, |
| 58 | + new VolumeMount[] { |
| 59 | + new VolumeMount(StackCommon.VOLUME_CONFIG, "/etc/loki"), |
| 60 | + new VolumeMount(StackCommon.VOLUME_DATA, "/data") |
| 61 | + })) |
| 62 | + .withConfigMapVolume(StackCommon.VOLUME_CONFIG, NAME, CONFIG_YML, CONFIG_YML) |
| 63 | + .withPVCVolume(StackCommon.VOLUME_DATA, NAME) |
| 64 | + .stream(System.out); |
| 65 | + |
| 66 | + ServiceWriter service = new ServiceWriter(NAME, StackCommon.NAMESPACE); |
| 67 | + service.withType("NodePort").withSelector(NAME) |
| 68 | + .withPort(3100, 30300, "logger") |
| 69 | + .stream(System.out); |
| 70 | + } |
| 71 | +} |
0 commit comments