Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1afbd9f

Browse files
authoredSep 26, 2024··
Add Applications.Dapr/configurationStores local-dev recipe (#75)
* Add Applications.Dapr/ConfigurationStores local-dev recipe Signed-off-by: SoTrxII <[email protected]> * Adding new configurationstores recipe to readme Signed-off-by: SoTrxII <[email protected]> --------- Signed-off-by: SoTrxII <[email protected]>
1 parent 2a091fe commit 1afbd9f

File tree

3 files changed

+159
-0
lines changed

3 files changed

+159
-0
lines changed
 

‎local-dev/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The [local-dev](/local-dev) directory contains lightweight Recipes for developme
66
77
| Recipe | Resource | Description | Template Path |
88
|--------|----------|-------------|---------------|
9+
| [`local-dev/daprconfigurationstores`](/local-dev/configurationstores.bicep) | `Applications.Dapr/configurationStores` | A lightweight container running the `redis` image and a Redis Dapr Configuration Store component for development purposes. | `ghcr.io/radius-project/recipes/local-dev/daprconfigurationstores:TAG` |
910
| [`local-dev/daprpubsubbrokers`](/local-dev/pubsubbrokers.bicep) | `Applications.Dapr/pubSubBrokers` | A lightweight container running the `redis` image and a Redis Dapr Pub/Sub component for development purposes. | `ghcr.io/radius-project/recipes/local-dev/daprpubsubbrokers:TAG` |
1011
| [`local-dev/daprstatestores`](/local-dev/statestores.bicep) | `Applications.Dapr/stateStores` |A lightweight container running the `redis` image and a Redis Dapr state store component for development purposes. | `ghcr.io/radius-project/recipes/local-dev/daprstatestores:TAG` |
1112
| [`local-dev/secretStores`](/local-dev/secretstores.bicep) | `Applications.Dapr/secretStores` | A kubernetes secret store type for development purposes. | `ghcr.io/radius-project/recipes/local-dev/secretstores:TAG` |

‎local-dev/configurationstores.bicep

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
Copyright 2023 The Radius Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
@description('Information about what resource is calling this Recipe. Generated by Radius. For more information visit https://docs.radapp.dev/operations/custom-recipes/')
18+
param context object
19+
20+
@description('Tag to pull for the redis container image.')
21+
param tag string = '7'
22+
23+
@description('Memory request for the redis deployment.')
24+
param memoryRequest string = '128Mi'
25+
26+
@description('Memory limit for the redis deployment')
27+
param memoryLimit string = '1024Mi'
28+
29+
extension kubernetes with {
30+
kubeConfig: ''
31+
namespace: context.runtime.kubernetes.namespace
32+
} as kubernetes
33+
34+
var uniqueName = 'daprconfig-${uniqueString(context.resource.id)}'
35+
var port = 6379
36+
37+
resource redis 'apps/Deployment@v1' = {
38+
metadata: {
39+
name: uniqueName
40+
}
41+
spec: {
42+
selector: {
43+
matchLabels: {
44+
app: 'dapr-config-redis'
45+
resource: context.resource.name
46+
}
47+
}
48+
template: {
49+
metadata: {
50+
labels: {
51+
app: 'dapr-config-redis'
52+
resource: context.resource.name
53+
54+
// Label pods with the application name so `rad run` can find the logs.
55+
'radapp.io/application': context.application == null ? '' : context.application.name
56+
}
57+
}
58+
spec: {
59+
containers: [
60+
{
61+
// This container is the running redis instance.
62+
name: 'redis'
63+
image: 'redis:${tag}'
64+
ports: [
65+
{
66+
containerPort: port
67+
}
68+
]
69+
resources: {
70+
requests: {
71+
memory: memoryRequest
72+
}
73+
limits: {
74+
memory: memoryLimit
75+
}
76+
}
77+
}
78+
]
79+
}
80+
}
81+
}
82+
}
83+
84+
resource svc 'core/Service@v1' = {
85+
metadata: {
86+
name: uniqueName
87+
}
88+
spec: {
89+
type: 'ClusterIP'
90+
selector: {
91+
app: 'dapr-config-redis'
92+
resource: context.resource.name
93+
}
94+
ports: [
95+
{
96+
port: port
97+
}
98+
]
99+
}
100+
}
101+
102+
var daprType = 'configuration.redis'
103+
var daprVersion = 'v1'
104+
105+
resource daprComponent 'dapr.io/Component@v1alpha1' = {
106+
metadata: {
107+
name: context.resource.name
108+
}
109+
spec: {
110+
type: daprType
111+
version: daprVersion
112+
metadata: [
113+
{
114+
name: 'redisHost'
115+
value: '${svc.metadata.name}.${svc.metadata.namespace}.svc.cluster.local:${port}'
116+
}
117+
{
118+
name: 'redisPassword'
119+
value: ''
120+
}
121+
]
122+
}
123+
}
124+
125+
output result object = {
126+
// This workaround is needed because the deployment engine omits Kubernetes resources from its output.
127+
// This allows Kubernetes resources to be cleaned up when the resource is deleted.
128+
// Once this gap is addressed, users won't need to do this.
129+
resources: [
130+
'/planes/kubernetes/local/namespaces/${svc.metadata.namespace}/providers/core/Service/${svc.metadata.name}'
131+
'/planes/kubernetes/local/namespaces/${redis.metadata.namespace}/providers/apps/Deployment/${redis.metadata.name}'
132+
'/planes/kubernetes/local/namespaces/${daprComponent.metadata.namespace}/providers/dapr.io/Component/${daprComponent.metadata.name}'
133+
]
134+
values: {
135+
type: daprType
136+
version: daprVersion
137+
metadata: daprComponent.spec.metadata
138+
}
139+
}

‎tests/test-local-dev-recipes.bicep

+19
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ resource env 'Applications.Core/environments@2023-10-01-preview' = {
7373
templatePath: '${registry}/recipes/local-dev/statestores:${version}'
7474
}
7575
}
76+
'Applications.Dapr/configurationStores': {
77+
default: {
78+
templateKind: 'bicep'
79+
plainHttp: true
80+
templatePath: '${registry}/recipes/local-dev/configurationstores:${version}'
81+
}
82+
}
7683
}
7784
}
7885
}
@@ -119,6 +126,9 @@ resource webapp 'Applications.Core/containers@2023-10-01-preview' = {
119126
daprstatestore: {
120127
source: statestore.id
121128
}
129+
daprconfigurationstore: {
130+
source: configurationstore.id
131+
}
122132
}
123133
container: {
124134
image: magpieimage
@@ -205,3 +215,12 @@ resource statestore 'Applications.Dapr/stateStores@2023-10-01-preview' = {
205215
environment: env.id
206216
}
207217
}
218+
219+
resource configurationstore 'Applications.Dapr/configurationStores@2023-10-01-preview' = {
220+
name: 'dapr-dcs-recipe'
221+
properties: {
222+
application: app.id
223+
environment: env.id
224+
}
225+
}
226+

0 commit comments

Comments
 (0)
Please sign in to comment.