Skip to content
Draft
Show file tree
Hide file tree
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
28 changes: 20 additions & 8 deletions cmd/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package helper

import (
"bufio"
"errors"
"bytes"
"fmt"
"io"
"os"
Expand All @@ -14,7 +14,6 @@ import (

"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
"gopkg.in/yaml.v3"
apiduration "k8s.io/apimachinery/pkg/util/duration"
k8syaml "sigs.k8s.io/yaml"
)
Expand Down Expand Up @@ -75,6 +74,7 @@ func Truncate(input, ellipsis string, maxlength int) string {
// ReadFrom will either read from stdin (-) or a file path an marshall from yaml to data
func ReadFrom(from string, data any, f func(target any)) error {
var reader io.Reader
var raw []byte
var err error
switch from {
case "-":
Expand All @@ -85,17 +85,29 @@ func ReadFrom(from string, data any, f func(target any)) error {
return fmt.Errorf("unable to open %s %w", from, err)
}
}
dec := yaml.NewDecoder(reader)
for {
err := dec.Decode(data)
if errors.Is(err, io.EOF) {
break

sc := bufio.NewScanner(reader)
for sc.Scan() {
raw = append(raw, sc.Bytes()...)
raw = append(raw, []byte("\n")...)
}
if err := sc.Err(); err != nil {
return fmt.Errorf("failed to read from %s %w", from, err)
}

for _, part := range bytes.Split(raw, []byte("---")) {
if len(part) == 0 {
continue
}

err := k8syaml.Unmarshal(part, data)
if err != nil {
return fmt.Errorf("decode error: %w", err)
return fmt.Errorf("failed to unmarshal: %w", err)
}

f(data)
}

return nil
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v3"

k8syaml "sigs.k8s.io/yaml"
)

const (
Expand Down Expand Up @@ -768,7 +769,7 @@ func (c *config) postgresEdit(args []string) error {
if err != nil {
return nil, err
}
content, err := yaml.Marshal(resp.Payload)
content, err := k8syaml.Marshal(resp.Payload)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/fi-ts/cloud-go/api/models"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"gopkg.in/yaml.v3"
k8syaml "sigs.k8s.io/yaml"

"github.com/fi-ts/cloud-go/api/client/project"
"github.com/fi-ts/cloudctl/cmd/helper"
Expand Down Expand Up @@ -310,7 +310,7 @@ func (c *config) projectEdit(args []string) error {
if err != nil {
return nil, fmt.Errorf("project describe error:%w", err)
}
content, err := yaml.Marshal(resp.Payload)
content, err := k8syaml.Marshal(resp.Payload)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/fi-ts/cloud-go/api/models"
"github.com/fi-ts/cloudctl/cmd/helper"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"gopkg.in/yaml.v3"
k8syaml "sigs.k8s.io/yaml"

"github.com/fi-ts/cloud-go/api/client/tenant"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -189,7 +189,7 @@ func (c *config) tenantEdit(args []string) error {
if err != nil {
return nil, fmt.Errorf("tenant describe error:%w", err)
}
content, err := yaml.Marshal(resp.Payload)
content, err := k8syaml.Marshal(resp.Payload)
if err != nil {
return nil, err
}
Expand Down
Loading