Add node affinity, pod affinity and pod antiaffinity validation for alpha annotations.

This commit is contained in:
Avesh Agarwal
2017-03-22 00:28:00 -04:00
parent 321acf00e5
commit ab5b462d17
2 changed files with 42 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ package api
import (
"crypto/md5"
"encoding/json"
"fmt"
"reflect"
"strings"
@@ -463,6 +464,11 @@ const (
// an object (e.g. secret, config map) before fetching it again from apiserver.
// This annotation can be attached to node.
ObjectTTLAnnotationKey string = "node.alpha.kubernetes.io/ttl"
// AffinityAnnotationKey represents the key of affinity data (json serialized)
// in the Annotations of a Pod.
// TODO: remove when alpha support for affinity is removed
AffinityAnnotationKey string = "scheduler.alpha.kubernetes.io/affinity"
)
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
@@ -596,6 +602,21 @@ func PodAnnotationsFromSysctls(sysctls []Sysctl) string {
return strings.Join(kvs, ",")
}
// GetAffinityFromPodAnnotations gets the json serialized affinity data from Pod.Annotations
// and converts it to the Affinity type in api.
// TODO: remove when alpha support for affinity is removed
func GetAffinityFromPodAnnotations(annotations map[string]string) (*Affinity, error) {
if len(annotations) > 0 && annotations[AffinityAnnotationKey] != "" {
var affinity Affinity
err := json.Unmarshal([]byte(annotations[AffinityAnnotationKey]), &affinity)
if err != nil {
return nil, err
}
return &affinity, nil
}
return nil, nil
}
// GetPersistentVolumeClass returns StorageClassName.
func GetPersistentVolumeClass(volume *PersistentVolume) string {
// Use beta annotation first