mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-07 16:27:27 +00:00
Use stdout when exporting objects
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
parent
46aa068fda
commit
f719d2bf76
7 changed files with 19 additions and 32 deletions
|
|
@ -19,7 +19,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
@ -114,12 +113,6 @@ func createSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpDir, err := os.MkdirTemp("", name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpDir)
|
|
||||||
|
|
||||||
var ignorePaths *string
|
var ignorePaths *string
|
||||||
if len(sourceBucketArgs.ignorePaths) > 0 {
|
if len(sourceBucketArgs.ignorePaths) > 0 {
|
||||||
ignorePathsStr := strings.Join(sourceBucketArgs.ignorePaths, "\n")
|
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")
|
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()
|
sourceLabels, err := parseLabels()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -114,12 +114,6 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpDir, err := os.MkdirTemp("", name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpDir)
|
|
||||||
|
|
||||||
if _, err := url.Parse(sourceHelmArgs.url); err != nil {
|
if _, err := url.Parse(sourceHelmArgs.url); err != nil {
|
||||||
return fmt.Errorf("url parse failed: %w", err)
|
return fmt.Errorf("url parse failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/fluxcd/flux2/v2/internal/utils"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
rbacv1 "k8s.io/api/rbac/v1"
|
rbacv1 "k8s.io/api/rbac/v1"
|
||||||
|
|
@ -32,6 +31,8 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/util/validation"
|
"k8s.io/apimachinery/pkg/util/validation"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
|
"github.com/fluxcd/flux2/v2/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var createTenantCmd = &cobra.Command{
|
var createTenantCmd = &cobra.Command{
|
||||||
|
|
@ -292,10 +293,10 @@ func exportTenant(namespace corev1.Namespace, account corev1.ServiceAccount, rol
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rootCmd.Println("---")
|
|
||||||
data = bytes.Replace(data, []byte("spec: {}\n"), []byte(""), 1)
|
data = bytes.Replace(data, []byte("spec: {}\n"), []byte(""), 1)
|
||||||
rootCmd.Println(resourceToString(data))
|
|
||||||
|
printlnStdout("---")
|
||||||
|
printlnStdout(resourceToString(data))
|
||||||
|
|
||||||
account.TypeMeta = metav1.TypeMeta{
|
account.TypeMeta = metav1.TypeMeta{
|
||||||
APIVersion: "v1",
|
APIVersion: "v1",
|
||||||
|
|
@ -305,10 +306,10 @@ func exportTenant(namespace corev1.Namespace, account corev1.ServiceAccount, rol
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rootCmd.Println("---")
|
|
||||||
data = bytes.Replace(data, []byte("spec: {}\n"), []byte(""), 1)
|
data = bytes.Replace(data, []byte("spec: {}\n"), []byte(""), 1)
|
||||||
rootCmd.Println(resourceToString(data))
|
|
||||||
|
printlnStdout("---")
|
||||||
|
printlnStdout(resourceToString(data))
|
||||||
|
|
||||||
roleBinding.TypeMeta = metav1.TypeMeta{
|
roleBinding.TypeMeta = metav1.TypeMeta{
|
||||||
APIVersion: "rbac.authorization.k8s.io/v1",
|
APIVersion: "rbac.authorization.k8s.io/v1",
|
||||||
|
|
@ -319,8 +320,8 @@ func exportTenant(namespace corev1.Namespace, account corev1.ServiceAccount, rol
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
rootCmd.Println("---")
|
printlnStdout("---")
|
||||||
rootCmd.Println(resourceToString(data))
|
printlnStdout(resourceToString(data))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,13 +109,13 @@ func (export exportCommand) run(cmd *cobra.Command, args []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printExport(export interface{}) error {
|
func printExport(export any) error {
|
||||||
data, err := yaml.Marshal(export)
|
data, err := yaml.Marshal(export)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
rootCmd.Println("---")
|
printlnStdout("---")
|
||||||
rootCmd.Println(resourceToString(data))
|
printlnStdout(resourceToString(data))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
return fmt.Errorf("install failed: %w", err)
|
return fmt.Errorf("install failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(os.Stderr, applyOutput)
|
rootCmd.Println(applyOutput)
|
||||||
|
|
||||||
if opts.ImagePullSecret != "" && opts.RegistryCredential != "" {
|
if opts.ImagePullSecret != "" && opts.RegistryCredential != "" {
|
||||||
logger.Actionf("generating image pull secret %s", opts.ImagePullSecret)
|
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.`
|
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)
|
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"))
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue