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
labelNodePrepareStrategy:
labelKey: "failure-domain.beta.kubernetes.io/zone"
labelValue: "zone1"
labelValues: ["zone1"]
initPods:
- podTemplatePath: config/pod-with-node-affinity.yaml
podsToSchedule:

View File

@ -980,22 +980,27 @@ func (*TrivialNodePrepareStrategy) CleanupDependentObjects(nodeName string, clie
}
type LabelNodePrepareStrategy struct {
LabelKey string
LabelValue string
LabelKey string
LabelValues []string
roundRobinIdx int
}
var _ PrepareNodeStrategy = &LabelNodePrepareStrategy{}
func NewLabelNodePrepareStrategy(labelKey string, labelValue string) *LabelNodePrepareStrategy {
func NewLabelNodePrepareStrategy(labelKey string, labelValues ...string) *LabelNodePrepareStrategy {
return &LabelNodePrepareStrategy{
LabelKey: labelKey,
LabelValue: labelValue,
LabelKey: labelKey,
LabelValues: labelValues,
}
}
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)
s.roundRobinIdx++
if s.roundRobinIdx == len(s.LabelValues) {
s.roundRobinIdx = 0
}
return []byte(patch)
}