weaveworks / kubediff

Kubediff: a tool for Kubernetes to show differences between running state and version controlled configuration.
Apache License 2.0
1.18k stars 104 forks source link

Solve Print Errors (Decode) #141

Closed imjoseangel closed 3 years ago

imjoseangel commented 3 years ago

During tests in #125 we have detected that the line

                    try:
                        running = kube_obj.get_from_cluster(config["kubeconfig"], config["context"])
                    except subprocess.CalledProcessError as e:
                        printer.diff(path, Difference(e.output, None))
                        differences += 1
                        continue

prints:

b'Error from server (NotFound): services "kubediff-app" not found\n'

And not:

Error from server (NotFound): services "kubediff-app" not found

We need to solve it adding decode:

printer.diff(path, Difference(e.output.decode('utf-8'), None))
imjoseangel commented 3 years ago

This will fix also the error:

Traceback (most recent call last):
  File "/Users/imjoseangel/source/imjoseangel/kubediff/kubediff", line 98, in <module>
    main()
  File "/Users/imjoseangel/source/imjoseangel/kubediff/kubediff", line 92, in main
    failed = check_files(options.args.paths, printer, config)
  File "/Users/imjoseangel/Documents/source/imjoseangel/kubediff/kubedifflib/_diff.py", line 271, in check_files
    printer.finish()
  File "/Users/imjoseangel/Documents/source/imjoseangel/kubediff/kubedifflib/_diff.py", line 254, in finish
    print(json.dumps(self.data, sort_keys=True, indent=2, separators=(',', ': ')))
  File "/Users/imjoseangel/.pyenv/versions/3.9.7/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 234, in dumps
    return cls(
  File "/Users/imjoseangel/.pyenv/versions/3.9.7/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 201, in encode
    chunks = list(chunks)
  File "/Users/imjoseangel/.pyenv/versions/3.9.7/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/Users/imjoseangel/.pyenv/versions/3.9.7/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/Users/imjoseangel/.pyenv/versions/3.9.7/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 325, in _iterencode_list
    yield from chunks
  File "/Users/imjoseangel/.pyenv/versions/3.9.7/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/Users/imjoseangel/.pyenv/versions/3.9.7/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable