Skip to content

Support serialization of objects as string using json/yaml format #843

@t3mi

Description

@t3mi

Feature Description

Problem Statement:
As part of RGD, I need to combine various pieces for worker configuration to be mounted as file from configMap, for example.

apiVersion: kro.run/v1alpha1
kind: ResourceGraphDefinition
metadata:
  name: app
spec:
  schema:
    apiVersion: v1alpha1
    kind: App
    spec:
      config: object
  resources:
    - id: configMap
      template:
        apiVersion: v1
        kind: ConfigMap
        metadata:
          name: ${schema.metadata.name}
        data:
          config.yaml: |
            ${schema.spec.config}

Logs:

2025-11-21T10:20:53.901Z	DEBUG	rgd-controller	setting resourcegraphdefinition as managed	{"controller": "ResourceGraphDefinition", "controllerGroup": "kro.run", "controllerKind": "ResourceGraphDefinition", "name": "app", "reconcileID": "ee549285-bad9-49b3-a453-c9e6664a427d"}
2025-11-21T10:20:53.901Z	DEBUG	rgd-controller	reconciling resource graph definition graph	{"controller": "ResourceGraphDefinition", "controllerGroup": "kro.run", "controllerKind": "ResourceGraphDefinition", "name": "app", "reconcileID": "ee549285-bad9-49b3-a453-c9e6664a427d"}
2025-11-21T10:20:53.902Z	DEBUG	rgd-controller	calculating resource graph definition status and conditions	{"controller": "ResourceGraphDefinition", "controllerGroup": "kro.run", "controllerKind": "ResourceGraphDefinition", "name": "app", "reconcileID": "ee549285-bad9-49b3-a453-c9e6664a427d"}
2025-11-21T10:20:53.902Z	DEBUG	rgd-controller	updating resource graph definition status	{"controller": "ResourceGraphDefinition", "controllerGroup": "kro.run", "controllerKind": "ResourceGraphDefinition", "name": "app", "reconcileID": "ee549285-bad9-49b3-a453-c9e6664a427d", "state": "Inactive", "conditions": 4}
2025-11-21T10:20:53.903Z	ERROR	rgd-controller	Reconciler error	{"controller": "ResourceGraphDefinition", "controllerGroup": "kro.run", "controllerKind": "ResourceGraphDefinition", "name": "app", "reconcileID": "ee549285-bad9-49b3-a453-c9e6664a427d", "error": "failed to validate node \"configMap\": type mismatch in resource \"configMap\" at path \"data[\\\"config.yaml\\\"]\": expression \"schema.spec.config\" returns type \"__type_schema.spec.config\" but expected \"string\": type kind mismatch: got \"__type_schema.spec.config\", expected \"string\""}
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).reconcileHandler
	sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:316
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).processNextWorkItem
	sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:263
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Start.func2.2
	sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:224

Logs for ${string(schema.spec.config)}:

2025-11-21T10:23:27.511Z	DEBUG	rgd-controller	setting resourcegraphdefinition as managed	{"controller": "ResourceGraphDefinition", "controllerGroup": "kro.run", "controllerKind": "ResourceGraphDefinition", "name": "app", "reconcileID": "4607b587-a4b8-4185-929b-92ed86ebfae0"}
2025-11-21T10:23:27.511Z	DEBUG	rgd-controller	reconciling resource graph definition graph	{"controller": "ResourceGraphDefinition", "controllerGroup": "kro.run", "controllerKind": "ResourceGraphDefinition", "name": "app", "reconcileID": "4607b587-a4b8-4185-929b-92ed86ebfae0"}
2025-11-21T10:23:27.514Z	DEBUG	rgd-controller	calculating resource graph definition status and conditions	{"controller": "ResourceGraphDefinition", "controllerGroup": "kro.run", "controllerKind": "ResourceGraphDefinition", "name": "app", "reconcileID": "4607b587-a4b8-4185-929b-92ed86ebfae0"}
2025-11-21T10:23:27.514Z	DEBUG	rgd-controller	updating resource graph definition status	{"controller": "ResourceGraphDefinition", "controllerGroup": "kro.run", "controllerKind": "ResourceGraphDefinition", "name": "app", "reconcileID": "4607b587-a4b8-4185-929b-92ed86ebfae0", "state": "Inactive", "conditions": 4}
2025-11-21T10:23:27.514Z	ERROR	rgd-controller	Reconciler error	{"controller": "ResourceGraphDefinition", "controllerGroup": "kro.run", "controllerKind": "ResourceGraphDefinition", "name": "app", "reconcileID": "4607b587-a4b8-4185-929b-92ed86ebfae0", "error": "failed to validate node \"configMap\": failed to type-check template expression \"string(schema.spec.config)\" at path \"data[\\\"config.yaml\\\"]\": ERROR: <input>:1:7: found no matching overload for 'string' applied to '(__type_schema.spec.config)'\n | string(schema.spec.config)\n | ......^"}
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).reconcileHandler
	sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:316
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).processNextWorkItem
	sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:263
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Start.func2.2
	sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:224

Proposed Solution:
Additional functions to dump content with yaml/json formatting
${toYaml(schema.spec.config)} and/or ${toJson(schema.spec.config)}

Alternatives Considered:
Currently, such configuration could be referenced outside the RGD but it will lack some additional properties which are computed as part of instance deployment.

Additional Context:

  • Please vote on this issue by adding a 👍 reaction to the original issue
  • If you are interested in working on this feature, please leave a comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/celkind/featureCategorizes issue or PR as related to a new feature.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions