Flux: Support JSON manifest files

Created on 16 Jan 2020  路  8Comments  路  Source: fluxcd/flux

Describe the bug
When deciding what files to pass to kubectl, flux ignores .json files in its target repository/branch/path.

To Reproduce
Set up a cluster with flux. Add a valid namespace manifest file such as the one below to the target git repo/branch/path and name it *.json

{
  "apiVersion": "v1",
  "kind": "Namespace",
  "metadata": {
    "namespace": "test-namespace"
  }
}

Expected behavior
Flux should pick up this file and apply it to the cluster under management.

What actually happens
Flux notices that the git repo has changed, and re-runs kubectl, but omits the JSON file from the things it passes to kubectl's stdin.

Additional notes
.yaml, .yml and .json files are all accepted by kubectl, and flux should mirror this behaviour.

enhancement help wanted

Most helpful comment

This is a false limitation and should be fixed :)

_Should_ is subjective, but I will happily accept a PR.

All 8 comments

Flux doesn't support json, just yaml files.

@2opremio I noticed :) Is there any underlying reason why that is?

@bricef Flux needs to parse and modify Kubernetes manifests, for this reason only YAML is supported as the patching is done with a library specialised in YAML only.
Ref:

Ah, I mentioned it since you opened a bug and not a feature request.

Legacy reasons. There isn't enough explicit community demand either (or they silently accept the status quo). It comes up from time to time but not enough to justify the effort, given the constrained manpower.

Well, we maintain kubeyaml because we want to preserve comments, see #2660 . JSON doesn't have that _problem_, making things easier.

I guess that's the reason why the community prefers YAMLs too.

@stefanprodan Valid JSON is also valid YAML, and can be parsed as such since YAML is a JSON superset. Kubeyaml should work with json files without issue. In fact, I just tried the underlying ruamel.yaml library with JSON and it works fine:

>>> from ruamel.yaml import YAML
>>> yaml=YAML()
>>> json="""
... {"menu": {
...   "id": "file",
...   "value": "File",
...   "popup": {
...     "menuitem": [
...       {"value": "New", "onclick": "CreateNewDoc()"},
...       {"value": "Open", "onclick": "OpenDoc()"},
...       {"value": "Close", "onclick": "CloseDoc()"}
...     ]
...   }
... }}
... """
>>> yaml.load(json)
ordereddict([('menu', ordereddict([('id', 'file'), ('value', 'File'), ('popup', ordereddict([('menuitem', [ordereddict([('value', 'New'), ('onclick', 'CreateNewDoc()')]), ordereddict([('value', 'Open'), ('onclick', 'OpenDoc()')]), ordereddict([('value', 'Close'), ('onclick', 'CloseDoc()')])])]))]))])
>>>

This is a false limitation and should be fixed :)

This is a false limitation and should be fixed :)

_Should_ is subjective, but I will happily accept a PR.

I'm not sure I would trust ruamel to output valid JSON given a JSON input. JSON-is-YAML works in your favour for the input, but not the output.

Was this page helpful?
0 / 5 - 0 ratings