Skip to content

Commit

Permalink
Fixes storage owner references. (#2750)
Browse files Browse the repository at this point in the history
* Fixes storage owner references.

This PR also fixes CheckForExistence() function and the unit test for updateStorageOwnerReference()

Signed-off-by: mik-dass <mrinald7@gmail.com>

* Added upstream reported issue link
  • Loading branch information
mik-dass committed Mar 30, 2020
1 parent 1eb878e commit 5cb97bc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/occlient/volumes.go
Expand Up @@ -194,7 +194,7 @@ func updateStorageOwnerReference(client *Client, pvc *corev1.PersistentVolumeCla
return err
}
for _, owRf := range ownerReference {
pvc.SetOwnerReferences(append(pvc.GetOwnerReferences(), owRf))
latestPVC.SetOwnerReferences(append(pvc.GetOwnerReferences(), owRf))
}
_, err = client.kubeClient.CoreV1().PersistentVolumeClaims(client.Namespace).Update(latestPVC)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/occlient/volumes_test.go
Expand Up @@ -289,12 +289,13 @@ func Test_updateStorageOwnerReference(t *testing.T) {
fakeClient, fakeClientSet := FakeNew()

fakeClientSet.Kubernetes.PrependReactor("get", "persistentvolumeclaims", func(action ktesting.Action) (handled bool, ret runtime.Object, err error) {
return true, tt.args.pvc, nil
returnedPVC := *tt.args.pvc
return true, &returnedPVC, nil
})

fakeClientSet.Kubernetes.PrependReactor("update", "persistentvolumeclaims", func(action ktesting.Action) (handled bool, ret runtime.Object, err error) {
pvc := action.(ktesting.UpdateAction).GetObject().(*corev1.PersistentVolumeClaim)
if pvc.OwnerReferences[0].Name != fakeDC.Name {
if pvc.OwnerReferences == nil || pvc.OwnerReferences[0].Name != fakeDC.Name {
t.Errorf("owner reference not set for dc %s", tt.args.pvc.Name)
}
return true, pvc, nil
Expand Down
28 changes: 22 additions & 6 deletions tests/helper/helper_oc.go
Expand Up @@ -450,10 +450,26 @@ func (oc *OcRunner) WaitForDCRollout(dcName string, project string, timeout time
session.Wait(timeout)
}

// CheckForExistence checks if the given resource type exists on the cluster
func (oc *OcRunner) CheckForExistence(resourceType, namespace string) {
session := CmdRunner(oc.path, "get", resourceType, "--namespace", namespace)
Eventually(session).Should(gexec.Exit(0))
output := string(session.Wait().Out.Contents())
Expect(strings.ToLower(output)).To(ContainSubstring(""))
// WaitAndCheckForExistence wait for the given and checks if the given resource type gets deleted on the cluster
func (oc *OcRunner) WaitAndCheckForExistence(resourceType, namespace string, timeoutMinutes int) bool {
pingTimeout := time.After(time.Duration(timeoutMinutes) * time.Minute)
// this is a test package so time.Tick() is acceptable
// nolint
tick := time.Tick(time.Second)
for {
select {
case <-pingTimeout:
Fail(fmt.Sprintf("Timeout out after %v minutes", timeoutMinutes))

case <-tick:
session := CmdRunner(oc.path, "get", resourceType, "--namespace", namespace)
Eventually(session).Should(gexec.Exit(0))
// https://github.com/kubernetes/kubectl/issues/847
output := string(session.Wait().Err.Contents())

if strings.Contains(strings.ToLower(output), "no resources found") {
return true
}
}
}
}
12 changes: 6 additions & 6 deletions tests/integration/component.go
Expand Up @@ -826,12 +826,12 @@ func componentTests(args ...string) {

helper.CmdShouldPass("odo", append(args, "delete", "-f", "--context", context)...)

oc.CheckForExistence("routes", project)
oc.CheckForExistence("dc", project)
oc.CheckForExistence("pvc", project)
oc.CheckForExistence("bc", project)
oc.CheckForExistence("is", project)
oc.CheckForExistence("service", project)
oc.WaitAndCheckForExistence("routes", project, 1)
oc.WaitAndCheckForExistence("dc", project, 1)
oc.WaitAndCheckForExistence("pvc", project, 1)
oc.WaitAndCheckForExistence("bc", project, 1)
oc.WaitAndCheckForExistence("is", project, 1)
oc.WaitAndCheckForExistence("service", project, 1)
})
})
}

0 comments on commit 5cb97bc

Please sign in to comment.