Skip to content

Commit

Permalink
getMigrationConfigPatch to support getting custom configs
Browse files Browse the repository at this point in the history
Signed-off-by: Itamar Holder <iholder@redhat.com>
  • Loading branch information
iholder101 committed Feb 23, 2022
1 parent 1710687 commit cb6bde5
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions pkg/virt-controller/watch/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,17 @@ var _ = Describe("Migration watcher", func() {
}
}

getMigrationConfigPatch := func() string {
migrationConfiguration := controller.clusterConfig.GetMigrationConfiguration()
Expect(migrationConfiguration).ToNot(BeNil())
getMigrationConfigPatch := func(customConfigs ...*virtv1.MigrationConfiguration) string {
Expect(customConfigs).To(Or(BeEmpty(), HaveLen(1)))

var migrationConfiguration *virtv1.MigrationConfiguration

if len(customConfigs) > 0 && customConfigs[0] != nil {
migrationConfiguration = customConfigs[0]
} else {
migrationConfiguration = controller.clusterConfig.GetMigrationConfiguration()
Expect(migrationConfiguration).ToNot(BeNil())
}

marshalledConfigs, err := json.Marshal(migrationConfiguration)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -1353,18 +1361,16 @@ var _ = Describe("Migration watcher", func() {
var pod *k8sv1.Pod

getExpectedVmiPatch := func(expectConfigUpdate bool, expectedConfigs *virtv1.MigrationConfiguration, migrationPolicy *migrationsv1.MigrationPolicy) string {
var migrationPolicyPatch string
if expectConfigUpdate {
marshalledConfigs, err := json.Marshal(*expectedConfigs)
Expect(err).ShouldNot(HaveOccurred())
var migrationPolicyNamePatch string

migrationPolicyPatch = fmt.Sprintf(`,"migrationPolicyName":"%s","migrationConfiguration":%s`, migrationPolicy.Name, string(marshalledConfigs))
if expectConfigUpdate {
migrationPolicyNamePatch = fmt.Sprintf(`,"migrationPolicyName":"%s"`, migrationPolicy.Name)
}

patch := fmt.Sprintf(`[{ "op": "add", "path": "/status/migrationState", `+
`"value": {"targetNode":"node01","targetPod":"%s","sourceNode":"tefwegwrerg","migrationUid":"testmigration"%s} }, `+
`"value": {"targetNode":"node01","targetPod":"%s","sourceNode":"tefwegwrerg","migrationUid":"testmigration"%s,%s} }, `+
`{ "op": "test", "path": "/metadata/labels", "value": {"mp-key-0":"mp-value-0"} }, `+
`{ "op": "replace", "path": "/metadata/labels", "value": {"kubevirt.io/migrationTargetNodeName":"node01","mp-key-0":"mp-value-0"} }]`, pod.Name, migrationPolicyPatch)
`{ "op": "replace", "path": "/metadata/labels", "value": {"kubevirt.io/migrationTargetNodeName":"node01","mp-key-0":"mp-value-0"} }]`, pod.Name, migrationPolicyNamePatch, getMigrationConfigPatch(expectedConfigs))

return patch
}
Expand Down

0 comments on commit cb6bde5

Please sign in to comment.