Ver Fonte

Add porter get values to get Helm values of a release

Mohammed Nafees há 4 anos atrás
pai
commit
1961126485
1 ficheiros alterados com 48 adições e 2 exclusões
  1. 48 2
      cli/cmd/get.go

+ 48 - 2
cli/cmd/get.go

@@ -28,11 +28,23 @@ var getCmd = &cobra.Command{
 	},
 }
 
+// getValuesCmd represents the "porter get values" command
+var getValuesCmd = &cobra.Command{
+	Use:   "values [release]",
+	Args:  cobra.ExactArgs(1),
+	Short: "Fetches the Helm values for a release.",
+	Run: func(cmd *cobra.Command, args []string) {
+		err := checkLoginAndRun(args, getValues)
+
+		if err != nil {
+			os.Exit(1)
+		}
+	},
+}
+
 var output string
 
 func init() {
-	rootCmd.AddCommand(getCmd)
-
 	getCmd.PersistentFlags().StringVar(
 		&namespace,
 		"namespace",
@@ -46,6 +58,10 @@ func init() {
 		"",
 		"the output format to use (\"yaml\" or \"json\")",
 	)
+
+	getCmd.AddCommand(getValuesCmd)
+
+	rootCmd.AddCommand(getCmd)
 }
 
 type getReleaseInfo struct {
@@ -94,3 +110,33 @@ func get(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []strin
 
 	return nil
 }
+
+func getValues(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
+	rel, err := client.GetRelease(context.Background(), config.Project, config.Cluster, namespace, args[0])
+
+	if err != nil {
+		return err
+	}
+
+	values := rel.Config
+
+	if output == "json" {
+		bytes, err := json.Marshal(values)
+
+		if err != nil {
+			return err
+		}
+
+		fmt.Println(string(bytes))
+	} else { // yaml is the default
+		bytes, err := yaml.Marshal(values)
+
+		if err != nil {
+			return err
+		}
+
+		fmt.Println(string(bytes))
+	}
+
+	return nil
+}