-
Notifications
You must be signed in to change notification settings - Fork 61
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
Improve the code to print the secrets using printTable #464
Conversation
cmoulliard
commented
Dec 19, 2024
- Improve the code to print the secrets using the cli-runtime line and printTable.
- Refactor the code to use the print functions from the util package
- See: [Suggestion] Enhance how we print the secret to show them using as format: Table, Yaml or JSON #463
This comment was marked as resolved.
This comment was marked as resolved.
…printTable. cnoe-io#463 Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
497a15a
to
666bfc7
Compare
Signed-off-by: cmoulliard <[email protected]>
Question: Should we for the core package secrets display the information as such ?
OR
|
We should review in a seperate PR how we will display the k=v data of the secrets labelized with
|
…r: isCore to make the distinction betweek the core secrets and secrets having the CNOE label Signed-off-by: cmoulliard <[email protected]>
Fixed |
…rmats supported Signed-off-by: cmoulliard <[email protected]>
I vote for 1st option. This way we can have flexibility for complex fields. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I suggest that we create a separate Printer package and Printer Interface.
pkg/cmd/get/root.go
Outdated
@@ -22,7 +22,7 @@ func init() { | |||
GetCmd.AddCommand(ClustersCmd) | |||
GetCmd.AddCommand(SecretsCmd) | |||
GetCmd.PersistentFlags().StringSliceVarP(&packages, "packages", "p", []string{}, "names of packages.") | |||
GetCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "", "Output format. json or yaml.") | |||
GetCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "", "Output format: table (default if not specified), json or yaml.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's name the default as "table" instead of "".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Fixed: 288284e
pkg/cmd/get/clusters.go
Outdated
func printClustersOutput(outWriter io.Writer, clusters []Cluster, format string) error { | ||
switch format { | ||
case "json": | ||
return util.PrintDataAsJson(clusters, outWriter) | ||
case "yaml": | ||
return util.PrintDataAsYaml(clusters, outWriter) | ||
case "": | ||
return util.PrintTable(generateClusterTable(clusters), outWriter) | ||
default: | ||
|
||
return fmt.Errorf("output format %s is not supported", format) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we combine this function for secret and cluster both and add it in utils package to avoid duplicate code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we combine this function for secret and cluster both and add it in utils package to avoid duplicate code?
Here is what I did which is still a WIP: 580042f, 13b4ad9
Improvements are welcome ;-) @punkwalker
pkg/cmd/get/secrets.go
Outdated
func generateSecret(s v1.Secret, isCoreSecret bool) Secret { | ||
secret := Secret{ | ||
Name: s.Name, | ||
Namespace: s.Namespace, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should name this populateSecrets
instead of generateSecret
. I felt we are creating a new secret.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed: 813c0cd
pkg/cmd/get/secrets.go
Outdated
|
||
type TemplateData struct { | ||
Name string `json:"name"` | ||
Namespace string `json:"namespace"` | ||
Data map[string]string `json:"data"` | ||
} | ||
|
||
type Secret struct { | ||
isCore bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the use of isCore
field just to control the printing of core package fields? Can we do that without this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the use of
isCore
field just to control the printing of core package fields?
It is used to figure out when we have a core package
secret containing as values: username, password and token (for gitea)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do that without this?
Not really
This is what I did |
Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
Great idea. Fixed: 771fd89 |
Why ? Can you elaborate ? |
Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
… Node, etc. and created printer methods. WIP Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
Signed-off-by: cmoulliard <[email protected]>
I prefer the second format but like you said, we can discuss that in another PR / issue. |
We can address this later. As of now, we can merge this PR |
Should we wait an approval from @nabuskey @blakeromano ? @punkwalker |