Skip to content

Commit

Permalink
Fix sidecar check for e2e test apps with IngressEnabled=false
Browse files Browse the repository at this point in the history
  • Loading branch information
wcs1only committed May 7, 2021
1 parent db799ba commit 5878f92
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
16 changes: 8 additions & 8 deletions tests/platforms/kubernetes/appmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ func (m *AppManager) Init() error {
log.Printf("Validating sidecar for app %v ....", m.app.AppName)
for i := 0; i <= maxSideCarDetectionRetries; i++ {
// Validate daprd side car is injected
if ok, err := m.ValidateSidecar(); err != nil || ok != m.app.IngressEnabled {
if err := m.ValidateSidecar(); err != nil {
if i == maxSideCarDetectionRetries {
return err
}

log.Printf("Did not find sidecar for app %v, retrying ....", m.app.AppName)
log.Printf("Did not find sidecar for app %v error %s, retrying ....", m.app.AppName, err)
time.Sleep(10 * time.Second)
continue
}
Expand Down Expand Up @@ -321,9 +321,9 @@ func (m *AppManager) IsDeploymentDeleted(deployment *appsv1.Deployment, err erro
}

// ValidateSidecar validates that dapr side car is running in dapr enabled pods
func (m *AppManager) ValidateSidecar() (bool, error) {
func (m *AppManager) ValidateSidecar() error {
if !m.app.DaprEnabled {
return false, fmt.Errorf("dapr is not enabled for this app")
return fmt.Errorf("dapr is not enabled for this app")
}

podClient := m.client.Pods(m.namespace)
Expand All @@ -332,11 +332,11 @@ func (m *AppManager) ValidateSidecar() (bool, error) {
LabelSelector: fmt.Sprintf("%s=%s", TestAppLabelKey, m.app.AppName),
})
if err != nil {
return false, err
return err
}

if len(podList.Items) != int(m.app.Replicas) {
return false, fmt.Errorf("expected number of pods for %s: %d, received: %d", m.app.AppName, m.app.Replicas, len(podList.Items))
return fmt.Errorf("expected number of pods for %s: %d, received: %d", m.app.AppName, m.app.Replicas, len(podList.Items))
}

// Each pod must have daprd sidecar
Expand All @@ -348,11 +348,11 @@ func (m *AppManager) ValidateSidecar() (bool, error) {
}
}
if !daprdFound {
return false, fmt.Errorf("cannot find dapr sidecar in pod %s", pod.Name)
return fmt.Errorf("cannot find dapr sidecar in pod %s", pod.Name)
}
}

return true, nil
return nil
}

// getSidecarInfo returns if sidecar is present and how many containers there are.
Expand Down
9 changes: 3 additions & 6 deletions tests/platforms/kubernetes/appmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,9 @@ func TestValidateSidecar(t *testing.T) {
})

appManager := NewAppManager(client, testNamespace, testApp)
found, err := appManager.ValidateSidecar()
err := appManager.ValidateSidecar()

assert.NoError(t, err)
assert.True(t, found)
})

t.Run("Sidecar is not injected", func(t *testing.T) {
Expand Down Expand Up @@ -321,8 +320,7 @@ func TestValidateSidecar(t *testing.T) {
})

appManager := NewAppManager(client, testNamespace, testApp)
found, err := appManager.ValidateSidecar()
assert.False(t, found)
err := appManager.ValidateSidecar()
assert.Error(t, err)
})

Expand All @@ -344,8 +342,7 @@ func TestValidateSidecar(t *testing.T) {
})

appManager := NewAppManager(client, testNamespace, testApp)
found, err := appManager.ValidateSidecar()
assert.False(t, found)
err := appManager.ValidateSidecar()
assert.Error(t, err)
})
}
Expand Down

0 comments on commit 5878f92

Please sign in to comment.