diff --git a/kpops/utils/yaml.py b/kpops/utils/yaml.py index a6aa5cbbb..586a106ef 100644 --- a/kpops/utils/yaml.py +++ b/kpops/utils/yaml.py @@ -121,6 +121,7 @@ def print_yaml(data: Mapping | str, *, substitution: dict | None = None) -> None """ if not isinstance(data, str): data = yaml.safe_dump(dict(data)) + data = f"---\n{data}" syntax = Syntax( substitute(data, substitution), "yaml", diff --git a/tests/pipeline/snapshots/test_manifest/test_manifest_command/manifest.yaml b/tests/pipeline/snapshots/test_manifest/test_manifest_command/manifest.yaml new file mode 100644 index 000000000..4dcabb92d --- /dev/null +++ b/tests/pipeline/snapshots/test_manifest/test_manifest_command/manifest.yaml @@ -0,0 +1,164 @@ +--- +apiVersion: batch/v1 +kind: Job +metadata: + labels: + app: resources-custom-config-app1 + chart: producer-app-2.9.0 + release: resources-custom-config-app1 + name: resources-custom-config-app1 +spec: + backoffLimit: 6 + template: + metadata: + labels: + app: resources-custom-config-app1 + release: resources-custom-config-app1 + spec: + affinity: null + containers: + - env: + - name: ENV_PREFIX + value: APP_ + - name: APP_BROKERS + value: http://k8kafka-cp-kafka-headless.kpops.svc.cluster.local:9092 + - name: APP_SCHEMA_REGISTRY_URL + value: http://localhost:8081/ + - name: APP_DEBUG + value: 'false' + - name: APP_OUTPUT_TOPIC + value: resources-custom-config-app1 + - name: JAVA_TOOL_OPTIONS + value: '-XX:MaxRAMPercentage=75.0 ' + image: producerApp:latest + imagePullPolicy: Always + name: resources-custom-config-app1 + resources: + limits: + cpu: 500m + memory: 2G + requests: + cpu: 200m + memory: 2G + restartPolicy: OnFailure + +--- +apiVersion: v1 +data: + jmx-kafka-streams-app-prometheus.yml: "jmxUrl: service:jmx:rmi:///jndi/rmi://localhost:5555/jmxrmi\n\ + lowercaseOutputName: true\nlowercaseOutputLabelNames: true\nssl: false\nrules:\n\ + \ - pattern: \".*\"\n" +kind: ConfigMap +metadata: + labels: + app: resources-custom-config-app2 + chart: streams-app-2.9.0 + heritage: Helm + release: resources-custom-config-app2 + name: resources-custom-config-app2-jmx-configmap + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: resources-custom-config-app2 + chart: streams-app-2.9.0 + pipeline: resources-custom-config + release: resources-custom-config-app2 + name: resources-custom-config-app2 +spec: + replicas: 1 + selector: + matchLabels: + app: resources-custom-config-app2 + release: resources-custom-config-app2 + template: + metadata: + annotations: + prometheus.io/port: '5556' + prometheus.io/scrape: 'true' + labels: + app: resources-custom-config-app2 + pipeline: resources-custom-config + release: resources-custom-config-app2 + spec: + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - podAffinityTerm: + labelSelector: + matchExpressions: + - key: app + operator: In + values: + - resources-custom-config-app2 + topologyKey: kubernetes.io/hostname + weight: 1 + containers: + - env: + - name: ENV_PREFIX + value: APP_ + - name: STREAMS_LARGE_MESSAGE_ID_GENERATOR + value: com.bakdata.kafka.MurmurHashIdGenerator + - name: KAFKA_JMX_PORT + value: '5555' + - name: APP_VOLATILE_GROUP_INSTANCE_ID + value: 'true' + - name: APP_BROKERS + value: http://k8kafka-cp-kafka-headless.kpops.svc.cluster.local:9092 + - name: APP_SCHEMA_REGISTRY_URL + value: http://localhost:8081/ + - name: APP_DEBUG + value: 'false' + - name: APP_INPUT_TOPICS + value: resources-custom-config-app1 + - name: APP_OUTPUT_TOPIC + value: resources-custom-config-app2 + - name: APP_ERROR_TOPIC + value: resources-custom-config-app2-error + - name: JAVA_TOOL_OPTIONS + value: '-Dcom.sun.management.jmxremote.port=5555 -Dcom.sun.management.jmxremote.authenticate=false + -Dcom.sun.management.jmxremote.ssl=false -XX:MaxRAMPercentage=75.0 ' + image: some-image:latest + imagePullPolicy: Always + name: resources-custom-config-app2 + ports: + - containerPort: 5555 + name: jmx + resources: + limits: + cpu: 500m + memory: 2G + requests: + cpu: 200m + memory: 300Mi + - command: + - java + - -XX:+UnlockExperimentalVMOptions + - -XX:+UseCGroupMemoryLimitForHeap + - -XX:MaxRAMFraction=1 + - -XshowSettings:vm + - -jar + - jmx_prometheus_httpserver.jar + - '5556' + - /etc/jmx-streams-app/jmx-kafka-streams-app-prometheus.yml + image: solsson/kafka-prometheus-jmx-exporter@sha256:6f82e2b0464f50da8104acd7363fb9b995001ddff77d248379f8788e78946143 + name: prometheus-jmx-exporter + ports: + - containerPort: 5556 + resources: + limits: + cpu: 300m + memory: 2G + requests: + cpu: 100m + memory: 500Mi + volumeMounts: + - mountPath: /etc/jmx-streams-app + name: jmx-config + volumes: + - configMap: + name: resources-custom-config-app2-jmx-configmap + name: jmx-config + diff --git a/tests/pipeline/test_manifest.py b/tests/pipeline/test_manifest.py index 8dc58ae93..c144a32c9 100644 --- a/tests/pipeline/test_manifest.py +++ b/tests/pipeline/test_manifest.py @@ -98,6 +98,20 @@ def test_custom_config(self, mock_execute: MagicMock): ) assert result.exit_code == 0, result.stdout + def test_manifest_command(self, snapshot: Snapshot): + result = runner.invoke( + app, + [ + "manifest", + str(RESOURCE_PATH / "custom-config/pipeline.yaml"), + "--environment", + "development", + ], + catch_exceptions=False, + ) + assert result.exit_code == 0, result.stdout + snapshot.assert_match(result.stdout, "manifest.yaml") + def test_python_api(self, snapshot: Snapshot): resources = kpops.manifest( RESOURCE_PATH / "custom-config/pipeline.yaml",