Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kuma-cp): add pod labels on dataplane and use proxy type labels #12453

Merged
merged 12 commits into from
Jan 15, 2025
7 changes: 7 additions & 0 deletions pkg/core/resources/model/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,13 @@ func ComputeLabels(
labels[mesh_proto.PolicyRoleLabel] = string(role)
}

if rd.IsProxy {
proxy, ok := resource.(ProxyResource)
if ok {
labels[mesh_proto.ProxyTypeLabel] = strings.ToLower(string(proxy.GetProxyType()))
Automaat marked this conversation as resolved.
Show resolved Hide resolved
}
}

return labels, nil
}

Expand Down
47 changes: 47 additions & 0 deletions pkg/core/resources/model/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,52 @@ var _ = Describe("ComputeLabels", func() {
"kuma.io/env": "kubernetes",
},
}),
Entry("gateway dataplane proxy", testCase{
mode: core.Zone,
isK8s: true,
localZone: "zone-1",
r: builders.Dataplane().
WithMesh("mesh-1").
WithBuiltInGateway("test-gateway").
Build(),
expectedLabels: map[string]string{
"kuma.io/mesh": "mesh-1",
"kuma.io/origin": "zone",
"kuma.io/zone": "zone-1",
"kuma.io/env": "kubernetes",
"kuma.io/proxy-type": "gateway",
},
}),
Entry("dataplane proxy", testCase{
mode: core.Zone,
isK8s: true,
localZone: "zone-1",
r: builders.Dataplane().
WithName("backend-1").
WithServices("backend").
WithMesh("mesh-1").
Build(),
expectedLabels: map[string]string{
"kuma.io/mesh": "mesh-1",
"kuma.io/origin": "zone",
"kuma.io/zone": "zone-1",
"kuma.io/env": "kubernetes",
"kuma.io/proxy-type": "sidecar",
},
}),
Entry("zone egress proxy", testCase{
mode: core.Zone,
isK8s: true,
localZone: "zone-1",
r: builders.ZoneEgress().
WithPort(1001).
Build(),
expectedLabels: map[string]string{
"kuma.io/origin": "zone",
"kuma.io/zone": "zone-1",
"kuma.io/env": "kubernetes",
"kuma.io/proxy-type": "zoneegress",
},
}),
)
})
7 changes: 4 additions & 3 deletions pkg/plugins/runtime/k8s/controllers/pod_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (p *PodConverter) PodToDataplane(
labels, err := model.ComputeLabels(
core_mesh.DataplaneResourceTypeDescriptor,
currentSpec,
map[string]string{},
pod.Labels,
model.NewNamespace(pod.Namespace, pod.Namespace == p.SystemNamespace),
dataplane.Mesh,
p.Mode,
Expand All @@ -78,6 +78,7 @@ func (p *PodConverter) PodToDataplane(
return nil
}
dataplane.SetSpec(dataplaneProto)
dataplane.SetLabels(labels)
return nil
}

Expand All @@ -102,7 +103,7 @@ func (p *PodConverter) PodToIngress(ctx context.Context, zoneIngress *mesh_k8s.Z
labels, err := model.ComputeLabels(
core_mesh.ZoneIngressResourceTypeDescriptor,
currentSpec,
map[string]string{},
pod.Labels,
model.NewNamespace(pod.Namespace, pod.Namespace == p.SystemNamespace),
model.NoMesh,
p.Mode,
Expand Down Expand Up @@ -141,7 +142,7 @@ func (p *PodConverter) PodToEgress(ctx context.Context, zoneEgress *mesh_k8s.Zon
labels, err := model.ComputeLabels(
core_mesh.ZoneEgressResourceTypeDescriptor,
currentSpec,
map[string]string{},
pod.Labels,
model.NewNamespace(pod.Namespace, pod.Namespace == p.SystemNamespace),
model.NoMesh,
p.Mode,
Expand Down
Loading