From 762e2bb4acd11f64ed5c147ba3bbe8029b74ff84 Mon Sep 17 00:00:00 2001 From: Artur Souza Date: Fri, 5 Jul 2024 20:16:40 -0700 Subject: [PATCH 01/25] Fix check for version to contain scheduler. (#1417) Signed-off-by: Artur Souza --- pkg/standalone/standalone.go | 6 +++++- pkg/standalone/standalone_test.go | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pkg/standalone/standalone.go b/pkg/standalone/standalone.go index f25bf9bfb..456ed74aa 100644 --- a/pkg/standalone/standalone.go +++ b/pkg/standalone/standalone.go @@ -176,7 +176,11 @@ func isSchedulerIncluded(runtimeVersion string) (bool, error) { return false, err } - return c.Check(v), nil + vNoPrerelease, err := v.SetPrerelease("") + if err != nil { + return false, err + } + return c.Check(&vNoPrerelease), nil } // Init installs Dapr on a local machine using the supplied runtimeVersion. diff --git a/pkg/standalone/standalone_test.go b/pkg/standalone/standalone_test.go index bf05b1f63..777d42ce2 100644 --- a/pkg/standalone/standalone_test.go +++ b/pkg/standalone/standalone_test.go @@ -334,3 +334,25 @@ func TestInitLogActualContainerRuntimeName(t *testing.T) { }) } } + +func TestIsSchedulerIncluded(t *testing.T) { + scenarios := []struct { + version string + isIncluded bool + }{ + {"1.13.0-rc.1", false}, + {"1.13.0", false}, + {"1.13.1", false}, + {"1.14.0", true}, + {"1.14.0-rc.1", true}, + {"1.14.0-mycompany.1", true}, + {"1.14.1", true}, + } + for _, scenario := range scenarios { + t.Run("isSchedulerIncludedIn"+scenario.version, func(t *testing.T) { + included, err := isSchedulerIncluded(scenario.version) + assert.NoError(t, err) + assert.Equal(t, scenario.isIncluded, included) + }) + } +} From ed0d3af2d064bcef303237062fc4adb8b98d60eb Mon Sep 17 00:00:00 2001 From: Mike Nguyen Date: Wed, 10 Jul 2024 17:37:34 +0100 Subject: [PATCH 02/25] fix: scheduler host address passed to runtime (#1421) * fix: scheduler host address passed to runtime Signed-off-by: mikeee * fix: scheduler client stream initialised for 1.14< Signed-off-by: mikeee * fix: modify scheduler host address validation if the scheduler container is not active, the scheduler flag will not be passed to the runtime Signed-off-by: mikeee * fix: lint and refactor Signed-off-by: mikeee --------- Signed-off-by: mikeee --- cmd/annotate.go | 1 - cmd/run.go | 111 ++++++++++-------- go.mod | 6 +- pkg/kubernetes/renew_certificate.go | 2 - pkg/kubernetes/uninstall.go | 1 - pkg/standalone/run.go | 42 ++++--- pkg/standalone/standalone.go | 4 - tests/e2e/common/common.go | 1 - .../standalone/windows_run_template_test.go | 2 - 9 files changed, 91 insertions(+), 79 deletions(-) diff --git a/cmd/annotate.go b/cmd/annotate.go index a5e9b6472..ab77757ba 100644 --- a/cmd/annotate.go +++ b/cmd/annotate.go @@ -221,7 +221,6 @@ func readInputsFromFS(path string) ([]io.Reader, error) { inputs = append(inputs, file) return nil }) - if err != nil { return nil, err } diff --git a/cmd/run.go b/cmd/run.go index 4b5959ec0..f91c772e6 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -24,6 +24,8 @@ import ( "strings" "time" + "golang.org/x/mod/semver" + "github.com/spf13/cobra" "github.com/spf13/viper" @@ -38,34 +40,35 @@ import ( ) var ( - appPort int - profilePort int - appID string - configFile string - port int - grpcPort int - internalGRPCPort int - maxConcurrency int - enableProfiling bool - logLevel string - protocol string - componentsPath string - resourcesPaths []string - appSSL bool - metricsPort int - maxRequestBodySize int - readBufferSize int - unixDomainSocket string - enableAppHealth bool - appHealthPath string - appHealthInterval int - appHealthTimeout int - appHealthThreshold int - enableAPILogging bool - apiListenAddresses string - runFilePath string - appChannelAddress string - enableRunK8s bool + appPort int + profilePort int + appID string + configFile string + port int + grpcPort int + internalGRPCPort int + maxConcurrency int + enableProfiling bool + logLevel string + protocol string + componentsPath string + resourcesPaths []string + appSSL bool + metricsPort int + maxRequestBodySize int + readBufferSize int + unixDomainSocket string + enableAppHealth bool + appHealthPath string + appHealthInterval int + appHealthTimeout int + appHealthThreshold int + enableAPILogging bool + apiListenAddresses string + schedulerHostAddress string + runFilePath string + appChannelAddress string + enableRunK8s bool ) const ( @@ -120,7 +123,6 @@ dapr run --run-file /path/to/directory -k Args: cobra.MinimumNArgs(0), PreRun: func(cmd *cobra.Command, args []string) { viper.BindPFlag("placement-host-address", cmd.Flags().Lookup("placement-host-address")) - viper.BindPFlag("scheduler-host-address", cmd.Flags().Lookup("scheduler-host-address")) }, Run: func(cmd *cobra.Command, args []string) { if len(runFilePath) > 0 { @@ -166,26 +168,26 @@ dapr run --run-file /path/to/directory -k } sharedRunConfig := &standalone.SharedRunConfig{ - ConfigFile: configFile, - EnableProfiling: enableProfiling, - LogLevel: logLevel, - MaxConcurrency: maxConcurrency, - AppProtocol: protocol, - PlacementHostAddr: viper.GetString("placement-host-address"), - SchedulerHostAddr: viper.GetString("scheduler-host-address"), - ComponentsPath: componentsPath, - ResourcesPaths: resourcesPaths, - AppSSL: appSSL, - MaxRequestBodySize: maxRequestBodySize, - HTTPReadBufferSize: readBufferSize, - EnableAppHealth: enableAppHealth, - AppHealthPath: appHealthPath, - AppHealthInterval: appHealthInterval, - AppHealthTimeout: appHealthTimeout, - AppHealthThreshold: appHealthThreshold, - EnableAPILogging: enableAPILogging, - APIListenAddresses: apiListenAddresses, - DaprdInstallPath: daprRuntimePath, + ConfigFile: configFile, + EnableProfiling: enableProfiling, + LogLevel: logLevel, + MaxConcurrency: maxConcurrency, + AppProtocol: protocol, + PlacementHostAddr: viper.GetString("placement-host-address"), + ComponentsPath: componentsPath, + ResourcesPaths: resourcesPaths, + AppSSL: appSSL, + MaxRequestBodySize: maxRequestBodySize, + HTTPReadBufferSize: readBufferSize, + EnableAppHealth: enableAppHealth, + AppHealthPath: appHealthPath, + AppHealthInterval: appHealthInterval, + AppHealthTimeout: appHealthTimeout, + AppHealthThreshold: appHealthThreshold, + EnableAPILogging: enableAPILogging, + APIListenAddresses: apiListenAddresses, + SchedulerHostAddress: schedulerHostAddress, + DaprdInstallPath: daprRuntimePath, } output, err := runExec.NewOutput(&standalone.RunConfig{ AppID: appID, @@ -227,6 +229,15 @@ dapr run --run-file /path/to/directory -k output.DaprHTTPPort, output.DaprGRPCPort) } + + if semver.Compare(fmt.Sprintf("v%v", daprVer.RuntimeVersion), "v1.14.0-rc.1") == -1 { + print.InfoStatusEvent(os.Stdout, "The scheduler is only compatible with dapr runtime 1.14 onwards.") + for i, arg := range output.DaprCMD.Args { + if strings.HasPrefix(arg, "--scheduler-host-address") { + output.DaprCMD.Args[i] = "" + } + } + } print.InfoStatusEvent(os.Stdout, startInfo) output.DaprCMD.Stdout = os.Stdout @@ -456,7 +467,7 @@ func init() { // By marking this as deprecated, the flag will be hidden from the help menu, but will continue to work. It will show a warning message when used. RunCmd.Flags().MarkDeprecated("components-path", "This flag is deprecated and will be removed in the future releases. Use \"resources-path\" flag instead") RunCmd.Flags().String("placement-host-address", "localhost", "The address of the placement service. Format is either for default port or : for custom port") - RunCmd.Flags().String("scheduler-host-address", "localhost", "The address of the scheduler service. Format is either for default port or : for custom port") + RunCmd.Flags().StringVarP(&schedulerHostAddress, "scheduler-host-address", "", "localhost", "The address of the scheduler service. Format is either for default port or : for custom port") // TODO: Remove below flag once the flag is removed in runtime in future release. RunCmd.Flags().BoolVar(&appSSL, "app-ssl", false, "Enable https when Dapr invokes the application") RunCmd.Flags().MarkDeprecated("app-ssl", "This flag is deprecated and will be removed in the future releases. Use \"app-protocol\" flag with https or grpcs values instead") diff --git a/go.mod b/go.mod index ea59e3d7b..146089460 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,10 @@ require ( sigs.k8s.io/yaml v1.4.0 ) -require github.com/Masterminds/semver/v3 v3.2.0 +require ( + github.com/Masterminds/semver/v3 v3.2.0 + golang.org/x/mod v0.14.0 +) require ( github.com/alphadose/haxmap v1.3.1 // indirect @@ -61,7 +64,6 @@ require ( go.mongodb.org/mongo-driver v1.12.1 // indirect go.opentelemetry.io/otel/metric v1.23.1 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/mod v0.14.0 // indirect golang.org/x/tools v0.17.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240116215550-a9fa1716bcac // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014 // indirect diff --git a/pkg/kubernetes/renew_certificate.go b/pkg/kubernetes/renew_certificate.go index 8880a7eb3..28dd49e77 100644 --- a/pkg/kubernetes/renew_certificate.go +++ b/pkg/kubernetes/renew_certificate.go @@ -52,7 +52,6 @@ func RenewCertificate(conf RenewCertificateParams) error { conf.RootCertificateFilePath, conf.IssuerCertificateFilePath, conf.IssuerPrivateKeyFilePath) - if err != nil { return err } @@ -60,7 +59,6 @@ func RenewCertificate(conf RenewCertificateParams) error { rootCertBytes, issuerCertBytes, issuerKeyBytes, err = GenerateNewCertificates( conf.ValidUntil, conf.RootPrivateKeyFilePath) - if err != nil { return err } diff --git a/pkg/kubernetes/uninstall.go b/pkg/kubernetes/uninstall.go index 7a0240920..1ab874dd0 100644 --- a/pkg/kubernetes/uninstall.go +++ b/pkg/kubernetes/uninstall.go @@ -54,7 +54,6 @@ func Uninstall(namespace string, uninstallAll bool, uninstallDev bool, timeout u } _, err = uninstallClient.Run(daprReleaseName) - if err != nil { return err } diff --git a/pkg/standalone/run.go b/pkg/standalone/run.go index 6f1f81127..3205b3599 100644 --- a/pkg/standalone/run.go +++ b/pkg/standalone/run.go @@ -14,6 +14,7 @@ limitations under the License. package standalone import ( + "context" "fmt" "net" "os" @@ -23,6 +24,8 @@ import ( "strconv" "strings" + dockerClient "github.com/docker/docker/client" + "github.com/Pallinder/sillyname-go" "github.com/phayes/freeport" "gopkg.in/yaml.v2" @@ -70,8 +73,6 @@ type SharedRunConfig struct { MaxConcurrency int `arg:"app-max-concurrency" annotation:"dapr.io/app-max-concurrerncy" yaml:"appMaxConcurrency" default:"-1"` // Speicifcally omitted from annotations similar to config file path above. PlacementHostAddr string `arg:"placement-host-address" yaml:"placementHostAddress"` - // Must use env for scheduler host address because using arg would cause a sidecar crash in older daprd versions. - SchedulerHostAddr string `env:"DAPR_SCHEDULER_HOST_ADDRESS" yaml:"schedulerHostAddress"` // Speicifcally omitted from annotations similar to config file path above. ComponentsPath string `arg:"components-path"` // Deprecated in run template file: use ResourcesPaths instead. // Speicifcally omitted from annotations similar to config file path above. @@ -89,10 +90,11 @@ type SharedRunConfig struct { AppHealthThreshold int `arg:"app-health-threshold" annotation:"dapr.io/app-health-threshold" ifneq:"0" yaml:"appHealthThreshold"` EnableAPILogging bool `arg:"enable-api-logging" annotation:"dapr.io/enable-api-logging" yaml:"enableApiLogging"` // Specifically omitted from annotations see https://github.com/dapr/cli/issues/1324 . - DaprdInstallPath string `yaml:"runtimePath"` - Env map[string]string `yaml:"env"` - DaprdLogDestination LogDestType `yaml:"daprdLogDestination"` - AppLogDestination LogDestType `yaml:"appLogDestination"` + DaprdInstallPath string `yaml:"runtimePath"` + Env map[string]string `yaml:"env"` + DaprdLogDestination LogDestType `yaml:"daprdLogDestination"` + AppLogDestination LogDestType `yaml:"appLogDestination"` + SchedulerHostAddress string `arg:"scheduler-host-address" yaml:"schedulerHostAddress"` } func (meta *DaprMeta) newAppID() string { @@ -139,18 +141,27 @@ func (config *RunConfig) validatePlacementHostAddr() error { } func (config *RunConfig) validateSchedulerHostAddr() error { - schedulerHostAddr := config.SchedulerHostAddr - if len(schedulerHostAddr) == 0 { - schedulerHostAddr = "localhost" + // If the scheduler isn't running - don't add the flag to the runtime cmd. + docker, err := dockerClient.NewClientWithOpts() + if err != nil { + return err } - if indx := strings.Index(schedulerHostAddr, ":"); indx == -1 { - if runtime.GOOS == daprWindowsOS { - schedulerHostAddr = fmt.Sprintf("%s:6060", schedulerHostAddr) - } else { - schedulerHostAddr = fmt.Sprintf("%s:50006", schedulerHostAddr) + _, err = docker.ContainerInspect(context.Background(), "dapr_scheduler") + if err == nil { + schedulerHostAddr := config.SchedulerHostAddress + if len(schedulerHostAddr) == 0 { + schedulerHostAddr = "localhost" } + if indx := strings.Index(schedulerHostAddr, ":"); indx == -1 { + if runtime.GOOS == daprWindowsOS { + schedulerHostAddr = fmt.Sprintf("%s:6060", schedulerHostAddr) + } else { + schedulerHostAddr = fmt.Sprintf("%s:50006", schedulerHostAddr) + } + } + config.SchedulerHostAddress = schedulerHostAddr + return nil } - config.SchedulerHostAddr = schedulerHostAddr return nil } @@ -237,7 +248,6 @@ func (config *RunConfig) Validate() error { } err = config.validateSchedulerHostAddr() - if err != nil { return err } diff --git a/pkg/standalone/standalone.go b/pkg/standalone/standalone.go index 456ed74aa..775420679 100644 --- a/pkg/standalone/standalone.go +++ b/pkg/standalone/standalone.go @@ -415,7 +415,6 @@ func runZipkin(wg *sync.WaitGroup, errorChan chan<- error, info initInfo) { args = append(args, imageName) } _, err = utils.RunCmdAndWait(runtimeCmd, args...) - if err != nil { runError := isContainerRunError(err) if !runError { @@ -481,7 +480,6 @@ func runRedis(wg *sync.WaitGroup, errorChan chan<- error, info initInfo) { args = append(args, imageName) } _, err = utils.RunCmdAndWait(runtimeCmd, args...) - if err != nil { runError := isContainerRunError(err) if !runError { @@ -568,7 +566,6 @@ func runPlacementService(wg *sync.WaitGroup, errorChan chan<- error, info initIn args = append(args, image) _, err = utils.RunCmdAndWait(runtimeCmd, args...) - if err != nil { runError := isContainerRunError(err) if !runError { @@ -668,7 +665,6 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn args = append(args, image) _, err = utils.RunCmdAndWait(runtimeCmd, args...) - if err != nil { runError := isContainerRunError(err) if !runError { diff --git a/tests/e2e/common/common.go b/tests/e2e/common/common.go index b6c1b5b4a..e52412944 100644 --- a/tests/e2e/common/common.go +++ b/tests/e2e/common/common.go @@ -1210,7 +1210,6 @@ func exportCurrentCertificate(daprPath string) error { os.RemoveAll("./certs") } _, err = spawn.Command(daprPath, "mtls", "export", "-o", "./certs") - if err != nil { return fmt.Errorf("error in exporting certificate %w", err) } diff --git a/tests/e2e/standalone/windows_run_template_test.go b/tests/e2e/standalone/windows_run_template_test.go index 28ccefed9..c570f94c7 100644 --- a/tests/e2e/standalone/windows_run_template_test.go +++ b/tests/e2e/standalone/windows_run_template_test.go @@ -115,7 +115,6 @@ func startAppsWithAppLogDestFile(t *testing.T, file string) { assert.NotContains(t, output, "msg=\"All outstanding components processed\" app_id=emit-metrics") assert.Contains(t, output, "Received signal to stop Dapr and app processes. Shutting down Dapr and app processes.") - } func startAppsWithAppLogDestConsole(t *testing.T, file string) { @@ -139,5 +138,4 @@ func startAppsWithAppLogDestConsole(t *testing.T, file string) { assert.NotContains(t, output, "msg=\"All outstanding components processed\" app_id=emit-metrics") assert.Contains(t, output, "Received signal to stop Dapr and app processes. Shutting down Dapr and app processes.") - } From ad3442b252fa475f7d55499ae441348dfaf09f27 Mon Sep 17 00:00:00 2001 From: Josh van Leeuwen Date: Fri, 12 Jul 2024 16:22:34 +0100 Subject: [PATCH 03/25] dapr_scheduler: Adds scheduler-volume flag (#1422) * dapr_scheduler: pre-create data dir Signed-off-by: joshvanl * Adds --scheduler-volume to specify volume for data directory Signed-off-by: joshvanl --------- Signed-off-by: joshvanl --- cmd/init.go | 8 +++++++- pkg/standalone/common.go | 11 ----------- pkg/standalone/standalone.go | 10 ++++++---- pkg/standalone/standalone_test.go | 2 +- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/cmd/init.go b/cmd/init.go index 86f785c66..83b07351a 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -45,6 +45,7 @@ var ( fromDir string containerRuntime string imageVariant string + schedulerVolume string ) var InitCmd = &cobra.Command{ @@ -170,7 +171,11 @@ dapr init --runtime-path print.FailureStatusEvent(os.Stdout, "Invalid container runtime. Supported values are docker and podman.") os.Exit(1) } - err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, daprRuntimePath) + var schedVol *string + if cmd.Flags().Changed("scheduler-volume") { + schedVol = &schedulerVolume + } + err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, daprRuntimePath, schedVol) if err != nil { print.FailureStatusEvent(os.Stderr, err.Error()) os.Exit(1) @@ -219,6 +224,7 @@ func init() { InitCmd.Flags().String("network", "", "The Docker network on which to deploy the Dapr runtime") InitCmd.Flags().StringVarP(&fromDir, "from-dir", "", "", "Use Dapr artifacts from local directory for self-hosted installation") InitCmd.Flags().StringVarP(&imageVariant, "image-variant", "", "", "The image variant to use for the Dapr runtime, for example: mariner") + InitCmd.Flags().StringVarP(&schedulerVolume, "scheduler-volume", "", "", "Self-hosted only. Optionally specify a volume for the scheduler service data directory. By default, scheduler data is not persisted and not resilient to restarts without this flag.") InitCmd.Flags().BoolP("help", "h", false, "Print this help message") InitCmd.Flags().StringArrayVar(&values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)") InitCmd.Flags().String("image-registry", "", "Custom/private docker image repository URL") diff --git a/pkg/standalone/common.go b/pkg/standalone/common.go index c47316ac0..5e2ee888e 100644 --- a/pkg/standalone/common.go +++ b/pkg/standalone/common.go @@ -17,7 +17,6 @@ import ( "os" path_filepath "path/filepath" "runtime" - "strconv" "strings" ) @@ -61,16 +60,6 @@ func getDaprBinPath(daprDir string) string { return path_filepath.Join(daprDir, defaultDaprBinDirName) } -// getSchedulerDataPath returns the data path of a given instance -// Receiving instanceID allows multiple instances of scheduler to run locally in the future. -func getSchedulerDataPath(daprDir string, instanceID int) string { - return path_filepath.Join( - daprDir, - defaultSchedulerDirName, - defaultSchedulerDataDirName, - strconv.Itoa(instanceID)) -} - func binaryFilePathWithDir(binaryDir string, binaryFilePrefix string) string { binaryPath := path_filepath.Join(binaryDir, binaryFilePrefix) if runtime.GOOS == daprWindowsOS { diff --git a/pkg/standalone/standalone.go b/pkg/standalone/standalone.go index 775420679..4e122d35b 100644 --- a/pkg/standalone/standalone.go +++ b/pkg/standalone/standalone.go @@ -143,6 +143,7 @@ type initInfo struct { imageRegistryURL string containerRuntime string imageVariant string + schedulerVolume *string } type daprImageInfo struct { @@ -184,7 +185,7 @@ func isSchedulerIncluded(runtimeVersion string) (bool, error) { } // Init installs Dapr on a local machine using the supplied runtimeVersion. -func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMode bool, imageRegistryURL string, fromDir string, containerRuntime string, imageVariant string, daprInstallPath string) error { +func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMode bool, imageRegistryURL string, fromDir string, containerRuntime string, imageVariant string, daprInstallPath string, schedulerVolume *string) error { var err error var bundleDet bundleDetails containerRuntime = strings.TrimSpace(containerRuntime) @@ -305,6 +306,7 @@ func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMod imageRegistryURL: imageRegistryURL, containerRuntime: containerRuntime, imageVariant: imageVariant, + schedulerVolume: schedulerVolume, } for _, step := range initSteps { // Run init on the configurations and containers. @@ -633,15 +635,15 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn } } - // instanceID is 0 because we run one instance only for now. - schedulerDataDir := getSchedulerDataPath(info.installDir, 0) args := []string{ "run", "--name", schedulerContainerName, "--restart", "always", "-d", "--entrypoint", "./scheduler", - "--volume", fmt.Sprintf("%v:/data-default-dapr-scheduler-server-0", schedulerDataDir), + } + if info.schedulerVolume != nil { + args = append(args, "--volume", *info.schedulerVolume+":/data-default-dapr-scheduler-server-0") } if info.dockerNetwork != "" { diff --git a/pkg/standalone/standalone_test.go b/pkg/standalone/standalone_test.go index 777d42ce2..7f8ae5c0c 100644 --- a/pkg/standalone/standalone_test.go +++ b/pkg/standalone/standalone_test.go @@ -328,7 +328,7 @@ func TestInitLogActualContainerRuntimeName(t *testing.T) { t.Skip("Skipping test as container runtime is available") } - err := Init(latestVersion, latestVersion, "", false, "", "", test.containerRuntime, "", "") + err := Init(latestVersion, latestVersion, "", false, "", "", test.containerRuntime, "", "", nil) assert.NotNil(t, err) assert.Contains(t, err.Error(), test.containerRuntime) }) From ddf43a5f55d5900753291e0edb5d774c05213ae0 Mon Sep 17 00:00:00 2001 From: Yaron Schneider Date: Tue, 16 Jul 2024 23:42:12 -0700 Subject: [PATCH 04/25] update link (#1426) Signed-off-by: yaron2 --- README.md | 6 +++--- cmd/init.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 27edc7b88..b5670956c 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ Output should look like so: ℹ️ dapr_redis container is running. ℹ️ dapr_zipkin container is running. ℹ️ Use `docker ps` to check running containers. -✅ Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started +✅ Success! Dapr is up and running. To get started, go here: https://docs.dapr.io/getting-started ``` > Note: To see that Dapr has been installed successfully, from a command prompt run the `docker ps` command and check that the `daprio/dapr:latest`, `dapr_redis` and `dapr_zipkin` container images are all running. @@ -120,7 +120,7 @@ Output should look like so: ℹ️ daprd binary has been installed to $HOME/.dapr/bin. ℹ️ placement binary has been installed. ℹ️ scheduler binary has been installed. -✅ Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started +✅ Success! Dapr is up and running. To get started, go here: https://docs.dapr.io/getting-started ``` >Note: When initializing Dapr with the `--slim` flag only the Dapr runtime, placement, and scheduler service binaries are installed. An empty default components folder is created with no default configuration files. During `dapr run` user should use `--resources-path` (`--components-path` is deprecated and will be removed in future releases) to point to a components directory with custom configurations files or alternatively place these files in the default directory. For Linux/MacOS, the default components directory path is `$HOME/.dapr/components` and for Windows it is `%USERPROFILE%\.dapr\components`. @@ -289,7 +289,7 @@ Output should look like as follows: ℹ️ Note: To install Dapr using Helm, see here: https://docs.dapr.io/getting-started/install-dapr/#install-with-helm-advanced ✅ Deploying the Dapr control plane to your cluster... -✅ Success! Dapr has been installed to namespace dapr-system. To verify, run "dapr status -k" in your terminal. To get started, go here: https://aka.ms/dapr-getting-started +✅ Success! Dapr has been installed to namespace dapr-system. To verify, run "dapr status -k" in your terminal. To get started, go here: https://docs.dapr.io/getting-started ``` #### Supplying Helm values diff --git a/cmd/init.go b/cmd/init.go index 83b07351a..c3c4133cd 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -147,7 +147,7 @@ dapr init --runtime-path print.FailureStatusEvent(os.Stderr, err.Error()) os.Exit(1) } - print.SuccessStatusEvent(os.Stdout, fmt.Sprintf("Success! Dapr has been installed to namespace %s. To verify, run `dapr status -k' in your terminal. To get started, go here: https://aka.ms/dapr-getting-started", config.Namespace)) + print.SuccessStatusEvent(os.Stdout, fmt.Sprintf("Success! Dapr has been installed to namespace %s. To verify, run `dapr status -k' in your terminal. To get started, go here: https://docs.dapr.io/getting-started", config.Namespace)) } else { dockerNetwork := "" imageRegistryURI := "" @@ -180,7 +180,7 @@ dapr init --runtime-path print.FailureStatusEvent(os.Stderr, err.Error()) os.Exit(1) } - print.SuccessStatusEvent(os.Stdout, "Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started") + print.SuccessStatusEvent(os.Stdout, "Success! Dapr is up and running. To get started, go here: https://docs.dapr.io/getting-started") } }, } From 29d29ab54978063c9248234fc5772569af98f8c4 Mon Sep 17 00:00:00 2001 From: Josh van Leeuwen Date: Wed, 17 Jul 2024 20:13:51 +0100 Subject: [PATCH 05/25] Give scheduler a default volume, making it resilient to restarts by (#1423) * Give scheduler a default volume, making it resilient to restarts by default Signed-off-by: joshvanl * Remove dapr_scheduler volume on uninstall, gated by `--all` Signed-off-by: joshvanl * Fix containerErrs in standaone.go Signed-off-by: joshvanl * Do not attempt to delete scheduler volume if no container runtime Signed-off-by: joshvanl * Increase upgrade test timeout to 40m Signed-off-by: joshvanl --------- Signed-off-by: joshvanl Co-authored-by: Artur Souza --- Makefile | 2 +- cmd/init.go | 8 ++------ cmd/uninstall.go | 2 +- pkg/standalone/uninstall.go | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 3bcc674c1..298c35d2d 100644 --- a/Makefile +++ b/Makefile @@ -174,7 +174,7 @@ e2e-build-run-k8s: build test-e2e-k8s ################################################################################ .PHONY: test-e2e-upgrade test-e2e-upgrade: test-deps - gotestsum --jsonfile $(TEST_OUTPUT_FILE) --format standard-verbose -- -timeout 30m -count=1 -tags=e2e ./tests/e2e/upgrade/... + gotestsum --jsonfile $(TEST_OUTPUT_FILE) --format standard-verbose -- -timeout 40m -count=1 -tags=e2e ./tests/e2e/upgrade/... ################################################################################ # Build, E2E Tests for Kubernetes Upgrade # diff --git a/cmd/init.go b/cmd/init.go index c3c4133cd..e3b5c0d6e 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -171,11 +171,7 @@ dapr init --runtime-path print.FailureStatusEvent(os.Stdout, "Invalid container runtime. Supported values are docker and podman.") os.Exit(1) } - var schedVol *string - if cmd.Flags().Changed("scheduler-volume") { - schedVol = &schedulerVolume - } - err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, daprRuntimePath, schedVol) + err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURI, fromDir, containerRuntime, imageVariant, daprRuntimePath, &schedulerVolume) if err != nil { print.FailureStatusEvent(os.Stderr, err.Error()) os.Exit(1) @@ -224,7 +220,7 @@ func init() { InitCmd.Flags().String("network", "", "The Docker network on which to deploy the Dapr runtime") InitCmd.Flags().StringVarP(&fromDir, "from-dir", "", "", "Use Dapr artifacts from local directory for self-hosted installation") InitCmd.Flags().StringVarP(&imageVariant, "image-variant", "", "", "The image variant to use for the Dapr runtime, for example: mariner") - InitCmd.Flags().StringVarP(&schedulerVolume, "scheduler-volume", "", "", "Self-hosted only. Optionally specify a volume for the scheduler service data directory. By default, scheduler data is not persisted and not resilient to restarts without this flag.") + InitCmd.Flags().StringVarP(&schedulerVolume, "scheduler-volume", "", "dapr_scheduler", "Self-hosted only. Specify a volume for the scheduler service data directory.") InitCmd.Flags().BoolP("help", "h", false, "Print this help message") InitCmd.Flags().StringArrayVar(&values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)") InitCmd.Flags().String("image-registry", "", "Custom/private docker image repository URL") diff --git a/cmd/uninstall.go b/cmd/uninstall.go index b8b672a11..a2c91085b 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -99,7 +99,7 @@ func init() { UninstallCmd.Flags().BoolVarP(&uninstallKubernetes, "kubernetes", "k", false, "Uninstall Dapr from a Kubernetes cluster") UninstallCmd.Flags().BoolVarP(&uninstallDev, "dev", "", false, "Uninstall Dapr Redis and Zipking installations from Kubernetes cluster") UninstallCmd.Flags().UintVarP(&timeout, "timeout", "", 300, "The timeout for the Kubernetes uninstall") - UninstallCmd.Flags().BoolVar(&uninstallAll, "all", false, "Remove .dapr directory, Redis, Placement, Scheduler, and Zipkin containers on local machine, and CRDs on a Kubernetes cluster") + UninstallCmd.Flags().BoolVar(&uninstallAll, "all", false, "Remove .dapr directory, Redis, Placement, Scheduler (and default volume in self-hosted mode), and Zipkin containers on local machine, and CRDs on a Kubernetes cluster") UninstallCmd.Flags().String("network", "", "The Docker network from which to remove the Dapr runtime") UninstallCmd.Flags().StringVarP(&uninstallNamespace, "namespace", "n", "dapr-system", "The Kubernetes namespace to uninstall Dapr from") UninstallCmd.Flags().BoolP("help", "h", false, "Print this help message") diff --git a/pkg/standalone/uninstall.go b/pkg/standalone/uninstall.go index 0162cbe43..7eb9fecbc 100644 --- a/pkg/standalone/uninstall.go +++ b/pkg/standalone/uninstall.go @@ -63,6 +63,20 @@ func removeDockerContainer(containerErrs []error, containerName, network, runtim return containerErrs } +func removeSchedulerVolume(containerErrs []error, runtimeCmd string) []error { + print.InfoStatusEvent(os.Stdout, "Removing volume if it exists: dapr_scheduler") + _, err := utils.RunCmdAndWait( + runtimeCmd, "volume", "rm", + "--force", + "dapr_scheduler") + if err != nil { + containerErrs = append( + containerErrs, + fmt.Errorf("could not remove dapr_scheduler volume: %w", err)) + } + return containerErrs +} + func removeDir(dirPath string) error { _, err := os.Stat(dirPath) if os.IsNotExist(err) { @@ -117,6 +131,10 @@ func Uninstall(uninstallAll bool, dockerNetwork string, containerRuntime string, if err != nil { print.WarningStatusEvent(os.Stdout, "WARNING: could not delete dapr dir %s: %s", installDir, err) } + + if containerRuntimeAvailable { + containerErrs = removeSchedulerVolume(containerErrs, runtimeCmd) + } } err = errors.New("uninstall failed") From 30d888f4e67144191a25a69e6ccea3661584a734 Mon Sep 17 00:00:00 2001 From: Josh van Leeuwen Date: Thu, 18 Jul 2024 20:50:16 +0100 Subject: [PATCH 06/25] Fix dapr init scheduler (#1428) * Add E2E to validate scheduler after init. Signed-off-by: Artur Souza * Adds dapr_scheduler verify container Signed-off-by: joshvanl * Assert eventually TCP connect Signed-off-by: joshvanl * Fix eventually t check Signed-off-by: joshvanl * Write etcd-data-dir to custom path with volume Signed-off-by: joshvanl * Adds Helpers to test funcs Signed-off-by: joshvanl * Adds container name to TCP check Signed-off-by: joshvanl * Use rc.3 for scheduler Signed-off-by: joshvanl * Print container logs on failed TCP conn Signed-off-by: joshvanl * Fix params Signed-off-by: joshvanl * Use b Signed-off-by: joshvanl * Addfs `dev` flag to rc init Signed-off-by: joshvanl * Fix version check Signed-off-by: joshvanl * Skip TCP check on slim mode Signed-off-by: joshvanl * Remove debug test code Signed-off-by: joshvanl --------- Signed-off-by: Artur Souza Signed-off-by: joshvanl Co-authored-by: Artur Souza --- pkg/standalone/standalone.go | 4 +- tests/e2e/standalone/init_test.go | 82 ++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/pkg/standalone/standalone.go b/pkg/standalone/standalone.go index 4e122d35b..08ad75d5d 100644 --- a/pkg/standalone/standalone.go +++ b/pkg/standalone/standalone.go @@ -643,7 +643,7 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn "--entrypoint", "./scheduler", } if info.schedulerVolume != nil { - args = append(args, "--volume", *info.schedulerVolume+":/data-default-dapr-scheduler-server-0") + args = append(args, "--volume", *info.schedulerVolume+":/var/run/dapr/scheduler") } if info.dockerNetwork != "" { @@ -664,7 +664,7 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn ) } - args = append(args, image) + args = append(args, image, "--etcd-data-dir=/var/run/dapr/scheduler") _, err = utils.RunCmdAndWait(runtimeCmd, args...) if err != nil { diff --git a/tests/e2e/standalone/init_test.go b/tests/e2e/standalone/init_test.go index 14a688bc2..e07b405a6 100644 --- a/tests/e2e/standalone/init_test.go +++ b/tests/e2e/standalone/init_test.go @@ -18,12 +18,16 @@ package standalone_test import ( "context" + "net" "os" "path/filepath" "runtime" + "strconv" "strings" "testing" + "time" + "github.com/Masterminds/semver" "github.com/dapr/cli/tests/e2e/common" "github.com/dapr/cli/tests/e2e/spawn" "github.com/docker/docker/api/types" @@ -157,6 +161,48 @@ func TestStandaloneInit(t *testing.T) { verifyContainers(t, latestDaprRuntimeVersion) verifyBinaries(t, daprPath, latestDaprRuntimeVersion, latestDaprDashboardVersion) verifyConfigs(t, daprPath) + + placementPort := 50005 + if runtime.GOOS == "windows" { + placementPort = 6050 + } + + verifyTCPLocalhost(t, placementPort) + }) + + t.Run("init version with scheduler", func(t *testing.T) { + // Ensure a clean environment + must(t, cmdUninstall, "failed to uninstall Dapr") + + args := []string{ + "--runtime-version", "1.14.0-rc.3", + "--dev", + } + output, err := cmdInit(args...) + t.Log(output) + require.NoError(t, err, "init failed") + assert.Contains(t, output, "Success! Dapr is up and running.") + + homeDir, err := os.UserHomeDir() + require.NoError(t, err, "failed to get user home directory") + + daprPath := filepath.Join(homeDir, ".dapr") + require.DirExists(t, daprPath, "Directory %s does not exist", daprPath) + + _, latestDaprDashboardVersion := common.GetVersionsFromEnv(t, true) + verifyContainers(t, "1.14.0-rc.3") + verifyBinaries(t, daprPath, "1.14.0-rc.3", latestDaprDashboardVersion) + verifyConfigs(t, daprPath) + + placementPort := 50005 + schedulerPort := 50006 + if runtime.GOOS == "windows" { + placementPort = 6050 + schedulerPort = 6060 + } + + verifyTCPLocalhost(t, placementPort) + verifyTCPLocalhost(t, schedulerPort) }) t.Run("init without runtime-version flag with mariner images", func(t *testing.T) { @@ -187,10 +233,11 @@ func TestStandaloneInit(t *testing.T) { // Note, in case of slim installation, the containers are not installed and // this test is automatically skipped. func verifyContainers(t *testing.T, daprRuntimeVersion string) { + t.Helper() + t.Run("verifyContainers", func(t *testing.T) { if isSlimMode() { - t.Log("Skipping container verification because of slim installation") - return + t.Skip("Skipping container verification because of slim installation") } cli, err := dockerClient.NewClientWithOpts(dockerClient.FromEnv) @@ -205,6 +252,12 @@ func verifyContainers(t *testing.T, daprRuntimeVersion string) { "dapr_redis": "", } + v, err := semver.NewVersion(daprRuntimeVersion) + require.NoError(t, err) + if v.Major() >= 1 && v.Minor() >= 14 { + daprContainers["dapr_scheduler"] = daprRuntimeVersion + } + for _, container := range containers { t.Logf("Found container: %v %s %s\n", container.Names, container.Image, container.State) if container.State != "running" { @@ -233,6 +286,8 @@ func verifyContainers(t *testing.T, daprRuntimeVersion string) { // verifyBinaries ensures that the correct binaries are present in the correct path. func verifyBinaries(t *testing.T, daprPath, runtimeVersion, dashboardVersion string) { + t.Helper() + binPath := filepath.Join(daprPath, "bin") require.DirExists(t, binPath, "Directory %s does not exist", binPath) @@ -247,6 +302,8 @@ func verifyBinaries(t *testing.T, daprPath, runtimeVersion, dashboardVersion str for bin, version := range binaries { t.Run("verifyBinaries/"+bin, func(t *testing.T) { + t.Helper() + file := filepath.Join(binPath, bin) if runtime.GOOS == "windows" { file += ".exe" @@ -265,6 +322,8 @@ func verifyBinaries(t *testing.T, daprPath, runtimeVersion, dashboardVersion str // verifyConfigs ensures that the Dapr configuration and component YAMLs // are present in the correct path and have the correct values. func verifyConfigs(t *testing.T, daprPath string) { + t.Helper() + configSpec := map[interface{}]interface{}{} // tracing is not enabled in slim mode by default. if !isSlimMode() { @@ -353,3 +412,22 @@ func verifyConfigs(t *testing.T, daprPath string) { }) } } + +// verifyTCPLocalhost verifies a given localhost TCP port is being listened to. +func verifyTCPLocalhost(t *testing.T, port int) { + t.Helper() + + if isSlimMode() { + t.Skip("Skipping container verification because of slim installation") + } + + // Check that the server is up and can accept connections. + endpoint := "127.0.0.1:" + strconv.Itoa(port) + assert.EventuallyWithT(t, func(c *assert.CollectT) { + conn, err := net.Dial("tcp", endpoint) + //nolint:testifylint + if assert.NoError(c, err) { + conn.Close() + } + }, time.Second*10, time.Millisecond*10) +} From 16a513ba7ad7f5e7f4aa97e9e5ae3d530b861c29 Mon Sep 17 00:00:00 2001 From: Josh van Leeuwen Date: Fri, 19 Jul 2024 00:29:43 +0100 Subject: [PATCH 07/25] Change scheduler container data dir from `/var/run/...` to `/var/lib`. (#1429) Signed-off-by: joshvanl --- pkg/standalone/standalone.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/standalone/standalone.go b/pkg/standalone/standalone.go index 08ad75d5d..ac9e7ae97 100644 --- a/pkg/standalone/standalone.go +++ b/pkg/standalone/standalone.go @@ -643,7 +643,7 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn "--entrypoint", "./scheduler", } if info.schedulerVolume != nil { - args = append(args, "--volume", *info.schedulerVolume+":/var/run/dapr/scheduler") + args = append(args, "--volume", *info.schedulerVolume+":/var/lib/dapr/scheduler") } if info.dockerNetwork != "" { @@ -664,7 +664,7 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn ) } - args = append(args, image, "--etcd-data-dir=/var/run/dapr/scheduler") + args = append(args, image, "--etcd-data-dir=/var/lib/dapr/scheduler") _, err = utils.RunCmdAndWait(runtimeCmd, args...) if err != nil { From e72f95393cc0c66b0cc4d726f5c45f80b916b400 Mon Sep 17 00:00:00 2001 From: Cassie Coyle Date: Fri, 19 Jul 2024 12:49:08 -0600 Subject: [PATCH 08/25] Fix Scheduler Data Dir Permissions Issue (#1432) * fix w/ @joshvanl & anton Signed-off-by: Cassandra Coyle * add a . Signed-off-by: Cassandra Coyle --------- Signed-off-by: Cassandra Coyle --- pkg/standalone/standalone.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/standalone/standalone.go b/pkg/standalone/standalone.go index ac9e7ae97..bc7fba008 100644 --- a/pkg/standalone/standalone.go +++ b/pkg/standalone/standalone.go @@ -643,7 +643,16 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn "--entrypoint", "./scheduler", } if info.schedulerVolume != nil { - args = append(args, "--volume", *info.schedulerVolume+":/var/lib/dapr/scheduler") + // Don't touch this file location unless things start breaking. + // In Docker, when Docker creates a volume and mounts that volume. Docker + // assumes the file permissions of that directory if it exists in the container. + // If that directory didn't exist in the container previously, then Docker sets + // the permissions owned by root and not writeable. + // We are lucky in that the Dapr containers have a world writeable directory at + // /var/lock and can therefore mount the Docker volume here. + // TODO: update the Dapr scheduler dockerfile to create a scheduler user id writeable + // directory at /var/lib/dapr/scheduler, then update the path here. + args = append(args, "--volume", *info.schedulerVolume+":/var/lock") } if info.dockerNetwork != "" { @@ -664,7 +673,7 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn ) } - args = append(args, image, "--etcd-data-dir=/var/lib/dapr/scheduler") + args = append(args, image, "--etcd-data-dir=/var/lock/dapr/scheduler") _, err = utils.RunCmdAndWait(runtimeCmd, args...) if err != nil { From ad67ce58c4540ca8871f087665733f8b7a019231 Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Mon, 22 Jul 2024 18:38:06 -0500 Subject: [PATCH 09/25] Add dapr scheduler server to the status command (#1434) Signed-off-by: Anton Troshin --- pkg/kubernetes/status.go | 1 + pkg/kubernetes/status_test.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/pkg/kubernetes/status.go b/pkg/kubernetes/status.go index acd4773c4..3d364c6ee 100644 --- a/pkg/kubernetes/status.go +++ b/pkg/kubernetes/status.go @@ -33,6 +33,7 @@ var controlPlaneLabels = []string{ "dapr-placement-server", "dapr-sidecar-injector", "dapr-dashboard", + "dapr-scheduler-server", } type StatusClient struct { diff --git a/pkg/kubernetes/status_test.go b/pkg/kubernetes/status_test.go index 3fc297ab4..a2f2778ab 100644 --- a/pkg/kubernetes/status_test.go +++ b/pkg/kubernetes/status_test.go @@ -233,6 +233,9 @@ func TestControlPlaneServices(t *testing.T) { {"dapr-sidecar-injector-74648c9dcb-5bsmn", "dapr-sidecar-injector", daprImageTag}, {"dapr-sidecar-injector-74648c9dcb-6bsmn", "dapr-sidecar-injector", daprImageTag}, {"dapr-sidecar-injector-74648c9dcb-7bsmn", "dapr-sidecar-injector", daprImageTag}, + {"dapr-scheduler-server-0", "dapr-scheduler-server", daprImageTag}, + {"dapr-scheduler-server-1", "dapr-scheduler-server", daprImageTag}, + {"dapr-scheduler-server-2", "dapr-scheduler-server", daprImageTag}, } expectedReplicas := map[string]int{} From fecf47d75237e4856a5107fac821dc646a5264fa Mon Sep 17 00:00:00 2001 From: Yaron Schneider Date: Tue, 23 Jul 2024 15:49:14 -0700 Subject: [PATCH 10/25] pin bitnami chart version for redis (#1437) Signed-off-by: yaron2 --- pkg/kubernetes/kubernetes.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/kubernetes/kubernetes.go b/pkg/kubernetes/kubernetes.go index f6bd78e5a..013247bd7 100644 --- a/pkg/kubernetes/kubernetes.go +++ b/pkg/kubernetes/kubernetes.go @@ -40,6 +40,7 @@ const ( daprReleaseName = "dapr" dashboardReleaseName = "dapr-dashboard" latestVersion = "latest" + bitnamiStableVersion = "17.14.5" // dev mode constants. thirdPartyDevNamespace = "default" @@ -99,9 +100,10 @@ func Init(config InitConfiguration) error { if config.EnableDev { redisChartVals := []string{ "image.tag=" + redisVersion, + "replica.replicaCount=0", } - err = installThirdPartyWithConsole(redisReleaseName, redisChartName, latestVersion, bitnamiHelmRepo, "Dapr Redis", redisChartVals, config) + err = installThirdPartyWithConsole(redisReleaseName, redisChartName, bitnamiStableVersion, bitnamiHelmRepo, "Dapr Redis", redisChartVals, config) if err != nil { return err } @@ -124,7 +126,7 @@ func installThirdPartyWithConsole(releaseName, chartName, releaseVersion, helmRe defer installSpinning(print.Failure) // releaseVersion of chart will always be latest version. - err := installThirdParty(releaseName, chartName, latestVersion, helmRepo, chartValues, config) + err := installThirdParty(releaseName, chartName, releaseVersion, helmRepo, chartValues, config) if err != nil { return err } @@ -214,7 +216,7 @@ func getHelmChart(version, releaseName, helmRepo string, config *helm.Configurat pull.Settings = &cli.EnvSettings{} - if version != latestVersion && (releaseName == daprReleaseName || releaseName == dashboardReleaseName) { + if version != latestVersion && (releaseName == daprReleaseName || releaseName == dashboardReleaseName || releaseName == redisChartName) { pull.Version = chartVersion(version) } From 027f5da3e1414b66d0b0e57e4fa31f437579295d Mon Sep 17 00:00:00 2001 From: Yaron Schneider Date: Thu, 25 Jul 2024 09:58:14 -0700 Subject: [PATCH 11/25] update redis version (#1439) Signed-off-by: yaron2 --- pkg/kubernetes/kubernetes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/kubernetes/kubernetes.go b/pkg/kubernetes/kubernetes.go index 013247bd7..54f79a578 100644 --- a/pkg/kubernetes/kubernetes.go +++ b/pkg/kubernetes/kubernetes.go @@ -48,7 +48,7 @@ const ( redisChartName = "redis" zipkinReleaseName = "dapr-dev-zipkin" redisReleaseName = "dapr-dev-redis" - redisVersion = "6.2" + redisVersion = "6.2.11" bitnamiHelmRepo = "https://charts.bitnami.com/bitnami" daprHelmRepo = "https://dapr.github.io/helm-charts" zipkinHelmRepo = "https://openzipkin.github.io/zipkin" From aa0436ebe0bf8876f313af928af3620096c1fc20 Mon Sep 17 00:00:00 2001 From: Rishab Kumar <45825464+rishabkumar7@users.noreply.github.com> Date: Tue, 6 Aug 2024 15:08:58 -0600 Subject: [PATCH 12/25] Added new holopin cli badge (#1399) Signed-off-by: Rishab Kumar Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> Co-authored-by: Mike Nguyen --- .github/holopin.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/holopin.yml b/.github/holopin.yml index 44a7f0c8a..5e8117599 100644 --- a/.github/holopin.yml +++ b/.github/holopin.yml @@ -1,6 +1,6 @@ organization: dapr -defaultSticker: clmjkxscc122740fl0mkmb7egi +defaultSticker: clutq4bgp107990fl1h4m7jp3b stickers: - - id: clmjkxscc122740fl0mkmb7egi - alias: ghc2023 + id: clutq4bgp107990fl1h4m7jp3b + alias: cli-badge From e08443b9b3e69fcead2c02340af7c4201aaf159a Mon Sep 17 00:00:00 2001 From: Josh van Leeuwen Date: Thu, 15 Aug 2024 15:53:26 -0500 Subject: [PATCH 13/25] Remove Docker client dependency from standalone run (#1443) Signed-off-by: joshvanl --- pkg/standalone/run.go | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/pkg/standalone/run.go b/pkg/standalone/run.go index 3205b3599..8fc89e412 100644 --- a/pkg/standalone/run.go +++ b/pkg/standalone/run.go @@ -14,7 +14,6 @@ limitations under the License. package standalone import ( - "context" "fmt" "net" "os" @@ -24,8 +23,6 @@ import ( "strconv" "strings" - dockerClient "github.com/docker/docker/client" - "github.com/Pallinder/sillyname-go" "github.com/phayes/freeport" "gopkg.in/yaml.v2" @@ -141,27 +138,21 @@ func (config *RunConfig) validatePlacementHostAddr() error { } func (config *RunConfig) validateSchedulerHostAddr() error { - // If the scheduler isn't running - don't add the flag to the runtime cmd. - docker, err := dockerClient.NewClientWithOpts() - if err != nil { - return err + schedulerHostAddr := config.SchedulerHostAddress + if len(schedulerHostAddr) == 0 { + return nil } - _, err = docker.ContainerInspect(context.Background(), "dapr_scheduler") - if err == nil { - schedulerHostAddr := config.SchedulerHostAddress - if len(schedulerHostAddr) == 0 { - schedulerHostAddr = "localhost" - } - if indx := strings.Index(schedulerHostAddr, ":"); indx == -1 { - if runtime.GOOS == daprWindowsOS { - schedulerHostAddr = fmt.Sprintf("%s:6060", schedulerHostAddr) - } else { - schedulerHostAddr = fmt.Sprintf("%s:50006", schedulerHostAddr) - } + + if indx := strings.Index(schedulerHostAddr, ":"); indx == -1 { + if runtime.GOOS == daprWindowsOS { + schedulerHostAddr = fmt.Sprintf("%s:6060", schedulerHostAddr) + } else { + schedulerHostAddr = fmt.Sprintf("%s:50006", schedulerHostAddr) } - config.SchedulerHostAddress = schedulerHostAddr - return nil } + + config.SchedulerHostAddress = schedulerHostAddr + return nil } From a3571c8464b08bba77a05706386c2e5a541a7385 Mon Sep 17 00:00:00 2001 From: Yetkin Timocin Date: Tue, 1 Oct 2024 09:17:12 -0700 Subject: [PATCH 14/25] Fix a typo (#1453) Signed-off-by: ytimocin --- cmd/stop.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/stop.go b/cmd/stop.go index fe2141092..dd76baf13 100644 --- a/cmd/stop.go +++ b/cmd/stop.go @@ -98,7 +98,7 @@ dapr stop --run-file /path/to/directory -k func init() { StopCmd.Flags().StringVarP(&stopAppID, "app-id", "a", "", "The application id to be stopped") StopCmd.Flags().StringVarP(&runFilePath, "run-file", "f", "", "Path to the run template file for the list of apps to stop") - StopCmd.Flags().BoolVarP(&stopK8s, "kubernetes", "k", false, "Stop deployments in Kunernetes based on multi-app run file") + StopCmd.Flags().BoolVarP(&stopK8s, "kubernetes", "k", false, "Stop deployments in Kubernetes based on multi-app run file") StopCmd.Flags().BoolP("help", "h", false, "Print this help message") RootCmd.AddCommand(StopCmd) } From db712e7eed983ea38ad1bed369b36b71dfc70c64 Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 1 Oct 2024 11:19:35 -0500 Subject: [PATCH 15/25] Fixing e2e tests, podman and scheduler fail with mariner images (#1450) * Fix standalone e2e tests Fix podman e2e install Fix scheduler start failure on standalone mariner image variant Signed-off-by: Anton Troshin * fix test Signed-off-by: Anton Troshin * revert Signed-off-by: Anton Troshin * Fix podman machine settings Add cleanups Remove parallel tests Fix mariner volume mount location Remove old build tags Signed-off-by: Anton Troshin --------- Signed-off-by: Anton Troshin --- .github/workflows/kind_e2e.yaml | 3 +- .github/workflows/self_hosted_e2e.yaml | 5 ++- pkg/standalone/standalone.go | 12 +++++- tests/e2e/standalone/commands.go | 1 - tests/e2e/standalone/init_negative_test.go | 5 --- .../standalone/init_run_custom_path_test.go | 1 - tests/e2e/standalone/init_test.go | 16 ++++---- tests/e2e/standalone/invoke_test.go | 1 - tests/e2e/standalone/list_test.go | 8 +++- tests/e2e/standalone/publish_test.go | 1 - tests/e2e/standalone/run_template_test.go | 26 ++++++------- tests/e2e/standalone/run_test.go | 1 - tests/e2e/standalone/stop_test.go | 10 ++++- .../standalone/stop_with_run_template_test.go | 21 +++++++--- tests/e2e/standalone/uninstall_test.go | 1 - tests/e2e/standalone/utils.go | 38 ++++++++++++++++++- tests/e2e/standalone/version_test.go | 1 - .../standalone/windows_run_template_test.go | 2 - 18 files changed, 102 insertions(+), 51 deletions(-) diff --git a/.github/workflows/kind_e2e.yaml b/.github/workflows/kind_e2e.yaml index af559b29a..ca5a110e2 100644 --- a/.github/workflows/kind_e2e.yaml +++ b/.github/workflows/kind_e2e.yaml @@ -50,11 +50,10 @@ jobs: name: E2E tests for K8s (KinD) runs-on: ubuntu-latest env: - DAPR_RUNTIME_PINNED_VERSION: 1.13.0-rc.2 + DAPR_RUNTIME_PINNED_VERSION: 1.13.5 DAPR_DASHBOARD_PINNED_VERSION: 0.14.0 DAPR_RUNTIME_LATEST_STABLE_VERSION: DAPR_DASHBOARD_LATEST_STABLE_VERSION: - DAPR_TGZ: dapr-1.13.0-rc.2.tgz strategy: fail-fast: false # Keep running if one leg fails. matrix: diff --git a/.github/workflows/self_hosted_e2e.yaml b/.github/workflows/self_hosted_e2e.yaml index c8c0441ba..3e67f4cef 100644 --- a/.github/workflows/self_hosted_e2e.yaml +++ b/.github/workflows/self_hosted_e2e.yaml @@ -38,12 +38,12 @@ jobs: GOARCH: ${{ matrix.target_arch }} GOPROXY: https://proxy.golang.org ARCHIVE_OUTDIR: dist/archives - DAPR_RUNTIME_PINNED_VERSION: "1.13.0-rc.2" + DAPR_RUNTIME_PINNED_VERSION: "1.13.5" DAPR_DASHBOARD_PINNED_VERSION: 0.14.0 DAPR_RUNTIME_LATEST_STABLE_VERSION: "" DAPR_DASHBOARD_LATEST_STABLE_VERSION: "" GOLANG_PROTOBUF_REGISTRATION_CONFLICT: warn - PODMAN_VERSION: 4.4.4 + PODMAN_VERSION: 4.9.3 strategy: # TODO: Remove this when our E2E tests are stable for podman on MacOS. fail-fast: false # Keep running if one leg fails. @@ -122,6 +122,7 @@ jobs: sudo podman-mac-helper install podman machine init podman machine start --log-level debug + podman machine ssh sudo sysctl -w kernel.keys.maxkeys=20000 echo "CONTAINER_RUNTIME=podman" >> $GITHUB_ENV - name: Determine latest Dapr Runtime version including Pre-releases if: github.base_ref == 'master' diff --git a/pkg/standalone/standalone.go b/pkg/standalone/standalone.go index bc7fba008..8dcca112d 100644 --- a/pkg/standalone/standalone.go +++ b/pkg/standalone/standalone.go @@ -652,7 +652,11 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn // /var/lock and can therefore mount the Docker volume here. // TODO: update the Dapr scheduler dockerfile to create a scheduler user id writeable // directory at /var/lib/dapr/scheduler, then update the path here. - args = append(args, "--volume", *info.schedulerVolume+":/var/lock") + if strings.EqualFold(info.imageVariant, "mariner") { + args = append(args, "--volume", *info.schedulerVolume+":/var/tmp") + } else { + args = append(args, "--volume", *info.schedulerVolume+":/var/lock") + } } if info.dockerNetwork != "" { @@ -673,7 +677,11 @@ func runSchedulerService(wg *sync.WaitGroup, errorChan chan<- error, info initIn ) } - args = append(args, image, "--etcd-data-dir=/var/lock/dapr/scheduler") + if strings.EqualFold(info.imageVariant, "mariner") { + args = append(args, image, "--etcd-data-dir=/var/tmp/dapr/scheduler") + } else { + args = append(args, image, "--etcd-data-dir=/var/lock/dapr/scheduler") + } _, err = utils.RunCmdAndWait(runtimeCmd, args...) if err != nil { diff --git a/tests/e2e/standalone/commands.go b/tests/e2e/standalone/commands.go index 7e35f34e8..efa1de751 100644 --- a/tests/e2e/standalone/commands.go +++ b/tests/e2e/standalone/commands.go @@ -1,5 +1,4 @@ //go:build e2e || template -// +build e2e template /* Copyright 2022 The Dapr Authors diff --git a/tests/e2e/standalone/init_negative_test.go b/tests/e2e/standalone/init_negative_test.go index 9fe67d5ee..adfa6549d 100644 --- a/tests/e2e/standalone/init_negative_test.go +++ b/tests/e2e/standalone/init_negative_test.go @@ -1,5 +1,4 @@ //go:build e2e && !template -// +build e2e,!template /* Copyright 2022 The Dapr Authors @@ -33,7 +32,6 @@ func TestStandaloneInitNegatives(t *testing.T) { require.NoError(t, err, "expected no error on querying for os home dir") t.Run("run without install", func(t *testing.T) { - t.Parallel() output, err := cmdRun("") require.Error(t, err, "expected error status on run without install") path := filepath.Join(homeDir, ".dapr", "components") @@ -45,21 +43,18 @@ func TestStandaloneInitNegatives(t *testing.T) { }) t.Run("list without install", func(t *testing.T) { - t.Parallel() output, err := cmdList("") require.NoError(t, err, "expected no error status on list without install") require.Equal(t, "No Dapr instances found.\n", output) }) t.Run("stop without install", func(t *testing.T) { - t.Parallel() output, err := cmdStopWithAppID("test") require.NoError(t, err, "expected no error on stop without install") require.Contains(t, output, "failed to stop app id test: couldn't find app id test", "expected output to match") }) t.Run("uninstall without install", func(t *testing.T) { - t.Parallel() output, err := cmdUninstall() require.NoError(t, err, "expected no error on uninstall without install") require.Contains(t, output, "Removing Dapr from your machine...", "expected output to contain message") diff --git a/tests/e2e/standalone/init_run_custom_path_test.go b/tests/e2e/standalone/init_run_custom_path_test.go index 2b684d01b..da7550a89 100644 --- a/tests/e2e/standalone/init_run_custom_path_test.go +++ b/tests/e2e/standalone/init_run_custom_path_test.go @@ -1,5 +1,4 @@ //go:build e2e && !template -// +build e2e,!template /* Copyright 2022 The Dapr Authors diff --git a/tests/e2e/standalone/init_test.go b/tests/e2e/standalone/init_test.go index e07b405a6..3497cc98c 100644 --- a/tests/e2e/standalone/init_test.go +++ b/tests/e2e/standalone/init_test.go @@ -1,5 +1,4 @@ //go:build e2e && !template -// +build e2e,!template /* Copyright 2022 The Dapr Authors @@ -167,15 +166,17 @@ func TestStandaloneInit(t *testing.T) { placementPort = 6050 } - verifyTCPLocalhost(t, placementPort) + verifyTCPLocalhost(t, placementPort) }) t.Run("init version with scheduler", func(t *testing.T) { // Ensure a clean environment must(t, cmdUninstall, "failed to uninstall Dapr") + latestDaprRuntimeVersion, latestDaprDashboardVersion := common.GetVersionsFromEnv(t, true) + args := []string{ - "--runtime-version", "1.14.0-rc.3", + "--runtime-version", latestDaprRuntimeVersion, "--dev", } output, err := cmdInit(args...) @@ -189,9 +190,8 @@ func TestStandaloneInit(t *testing.T) { daprPath := filepath.Join(homeDir, ".dapr") require.DirExists(t, daprPath, "Directory %s does not exist", daprPath) - _, latestDaprDashboardVersion := common.GetVersionsFromEnv(t, true) - verifyContainers(t, "1.14.0-rc.3") - verifyBinaries(t, daprPath, "1.14.0-rc.3", latestDaprDashboardVersion) + verifyContainers(t, latestDaprRuntimeVersion) + verifyBinaries(t, daprPath, latestDaprRuntimeVersion, latestDaprDashboardVersion) verifyConfigs(t, daprPath) placementPort := 50005 @@ -201,8 +201,8 @@ func TestStandaloneInit(t *testing.T) { schedulerPort = 6060 } - verifyTCPLocalhost(t, placementPort) - verifyTCPLocalhost(t, schedulerPort) + verifyTCPLocalhost(t, placementPort) + verifyTCPLocalhost(t, schedulerPort) }) t.Run("init without runtime-version flag with mariner images", func(t *testing.T) { diff --git a/tests/e2e/standalone/invoke_test.go b/tests/e2e/standalone/invoke_test.go index 812d0ea4b..c21ec212b 100644 --- a/tests/e2e/standalone/invoke_test.go +++ b/tests/e2e/standalone/invoke_test.go @@ -1,5 +1,4 @@ //go:build e2e && !template -// +build e2e,!template /* Copyright 2022 The Dapr Authors diff --git a/tests/e2e/standalone/list_test.go b/tests/e2e/standalone/list_test.go index a33345644..527642163 100644 --- a/tests/e2e/standalone/list_test.go +++ b/tests/e2e/standalone/list_test.go @@ -1,5 +1,4 @@ //go:build e2e && !template -// +build e2e,!template /* Copyright 2022 The Dapr Authors @@ -137,6 +136,13 @@ func TestStandaloneList(t *testing.T) { t.Log(output) require.NoError(t, err, "expected no error status on list") require.Equal(t, "No Dapr instances found.\n", output) + + // This test is skipped on Windows, but just in case, try to terminate dashboard process only on non-Windows OSs + // stopProcess uses kill command, won't work on windows + if runtime.GOOS != "windows" { + err = stopProcess("dashboard", "--port", "5555") + require.NoError(t, err, "failed to stop dashboard process") + } }) } diff --git a/tests/e2e/standalone/publish_test.go b/tests/e2e/standalone/publish_test.go index e7e334a75..845eb5576 100644 --- a/tests/e2e/standalone/publish_test.go +++ b/tests/e2e/standalone/publish_test.go @@ -1,5 +1,4 @@ //go:build e2e && !template -// +build e2e,!template /* Copyright 2022 The Dapr Authors diff --git a/tests/e2e/standalone/run_template_test.go b/tests/e2e/standalone/run_template_test.go index 4ef006b61..907fd8fc0 100644 --- a/tests/e2e/standalone/run_template_test.go +++ b/tests/e2e/standalone/run_template_test.go @@ -1,6 +1,4 @@ //go:build !windows && (e2e || template) -// +build !windows -// +build e2e template /* Copyright 2023 The Dapr Authors @@ -23,7 +21,6 @@ import ( "context" "fmt" "io/ioutil" - "os" "path/filepath" "strings" "testing" @@ -43,6 +40,7 @@ type AppTestOutput struct { } func TestRunWithTemplateFile(t *testing.T) { + cleanUpLogs() ensureDaprInstallation(t) t.Cleanup(func() { // remove dapr installation after all tests in this function. @@ -54,8 +52,7 @@ func TestRunWithTemplateFile(t *testing.T) { runFilePath := "../testdata/run-template-files/wrong_emit_metrics_app_dapr.yaml" t.Cleanup(func() { // assumption in the test is that there is only one set of app and daprd logs in the logs directory. - os.RemoveAll("../../apps/emit-metrics/.dapr/logs") - os.RemoveAll("../../apps/processor/.dapr/logs") + cleanUpLogs() stopAllApps(t, runFilePath) }) args := []string{ @@ -104,8 +101,7 @@ func TestRunWithTemplateFile(t *testing.T) { runFilePath := "../testdata/run-template-files/dapr.yaml" t.Cleanup(func() { // assumption in the test is that there is only one set of app and daprd logs in the logs directory. - os.RemoveAll("../../apps/emit-metrics/.dapr/logs") - os.RemoveAll("../../apps/processor/.dapr/logs") + cleanUpLogs() stopAllApps(t, runFilePath) }) args := []string{ @@ -161,8 +157,7 @@ func TestRunWithTemplateFile(t *testing.T) { runFilePath := "../testdata/run-template-files/env_var_not_set_dapr.yaml" t.Cleanup(func() { // assumption in the test is that there is only one set of app and daprd logs in the logs directory. - os.RemoveAll("../../apps/emit-metrics/.dapr/logs") - os.RemoveAll("../../apps/processor/.dapr/logs") + cleanUpLogs() stopAllApps(t, runFilePath) }) args := []string{ @@ -212,8 +207,7 @@ func TestRunWithTemplateFile(t *testing.T) { runFilePath := "../testdata/run-template-files/no_app_command.yaml" t.Cleanup(func() { // assumption in the test is that there is only one set of app and daprd logs in the logs directory. - os.RemoveAll("../../apps/emit-metrics/.dapr/logs") - os.RemoveAll("../../apps/processor/.dapr/logs") + cleanUpLogs() stopAllApps(t, runFilePath) }) args := []string{ @@ -264,8 +258,7 @@ func TestRunWithTemplateFile(t *testing.T) { runFilePath := "../testdata/run-template-files/empty_app_command.yaml" t.Cleanup(func() { // assumption in the test is that there is only one set of app and daprd logs in the logs directory. - os.RemoveAll("../../apps/emit-metrics/.dapr/logs") - os.RemoveAll("../../apps/processor/.dapr/logs") + cleanUpLogs() stopAllApps(t, runFilePath) }) args := []string{ @@ -313,8 +306,7 @@ func TestRunWithTemplateFile(t *testing.T) { runFilePath := "../testdata/run-template-files/app_output_to_file_and_console.yaml" t.Cleanup(func() { // assumption in the test is that there is only one set of app and daprd logs in the logs directory. - os.RemoveAll("../../apps/emit-metrics/.dapr/logs") - os.RemoveAll("../../apps/processor/.dapr/logs") + cleanUpLogs() stopAllApps(t, runFilePath) }) args := []string{ @@ -372,6 +364,10 @@ func TestRunTemplateFileWithoutDaprInit(t *testing.T) { // remove any dapr installation before this test. must(t, cmdUninstall, "failed to uninstall Dapr") t.Run("valid template file without dapr init", func(t *testing.T) { + t.Cleanup(func() { + // assumption in the test is that there is only one set of app and daprd logs in the logs directory. + cleanUpLogs() + }) args := []string{ "-f", "../testdata/run-template-files/no_app_command.yaml", } diff --git a/tests/e2e/standalone/run_test.go b/tests/e2e/standalone/run_test.go index 934f4fd0c..7e95696e8 100644 --- a/tests/e2e/standalone/run_test.go +++ b/tests/e2e/standalone/run_test.go @@ -1,5 +1,4 @@ //go:build e2e && !template -// +build e2e,!template /* Copyright 2022 The Dapr Authors diff --git a/tests/e2e/standalone/stop_test.go b/tests/e2e/standalone/stop_test.go index c14ac364a..f0c25b30b 100644 --- a/tests/e2e/standalone/stop_test.go +++ b/tests/e2e/standalone/stop_test.go @@ -1,5 +1,4 @@ //go:build e2e && !template -// +build e2e,!template /* Copyright 2022 The Dapr Authors @@ -18,6 +17,7 @@ package standalone_test import ( "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -25,6 +25,14 @@ import ( func TestStandaloneStop(t *testing.T) { ensureDaprInstallation(t) + + time.Sleep(5 * time.Second) + + t.Cleanup(func() { + // remove dapr installation after all tests in this function. + must(t, cmdUninstall, "failed to uninstall Dapr") + }) + executeAgainstRunningDapr(t, func() { t.Run("stop", func(t *testing.T) { output, err := cmdStopWithAppID("dapr_e2e_stop") diff --git a/tests/e2e/standalone/stop_with_run_template_test.go b/tests/e2e/standalone/stop_with_run_template_test.go index ae4adaf14..ce400284f 100644 --- a/tests/e2e/standalone/stop_with_run_template_test.go +++ b/tests/e2e/standalone/stop_with_run_template_test.go @@ -1,6 +1,4 @@ //go:build !windows && (e2e || template) -// +build !windows -// +build e2e template /* Copyright 2023 The Dapr Authors @@ -22,7 +20,6 @@ package standalone_test import ( "encoding/json" "fmt" - "os" "testing" "time" @@ -31,6 +28,9 @@ import ( ) func TestStopAppsStartedWithRunTemplate(t *testing.T) { + // clean up logs before starting the tests + cleanUpLogs() + ensureDaprInstallation(t) t.Cleanup(func() { // remove dapr installation after all tests in this function. @@ -38,6 +38,9 @@ func TestStopAppsStartedWithRunTemplate(t *testing.T) { }) t.Run("stop apps by passing run template file", func(t *testing.T) { + t.Cleanup(func() { + cleanUpLogs() + }) go ensureAllAppsStartedWithRunTemplate(t) time.Sleep(10 * time.Second) cliPID := getCLIPID(t) @@ -50,6 +53,9 @@ func TestStopAppsStartedWithRunTemplate(t *testing.T) { }) t.Run("stop apps by passing a directory containing dapr.yaml", func(t *testing.T) { + t.Cleanup(func() { + cleanUpLogs() + }) go ensureAllAppsStartedWithRunTemplate(t) time.Sleep(10 * time.Second) cliPID := getCLIPID(t) @@ -60,6 +66,9 @@ func TestStopAppsStartedWithRunTemplate(t *testing.T) { }) t.Run("stop apps by passing an invalid directory", func(t *testing.T) { + t.Cleanup(func() { + cleanUpLogs() + }) go ensureAllAppsStartedWithRunTemplate(t) time.Sleep(10 * time.Second) output, err := cmdStopWithRunTemplate("../testdata/invalid-dir") @@ -72,6 +81,9 @@ func TestStopAppsStartedWithRunTemplate(t *testing.T) { }) t.Run("stop apps started with run template", func(t *testing.T) { + t.Cleanup(func() { + cleanUpLogs() + }) go ensureAllAppsStartedWithRunTemplate(t) time.Sleep(10 * time.Second) cliPID := getCLIPID(t) @@ -95,8 +107,7 @@ func ensureAllAppsStartedWithRunTemplate(t *testing.T) { func tearDownTestSetup(t *testing.T) { // remove dapr installation after all tests in this function. must(t, cmdUninstall, "failed to uninstall Dapr") - os.RemoveAll("../../apps/emit-metrics/.dapr/logs") - os.RemoveAll("../../apps/processor/.dapr/logs") + cleanUpLogs() } func getCLIPID(t *testing.T) string { diff --git a/tests/e2e/standalone/uninstall_test.go b/tests/e2e/standalone/uninstall_test.go index ae1545a99..5d9cf65e3 100644 --- a/tests/e2e/standalone/uninstall_test.go +++ b/tests/e2e/standalone/uninstall_test.go @@ -1,5 +1,4 @@ //go:build e2e && !template -// +build e2e,!template /* Copyright 2022 The Dapr Authors diff --git a/tests/e2e/standalone/utils.go b/tests/e2e/standalone/utils.go index 87d2fa78c..b41b50754 100644 --- a/tests/e2e/standalone/utils.go +++ b/tests/e2e/standalone/utils.go @@ -1,5 +1,4 @@ //go:build e2e || template -// +build e2e template /* Copyright 2022 The Dapr Authors @@ -157,3 +156,40 @@ func containerRuntime() string { } return "" } + +func getRunningProcesses() []string { + cmd := exec.Command("ps", "-o", "pid,command") + output, err := cmd.Output() + if err != nil { + return nil + } + + processes := strings.Split(string(output), "\n") + + // clean the process output whitespace + for i, process := range processes { + processes[i] = strings.TrimSpace(process) + } + return processes +} + +func stopProcess(args ...string) error { + processCommand := strings.Join(args, " ") + processes := getRunningProcesses() + for _, process := range processes { + if strings.Contains(process, processCommand) { + processSplit := strings.SplitN(process, " ", 2) + cmd := exec.Command("kill", "-9", processSplit[0]) + err := cmd.Run() + if err != nil { + return err + } + } + } + return nil +} + +func cleanUpLogs() { + os.RemoveAll("../../apps/emit-metrics/.dapr/logs") + os.RemoveAll("../../apps/processor/.dapr/logs") +} diff --git a/tests/e2e/standalone/version_test.go b/tests/e2e/standalone/version_test.go index 269389998..c3372a168 100644 --- a/tests/e2e/standalone/version_test.go +++ b/tests/e2e/standalone/version_test.go @@ -1,5 +1,4 @@ //go:build e2e && !template -// +build e2e,!template /* Copyright 2022 The Dapr Authors diff --git a/tests/e2e/standalone/windows_run_template_test.go b/tests/e2e/standalone/windows_run_template_test.go index c570f94c7..b53f64a3b 100644 --- a/tests/e2e/standalone/windows_run_template_test.go +++ b/tests/e2e/standalone/windows_run_template_test.go @@ -1,6 +1,4 @@ //go:build windows && (e2e || template) -// +build windows -// +build e2e template /* Copyright 2023 The Dapr Authors From 1f080952a512eb9804e6b385c1b2a5437112d21b Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 5 Nov 2024 00:56:45 -0600 Subject: [PATCH 16/25] Add logs Signed-off-by: Anton Troshin --- tests/e2e/common/common.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/e2e/common/common.go b/tests/e2e/common/common.go index e52412944..9dd93eedf 100644 --- a/tests/e2e/common/common.go +++ b/tests/e2e/common/common.go @@ -1181,8 +1181,10 @@ func waitAllPodsRunning(t *testing.T, namespace string, haEnabled bool, done, po Limit: 100, }) require.NoError(t, err, "error getting pods list from k8s") + t.Logf("items %d", len(list.Items)) countOfReadyPods := 0 for _, item := range list.Items { + t.Log(item.ObjectMeta.Name) // Check pods running, and containers ready. if item.Status.Phase == core_v1.PodRunning && len(item.Status.ContainerStatuses) != 0 { size := len(item.Status.ContainerStatuses) From 086a3b9adb57a024df5ff240f6d3429012e457eb Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 5 Nov 2024 01:09:47 -0600 Subject: [PATCH 17/25] Fix number of pods to wait in tests Signed-off-by: Anton Troshin --- tests/e2e/common/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/common/common.go b/tests/e2e/common/common.go index 9dd93eedf..8f5c9be9b 100644 --- a/tests/e2e/common/common.go +++ b/tests/e2e/common/common.go @@ -47,7 +47,7 @@ const ( ClusterRoleBindings numHAPods = 13 - numNonHAPods = 5 + numNonHAPods = 6 thirdPartyDevNamespace = "default" devRedisReleaseName = "dapr-dev-redis" From 376690b43e63598298fa7ca58be833946c19fcae Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 5 Nov 2024 01:35:53 -0600 Subject: [PATCH 18/25] Fix number of HA mode pods to wait in tests Signed-off-by: Anton Troshin --- tests/e2e/common/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/common/common.go b/tests/e2e/common/common.go index 8f5c9be9b..a939c71cd 100644 --- a/tests/e2e/common/common.go +++ b/tests/e2e/common/common.go @@ -46,7 +46,7 @@ const ( ClusterRoles ClusterRoleBindings - numHAPods = 13 + numHAPods = 16 numNonHAPods = 6 thirdPartyDevNamespace = "default" From 9bc96c2fa0076812d49343863762616199af7018 Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 5 Nov 2024 02:11:25 -0600 Subject: [PATCH 19/25] Fix test Signed-off-by: Anton Troshin --- tests/e2e/standalone/run_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/standalone/run_test.go b/tests/e2e/standalone/run_test.go index 7e95696e8..fa75f3187 100644 --- a/tests/e2e/standalone/run_test.go +++ b/tests/e2e/standalone/run_test.go @@ -53,7 +53,7 @@ func TestStandaloneRun(t *testing.T) { output, err := cmdRun(path, "--dapr-internal-grpc-port", "9999", "--", "bash", "-c", "echo test") t.Log(output) require.NoError(t, err, "run failed") - assert.Contains(t, output, "Internal gRPC server is running on port 9999") + assert.Contains(t, output, "Internal gRPC server is running on :9999") assert.Contains(t, output, "Exited App successfully") assert.Contains(t, output, "Exited Dapr successfully") assert.NotContains(t, output, "Could not update sidecar metadata for cliPID") From d781b03002d588b87a88a0c83b52cb40e076abdf Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 5 Nov 2024 03:07:52 -0600 Subject: [PATCH 20/25] Change podman mount to home Signed-off-by: Anton Troshin --- .github/workflows/self_hosted_e2e.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/self_hosted_e2e.yaml b/.github/workflows/self_hosted_e2e.yaml index 3e67f4cef..8678663b2 100644 --- a/.github/workflows/self_hosted_e2e.yaml +++ b/.github/workflows/self_hosted_e2e.yaml @@ -120,7 +120,7 @@ jobs: # Start podman machine sudo podman-mac-helper install - podman machine init + podman machine init -v $HOME:$HOME podman machine start --log-level debug podman machine ssh sudo sysctl -w kernel.keys.maxkeys=20000 echo "CONTAINER_RUNTIME=podman" >> $GITHUB_ENV From 1152a1ef55e34a5991cb66ab61aa733ddd36041d Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 5 Nov 2024 16:22:01 -0600 Subject: [PATCH 21/25] Add placement and scheduler in slim mode self-hosted tests Signed-off-by: Anton Troshin --- tests/e2e/standalone/commands.go | 43 ++++++++++++++++++++++++++++++++ tests/e2e/standalone/run_test.go | 15 +++++++++++ 2 files changed, 58 insertions(+) diff --git a/tests/e2e/standalone/commands.go b/tests/e2e/standalone/commands.go index efa1de751..c75bc7171 100644 --- a/tests/e2e/standalone/commands.go +++ b/tests/e2e/standalone/commands.go @@ -18,8 +18,10 @@ package standalone_test import ( "context" "fmt" + "path/filepath" "strings" + "github.com/dapr/cli/pkg/standalone" "github.com/dapr/cli/tests/e2e/common" "github.com/dapr/cli/tests/e2e/spawn" "github.com/dapr/cli/utils" @@ -46,6 +48,47 @@ func cmdDashboard(ctx context.Context, port string) error { return fmt.Errorf("Dashboard could not be started: %s", errOutput) } +func cmdProcess(ctx context.Context, executable string, log func(args ...any), args ...string) (string, error) { + path, err := GetExecutablePath(executable) + if err != nil { + return "", err + } + + stdOutChan, stdErrChan, err := spawn.CommandWithContext(ctx, path, args...) + if err != nil { + return "", err + } + + if log != nil { + go func() { + for { + select { + case output := <-stdOutChan: + if output != "" { + log(executable + ": " + output) + } + case output := <-stdErrChan: + if output != "" { + log(executable + ": " + output) + } + case <-ctx.Done(): + return + } + } + }() + } + + return "", nil +} + +func GetExecutablePath(executable string) (string, error) { + path, err := standalone.GetDaprRuntimePath("") + if err != nil { + return "", err + } + return filepath.Join(path, "bin", executable), nil +} + // cmdInit installs Dapr with the init command and returns the command output and error. // // When DAPR_E2E_INIT_SLIM is true, it will install Dapr without Docker containers. diff --git a/tests/e2e/standalone/run_test.go b/tests/e2e/standalone/run_test.go index fa75f3187..c98d71f0e 100644 --- a/tests/e2e/standalone/run_test.go +++ b/tests/e2e/standalone/run_test.go @@ -16,6 +16,7 @@ limitations under the License. package standalone_test import ( + "context" "fmt" "runtime" "testing" @@ -26,9 +27,23 @@ import ( func TestStandaloneRun(t *testing.T) { ensureDaprInstallation(t) + + ctx, cancelFunc := context.WithCancel(context.Background()) + defer cancelFunc() + + if isSlimMode() { + output, err := cmdProcess(ctx, "placement", t.Log, "--metrics-port", "9091", "--healthz-port", "8081") + require.NoError(t, err) + t.Log(output) + output, err = cmdProcess(ctx, "scheduler", t.Log, "--metrics-port", "9092", "--healthz-port", "8082") + require.NoError(t, err) + t.Log(output) + } t.Cleanup(func() { // remove dapr installation after all tests in this function. must(t, cmdUninstall, "failed to uninstall Dapr") + // Call cancelFunc to stop the processes + cancelFunc() }) for _, path := range getSocketCases() { t.Run(fmt.Sprintf("normal exit, socket: %s", path), func(t *testing.T) { From 5446171840047463b11f4905b058816589d2f6ba Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 5 Nov 2024 17:38:38 -0600 Subject: [PATCH 22/25] Add versioned pod number validation Signed-off-by: Anton Troshin --- tests/e2e/common/common.go | 55 +++++++++++++--- tests/e2e/common/common_test.go | 113 ++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+), 8 deletions(-) create mode 100644 tests/e2e/common/common_test.go diff --git a/tests/e2e/common/common.go b/tests/e2e/common/common.go index a939c71cd..e79b5a50c 100644 --- a/tests/e2e/common/common.go +++ b/tests/e2e/common/common.go @@ -23,6 +23,7 @@ import ( "testing" "time" + "github.com/Masterminds/semver/v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" core_v1 "k8s.io/api/core/v1" @@ -46,14 +47,18 @@ const ( ClusterRoles ClusterRoleBindings - numHAPods = 16 - numNonHAPods = 6 + numHAPodsWithScheduler = 16 + numHAPodsOld = 13 + numNonHAPodsWithScheduler = 6 + numNonHAPodsOld = 5 thirdPartyDevNamespace = "default" devRedisReleaseName = "dapr-dev-redis" devZipkinReleaseName = "dapr-dev-zipkin" ) +var VersionWithScheduler = semver.MustParse("1.14.0") + type VersionDetails struct { RuntimeVersion string DashboardVersion string @@ -131,7 +136,7 @@ func UpgradeTest(details VersionDetails, opts TestOptions) func(t *testing.T) { done := make(chan struct{}) podsRunning := make(chan struct{}) - go waitAllPodsRunning(t, DaprTestNamespace, opts.HAEnabled, done, podsRunning) + go waitAllPodsRunning(t, DaprTestNamespace, opts.HAEnabled, done, podsRunning, details) select { case <-podsRunning: t.Logf("verified all pods running in namespace %s are running after upgrade", DaprTestNamespace) @@ -544,7 +549,7 @@ func GenerateNewCertAndRenew(details VersionDetails, opts TestOptions) func(t *t done := make(chan struct{}) podsRunning := make(chan struct{}) - go waitAllPodsRunning(t, DaprTestNamespace, opts.HAEnabled, done, podsRunning) + go waitAllPodsRunning(t, DaprTestNamespace, opts.HAEnabled, done, podsRunning, details) select { case <-podsRunning: t.Logf("verified all pods running in namespace %s are running after certficate change", DaprTestNamespace) @@ -575,7 +580,7 @@ func UseProvidedPrivateKeyAndRenewCerts(details VersionDetails, opts TestOptions done := make(chan struct{}) podsRunning := make(chan struct{}) - go waitAllPodsRunning(t, DaprTestNamespace, opts.HAEnabled, done, podsRunning) + go waitAllPodsRunning(t, DaprTestNamespace, opts.HAEnabled, done, podsRunning, details) select { case <-podsRunning: t.Logf("verified all pods running in namespace %s are running after certficate change", DaprTestNamespace) @@ -608,7 +613,7 @@ func UseProvidedNewCertAndRenew(details VersionDetails, opts TestOptions) func(t done := make(chan struct{}) podsRunning := make(chan struct{}) - go waitAllPodsRunning(t, DaprTestNamespace, opts.HAEnabled, done, podsRunning) + go waitAllPodsRunning(t, DaprTestNamespace, opts.HAEnabled, done, podsRunning, details) select { case <-podsRunning: t.Logf("verified all pods running in namespace %s are running after certficate change", DaprTestNamespace) @@ -1164,7 +1169,7 @@ func waitPodDeletion(t *testing.T, done, podsDeleted chan struct{}) { } } -func waitAllPodsRunning(t *testing.T, namespace string, haEnabled bool, done, podsRunning chan struct{}) { +func waitAllPodsRunning(t *testing.T, namespace string, haEnabled bool, done, podsRunning chan struct{}, details VersionDetails) { for { select { case <-done: // if timeout was reached. @@ -1198,7 +1203,11 @@ func waitAllPodsRunning(t *testing.T, namespace string, haEnabled bool, done, po } } } - if len(list.Items) == countOfReadyPods && ((haEnabled && countOfReadyPods == numHAPods) || (!haEnabled && countOfReadyPods == numNonHAPods)) { + pods, err := getVersionedNumberOfPods(haEnabled, details) + if err != nil { + t.Error(err) + } + if len(list.Items) == countOfReadyPods && ((haEnabled && countOfReadyPods == pods) || (!haEnabled && countOfReadyPods == pods)) { podsRunning <- struct{}{} } @@ -1206,6 +1215,36 @@ func waitAllPodsRunning(t *testing.T, namespace string, haEnabled bool, done, po } } +func getVersionedNumberOfPods(isHAEnabled bool, details VersionDetails) (int, error) { + if isHAEnabled { + if details.UseDaprLatestVersion { + return numHAPodsWithScheduler, nil + } + rv, err := semver.NewVersion(details.RuntimeVersion) + if err != nil { + return 0, err + } + + if rv.LessThan(VersionWithScheduler) { + return numHAPodsOld, nil + } + return numHAPodsWithScheduler, nil + } else { + if details.UseDaprLatestVersion { + return numNonHAPodsWithScheduler, nil + } + rv, err := semver.NewVersion(details.RuntimeVersion) + if err != nil { + return 0, err + } + + if rv.LessThan(VersionWithScheduler) { + return numNonHAPodsOld, nil + } + return numNonHAPodsWithScheduler, nil + } +} + func exportCurrentCertificate(daprPath string) error { _, err := os.Stat("./certs") if err != nil { diff --git a/tests/e2e/common/common_test.go b/tests/e2e/common/common_test.go new file mode 100644 index 000000000..157b85fb0 --- /dev/null +++ b/tests/e2e/common/common_test.go @@ -0,0 +1,113 @@ +/* +Copyright 2024 The Dapr Authors +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package common + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetVersionedNumberOfPods(t *testing.T) { + tests := []struct { + name string + isHAEnabled bool + details VersionDetails + expectedNumber int + expectedError bool + }{ + { + name: "HA enabled with latest version", + isHAEnabled: true, + details: VersionDetails{UseDaprLatestVersion: true}, + expectedNumber: numHAPodsWithScheduler, + expectedError: false, + }, + { + name: "HA enabled with old version", + isHAEnabled: true, + details: VersionDetails{UseDaprLatestVersion: false, RuntimeVersion: "1.13.0"}, + expectedNumber: numHAPodsOld, + expectedError: false, + }, + { + name: "HA disabled with latest version", + isHAEnabled: false, + details: VersionDetails{UseDaprLatestVersion: true}, + expectedNumber: numNonHAPodsWithScheduler, + expectedError: false, + }, + { + name: "HA disabled with old version", + isHAEnabled: false, + details: VersionDetails{UseDaprLatestVersion: false, RuntimeVersion: "1.13.0"}, + expectedNumber: numNonHAPodsOld, + expectedError: false, + }, + { + name: "HA enabled with new version", + isHAEnabled: true, + details: VersionDetails{UseDaprLatestVersion: false, RuntimeVersion: "1.14.4"}, + expectedNumber: numHAPodsWithScheduler, + expectedError: false, + }, + { + name: "HA disabled with new version", + isHAEnabled: false, + details: VersionDetails{UseDaprLatestVersion: false, RuntimeVersion: "1.14.4"}, + expectedNumber: numNonHAPodsWithScheduler, + expectedError: false, + }, + { + name: "HA enabled with invalid version", + isHAEnabled: true, + details: VersionDetails{UseDaprLatestVersion: false, RuntimeVersion: "invalid version"}, + expectedNumber: 0, + expectedError: true, + }, + { + name: "HA disabled with invalid version", + isHAEnabled: false, + details: VersionDetails{UseDaprLatestVersion: false, RuntimeVersion: "invalid version"}, + expectedNumber: 0, + expectedError: true, + }, + { + name: "HA enabled with new RC version", + isHAEnabled: true, + details: VersionDetails{UseDaprLatestVersion: false, RuntimeVersion: "1.15.0-rc.1"}, + expectedNumber: numHAPodsWithScheduler, + expectedError: false, + }, + { + name: "HA disabled with new RC version", + isHAEnabled: false, + details: VersionDetails{UseDaprLatestVersion: false, RuntimeVersion: "1.15.0-rc.1"}, + expectedNumber: numNonHAPodsWithScheduler, + expectedError: false, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + number, err := getVersionedNumberOfPods(tc.isHAEnabled, tc.details) + if tc.expectedError { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.Equal(t, tc.expectedNumber, number) + } + }) + } +} From 6d5e64d96499fc3747e5e9ed375aaabd3b1ef7ad Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Fri, 8 Nov 2024 12:33:08 -0600 Subject: [PATCH 23/25] Fix tests running master in CI with specific dapr version (#1461) * Fix tests running master in CI with specific dapr version Signed-off-by: Anton Troshin * move env version load into common Signed-off-by: Anton Troshin * fix k8s test files Signed-off-by: Anton Troshin * Revert "fix k8s test files" This reverts commit 344867d19ca4b38e5a83a82a2a00bb04c1775bab. Signed-off-by: Anton Troshin * Revert "move env version load into common" This reverts commit 39e8c8caf54a157464bb44dffe448fc75727487f. Signed-off-by: Anton Troshin * Revert "Fix tests running master in CI with specific dapr version" This reverts commit a02c81f7e25a6bbdb8e3b172a8e215dae60d321f. Signed-off-by: Anton Troshin * Add GetRuntimeVersion to be able to compare semver dapr versions for conditional tests Use GetRuntimeVersion in test Signed-off-by: Anton Troshin --------- Signed-off-by: Anton Troshin --- tests/e2e/common/common.go | 9 ++++++++- tests/e2e/standalone/run_test.go | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tests/e2e/common/common.go b/tests/e2e/common/common.go index e79b5a50c..a10fba8c0 100644 --- a/tests/e2e/common/common.go +++ b/tests/e2e/common/common.go @@ -57,7 +57,7 @@ const ( devZipkinReleaseName = "dapr-dev-zipkin" ) -var VersionWithScheduler = semver.MustParse("1.14.0") +var VersionWithScheduler = semver.MustParse("1.14.0-rc.1") type VersionDetails struct { RuntimeVersion string @@ -109,6 +109,13 @@ func GetVersionsFromEnv(t *testing.T, latest bool) (string, string) { return daprRuntimeVersion, daprDashboardVersion } +func GetRuntimeVersion(t *testing.T, latest bool) *semver.Version { + daprRuntimeVersion, _ := GetVersionsFromEnv(t, latest) + runtimeVersion, err := semver.NewVersion(daprRuntimeVersion) + require.NoError(t, err) + return runtimeVersion +} + func UpgradeTest(details VersionDetails, opts TestOptions) func(t *testing.T) { return func(t *testing.T) { daprPath := GetDaprPath() diff --git a/tests/e2e/standalone/run_test.go b/tests/e2e/standalone/run_test.go index c98d71f0e..d4260aa9e 100644 --- a/tests/e2e/standalone/run_test.go +++ b/tests/e2e/standalone/run_test.go @@ -21,6 +21,8 @@ import ( "runtime" "testing" + "github.com/dapr/cli/tests/e2e/common" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -35,9 +37,12 @@ func TestStandaloneRun(t *testing.T) { output, err := cmdProcess(ctx, "placement", t.Log, "--metrics-port", "9091", "--healthz-port", "8081") require.NoError(t, err) t.Log(output) - output, err = cmdProcess(ctx, "scheduler", t.Log, "--metrics-port", "9092", "--healthz-port", "8082") - require.NoError(t, err) - t.Log(output) + + if common.GetRuntimeVersion(t, false).GreaterThan(common.VersionWithScheduler) { + output, err = cmdProcess(ctx, "scheduler", t.Log, "--metrics-port", "9092", "--healthz-port", "8082") + require.NoError(t, err) + t.Log(output) + } } t.Cleanup(func() { // remove dapr installation after all tests in this function. @@ -68,7 +73,11 @@ func TestStandaloneRun(t *testing.T) { output, err := cmdRun(path, "--dapr-internal-grpc-port", "9999", "--", "bash", "-c", "echo test") t.Log(output) require.NoError(t, err, "run failed") - assert.Contains(t, output, "Internal gRPC server is running on :9999") + if common.GetRuntimeVersion(t, false).GreaterThan(common.VersionWithScheduler) { + assert.Contains(t, output, "Internal gRPC server is running on :9999") + } else { + assert.Contains(t, output, "Internal gRPC server is running on port 9999") + } assert.Contains(t, output, "Exited App successfully") assert.Contains(t, output, "Exited Dapr successfully") assert.NotContains(t, output, "Could not update sidecar metadata for cliPID") From 25d9ece42f73b5ac2d43c5e39b50a291fd83560c Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Fri, 22 Nov 2024 15:59:51 -0600 Subject: [PATCH 24/25] Add version parsing check skip malformed versions and avoid panic (#1469) * Add version parsing check skip malformed versions and avoid panic Signed-off-by: Anton Troshin * lint Signed-off-by: Anton Troshin * do not return error on nil, skip bad versions Signed-off-by: Anton Troshin * simplify condition to skip prerelease and versions with metadata print warning on error and non-semver version tag Signed-off-by: Anton Troshin --------- Signed-off-by: Anton Troshin --- pkg/version/version.go | 17 ++++++++++---- pkg/version/version_test.go | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/pkg/version/version.go b/pkg/version/version.go index d25f6d92e..22aa2e75a 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -119,11 +119,18 @@ func GetLatestReleaseGithub(githubURL string) (string, error) { latestVersion := defaultVersion for _, release := range githubRepoReleases { - if !strings.Contains(release.TagName, "-rc") { - cur, _ := version.NewVersion(strings.TrimPrefix(release.TagName, "v")) - if cur.GreaterThan(latestVersion) { - latestVersion = cur - } + cur, err := version.NewVersion(strings.TrimPrefix(release.TagName, "v")) + if err != nil || cur == nil { + print.WarningStatusEvent(os.Stdout, "Malformed version %s, skipping", release.TagName) + continue + } + // Prerelease versions and versions with metadata are skipped. + if cur.Prerelease() != "" || cur.Metadata() != "" { + continue + } + + if cur.GreaterThan(latestVersion) { + latestVersion = cur } } diff --git a/pkg/version/version_test.go b/pkg/version/version_test.go index 0642e2700..24cb69b93 100644 --- a/pkg/version/version_test.go +++ b/pkg/version/version_test.go @@ -162,6 +162,52 @@ func TestGetVersionsGithub(t *testing.T) { "no releases", "", }, + { + "Malformed version no releases", + "/malformed_version_no_releases", + `[ + { + "url": "https://api.github.com/repos/dapr/dapr/releases/186741665", + "html_url": "https://github.com/dapr/dapr/releases/tag/vedge", + "id": 186741665, + "tag_name": "vedge", + "target_commitish": "master", + "name": "Dapr Runtime vedge", + "draft": false, + "prerelease": false + } +] `, + "no releases", + "", + }, + { + "Malformed version with latest", + "/malformed_version_with_latest", + `[ + { + "url": "https://api.github.com/repos/dapr/dapr/releases/186741665", + "html_url": "https://github.com/dapr/dapr/releases/tag/vedge", + "id": 186741665, + "tag_name": "vedge", + "target_commitish": "master", + "name": "Dapr Runtime vedge", + "draft": false, + "prerelease": false + }, + { + "url": "https://api.github.com/repos/dapr/dapr/releases/44766923", + "html_url": "https://github.com/dapr/dapr/releases/tag/v1.5.1", + "id": 44766923, + "tag_name": "v1.5.1", + "target_commitish": "master", + "name": "Dapr Runtime v1.5.1", + "draft": false, + "prerelease": false + } +] `, + "", + "1.5.1", + }, } m := http.NewServeMux() s := http.Server{Addr: ":12345", Handler: m, ReadHeaderTimeout: time.Duration(5) * time.Second} From dbbe022a8abeb53ff536d8243fbdfa019441af84 Mon Sep 17 00:00:00 2001 From: Mike Nguyen Date: Tue, 26 Nov 2024 21:09:01 +0000 Subject: [PATCH 25/25] fix: allow the scheduler client to initialise for edge builds (#1467) Signed-off-by: mikeee --- cmd/run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/run.go b/cmd/run.go index f91c772e6..45247cd09 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -230,7 +230,7 @@ dapr run --run-file /path/to/directory -k output.DaprGRPCPort) } - if semver.Compare(fmt.Sprintf("v%v", daprVer.RuntimeVersion), "v1.14.0-rc.1") == -1 { + if (daprVer.RuntimeVersion != "edge") && (semver.Compare(fmt.Sprintf("v%v", daprVer.RuntimeVersion), "v1.14.0-rc.1") == -1) { print.InfoStatusEvent(os.Stdout, "The scheduler is only compatible with dapr runtime 1.14 onwards.") for i, arg := range output.DaprCMD.Args { if strings.HasPrefix(arg, "--scheduler-host-address") {