Use stdout when exporting objects
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
@@ -19,7 +19,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -114,12 +113,6 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
tmpDir, err := os.MkdirTemp("", name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
var ignorePaths *string
|
||||
if len(sourceBucketArgs.ignorePaths) > 0 {
|
||||
ignorePathsStr := strings.Join(sourceBucketArgs.ignorePaths, "\n")
|
||||
|
||||
@@ -191,12 +191,6 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("specifying a CA file is not supported for Git over SSH")
|
||||
}
|
||||
|
||||
tmpDir, err := os.MkdirTemp("", name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
sourceLabels, err := parseLabels()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -114,12 +114,6 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
tmpDir, err := os.MkdirTemp("", name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
if _, err := url.Parse(sourceHelmArgs.url); err != nil {
|
||||
return fmt.Errorf("url parse failed: %w", err)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/fluxcd/flux2/v2/internal/utils"
|
||||
"github.com/spf13/cobra"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
rbacv1 "k8s.io/api/rbac/v1"
|
||||
@@ -32,6 +31,8 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/validation"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/fluxcd/flux2/v2/internal/utils"
|
||||
)
|
||||
|
||||
var createTenantCmd = &cobra.Command{
|
||||
@@ -292,10 +293,10 @@ func exportTenant(namespace corev1.Namespace, account corev1.ServiceAccount, rol
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rootCmd.Println("---")
|
||||
data = bytes.Replace(data, []byte("spec: {}\n"), []byte(""), 1)
|
||||
rootCmd.Println(resourceToString(data))
|
||||
|
||||
printlnStdout("---")
|
||||
printlnStdout(resourceToString(data))
|
||||
|
||||
account.TypeMeta = metav1.TypeMeta{
|
||||
APIVersion: "v1",
|
||||
@@ -305,10 +306,10 @@ func exportTenant(namespace corev1.Namespace, account corev1.ServiceAccount, rol
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rootCmd.Println("---")
|
||||
data = bytes.Replace(data, []byte("spec: {}\n"), []byte(""), 1)
|
||||
rootCmd.Println(resourceToString(data))
|
||||
|
||||
printlnStdout("---")
|
||||
printlnStdout(resourceToString(data))
|
||||
|
||||
roleBinding.TypeMeta = metav1.TypeMeta{
|
||||
APIVersion: "rbac.authorization.k8s.io/v1",
|
||||
@@ -319,8 +320,8 @@ func exportTenant(namespace corev1.Namespace, account corev1.ServiceAccount, rol
|
||||
return err
|
||||
}
|
||||
|
||||
rootCmd.Println("---")
|
||||
rootCmd.Println(resourceToString(data))
|
||||
printlnStdout("---")
|
||||
printlnStdout(resourceToString(data))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -109,13 +109,13 @@ func (export exportCommand) run(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func printExport(export interface{}) error {
|
||||
func printExport(export any) error {
|
||||
data, err := yaml.Marshal(export)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rootCmd.Println("---")
|
||||
rootCmd.Println(resourceToString(data))
|
||||
printlnStdout("---")
|
||||
printlnStdout(resourceToString(data))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("install failed: %w", err)
|
||||
}
|
||||
|
||||
fmt.Fprintln(os.Stderr, applyOutput)
|
||||
rootCmd.Println(applyOutput)
|
||||
|
||||
if opts.ImagePullSecret != "" && opts.RegistryCredential != "" {
|
||||
logger.Actionf("generating image pull secret %s", opts.ImagePullSecret)
|
||||
|
||||
@@ -247,3 +247,8 @@ While we try our best to not introduce breaking changes, they may occur when
|
||||
we adapt to new features and/or find better ways to facilitate what it does.`
|
||||
return fmt.Sprintf("%s\n\n%s", strings.TrimSpace(desc), previewNote)
|
||||
}
|
||||
|
||||
// printlnStdout prints the given text to stdout with a newline.
|
||||
func printlnStdout(txt string) {
|
||||
_, _ = rootCmd.OutOrStdout().Write([]byte(txt + "\n"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user