mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-08-27 00:37:20 +00:00
* v1beta3 spec can be read by preflight * added test files for ease of testing * updated v1beta3 guide doc and added tests * fixed not removing tmp files from v1beta3 processing * created v1beta2 to v1beta3 converter
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package docrewrite
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
func ConvertToV1Beta2(doc []byte) ([]byte, error) {
|
|
var parsed map[string]interface{}
|
|
err := yaml.Unmarshal(doc, &parsed)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to unmarshal yaml")
|
|
}
|
|
|
|
v, ok := parsed["apiVersion"]
|
|
if !ok {
|
|
return nil, errors.New("no apiVersion in document")
|
|
}
|
|
|
|
if v == "troubleshoot.sh/v1beta2" {
|
|
return doc, nil
|
|
}
|
|
|
|
if v == "troubleshoot.sh/v1beta3" {
|
|
// For v1beta3, just change the apiVersion to v1beta2
|
|
// The actual template rendering will be handled elsewhere
|
|
parsed["apiVersion"] = "troubleshoot.sh/v1beta2"
|
|
newDoc, err := yaml.Marshal(parsed)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to marshal new spec")
|
|
}
|
|
return newDoc, nil
|
|
}
|
|
|
|
if v != "troubleshoot.replicated.com/v1beta1" {
|
|
return nil, errors.Errorf("cannot convert %s", v)
|
|
}
|
|
|
|
parsed["apiVersion"] = "troubleshoot.sh/v1beta2"
|
|
newDoc, err := yaml.Marshal(parsed)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to marshal new spec")
|
|
}
|
|
|
|
return newDoc, nil
|
|
}
|