Skip to content

Commit

Permalink
Add YAML separator (---) to stdout (#491)
Browse files Browse the repository at this point in the history
The output is not a valid Kubernetes manifest whenever calling the'
manifest' command.
```diff
+ ---
apiVersion: batch/v1
kind: Job
metadata:
  labels:
    app: word-count-data-producer
#...
+ ---
apiVersion: apps/v1
kind: Deployment
#...
```
  • Loading branch information
raminqaf authored May 22, 2024
1 parent d004b1b commit c111156
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 0 deletions.
1 change: 1 addition & 0 deletions kpops/utils/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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

14 changes: 14 additions & 0 deletions tests/pipeline/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c111156

Please sign in to comment.