Skip to content

Commit

Permalink
Deduplicate code in deploy / wipe infra function
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Bednar <[email protected]>
  • Loading branch information
lukas-bednar committed Dec 17, 2018
1 parent d17e900 commit a837dc5
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,6 @@ func DeleteRawManifest(object unstructured.Unstructured) error {

uri := composeResourceURI(object)
uri = uri + "/" + object.GetName()
PanicOnError(err)
result := virtCli.CoreV1().RESTClient().Delete().RequestURI(uri).Do()
if result.Error() != nil && !errors.IsNotFound(result.Error()) {
fmt.Printf(fmt.Sprintf("ERROR: Can not delete %s err: %#v %s\n", object.GetName(), result.Error(), object))
Expand All @@ -755,38 +754,35 @@ func DeleteRawManifest(object unstructured.Unstructured) error {
return nil
}

func DeployTestingInfrastructure() {
func deployOrWipeTestingInfrastrucure(actionOnObject func(unstructured.Unstructured) error) {
// Scale down KubeVirt
err, replicasApi := DoScaleDeployment(KubeVirtInstallNamespace, "virt-api", 0)
PanicOnError(err)
err, replicasController := DoScaleDeployment(KubeVirtInstallNamespace, "virt-controller", 0)
PanicOnError(err)
// Deploy test infrastructure / dependencies
// Deploy / delete test infrastructure / dependencies
manifests := GetListOfManifests(PathToTestingInfrastrucureManifests)
for _, manifest := range manifests {
objects := ReadManifestYamlFile(manifest)
for _, obj := range objects {
err := ApplyRawManifest(obj)
err := actionOnObject(obj)
PanicOnError(err)
}
}
// Scale up KubeVirt
// Scale KubeVirt back
err, _ = DoScaleDeployment(KubeVirtInstallNamespace, "virt-api", replicasApi)
PanicOnError(err)
err, _ = DoScaleDeployment(KubeVirtInstallNamespace, "virt-controller", replicasController)
PanicOnError(err)
WaitForAllPodsReady(3*time.Minute, metav1.ListOptions{})
}

func DeployTestingInfrastructure() {
deployOrWipeTestingInfrastrucure(ApplyRawManifest)
}

func WipeTestingInfrastructure() {
manifests := GetListOfManifests(PathToTestingInfrastrucureManifests)
for _, manifest := range manifests {
objects := ReadManifestYamlFile(manifest)
for _, obj := range objects {
err := DeleteRawManifest(obj)
PanicOnError(err)
}
}
deployOrWipeTestingInfrastrucure(DeleteRawManifest)
}

func cleanupSubresourceServiceAccount() {
Expand Down

0 comments on commit a837dc5

Please sign in to comment.