{"id":21923204,"url":"https://github.com/deislabs/kubectl-output-parser","last_synced_at":"2025-04-19T15:21:18.543Z","repository":{"id":51961290,"uuid":"185086828","full_name":"deislabs/kubectl-output-parser","owner":"deislabs","description":"Functions for parsing kubectl output","archived":false,"fork":false,"pushed_at":"2023-05-01T01:30:36.000Z","size":90,"stargazers_count":2,"open_issues_count":7,"forks_count":3,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-04T13:46:09.516Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deislabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-05T22:04:12.000Z","updated_at":"2021-07-19T21:24:43.000Z","dependencies_parsed_at":"2024-11-28T21:32:05.124Z","dependency_job_id":null,"html_url":"https://github.com/deislabs/kubectl-output-parser","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"bfeb23bb8cc31575e611abf125d629cc6353522a"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deislabs%2Fkubectl-output-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deislabs%2Fkubectl-output-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deislabs%2Fkubectl-output-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deislabs%2Fkubectl-output-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deislabs","download_url":"https://codeload.github.com/deislabs/kubectl-output-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249725151,"owners_count":21316129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-28T21:09:40.355Z","updated_at":"2025-04-19T15:21:18.487Z","avatar_url":"https://github.com/deislabs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kubectl Output Parser\n\nA NPM package containing utility functions for parsing output from the Kubernetes `kubectl` command\nline tool.\n\n# Reference\n\n## Table format functions\n\nThese functions are for use with `kubectl` commands that return data in tabular format -\nthat is, of the form:\n\n```\nTITLE1    TITLE2       TITLE3\nvalue11   value12      value13\nvalue21   value22      value23\n```\n\nwhere no column header or value contains a space, and columns are separated by one or more spaces.\nExamples include the default behaviour of `kubectl get`, for example `kubectl get pods` or\n`kubectl get pods -o wide` to get a list of pods.\n\nIn all cases:\n\n* The function takes a `KubectlOutput`: that is, either a `ShellResult` (an object with numeric `code`,\n`stdout` string and `stderr` string properties), or `undefined`.  `code` and `stderr` are used\nfor error handling; on the happy path, the function will operate on the `stdout` string.\n* The function returns an `Errorable`: that is, an object with a boolean `succeeded` property.  If\n`succeeded` is true, the object also has a `result` property containing the result of the function;\nif `succeeded` is false, the object has `reason` and `error` properties describing the failure.\n* If the input is `undefined`, or has a non-zero `code`, the function returns a _failed_ Errorable.\n* The function does not check the format of the provided `stdout`.  You should use it **only** on the output\nof `kubectl` commands that return tabular data without spaces or missing values.\n\n### parseTabular\n\n**JavaScript:** `parseTabular(output)`\n\n**TypeScript:** `parseTabular(output: KubectlOutput): Errorable\u003cDictionary\u003cstring\u003e[]\u003e`\n\nParses tabular `kubectl` output into an array of key-value objects, one per line.\n\nThe result is an array of the form:\n\n```javascript\n[\n    {\n        title1: \"value11\",\n        title2: \"value12\",\n        title3: \"value13\"\n    },\n    {\n        title1: \"value21\",\n        title2: \"value22\",\n        title3: \"value23\"\n    }\n]\n```\n\nEach non-header row is parsed as an object within the array.  Each object's keys are the lowercased\ncolumn headers, and the value of each key is the string under that header in the object's row.\n\nIf `output.stdout` is empty then the function returns success with an empty array.\n\n**TypeScript:** `Dictionary\u003cT\u003e` is an alias for `{ [key: string]: T }`.\n\n### asTableLines\n\n**JavaScript:** `asTableLines(output)`\n\n**TypeScript:** `asTableLines(output: KubectlOutput): Errorable\u003cTableLines\u003e`\n\nSplits tabular `kubectl` output into a header line and an array of body lines.  The result is\nan object of the form:\n\n```javascript\n{\n    header: \"TITLE1    TITLE2       TITLE3\",\n    body: [\n        \"value11   value12      value13\".\n        \"value21   value22      value23\"\n    ]\n}\n```\n\nIf `output.stdout` is empty then the function returns success with an empty string `header` and\nan empty `body` array.\n\n## JSON format functions\n\nThese functions are for use with `kubectl` commands that return data in JSON format.\nThis is typically triggered by the `-o json` option and may be used for lists or for single\nresources, e.g. `kubectl get pods -o json` or `kubectl get deploy/nginx -o json`.\n\nIn all cases:\n\n* The function takes a `KubectlOutput`: that is, either a `ShellResult` (an object with numeric `code`,\n`stdout` string and `stderr` string properties), or `undefined`.  `code` and `stderr` are used\nfor error handling; on the happy path, the function will operate on the `stdout` string.\n* The function returns an `Errorable`: that is, an object with a boolean `succeeded` property.  If\n`succeeded` is true, the object also has a `result` property containing the result of the function;\nif `succeeded` is false, the object has `reason` and `error` properties describing the failure.\n* If the input is `undefined`, or has a non-zero `code`, or if `stdout` is empty, the function\nreturns a _failed_ Errorable.\n* The function does not check the format of the provided `stdout`.  You should use it **only** on the output\nof `kubectl` commands that return JSON data.\n\n### parseJSON\n\n**JavaScript:** `parseJSON(output)`\n\n**TypeScript:** `parseJSON\u003cT\u003e(output: KubectlOutput): Errorable\u003cT\u003e`\n\nChecks for `kubectl` failure and then returns the deserialised object corresponding to the\n`stdout` JSON.\n\n### parseJSONCollection\n\n**TypeScript:** `parseJSONCollection\u003cT\u003e(output: KubectlOutput): Errorable\u003cKubernetesList\u003cT\u003e\u003e`\n\nChecks for `kubectl` failure and then returns the deserialised object corresponding to the\n`stdout` JSON, where this is a Kubernetes item list object.\n\nThis is equivalent to writing `parseJSON\u003cKubernetesList\u003cT\u003e\u003e`; it is provided for TypeScript\nusers to reduce generics clutter in their code.  (In untyped JavaScript, there's no difference\nbetween this and the `parseJSON` function.)\n\n# Contributing\n\nThis project welcomes contributions and suggestions.  Most contributions require you to agree to a\nContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\nthe rights to use your contribution. For details, visit https://cla.microsoft.com.\n\nWhen you submit a pull request, a CLA-bot will automatically determine whether you need to provide\na CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions\nprovided by the bot. You will only need to do this once across all repos using our CLA.\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).\nFor more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or\ncontact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeislabs%2Fkubectl-output-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeislabs%2Fkubectl-output-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeislabs%2Fkubectl-output-parser/lists"}