Skip to content

Commit 9849624

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
resources: for share based resources add security & config labels
Add labels for "samba-operator.samba.org/common-config-from" and "samba-operator.samba.org/security-config-from" when the server instance is derived from a share using common config or security config CRs. The values of the labels map back to the names of the resources. This can be handy for quickly seeing what resources came from where and when writing tests that need to associate a pod with a CR resource beyond just the SmbShare name. Signed-off-by: John Mulligan <[email protected]>
1 parent d2e5577 commit 9849624

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

internal/resources/deployments.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ import (
2727
)
2828

2929
var (
30-
serviceLabel = "samba-operator.samba.org/service"
30+
serviceLabel = "samba-operator.samba.org/service"
31+
commonConfigLabel = "samba-operator.samba.org/common-config-from"
32+
securityConfigLabel = "samba-operator.samba.org/security-config-from"
3133
)
3234

3335
// buildDeployment returns a samba server deployment object
3436
func buildDeployment(cfg *conf.OperatorConfig,
3537
planner *pln.Planner, pvcName, ns string) *appsv1.Deployment {
3638
// construct a deployment based on the following labels
37-
labels := labelsForSmbServer(planner.InstanceName())
39+
labels := labelsForSmbServer(planner)
3840
var size int32 = 1
3941

4042
deployment := &appsv1.Deployment{
@@ -65,7 +67,18 @@ func buildDeployment(cfg *conf.OperatorConfig,
6567

6668
// labelsForSmbServer returns the labels for selecting the resources
6769
// belonging to the given CR name.
68-
func labelsForSmbServer(name string) map[string]string {
70+
func labelsForSmbServer(planner *pln.Planner) map[string]string {
71+
labels := labelsForManagedResource(planner.InstanceName())
72+
if planner.CommonConfig != nil {
73+
labels[commonConfigLabel] = labelValue(planner.CommonConfig.Name)
74+
}
75+
if planner.SecurityConfig != nil {
76+
labels[securityConfigLabel] = labelValue(planner.SecurityConfig.Name)
77+
}
78+
return labels
79+
}
80+
81+
func labelsForManagedResource(name string) map[string]string {
6982
return map[string]string{
7083
// top level labes
7184
"app": "samba",

internal/resources/metrics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (m *SmbShareManager) getOrCreateMetricsService(
9191
return nil, false, err
9292
}
9393
inst := pl.SmbShare
94-
labels := labelsForSmbServer(metricsInstanceName(pl))
94+
labels := labelsForManagedResource(metricsInstanceName(pl))
9595
srvWant := &corev1.Service{
9696
ObjectMeta: metav1.ObjectMeta{
9797
Namespace: srvKey.Namespace,
@@ -168,7 +168,7 @@ func (m *SmbShareManager) getOrCreateMetricsServiceMonitor(
168168
return nil, false, err
169169
}
170170
inst := pl.SmbShare
171-
labels := labelsForSmbServer(metricsInstanceName(pl))
171+
labels := labelsForManagedResource(metricsInstanceName(pl))
172172
smWant := &monitoringv1.ServiceMonitor{
173173
ObjectMeta: metav1.ObjectMeta{
174174
Namespace: smKey.Namespace,

internal/resources/services.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
var svcSelectorKey = "samba-operator.samba.org/service"
2727

2828
func newServiceForSmb(planner *pln.Planner, ns string) *corev1.Service {
29-
labels := labelsForSmbServer(planner.InstanceName())
29+
labels := labelsForSmbServer(planner)
3030
return &corev1.Service{
3131
ObjectMeta: metav1.ObjectMeta{
3232
Name: planner.InstanceName(),

internal/resources/statefulsets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func buildStatefulSet(
2727
planner *pln.Planner,
2828
dataPVCName, statePVCName, ns string) *appsv1.StatefulSet {
2929
// ---
30-
labels := labelsForSmbServer(planner.InstanceName())
30+
labels := labelsForSmbServer(planner)
3131
size := planner.ClusterSize()
3232
podSpec := buildClusteredPodSpec(planner, dataPVCName, statePVCName)
3333
if planner.NodeSpread() {

0 commit comments

Comments
 (0)