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

Make it possible to call inspects with existing k8s client #741

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pkg/hhfctl/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,31 @@ func Run[TIn In, TOut Out](ctx context.Context, f Func[TIn, TOut], args Args, in
return errors.Wrapf(err, "failed to run inspect function")
}

return Render(args.Output, w, out)
}

func Render[TOut Out](output OutputType, w io.Writer, out TOut) error {
var data []byte
if args.Output == OutputTypeText {
var err error
if output == OutputTypeText {
dataS, err := out.MarshalText()
if err != nil {
return errors.Wrapf(err, "failed to get marshal output as text")
}

data = []byte(dataS)
} else if args.Output == OutputTypeYAML {
} else if output == OutputTypeYAML {
data, err = yaml.Marshal(out)
if err != nil {
return errors.Wrapf(err, "failed to marshal inspect output as yaml")
}
} else if args.Output == OutputTypeJSON {
} else if output == OutputTypeJSON {
data, err = json.MarshalIndent(out, "", " ")
if err != nil {
return errors.Wrapf(err, "failed to marshal inspect output as json")
}
} else {
return errors.Errorf("output type %s is not implemented", args.Output)
return errors.Errorf("output type %s is not implemented", output)
}

_, err = w.Write(data)
Expand Down