From 285631446e21151ef724438dd2de8328d72492ca Mon Sep 17 00:00:00 2001 From: danj-replicated <108552543+danj-replicated@users.noreply.github.com> Date: Fri, 14 Apr 2023 00:25:42 +0100 Subject: [PATCH] Add ability to fetch preflights from OCI registry to standard out (#1117) * add oci-fetch command --- cmd/preflight/cli/oci_fetch.go | 26 ++++++++++++++++++++++++++ cmd/preflight/cli/root.go | 1 + 2 files changed, 27 insertions(+) create mode 100644 cmd/preflight/cli/oci_fetch.go diff --git a/cmd/preflight/cli/oci_fetch.go b/cmd/preflight/cli/oci_fetch.go new file mode 100644 index 00000000..f9bd147a --- /dev/null +++ b/cmd/preflight/cli/oci_fetch.go @@ -0,0 +1,26 @@ +package cli + +import ( + "fmt" + + "github.com/replicatedhq/troubleshoot/pkg/oci" + "github.com/spf13/cobra" +) + +func OciFetchCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "oci-fetch [URI]", + Args: cobra.MinimumNArgs(1), + Short: "Fetch a preflight from an OCI registry and print it to standard out", + RunE: func(cmd *cobra.Command, args []string) error { + uri := args[0] + data, err := oci.PullPreflightFromOCI(uri) + if err != nil { + return err + } + fmt.Println(string(data)) + return nil + }, + } + return cmd +} diff --git a/cmd/preflight/cli/root.go b/cmd/preflight/cli/root.go index 102bfd05..591c67fa 100644 --- a/cmd/preflight/cli/root.go +++ b/cmd/preflight/cli/root.go @@ -60,6 +60,7 @@ that a cluster meets the requirements to run an application.`, cobra.OnInitialize(initConfig) cmd.AddCommand(VersionCmd()) + cmd.AddCommand(OciFetchCmd()) preflight.AddFlags(cmd.PersistentFlags()) k8sutil.AddFlags(cmd.Flags())