Skip to content

Commit

Permalink
Merge pull request #578 from wcs1only/fix-config-slim
Browse files Browse the repository at this point in the history
Add config file with --slim (#556)
  • Loading branch information
wcs1only authored Jan 13, 2021
2 parents 17e8b94 + 0918505 commit 7cf8fad
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 13 deletions.
41 changes: 28 additions & 13 deletions pkg/standalone/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ type configuration struct {
} `yaml:"metadata"`
Spec struct {
Tracing struct {
SamplingRate string `yaml:"samplingRate"`
SamplingRate string `yaml:"samplingRate,omitempty"`
Zipkin struct {
EndpointAddress string `yaml:"endpointAddress"`
} `yaml:"zipkin"`
} `yaml:"tracing"`
EndpointAddress string `yaml:"endpointAddress,omitempty"`
} `yaml:"zipkin,omitempty"`
} `yaml:"tracing,omitempty"`
} `yaml:"spec"`
}

Expand Down Expand Up @@ -124,14 +124,16 @@ func Init(runtimeVersion string, dockerNetwork string, slimMode bool) error {
if slimMode {
// Install 3 binaries in slim mode: daprd, dashboard, placement
wg.Add(3)
initSteps = append(initSteps, createSlimConfiguration)
} else {
// Install 2 binaries: daprd, dashboard
wg.Add(2)
initSteps = append(initSteps, createComponentsAndConfiguration, runPlacementService, runRedis, runZipkin)
// Init other configurations, containers
wg.Add(len(initSteps))
}

// Init other configurations, containers
wg.Add(len(initSteps))

msg := "Downloading binaries and setting up components..."
var s *spinner.Spinner
if runtime.GOOS == daprWindowsOS {
Expand Down Expand Up @@ -159,11 +161,11 @@ func Init(runtimeVersion string, dockerNetwork string, slimMode bool) error {
if slimMode {
// Initialize placement binary only on slim install
go installBinary(&wg, errorChan, daprBinDir, runtimeVersion, placementServiceFilePrefix, dockerNetwork, cli_ver.DaprGitHubRepo)
} else {
for _, step := range initSteps {
// Run init on the configurations and containers
go step(&wg, errorChan, daprBinDir, runtimeVersion, dockerNetwork)
}
}

for _, step := range initSteps {
// Run init on the configurations and containers
go step(&wg, errorChan, daprBinDir, runtimeVersion, dockerNetwork)
}

go func() {
Expand Down Expand Up @@ -569,6 +571,17 @@ func createComponentsAndConfiguration(wg *sync.WaitGroup, errorChan chan<- error
}
}

func createSlimConfiguration(wg *sync.WaitGroup, errorChan chan<- error, _, _ string, _ string) {
defer wg.Done()

// For --slim we pass empty string so that we do not configure zipkin.
err := createDefaultConfiguration("", DefaultConfigFilePath())
if err != nil {
errorChan <- fmt.Errorf("error creating default configuration file: %s", err)
return
}
}

func makeDefaultComponentsDir() error {
// Make default components directory
componentsDir := DefaultComponentsDirPath()
Expand Down Expand Up @@ -870,8 +883,10 @@ func createDefaultConfiguration(zipkinHost, filePath string) error {
Kind: "Configuration",
}
defaultConfig.Metadata.Name = "daprConfig"
defaultConfig.Spec.Tracing.SamplingRate = "1"
defaultConfig.Spec.Tracing.Zipkin.EndpointAddress = fmt.Sprintf("http://%s:9411/api/v2/spans", zipkinHost)
if zipkinHost != "" {
defaultConfig.Spec.Tracing.SamplingRate = "1"
defaultConfig.Spec.Tracing.Zipkin.EndpointAddress = fmt.Sprintf("http://%s:9411/api/v2/spans", zipkinHost)
}
b, err := yaml.Marshal(&defaultConfig)
if err != nil {
return err
Expand Down
54 changes: 54 additions & 0 deletions pkg/standalone/standalone_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------------------------------

package standalone

import (
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestStandaloneConfig(t *testing.T) {
testFile := "./test.yaml"

t.Run("Standalone config", func(t *testing.T) {
expectConfigZipkin := `apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: daprConfig
spec:
tracing:
samplingRate: "1"
zipkin:
endpointAddress: http://test_zipkin_host:9411/api/v2/spans
`
os.Remove(testFile)
createDefaultConfiguration("test_zipkin_host", testFile)
assert.FileExists(t, testFile)
content, err := ioutil.ReadFile(testFile)
assert.NoError(t, err)
assert.Equal(t, expectConfigZipkin, string(content))
})

t.Run("Standalone config slim", func(t *testing.T) {
expectConfigSlim := `apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: daprConfig
spec: {}
`
os.Remove(testFile)
createDefaultConfiguration("", testFile)
assert.FileExists(t, testFile)
content, err := ioutil.ReadFile(testFile)
assert.NoError(t, err)
assert.Equal(t, expectConfigSlim, string(content))
})

os.Remove(testFile)
}

0 comments on commit 7cf8fad

Please sign in to comment.