Skip to content

Commit 05345a6

Browse files
Merge branch 'master' into feat/add-no-warning-flag
2 parents 5c5e0bb + d229506 commit 05345a6

18 files changed

+1397
-911
lines changed

.github/workflows/self_hosted_e2e.yaml

+6-3
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ jobs:
4545
DAPR_TGZ: dapr-1.7.0.tgz
4646
strategy:
4747
matrix:
48-
os: [ubuntu-latest, macos-10.15]
48+
os: [macos-10.15, ubuntu-latest, windows-latest]
4949
target_arch: [amd64]
5050
include:
5151
- os: ubuntu-latest
5252
target_os: linux
5353
- os: macOS-10.15
5454
target_os: darwin
55-
#- os: windows-latest
56-
#target_os: windows
55+
- os: windows-latest
56+
target_os: windows
5757
steps:
5858
- name: Set up Go ${{ env.GOVER }}
5959
uses: actions/setup-go@v2
@@ -88,6 +88,7 @@ jobs:
8888
if: github.event.schedule == '0 */6 * * *'
8989
env:
9090
DAPR_DEFAULT_IMAGE_REGISTRY: ghcr
91+
DAPR_E2E_INIT_SLIM: ${{ contains(matrix.os, 'windows-latest') }}
9192
run: |
9293
export TEST_OUTPUT_FILE=$GITHUB_WORKSPACE/test-e2e-standalone.json
9394
echo "TEST_OUTPUT_FILE=$TEST_OUTPUT_FILE" >> $GITHUB_ENV
@@ -96,6 +97,8 @@ jobs:
9697
shell: bash
9798
- name: Run E2E tests with Docker hub
9899
if: github.event.schedule != '0 */6 * * *'
100+
env:
101+
DAPR_E2E_INIT_SLIM: ${{ contains(matrix.os, 'windows-latest') }}
99102
run: |
100103
export TEST_OUTPUT_FILE=$GITHUB_WORKSPACE/test-e2e-standalone.json
101104
echo "TEST_OUTPUT_FILE=$TEST_OUTPUT_FILE" >> $GITHUB_ENV

pkg/kubernetes/upgrade.go

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ func Upgrade(conf UpgradeConfig) error {
128128

129129
func highAvailabilityEnabled(status []StatusOutput) bool {
130130
for _, s := range status {
131+
if s.Name == "dapr-dashboard" {
132+
continue
133+
}
131134
if s.Replicas > 1 {
132135
return true
133136
}

pkg/standalone/standalone.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const (
5555
// used when DAPR_DEFAULT_IMAGE_REGISTRY is not set.
5656
dockerContainerRegistryName = "dockerhub"
5757
daprDockerImageName = "daprio/dapr"
58-
redisDockerImageName = "redis"
58+
redisDockerImageName = "redis:6"
5959
zipkinDockerImageName = "openzipkin/zipkin"
6060

6161
// used when DAPR_DEFAULT_IMAGE_REGISTRY is set as GHCR.

pkg/standalone/standalone_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestResolveImageWithGHCR(t *testing.T) {
105105
}
106106

107107
func TestResolveImageWithDockerHub(t *testing.T) {
108-
expectedRedisImageName := "redis"
108+
expectedRedisImageName := "redis:6"
109109
expectedZipkinImageName := "openzipkin/zipkin"
110110
expectedPlacementImageName := "daprio/dapr"
111111

tests/e2e/common/common.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func GetVersionsFromEnv(t *testing.T) (string, string) {
9090

9191
func UpgradeTest(details VersionDetails, opts TestOptions) func(t *testing.T) {
9292
return func(t *testing.T) {
93-
daprPath := getDaprPath()
93+
daprPath := GetDaprPath()
9494
args := []string{
9595
"upgrade", "-k",
9696
"--runtime-version", details.RuntimeVersion,
@@ -117,7 +117,7 @@ func UpgradeTest(details VersionDetails, opts TestOptions) func(t *testing.T) {
117117
}
118118

119119
func EnsureUninstall(all bool) (string, error) {
120-
daprPath := getDaprPath()
120+
daprPath := GetDaprPath()
121121

122122
var _command [10]string
123123
command := append(_command[0:], "uninstall", "-k")
@@ -187,7 +187,7 @@ func GetTestsPostCertificateRenewal(details VersionDetails, opts TestOptions) []
187187

188188
func MTLSTestOnInstallUpgrade(opts TestOptions) func(t *testing.T) {
189189
return func(t *testing.T) {
190-
daprPath := getDaprPath()
190+
daprPath := GetDaprPath()
191191
output, err := spawn.Command(daprPath, "mtls", "-k")
192192
require.NoError(t, err, "expected no error on querying for mtls")
193193
if !opts.MTLSEnabled {
@@ -233,7 +233,7 @@ func MTLSTestOnInstallUpgrade(opts TestOptions) func(t *testing.T) {
233233

234234
func ComponentsTestOnInstallUpgrade(opts TestOptions) func(t *testing.T) {
235235
return func(t *testing.T) {
236-
daprPath := getDaprPath()
236+
daprPath := GetDaprPath()
237237
// if dapr is installed.
238238
if opts.ApplyComponentChanges {
239239
// apply any changes to the component.
@@ -256,7 +256,7 @@ func ComponentsTestOnInstallUpgrade(opts TestOptions) func(t *testing.T) {
256256

257257
func StatusTestOnInstallUpgrade(details VersionDetails, opts TestOptions) func(t *testing.T) {
258258
return func(t *testing.T) {
259-
daprPath := getDaprPath()
259+
daprPath := GetDaprPath()
260260
output, err := spawn.Command(daprPath, "status", "-k")
261261
require.NoError(t, err, "status check failed")
262262
var notFound map[string][]string
@@ -419,7 +419,7 @@ func CRDTest(details VersionDetails, opts TestOptions) func(t *testing.T) {
419419

420420
func GenerateNewCertAndRenew(details VersionDetails, opts TestOptions) func(t *testing.T) {
421421
return func(t *testing.T) {
422-
daprPath := getDaprPath()
422+
daprPath := GetDaprPath()
423423
err := exportCurrentCertificate(daprPath)
424424
require.NoError(t, err, "expected no error on certificate exporting")
425425

@@ -445,7 +445,7 @@ func GenerateNewCertAndRenew(details VersionDetails, opts TestOptions) func(t *t
445445

446446
func UseProvidedPrivateKeyAndRenewCerts(details VersionDetails, opts TestOptions) func(t *testing.T) {
447447
return func(t *testing.T) {
448-
daprPath := getDaprPath()
448+
daprPath := GetDaprPath()
449449
args := []string{
450450
"mtls", "renew-certificate", "-k",
451451
"--private-key", "../testdata/example-root.key",
@@ -473,7 +473,7 @@ func UseProvidedPrivateKeyAndRenewCerts(details VersionDetails, opts TestOptions
473473

474474
func UseProvidedNewCertAndRenew(details VersionDetails, opts TestOptions) func(t *testing.T) {
475475
return func(t *testing.T) {
476-
daprPath := getDaprPath()
476+
daprPath := GetDaprPath()
477477
args := []string{
478478
"mtls", "renew-certificate", "-k",
479479
"--ca-root-certificate", "./certs/ca.crt",
@@ -507,7 +507,7 @@ func UseProvidedNewCertAndRenew(details VersionDetails, opts TestOptions) func(t
507507

508508
func NegativeScenarioForCertRenew() func(t *testing.T) {
509509
return func(t *testing.T) {
510-
daprPath := getDaprPath()
510+
daprPath := GetDaprPath()
511511
args := []string{
512512
"mtls", "renew-certificate", "-k",
513513
"--ca-root-certificate", "invalid_cert_file.pem",
@@ -551,7 +551,7 @@ func NegativeScenarioForCertRenew() func(t *testing.T) {
551551

552552
func CheckMTLSStatus(details VersionDetails, opts TestOptions, shouldWarningExist bool) func(t *testing.T) {
553553
return func(t *testing.T) {
554-
daprPath := getDaprPath()
554+
daprPath := GetDaprPath()
555555
output, err := spawn.Command(daprPath, "mtls", "-k")
556556
require.NoError(t, err, "expected no error on querying for mtls")
557557
if !opts.MTLSEnabled {
@@ -595,7 +595,7 @@ func (v VersionDetails) constructFoundMap(res Resource) map[string]bool {
595595
return foundMap
596596
}
597597

598-
func getDaprPath() string {
598+
func GetDaprPath() string {
599599
distDir := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)
600600

601601
return filepath.Join("..", "..", "..", "dist", distDir, "release", "dapr")
@@ -642,7 +642,7 @@ func getClient() (*k8s.Clientset, error) {
642642

643643
func installTest(details VersionDetails, opts TestOptions) func(t *testing.T) {
644644
return func(t *testing.T) {
645-
daprPath := getDaprPath()
645+
daprPath := GetDaprPath()
646646
args := []string{
647647
"init", "-k",
648648
"--wait",
@@ -693,7 +693,7 @@ func kubernetesTestOnUninstall() func(t *testing.T) {
693693
return func(t *testing.T) {
694694
_, err := EnsureUninstall(true)
695695
require.NoError(t, err, "uninstall failed")
696-
daprPath := getDaprPath()
696+
daprPath := GetDaprPath()
697697
output, err := spawn.Command(daprPath, "uninstall", "-k")
698698
require.NoError(t, err, "expected no error on uninstall without install")
699699
require.Contains(t, output, "Removing Dapr from your cluster...", "expected output to contain message")
@@ -704,7 +704,7 @@ func kubernetesTestOnUninstall() func(t *testing.T) {
704704

705705
func uninstallMTLSTest() func(t *testing.T) {
706706
return func(t *testing.T) {
707-
daprPath := getDaprPath()
707+
daprPath := GetDaprPath()
708708
output, err := spawn.Command(daprPath, "mtls", "-k")
709709
require.Error(t, err, "expected error to be return if dapr not installed")
710710
require.Contains(t, output, "error checking mTLS: system configuration not found", "expected output to match")
@@ -713,7 +713,7 @@ func uninstallMTLSTest() func(t *testing.T) {
713713

714714
func componentsTestOnUninstall(all bool) func(t *testing.T) {
715715
return func(t *testing.T) {
716-
daprPath := getDaprPath()
716+
daprPath := GetDaprPath()
717717
// On Dapr uninstall CRDs are not removed, consequently the components will not be removed.
718718
// TODO Related to https://github.com/dapr/cli/issues/656.
719719
// For now the components remain.
@@ -747,7 +747,7 @@ func componentsTestOnUninstall(all bool) func(t *testing.T) {
747747

748748
func statusTestOnUninstall() func(t *testing.T) {
749749
return func(t *testing.T) {
750-
daprPath := getDaprPath()
750+
daprPath := GetDaprPath()
751751
output, err := spawn.Command(daprPath, "status", "-k")
752752
t.Log("checking status fails as expected")
753753
require.Error(t, err, "status check did not fail as expected")

tests/e2e/spawn/spawn.go

+31
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,40 @@ limitations under the License.
1414
package spawn
1515

1616
import (
17+
"bufio"
18+
"context"
1719
"os/exec"
1820
)
1921

22+
// CommandWithContext runs a command with its arguments in background.
23+
// The provided context is used to kill the command (by calling os.Process.Kill)
24+
// if the context becomes done before the command completes on its own.
25+
// The return channel can be used to read the stdout.
26+
func CommandWithContext(ctx context.Context, command string, arguments ...string) (chan string, error) {
27+
cmd := exec.CommandContext(ctx, command, arguments...)
28+
stdout, err := cmd.StdoutPipe()
29+
if err != nil {
30+
return nil, err
31+
}
32+
33+
if err = cmd.Start(); err != nil {
34+
return nil, err
35+
}
36+
37+
stdOutChan := make(chan string)
38+
39+
go func() {
40+
scanner := bufio.NewScanner(stdout)
41+
for scanner.Scan() {
42+
stdOutChan <- scanner.Text()
43+
}
44+
close(stdOutChan)
45+
cmd.Wait()
46+
}()
47+
48+
return stdOutChan, nil
49+
}
50+
2051
// Command runs a command with its arguments and returns the stdout or stderr or the error.
2152
func Command(command string, arguments ...string) (string, error) {
2253
cmd := exec.Command(command, arguments...)

tests/e2e/standalone/commands.go

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
//go:build e2e
2+
// +build e2e
3+
4+
/*
5+
Copyright 2022 The Dapr Authors
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package standalone_test
18+
19+
import (
20+
"context"
21+
"errors"
22+
"strings"
23+
24+
"github.com/dapr/cli/tests/e2e/common"
25+
"github.com/dapr/cli/tests/e2e/spawn"
26+
)
27+
28+
// cmdDashboard runs the Dapr dashboard and blocks until it is started.
29+
// If the context is done, the dashboard is stopped.
30+
func cmdDashboard(ctx context.Context, port string) error {
31+
stdOutChan, err := spawn.CommandWithContext(ctx, common.GetDaprPath(), "dashboard", "--port", port)
32+
if err != nil {
33+
return err
34+
}
35+
for output := range stdOutChan {
36+
if strings.Contains(output, "Dapr Dashboard running on") {
37+
return nil
38+
}
39+
}
40+
return errors.New("Dashboard could not be started")
41+
}
42+
43+
// cmdInit installs Dapr with the init command and returns the command output and error.
44+
//
45+
// When DAPR_E2E_INIT_SLIM is true, it will install Dapr without Docker containers.
46+
// This is useful for scenarios where Docker containers are not available, e.g.,
47+
// in GitHub actions Windows runner.
48+
//
49+
// Arguments to the init command can be passed via args.
50+
func cmdInit(runtimeVersion string, args ...string) (string, error) {
51+
initArgs := []string{"init", "--log-as-json", "--runtime-version", runtimeVersion}
52+
53+
if isSlimMode() {
54+
initArgs = append(initArgs, "--slim")
55+
}
56+
57+
initArgs = append(initArgs, args...)
58+
59+
return spawn.Command(common.GetDaprPath(), initArgs...)
60+
}
61+
62+
// cmdInvoke invokes a method on the specified app and returns the command output and error.
63+
func cmdInvoke(appId, method, unixDomainSocket string, args ...string) (string, error) {
64+
invokeArgs := []string{"invoke", "--log-as-json", "--app-id", appId, "--method", method}
65+
66+
if unixDomainSocket != "" {
67+
invokeArgs = append(invokeArgs, "--unix-domain-socket", unixDomainSocket)
68+
}
69+
70+
invokeArgs = append(invokeArgs, args...)
71+
72+
return spawn.Command(common.GetDaprPath(), invokeArgs...)
73+
}
74+
75+
// cmdList lists the running dapr instances and returns the command output and error.
76+
// format can be empty, "table", "json", or "yaml"
77+
func cmdList(output string) (string, error) {
78+
args := []string{"list"}
79+
80+
if output != "" {
81+
args = append(args, "-o", output)
82+
}
83+
84+
return spawn.Command(common.GetDaprPath(), args...)
85+
}
86+
87+
// cmdPublish publishes a message to the specified pubsub and topic, and returns the command output and error.
88+
func cmdPublish(appId, pubsub, topic, unixDomainSocket string, args ...string) (string, error) {
89+
publishArgs := []string{"publish", "--log-as-json", "--publish-app-id", appId, "--pubsub", pubsub, "--topic", topic}
90+
91+
if unixDomainSocket != "" {
92+
publishArgs = append(publishArgs, "--unix-domain-socket", unixDomainSocket)
93+
}
94+
95+
publishArgs = append(publishArgs, args...)
96+
97+
return spawn.Command(common.GetDaprPath(), publishArgs...)
98+
}
99+
100+
// cmdRun runs a Dapr instance and returns the command output and error.
101+
func cmdRun(unixDomainSocket string, args ...string) (string, error) {
102+
runArgs := append([]string{"run"})
103+
104+
if unixDomainSocket != "" {
105+
runArgs = append(runArgs, "--unix-domain-socket", unixDomainSocket)
106+
}
107+
108+
runArgs = append(runArgs, args...)
109+
110+
return spawn.Command(common.GetDaprPath(), runArgs...)
111+
}
112+
113+
// cmdStop stops the specified app and returns the command output and error.
114+
func cmdStop(appId string, args ...string) (string, error) {
115+
stopArgs := append([]string{"stop", "--log-as-json", "--app-id", appId}, args...)
116+
return spawn.Command(common.GetDaprPath(), stopArgs...)
117+
}
118+
119+
// cmdUninstall uninstalls Dapr with --all flag and returns the command output and error.
120+
func cmdUninstall() (string, error) {
121+
return spawn.Command(common.GetDaprPath(), "uninstall", "--all")
122+
}
123+
124+
// cmdVersion checks the version of Dapr and returns the command output and error.
125+
// output can be empty or "json"
126+
func cmdVersion(output string) (string, error) {
127+
args := []string{"version"}
128+
129+
if output != "" {
130+
args = append(args, "-o", output)
131+
}
132+
133+
return spawn.Command(common.GetDaprPath(), args...)
134+
}

0 commit comments

Comments
 (0)