Пример #1
0
func (m Metadata) parseTemplates(templates map[string]string, attributes map[string]interface{}) (map[string]interface{}, error) {
	var specs = map[string]interface{}{}
	for specName, templateFile := range templates {
		log.Debugf("Going to parse %s/%s", m.path, templateFile)
		specMap, err := parseTemplate(fmt.Sprintf("%s/%s", m.path, templateFile), attributes)
		if err != nil {
			return nil, fmt.Errorf("error parsing template %s: %v", templateFile, err)
		}
		s, err := digger.NewMapDigger(specMap)
		if err != nil {
			return nil, fmt.Errorf("error parsing template %s: %v", templateFile, err)
		}
		name, err := s.GetString("metadata/name")
		if err != nil {
			return nil, fmt.Errorf("error parsing template %s: %v", templateFile, err)
		}
		if name != specName {
			return nil, fmt.Errorf("non matching resource name in %s", templateFile)
		}
		err = addKubewareLabel(m.Name, m.Version, specMap)
		if err != nil {
			return nil, fmt.Errorf("error adding kubeware labels to %s: %v", templateFile, err)
		}
		specs[specName] = specMap
	}
	return specs, nil
}
Пример #2
0
func extractKubeVersion(rc map[string]interface{}) (string, error) {
	d, err := digger.NewMapDigger(rc)
	if err != nil {
		return "", err
	}
	k, err := d.GetString("metadata/labels/kubeware")
	if err != nil {
		return "", err
	}
	v, err := d.GetString("metadata/labels/kubeware-version")
	if err != nil {
		return "", err
	}
	return fmt.Sprintf("%s-%s", k, v), nil
}
Пример #3
0
// CheckRequiredAttributes returns an error if some required attribute is missing
func (m Metadata) CheckRequiredAttributes(attributes map[string]interface{}) error {
	reqs, err := m.RequiredAttributes()
	if err != nil {
		return fmt.Errorf("could not calculate required attributes: %v", err)
	}
	digger, err := digger.NewMapDigger(attributes)
	if err != nil {
		return fmt.Errorf("could not build digger: %v", err)
	}
	for _, att := range reqs {
		_, err := digger.Get(att)
		if err != nil {
			return fmt.Errorf("required attribute not present: '%s'", att)
		}
	}
	return nil
}