Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support yaml format output #44

Closed
yonahd opened this issue Aug 30, 2023 · 8 comments · Fixed by #56
Closed

Support yaml format output #44

yonahd opened this issue Aug 30, 2023 · 8 comments · Fixed by #56
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@yonahd
Copy link
Owner

yonahd commented Aug 30, 2023

In the output options support outputting in yaml format
Using https://github.com/kubernetes-sigs/yaml/blob/v1.3.0/yaml.go#L82 we can support yaml and json using the same function.

@yonahd yonahd added enhancement New feature or request good first issue Good for newcomers labels Aug 30, 2023
@loaynaser3
Copy link
Contributor

loaynaser3 commented Aug 31, 2023

taking the current code and that you already can provide json response, here's a way that works and may fit your request
for example for configmap
cmd/kor/configmaps.go


if outputFormat == "json" {
	res, _ := kor.GetUnusedConfigmapsJSON(namespace, kubeconfig)
	fmt.Println(res)
} else if outputFormat == "yaml" {
	res, _ := kor.GetUnusedConfigmapsYAML(namespace, kubeconfig)
	fmt.Println(res)

} else {
	kor.GetUnusedConfigmaps(namespace, kubeconfig)
}

pkg/kor/configmaps.go


import (

"sigs.k8s.io/yaml"

)



func GetUnusedConfigmapsYAML(namespace string, kubeconfig string) (string, error) {
	jsonResponse, err := GetUnusedConfigmapsJSON(namespace, kubeconfig)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to process namespace %s: %v\n", namespace, err)
	}

	yamlResponse, err := yaml.JSONToYAML([]byte(jsonResponse))
	if err != nil {
		fmt.Printf("err: %v\n", err)
	}
	return (string(yamlResponse)), nil
}

@yonahd
Copy link
Owner Author

yonahd commented Aug 31, 2023

@loaynaser3 Yep. That is the idea.
Are you open to contributing this?

@loaynaser3
Copy link
Contributor

Gladly 😊

@yonahd
Copy link
Owner Author

yonahd commented Aug 31, 2023

Great!
Assigned to you

@yonahd
Copy link
Owner Author

yonahd commented Sep 4, 2023

@loaynaser3 I see you closed the MR. Are you just reworking it or should I assign to someone else?

@loaynaser3
Copy link
Contributor

@yonahd reworking
i'll create a PR either tonight or tomorrow max ...
BTW if issue #45 still unassigned you can assigne it to me also and i'll create a seperate PR for it

@yonahd
Copy link
Owner Author

yonahd commented Sep 4, 2023

Looks like someone started on it. #49
You can check with them if they intend to complete the work

@loaynaser3
Copy link
Contributor

@yonahd this issue can be closed, relted PR #56

@yonahd yonahd linked a pull request Sep 5, 2023 that will close this issue
@yonahd yonahd closed this as completed Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants