Unverified Commit 283b20c9 authored by Neelay Shah's avatar Neelay Shah Committed by GitHub
Browse files

fix: apply labels to Kubernetes Service objects in operator (#5459)


Co-authored-by: default avatarClaude Opus 4.5 <noreply@anthropic.com>
parent d1545621
...@@ -567,10 +567,24 @@ func GenerateComponentService(ctx context.Context, dynamoDeployment *v1alpha1.Dy ...@@ -567,10 +567,24 @@ func GenerateComponentService(ctx context.Context, dynamoDeployment *v1alpha1.Dy
Protocol: corev1.ProtocolTCP, Protocol: corev1.ProtocolTCP,
} }
} }
// Start with user-defined labels from component.Labels
labels := make(map[string]string)
for k, v := range component.Labels {
labels[k] = v
}
// Add k8s discovery labels (these take precedence over user labels)
if isK8sDiscoveryEnabled {
labels[commonconsts.KubeLabelDynamoDiscoveryBackend] = "kubernetes"
labels[commonconsts.KubeLabelDynamoDiscoveryEnabled] = commonconsts.KubeLabelValueTrue
}
service := &corev1.Service{ service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: componentName, Name: componentName,
Namespace: dynamoDeployment.Namespace, Namespace: dynamoDeployment.Namespace,
Labels: labels,
}, },
Spec: corev1.ServiceSpec{ Spec: corev1.ServiceSpec{
Selector: map[string]string{ Selector: map[string]string{
...@@ -580,12 +594,6 @@ func GenerateComponentService(ctx context.Context, dynamoDeployment *v1alpha1.Dy ...@@ -580,12 +594,6 @@ func GenerateComponentService(ctx context.Context, dynamoDeployment *v1alpha1.Dy
Ports: []corev1.ServicePort{servicePort}, Ports: []corev1.ServicePort{servicePort},
}, },
} }
if isK8sDiscoveryEnabled {
service.Labels = map[string]string{
commonconsts.KubeLabelDynamoDiscoveryBackend: "kubernetes",
commonconsts.KubeLabelDynamoDiscoveryEnabled: commonconsts.KubeLabelValueTrue,
}
}
return service, nil return service, nil
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment