github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/kubernetes/validators.go (about)

     1  package kubernetes
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"k8s.io/kubernetes/pkg/api/resource"
     8  	apiValidation "k8s.io/kubernetes/pkg/api/validation"
     9  	utilValidation "k8s.io/kubernetes/pkg/util/validation"
    10  )
    11  
    12  func validateAnnotations(value interface{}, key string) (ws []string, es []error) {
    13  	m := value.(map[string]interface{})
    14  	for k, _ := range m {
    15  		errors := utilValidation.IsQualifiedName(strings.ToLower(k))
    16  		if len(errors) > 0 {
    17  			for _, e := range errors {
    18  				es = append(es, fmt.Errorf("%s (%q) %s", key, k, e))
    19  			}
    20  		}
    21  	}
    22  	return
    23  }
    24  
    25  func validateName(value interface{}, key string) (ws []string, es []error) {
    26  	v := value.(string)
    27  
    28  	errors := apiValidation.NameIsDNSLabel(v, false)
    29  	if len(errors) > 0 {
    30  		for _, err := range errors {
    31  			es = append(es, fmt.Errorf("%s %s", key, err))
    32  		}
    33  	}
    34  	return
    35  }
    36  
    37  func validateGenerateName(value interface{}, key string) (ws []string, es []error) {
    38  	v := value.(string)
    39  
    40  	errors := apiValidation.NameIsDNSLabel(v, true)
    41  	if len(errors) > 0 {
    42  		for _, err := range errors {
    43  			es = append(es, fmt.Errorf("%s %s", key, err))
    44  		}
    45  	}
    46  	return
    47  }
    48  
    49  func validateLabels(value interface{}, key string) (ws []string, es []error) {
    50  	m := value.(map[string]interface{})
    51  	for k, v := range m {
    52  		for _, msg := range utilValidation.IsQualifiedName(k) {
    53  			es = append(es, fmt.Errorf("%s (%q) %s", key, k, msg))
    54  		}
    55  		val := v.(string)
    56  		for _, msg := range utilValidation.IsValidLabelValue(val) {
    57  			es = append(es, fmt.Errorf("%s (%q) %s", key, val, msg))
    58  		}
    59  	}
    60  	return
    61  }
    62  
    63  func validateResourceList(value interface{}, key string) (ws []string, es []error) {
    64  	m := value.(map[string]interface{})
    65  	for k, v := range m {
    66  		val := v.(string)
    67  		_, err := resource.ParseQuantity(val)
    68  		if err != nil {
    69  			es = append(es, fmt.Errorf("%s.%s (%q): %s", key, k, val, err))
    70  		}
    71  	}
    72  	return
    73  }