Skip to content

Commit 6a85f48

Browse files
Merge branch 'release-1.12' into merge_rel_1.12_master
2 parents 3fe6d8f + df8f242 commit 6a85f48

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

pkg/kubernetes/kubernetes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ auth:
449449
secretStore: kubernetes
450450
`
451451

452+
// This config needs to be named as appconfig, as it is used in later steps in `dapr run -f . -k`. See `pkg/kubernetes/run.go`.
452453
zipkinConfig := `
453454
apiVersion: dapr.io/v1alpha1
454455
kind: Configuration

pkg/kubernetes/run.go

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,25 @@ import (
3939
"github.com/dapr/cli/pkg/runfileconfig"
4040
daprsyscall "github.com/dapr/cli/pkg/syscall"
4141
"github.com/dapr/cli/utils"
42+
"github.com/dapr/dapr/pkg/client/clientset/versioned"
4243
)
4344

4445
const (
45-
serviceKind = "Service"
46-
deploymentKind = "Deployment"
47-
serviceAPIVersion = "v1"
48-
deploymentAPIVersion = "apps/v1"
49-
loadBalanceType = "LoadBalancer"
50-
daprEnableAnnotationKey = "dapr.io/enabled"
51-
serviceFileName = "service.yaml"
52-
deploymentFileName = "deployment.yaml"
53-
appLabelKey = "app"
54-
nameKey = "name"
55-
labelsKey = "labels"
56-
tcpProtocol = "TCP"
46+
serviceKind = "Service"
47+
deploymentKind = "Deployment"
48+
serviceAPIVersion = "v1"
49+
deploymentAPIVersion = "apps/v1"
50+
loadBalanceType = "LoadBalancer"
51+
daprEnableAnnotationKey = "dapr.io/enabled"
52+
daprConfigAnnotationKey = "dapr.io/config"
53+
daprConfigAnnotationValue = "appconfig"
54+
serviceFileName = "service.yaml"
55+
deploymentFileName = "deployment.yaml"
56+
appLabelKey = "app"
57+
nameKey = "name"
58+
namespaceKey = "namespace"
59+
labelsKey = "labels"
60+
tcpProtocol = "TCP"
5761

5862
podCreationDeletionTimeout = 1 * time.Minute
5963
)
@@ -87,13 +91,20 @@ func Run(runFilePath string, config runfileconfig.RunFileConfig) (bool, error) {
8791
// Validations and default setting will only be done after this point.
8892
var exitWithError bool
8993

90-
// get k8s client PodsInterface.
94+
// get k8s client for PodsInterface.
9195
client, cErr := Client()
9296
if cErr != nil {
9397
// exit with error.
9498
return true, fmt.Errorf("error getting k8s client: %w", cErr)
9599
}
96100

101+
// get dapr k8s client.
102+
daprClient, cErr := DaprClient()
103+
if cErr != nil {
104+
// exit with error.
105+
return true, fmt.Errorf("error getting dapr k8s client: %w", cErr)
106+
}
107+
97108
namespace := corev1.NamespaceDefault
98109
podsInterface := client.CoreV1().Pods(namespace)
99110

@@ -128,7 +139,7 @@ func Run(runFilePath string, config runfileconfig.RunFileConfig) (bool, error) {
128139
}
129140

130141
// create default deployment config.
131-
dep := createDeploymentConfig(app)
142+
dep := createDeploymentConfig(daprClient, app)
132143
if err != nil {
133144
print.FailureStatusEvent(os.Stderr, "Error creating deployment file for app %q present in %s: %s", app.RunConfig.AppID, runFilePath, err.Error())
134145
exitWithError = true
@@ -255,13 +266,14 @@ func createServiceConfig(app runfileconfig.App) serviceConfig {
255266
}
256267
}
257268

258-
func createDeploymentConfig(app runfileconfig.App) deploymentConfig {
269+
func createDeploymentConfig(client versioned.Interface, app runfileconfig.App) deploymentConfig {
259270
replicas := int32(1)
260271
dep := deploymentConfig{
261272
Kind: deploymentKind,
262273
APIVersion: deploymentAPIVersion,
263274
Metadata: map[string]any{
264-
nameKey: app.AppID,
275+
nameKey: app.AppID,
276+
namespaceKey: corev1.NamespaceDefault,
265277
},
266278
}
267279

@@ -294,6 +306,13 @@ func createDeploymentConfig(app runfileconfig.App) deploymentConfig {
294306
// Set dapr.io/enable annotation.
295307
dep.Spec.Template.ObjectMeta.Annotations[daprEnableAnnotationKey] = "true"
296308

309+
if ok, _ := isConfigurationPresent(client, corev1.NamespaceDefault, daprConfigAnnotationValue); ok {
310+
// Set dapr.io/config annotation only if present.
311+
dep.Spec.Template.ObjectMeta.Annotations[daprConfigAnnotationKey] = daprConfigAnnotationValue
312+
} else {
313+
print.WarningStatusEvent(os.Stderr, "Dapr configuration %q not found in namespace %q. Skipping annotation %q", daprConfigAnnotationValue, corev1.NamespaceDefault, daprConfigAnnotationKey)
314+
}
315+
297316
// set containerPort only if app port is present.
298317
if app.AppPort != 0 {
299318
dep.Spec.Template.Spec.Containers[0].Ports = []corev1.ContainerPort{

0 commit comments

Comments
 (0)