Cleanup work to enable feature gating annotations

This commit is contained in:
Timothy St. Clair
2017-02-16 11:38:03 -06:00
parent 32c4683242
commit 2bcd63c524
17 changed files with 242 additions and 167 deletions

View File

@@ -17,14 +17,12 @@ limitations under the License.
package v1
import (
"fmt"
"reflect"
"testing"
apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
utilfeature "k8s.io/apiserver/pkg/util/feature"
)
func TestAddToNodeAddresses(t *testing.T) {
@@ -647,6 +645,7 @@ func TestSysctlsFromPodAnnotation(t *testing.T) {
}
}
// TODO: remove when alpha support for affinity is removed
func TestGetAffinityFromPodAnnotations(t *testing.T) {
testCases := []struct {
pod *Pod
@@ -702,124 +701,3 @@ func TestGetAffinityFromPodAnnotations(t *testing.T) {
}
}
}
func TestReconcileAffinity(t *testing.T) {
baseAffinity := &Affinity{
NodeAffinity: &NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &NodeSelector{
NodeSelectorTerms: []NodeSelectorTerm{
{
MatchExpressions: []NodeSelectorRequirement{
{
Key: "foo",
Operator: NodeSelectorOpIn,
Values: []string{"bar", "value2"},
},
},
},
},
},
},
PodAffinity: &PodAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []PodAffinityTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "security",
Operator: metav1.LabelSelectorOpDoesNotExist,
Values: []string{"securityscan"},
},
},
},
TopologyKey: "topologyKey1",
},
},
},
PodAntiAffinity: &PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []PodAffinityTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "service",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"S1", "value2"},
},
},
},
TopologyKey: "topologyKey2",
Namespaces: []string{"ns1"},
},
},
},
}
nodeAffinityAnnotation := map[string]string{
AffinityAnnotationKey: `
{"nodeAffinity": {"preferredDuringSchedulingIgnoredDuringExecution": [
{
"weight": 2,
"preference": {"matchExpressions": [
{
"key": "foo",
"operator": "In", "values": ["bar"]
}
]}
}
]}}`,
}
testCases := []struct {
pod *Pod
expected *Affinity
annotationsEnabled bool
}{
{
pod: &Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: nodeAffinityAnnotation,
},
Spec: PodSpec{
Affinity: baseAffinity,
},
},
expected: baseAffinity,
annotationsEnabled: true,
},
{
pod: &Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: nodeAffinityAnnotation,
},
},
expected: &Affinity{
NodeAffinity: &NodeAffinity{
PreferredDuringSchedulingIgnoredDuringExecution: []PreferredSchedulingTerm{
{
Weight: 2,
Preference: NodeSelectorTerm{
MatchExpressions: []NodeSelectorRequirement{
{
Key: "foo",
Operator: NodeSelectorOpIn,
Values: []string{"bar"},
},
},
},
},
},
},
},
annotationsEnabled: true,
},
}
for i, tc := range testCases {
utilfeature.DefaultFeatureGate.Set(fmt.Sprintf("AffinityInAnnotations=%t", tc.annotationsEnabled))
affinity := ReconcileAffinity(tc.pod)
if affinity != tc.expected {
t.Errorf("[%v]did not get expected affinity. got: %v instead of %v", i, affinity, tc.expected)
}
}
}