Skip to content

Commit ad44543

Browse files
Merge branch 'master' into feat/interact-with-kubernetes-dapr-apps
2 parents 7c125f4 + 9ab798d commit ad44543

21 files changed

+626
-167
lines changed

.github/workflows/dapr_cli.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
uses: actions/checkout@v2
6363
- name: Run golangci-lint
6464
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
65-
uses: golangci/golangci-lint-action@v2
65+
uses: golangci/golangci-lint-action@v3.1.0
6666
with:
6767
version: ${{ env.GOLANG_CI_LINT_VER }}
6868
only-new-issues: true

.github/workflows/kind_e2e.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ jobs:
4646
runs-on: ubuntu-latest
4747
env:
4848
GOVER: 1.17
49-
DAPR_RUNTIME_VERSION: 1.7.0-rc.1
50-
DAPR_DASHBOARD_VERSION: 0.10.0-rc.1
51-
DAPR_TGZ: dapr-1.7.0-rc.1.tgz
49+
DAPR_RUNTIME_VERSION: 1.7.0
50+
DAPR_DASHBOARD_VERSION: 0.10.0
51+
DAPR_TGZ: dapr-1.7.0.tgz
5252
strategy:
5353
fail-fast: false # Keep running if one leg fails.
5454
matrix:

.github/workflows/self_hosted_e2e.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ jobs:
3636
GOARCH: ${{ matrix.target_arch }}
3737
GOPROXY: https://proxy.golang.org
3838
ARCHIVE_OUTDIR: dist/archives
39-
DAPR_RUNTIME_VERSION: "1.7.0-rc.1"
40-
DAPR_DASHBOARD_VERSION: 0.10.0-rc.1
41-
DAPR_TGZ: dapr-1.7.0-rc.1.tgz
39+
DAPR_RUNTIME_VERSION: "1.7.0"
40+
DAPR_DASHBOARD_VERSION: 0.10.0
41+
DAPR_TGZ: dapr-1.7.0.tgz
4242
strategy:
4343
matrix:
4444
os: [ubuntu-latest, macos-latest]

README.md

+43-12
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ You can install or upgrade to a specific version of the Dapr runtime using `dapr
120120

121121
```bash
122122
# Install v1.0.0 runtime
123-
$ dapr init --runtime-version 1.0.0
123+
dapr init --runtime-version 1.0.0
124124

125125
# Check the versions of CLI and runtime
126-
$ dapr --version
126+
dapr --version
127127
CLI version: v1.0.0
128128
Runtime version: v1.0.0
129129
```
@@ -134,7 +134,35 @@ You can install Dapr runtime by pulling docker images from a given private regis
134134
135135
```bash
136136
# Example of pulling images from a private registry.
137-
$ dapr init --image-registry example.io/<username>
137+
dapr init --image-registry example.io/<username>
138+
```
139+
140+
#### Install in airgap environment
141+
142+
You can install Dapr runtime in airgap (offline) environment using a pre-downloaded [installer bundle](https://github.com/dapr/installer-bundle/releases). You need to download the archived bundle for your OS beforehand (e.g., daprbundle_linux_amd64.tar.gz,) and unpack it. Thereafter use the local Dapr CLI binary in the bundle with `--from-dir` flag in the init command to point to the extracted bundle location to initialize Dapr.
143+
144+
Move to the bundle directory and run the following command:
145+
146+
```bash
147+
# Initializing dapr in airgap environment
148+
./dapr init --from-dir .
149+
```
150+
151+
> For windows, use `.\dapr.exe` to point to the local Dapr CLI binary.
152+
153+
> If you are not running the above command from the bundle directory, provide the full path to bundle directory as input. For example, assuming the bundle directory path is $HOME/daprbundle, run `$HOME/daprbundle/dapr init --from-dir $HOME/daprbundle` to have the same behavior.
154+
155+
> Note: Dapr Installer bundle just contains the placement container apart from the binaries and so `zipkin` and `redis` are not enabled by default. You can pull the images locally either from network or private registry and run as follows:
156+
157+
```bash
158+
docker run --name "dapr_zipkin" --restart always -d -p 9411:9411 openzipkin/zipkin
159+
docker run --name "dapr_redis" --restart always -d -p 6379:6379 redis
160+
```
161+
162+
Alternatively to the above, you can also have slim installation as well to install dapr without running any Docker containers in airgap mode.
163+
164+
```bash
165+
./dapr init --slim --from-dir .
138166
```
139167

140168
#### Install to a specific Docker network
@@ -143,10 +171,10 @@ You can install the Dapr runtime to a specific Docker network in order to isolat
143171

144172
```bash
145173
# Create Docker network
146-
$ docker network create dapr-network
174+
docker network create dapr-network
147175

148176
# Install Dapr to the network
149-
$ dapr init --network dapr-network
177+
dapr init --network dapr-network
150178
```
151179

152180
> Note: When installed to a specific Docker network, you will need to add the `--placement-host-address` arguments to `dapr run` commands run in any containers within that network.
@@ -190,8 +218,12 @@ The init command will install Dapr to a Kubernetes cluster. For more advanced us
190218
*Note: The default namespace is dapr-system. The installation will appear under the name `dapr` for Helm*
191219

192220
```bash
193-
$ dapr init -k
221+
dapr init -k
222+
```
194223

224+
Output should look like as follows:
225+
226+
```
195227
⌛ Making the jump to hyperspace...
196228
ℹ️ Note: To install Dapr using Helm, see here: https://docs.dapr.io/getting-started/install-dapr/#install-with-helm-advanced
197229
@@ -575,27 +607,26 @@ dapr completion
575607
In order to enable Unix domain socket to connect Dapr API server, use the `--unix-domain-socket` flag:
576608

577609
```
578-
$ dapr run --app-id nodeapp --unix-domain-socket node app.js
610+
dapr run --app-id nodeapp --unix-domain-socket node app.js
579611
```
580612

581613
Dapr will automatically create a Unix domain socket to connect Dapr API server.
582614

583615
If you want to invoke your app, also use this flag:
584616

585617
```
586-
$ dapr invoke --app-id nodeapp --unix-domain-socket --method mymethod
618+
dapr invoke --app-id nodeapp --unix-domain-socket --method mymethod
587619
```
588620

589621
### Set API log level
590622

591-
In order to set the Dapr runtime API calls log verbosity level, use the `api-log-level` flag:
623+
In order to set the Dapr runtime to log API calls with `INFO` log verbosity, use the `enable-api-logging` flag:
592624

593625
```bash
594-
dapr run --app-id nodeapp --app-port 3000 node app.js --api-log-level info
626+
dapr run --app-id nodeapp --app-port 3000 node app.js enable-api-logging
595627
```
596628

597-
This sets the Dapr API log level to `info`.
598-
The default is `debug`.
629+
The default is `false`.
599630

600631
For more details, please run the command and check the examples to apply to your shell.
601632

cmd/init.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package cmd
1616
import (
1717
"fmt"
1818
"os"
19+
"strings"
1920

2021
"github.com/spf13/cobra"
2122
"github.com/spf13/viper"
@@ -52,7 +53,8 @@ var InitCmd = &cobra.Command{
5253
# Initialize Dapr in self-hosted mode
5354
dapr init
5455
55-
#Initialize Dapr in self-hosted mode with a provided docker image registry. Image looked up as <registry-url>/<image>
56+
# Initialize Dapr in self-hosted mode with a provided docker image registry. Image looked up as <registry-url>/<image>.
57+
# Check docs or README for more information on the format of the image path that is required.
5658
dapr init --image-registry <registry-url>
5759
5860
# Initialize Dapr in Kubernetes
@@ -103,10 +105,15 @@ dapr init --from-dir <path-to-directory>
103105
dockerNetwork = viper.GetString("network")
104106
imageRegistryURL = viper.GetString("image-registry")
105107
}
106-
if fromDir != "" {
107-
print.WarningStatusEvent(os.Stdout, "Local bundle installation using from-dir flag is currently a preview feature.")
108+
// If both --image-registry and --from-dir flags are given, error out saying only one can be given.
109+
if len(strings.TrimSpace(imageRegistryURL)) != 0 && len(strings.TrimSpace(fromDir)) != 0 {
110+
print.FailureStatusEvent(os.Stderr, "both --image-registry and --from-dir flags cannot be given at the same time")
111+
os.Exit(1)
112+
}
113+
if len(strings.TrimSpace(fromDir)) != 0 {
114+
print.WarningStatusEvent(os.Stdout, "Local bundle installation using --from-dir flag is currently a preview feature and is subject to change. It is only available from CLI version 1.7 onwards.")
108115
}
109-
if imageRegistryURL != "" {
116+
if len(strings.TrimSpace(imageRegistryURL)) != 0 {
110117
print.WarningStatusEvent(os.Stdout, "Flag --image-registry is a preview feature and is subject to change. It is only available from CLI version 1.7 onwards.")
111118
}
112119
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode, imageRegistryURL, fromDir)
@@ -142,9 +149,9 @@ func init() {
142149
InitCmd.Flags().BoolVarP(&enableMTLS, "enable-mtls", "", true, "Enable mTLS in your cluster")
143150
InitCmd.Flags().BoolVarP(&enableHA, "enable-ha", "", false, "Enable high availability (HA) mode")
144151
InitCmd.Flags().String("network", "", "The Docker network on which to deploy the Dapr runtime")
145-
InitCmd.Flags().StringVarP(&fromDir, "from-dir", "", "", "Use Dapr artifacts from local directory instead of from network to init")
152+
InitCmd.Flags().StringVarP(&fromDir, "from-dir", "", "", "Use Dapr artifacts from local directory for self-hosted installation")
146153
InitCmd.Flags().BoolP("help", "h", false, "Print this help message")
147154
InitCmd.Flags().StringArrayVar(&values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
148-
InitCmd.Flags().String("image-registry", "", "Custom/Private docker image repository url")
155+
InitCmd.Flags().String("image-registry", "", "Custom/Private docker image repository URL")
149156
RootCmd.AddCommand(InitCmd)
150157
}

cmd/renew_certificate.go

+34-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package cmd
1616
import (
1717
"fmt"
1818
"os"
19+
"strings"
1920
"time"
2021

2122
"github.com/spf13/cobra"
@@ -47,17 +48,29 @@ dapr mtls renew-certificate -k --valid-until <no of days> --restart
4748
dapr mtls renew-certificate -k --private-key myprivatekey.key --valid-until <no of days>
4849
4950
# Rotates certificate of your kubernetes cluster with provided ca.cert, issuer.crt and issuer.key file path
50-
dapr mtls renew-certificate -k --ca-root-certificate <ca.crt> --issuer-private-key <issuer.key> --issuer-public-certificate <issuer.crt> --restart
51+
dapr mtls renew-certificate -k --ca-root-certificate <root.pem> --issuer-private-key <issuer.key> --issuer-public-certificate <issuer.pem> --restart
5152
5253
# See more at: https://docs.dapr.io/getting-started/
5354
`,
5455

5556
Run: func(cmd *cobra.Command, args []string) {
57+
var err error
58+
pkFlag := cmd.Flags().Lookup("private-key").Changed
59+
rootcertFlag := cmd.Flags().Lookup("ca-root-certificate").Changed
60+
issuerKeyFlag := cmd.Flags().Lookup("issuer-private-key").Changed
61+
issuerCertFlag := cmd.Flags().Lookup("issuer-public-certificate").Changed
62+
5663
if kubernetesMode {
5764
print.PendingStatusEvent(os.Stdout, "Starting certificate rotation")
58-
if caRootCertificateFile != "" && issuerPrivateKeyFile != "" && issuerPublicCertificateFile != "" {
65+
if rootcertFlag || issuerKeyFlag || issuerCertFlag {
66+
flagArgsEmpty := checkReqFlagArgsEmpty(caRootCertificateFile, issuerPrivateKeyFile, issuerPublicCertificateFile)
67+
if flagArgsEmpty {
68+
err = fmt.Errorf("all required flags for this certificate rotation path, %q, %q and %q are not present",
69+
"ca-root-certificate", "issuer-private-key", "issuer-public-certificate")
70+
logErrorAndExit(err)
71+
}
5972
print.InfoStatusEvent(os.Stdout, "Using provided certificates")
60-
err := kubernetes.RenewCertificate(kubernetes.RenewCertificateParams{
73+
err = kubernetes.RenewCertificate(kubernetes.RenewCertificateParams{
6174
RootCertificateFilePath: caRootCertificateFile,
6275
IssuerCertificateFilePath: issuerPublicCertificateFile,
6376
IssuerPrivateKeyFilePath: issuerPrivateKeyFile,
@@ -66,9 +79,14 @@ dapr mtls renew-certificate -k --ca-root-certificate <ca.crt> --issuer-private-k
6679
if err != nil {
6780
logErrorAndExit(err)
6881
}
69-
} else if privateKey != "" {
82+
} else if pkFlag {
83+
flagArgsEmpty := checkReqFlagArgsEmpty(privateKey)
84+
if flagArgsEmpty {
85+
err = fmt.Errorf("%q flag has incorrect value", "privateKey")
86+
logErrorAndExit(err)
87+
}
7088
print.InfoStatusEvent(os.Stdout, "Using password file to generate root certificate")
71-
err := kubernetes.RenewCertificate(kubernetes.RenewCertificateParams{
89+
err = kubernetes.RenewCertificate(kubernetes.RenewCertificateParams{
7290
RootPrivateKeyFilePath: privateKey,
7391
ValidUntil: time.Hour * time.Duration(validUntil*24),
7492
Timeout: timeout,
@@ -78,7 +96,7 @@ dapr mtls renew-certificate -k --ca-root-certificate <ca.crt> --issuer-private-k
7896
}
7997
} else {
8098
print.InfoStatusEvent(os.Stdout, "generating fresh certificates")
81-
err := kubernetes.RenewCertificate(kubernetes.RenewCertificateParams{
99+
err = kubernetes.RenewCertificate(kubernetes.RenewCertificateParams{
82100
ValidUntil: time.Hour * time.Duration(validUntil*24),
83101
Timeout: timeout,
84102
})
@@ -118,8 +136,17 @@ dapr mtls renew-certificate -k --ca-root-certificate <ca.crt> --issuer-private-k
118136
return command
119137
}
120138

139+
func checkReqFlagArgsEmpty(params ...string) bool {
140+
for _, val := range params {
141+
if len(strings.TrimSpace(val)) == 0 {
142+
return true
143+
}
144+
}
145+
return false
146+
}
147+
121148
func logErrorAndExit(err error) {
122-
err = fmt.Errorf("certificate rotation failed %w", err)
149+
err = fmt.Errorf("certificate rotation failed: %w", err)
123150
print.FailureStatusEvent(os.Stderr, err.Error())
124151
os.Exit(1)
125152
}

cmd/run.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var (
4747
metricsPort int
4848
maxRequestBodySize int
4949
unixDomainSocket string
50-
apiLogLevel string
50+
enableAPILogging bool
5151
)
5252

5353
const (
@@ -116,7 +116,7 @@ dapr run --app-id myapp --app-port 3000 --app-protocol grpc -- go run main.go
116116
MetricsPort: metricsPort,
117117
MaxRequestBodySize: maxRequestBodySize,
118118
UnixDomainSocket: unixDomainSocket,
119-
APILogLevel: apiLogLevel,
119+
EnableAPILogging: enableAPILogging,
120120
})
121121
if err != nil {
122122
print.FailureStatusEvent(os.Stderr, err.Error())
@@ -365,7 +365,7 @@ func init() {
365365
RunCmd.Flags().BoolP("help", "h", false, "Print this help message")
366366
RunCmd.Flags().IntVarP(&maxRequestBodySize, "dapr-http-max-request-size", "", -1, "Max size of request body in MB")
367367
RunCmd.Flags().StringVarP(&unixDomainSocket, "unix-domain-socket", "u", "", "Path to a unix domain socket dir. If specified, Dapr API servers will use Unix Domain Sockets")
368-
RunCmd.Flags().StringVarP(&apiLogLevel, "api-log-level", "", "debug", "The api calls log verbosity. Valid values are: debug, info, off")
368+
RunCmd.Flags().BoolVar(&enableAPILogging, "enable-api-logging", false, "Log API calls at INFO verbosity. Valid values are: true or false")
369369

370370
RootCmd.AddCommand(RunCmd)
371371
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.17
55
require (
66
github.com/Pallinder/sillyname-go v0.0.0-20130730142914-97aeae9e6ba1
77
github.com/briandowns/spinner v1.6.1
8-
github.com/dapr/dapr v1.7.0-rc.1
8+
github.com/dapr/dapr v1.7.0
99
github.com/dapr/go-sdk v1.0.0
1010
github.com/docker/docker v20.10.12+incompatible
1111
github.com/fatih/color v1.13.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ github.com/d2g/dhcp4client v1.0.0/go.mod h1:j0hNfjhrt2SxUOw55nL0ATM/z4Yt3t2Kd1mW
345345
github.com/d2g/dhcp4server v0.0.0-20181031114812-7d4a0a7f59a5/go.mod h1:Eo87+Kg/IX2hfWJfwxMzLyuSZyxSoAug2nGa1G2QAi8=
346346
github.com/d2g/hardwareaddr v0.0.0-20190221164911-e7d9fbe030e4/go.mod h1:bMl4RjIciD2oAxI7DmWRx6gbeqrkoLqv3MV0vzNad+I=
347347
github.com/danieljoos/wincred v1.1.0/go.mod h1:XYlo+eRTsVA9aHGp7NGjFkPla4m+DCL7hqDjlFjiygg=
348-
github.com/dapr/dapr v1.7.0-rc.1 h1:NEXZXuMHQZsd0I3Pi5bTJQdK1anDt0TRHLA1JzQnR78=
349-
github.com/dapr/dapr v1.7.0-rc.1/go.mod h1:YbacMSteh7nGRP777IJDuCn5sgJxL9cRVdiWEirBXbM=
348+
github.com/dapr/dapr v1.7.0 h1:6D92cycMjrzxOSASfXDMfn1t3dGaDysA28ONogaOE4s=
349+
github.com/dapr/dapr v1.7.0/go.mod h1:MIXtm4c4Vv1Z7GScHOgctDcjZ28W2jGYxXvr28+LGpM=
350350
github.com/dapr/go-sdk v1.0.0 h1:3nOmFzsPaHzzgINQQD9AFofVX6LV8QYJtpogaBfwkUg=
351351
github.com/dapr/go-sdk v1.0.0/go.mod h1:zyhsocIKv4pqQ2VtvWvf2CK1UhP7Z2OAOXgEpVxMgIs=
352352
github.com/dapr/kit v0.0.2-0.20210614175626-b9074b64d233 h1:M0dWIG8kUxEFU57IqTWeqptNqlBsfosFgsA5Ov7rJ8g=

pkg/kubernetes/mtls.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ func Expiry() (*time.Time, error) {
165165
return nil, err
166166
}
167167

168-
caCrt := secret.Data["ca.crt"]
168+
caCrt, ok := secret.Data["ca.crt"]
169+
if !ok {
170+
return nil, errors.New("root certificate not loaded yet, please try again in few minutes")
171+
}
169172
block, _ := pem.Decode(caCrt)
170173
cert, err := x509.ParseCertificate(block.Bytes)
171174
if err != nil {

0 commit comments

Comments
 (0)