mirror of
https://github.com/rancher/rke.git
synced 2025-08-31 14:36:32 +00:00
Format user addon YAML before concat
This commit is contained in:
committed by
Alena Prokharchyk
parent
1a1080a234
commit
ae44a9510f
@@ -157,16 +157,18 @@ func (c *Cluster) deployAddonsInclude(ctx context.Context) error {
|
||||
log.Infof(ctx, "[addons] Adding addon from url %s", addon)
|
||||
logrus.Debugf("URL Yaml: %s", addonYAML)
|
||||
|
||||
// make sure we properly separated manifests
|
||||
addonYAMLStr := string(addonYAML)
|
||||
|
||||
formattedAddonYAML := formatAddonYAML(addonYAMLStr)
|
||||
|
||||
addonYAML = []byte(formattedAddonYAML)
|
||||
logrus.Debugf("Formatted Yaml: %s", addonYAML)
|
||||
|
||||
if err := validateUserAddonYAML(addonYAML); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Put 3 dashes (---) at beginning of next YAML if it is not there already so we can append to manifests
|
||||
dashes := "---\n"
|
||||
if !strings.HasPrefix(string(addonYAML[:]), dashes) {
|
||||
addonYAML = append([]byte(dashes), addonYAML...)
|
||||
}
|
||||
|
||||
manifests = append(manifests, addonYAML...)
|
||||
} else if isFilePath(addon) {
|
||||
addonYAML, err := ioutil.ReadFile(addon)
|
||||
@@ -178,9 +180,12 @@ func (c *Cluster) deployAddonsInclude(ctx context.Context) error {
|
||||
|
||||
// make sure we properly separated manifests
|
||||
addonYAMLStr := string(addonYAML)
|
||||
if !strings.HasPrefix(addonYAMLStr, "---") {
|
||||
addonYAML = []byte(fmt.Sprintf("%s\n%s", "---", addonYAMLStr))
|
||||
}
|
||||
|
||||
formattedAddonYAML := formatAddonYAML(addonYAMLStr)
|
||||
|
||||
addonYAML = []byte(formattedAddonYAML)
|
||||
logrus.Debugf("Formatted Yaml: %s", addonYAML)
|
||||
|
||||
if err := validateUserAddonYAML(addonYAML); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -195,6 +200,19 @@ func (c *Cluster) deployAddonsInclude(ctx context.Context) error {
|
||||
return c.doAddonDeploy(ctx, string(manifests), UserAddonsIncludeResourceName, false)
|
||||
}
|
||||
|
||||
func formatAddonYAML(addonYAMLStr string) string {
|
||||
if !strings.HasPrefix(addonYAMLStr, "---") {
|
||||
logrus.Debug("Yaml does not start with dashes")
|
||||
addonYAMLStr = fmt.Sprintf("%s\n%s", "---", addonYAMLStr)
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(addonYAMLStr, "\n") {
|
||||
logrus.Debug("Yaml does not end with newline")
|
||||
addonYAMLStr = fmt.Sprintf("%s\n", addonYAMLStr)
|
||||
}
|
||||
return addonYAMLStr
|
||||
}
|
||||
|
||||
func validateUserAddonYAML(addon []byte) error {
|
||||
yamlContents := make(map[string]interface{})
|
||||
|
||||
|
Reference in New Issue
Block a user