Add support for multiple label values in test cases

They are assigned in a round robin fashion

Signed-off-by: Aldo Culquicondor <acondor@google.com>
This commit is contained in:
Aldo Culquicondor 2020-03-20 16:18:44 -04:00
parent 1616525eac
commit c9314dde59
2 changed files with 12 additions and 7 deletions

View File

@ -162,7 +162,7 @@
nodeTemplatePath: config/node-default.yaml nodeTemplatePath: config/node-default.yaml
labelNodePrepareStrategy: labelNodePrepareStrategy:
labelKey: "failure-domain.beta.kubernetes.io/zone" labelKey: "failure-domain.beta.kubernetes.io/zone"
labelValue: "zone1" labelValues: ["zone1"]
initPods: initPods:
- podTemplatePath: config/pod-with-node-affinity.yaml - podTemplatePath: config/pod-with-node-affinity.yaml
podsToSchedule: podsToSchedule:

View File

@ -981,21 +981,26 @@ func (*TrivialNodePrepareStrategy) CleanupDependentObjects(nodeName string, clie
type LabelNodePrepareStrategy struct { type LabelNodePrepareStrategy struct {
LabelKey string LabelKey string
LabelValue string LabelValues []string
roundRobinIdx int
} }
var _ PrepareNodeStrategy = &LabelNodePrepareStrategy{} var _ PrepareNodeStrategy = &LabelNodePrepareStrategy{}
func NewLabelNodePrepareStrategy(labelKey string, labelValue string) *LabelNodePrepareStrategy { func NewLabelNodePrepareStrategy(labelKey string, labelValues ...string) *LabelNodePrepareStrategy {
return &LabelNodePrepareStrategy{ return &LabelNodePrepareStrategy{
LabelKey: labelKey, LabelKey: labelKey,
LabelValue: labelValue, LabelValues: labelValues,
} }
} }
func (s *LabelNodePrepareStrategy) PreparePatch(*v1.Node) []byte { func (s *LabelNodePrepareStrategy) PreparePatch(*v1.Node) []byte {
labelString := fmt.Sprintf("{\"%v\":\"%v\"}", s.LabelKey, s.LabelValue) labelString := fmt.Sprintf("{\"%v\":\"%v\"}", s.LabelKey, s.LabelValues[s.roundRobinIdx])
patch := fmt.Sprintf(`{"metadata":{"labels":%v}}`, labelString) patch := fmt.Sprintf(`{"metadata":{"labels":%v}}`, labelString)
s.roundRobinIdx++
if s.roundRobinIdx == len(s.LabelValues) {
s.roundRobinIdx = 0
}
return []byte(patch) return []byte(patch)
} }