kubernetes-client icon indicating copy to clipboard operation
kubernetes-client copied to clipboard

[Suggestion] Generate the YAML string where resources are separated with "---"

Open cmoulliard opened this issue 6 months ago • 1 comments

Is your enhancement related to a problem? Please describe

Until now if we provide a List of objects to be serialized using the class io.quarkiverse.tekton.common.utils.Serialization and the method: asYaml() we got a wrong yaml result that we cannot install on a kubernetes cluster

---
- apiVersion: "v1"
  kind: "ConfigMap"
  metadata:
    name: "my-quarkus-hello-maven-settings"
  data:
...
- apiVersion: "v1"
  kind: "ConfigMap"
  metadata:
    name: "my-quarkus-hello-maven-settings"
  data:
...

Describe the solution you'd like

Ideally, the serializer should be able to iterate through the list of the objects to trim it and add a CR as such

    public void process(List<HasMetadata> resources) {
        // Iterate through the list of the resources to process them individually to include ---
        // as separator between them instead of a list of items
        StringBuilder yamlOutput = new StringBuilder();
        for (HasMetadata resource : resources) {
            String yaml = Serialization.asYaml(resource).trim();
            yamlOutput.append(yaml).append("\n");
        }

       write(yamlOutput.toString();

By doing that, we get as result

---
apiVersion: "v1"
kind: "ConfigMap"
metadata:
  name: "my-quarkus-hello-maven-settings"
data:
  settings.xml: |
...
---
apiVersion: "v1"
kind: "PersistentVolumeClaim"
metadata:
  name: "my-quarkus-hello-project-pvc"
spec:
  accessModes:
  - "ReadWriteOnce"
  resources:
    requests:
      storage: "2Gi"
  volumeMode: "Filesystem"
---
etc.

Describe alternatives you've considered

No response

Additional context

No response

cmoulliard avatar Apr 15 '25 14:04 cmoulliard