Fix: Make the out flag print to one file using seperator (#1541)
* fix: make the out flag print to one file using seperator * fix: comment an unused function * fix: update test script * fix: update output k8s * fix: update the json output error condition * fix: update envvars interpolation tests * chore: update e2e tests to support yaml generation instead of JSON format * fix: update e2e tests according to ci environment * fix: apply PR changes
This commit is contained in:
@@ -148,17 +148,6 @@ func getDirName(opt kobject.ConvertOptions) string {
|
||||
return dirName
|
||||
}
|
||||
|
||||
func objectToRaw(object runtime.Object) runtime.RawExtension {
|
||||
r := runtime.RawExtension{
|
||||
Object: object,
|
||||
}
|
||||
|
||||
bytes, _ := json.Marshal(object)
|
||||
r.Raw = bytes
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// PrintList will take the data converted and decide on the commandline attributes given
|
||||
func PrintList(objects []runtime.Object, opt kobject.ConvertOptions) error {
|
||||
var f *os.File
|
||||
@@ -192,36 +181,31 @@ func PrintList(objects []runtime.Object, opt kobject.ConvertOptions) error {
|
||||
}
|
||||
|
||||
var files []string
|
||||
|
||||
// if asked to print to stdout or to put in single file
|
||||
// we will create a list
|
||||
if opt.ToStdout || f != nil {
|
||||
list := &api.List{}
|
||||
// convert objects to versioned and add them to list
|
||||
if opt.GenerateJSON {
|
||||
return fmt.Errorf("cannot convert to one file while specifying a json output file or stdout option")
|
||||
}
|
||||
for _, object := range objects {
|
||||
versionedObject, err := convertToVersion(object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
list.Items = append(list.Items, objectToRaw(versionedObject))
|
||||
data, err := marshal(versionedObject, opt.GenerateJSON, opt.YAMLIndent)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error in marshalling the List: %v", err)
|
||||
}
|
||||
// this part add --- which unifies the file
|
||||
data = []byte(fmt.Sprintf("---\n%s", data))
|
||||
printVal, err := transformer.Print("", dirName, "", data, opt.ToStdout, opt.GenerateJSON, f, opt.Provider)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "transformer to print to one single file failed")
|
||||
}
|
||||
files = append(files, printVal)
|
||||
}
|
||||
// version list itself
|
||||
list.Kind = "List"
|
||||
list.APIVersion = "v1"
|
||||
convertedList, err := convertToVersion(list)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := marshal(convertedList, opt.GenerateJSON, opt.YAMLIndent)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error in marshalling the List: %v", err)
|
||||
}
|
||||
printVal, err := transformer.Print("", dirName, "", data, opt.ToStdout, opt.GenerateJSON, f, opt.Provider)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "transformer.Print failed")
|
||||
}
|
||||
files = append(files, printVal)
|
||||
} else {
|
||||
finalDirName := dirName
|
||||
if opt.CreateChart {
|
||||
|
||||
Reference in New Issue
Block a user