Skip to content

Commit

Permalink
feat: allow service annotation on pods to override Service-based value
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <[email protected]>
  • Loading branch information
michaelbeaumont committed Dec 15, 2021
1 parent 0aa9898 commit b1db0c5
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pkg/plugins/runtime/k8s/controllers/gateway_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ import (
// createorUpdateBuiltinGatewayDataplane manages the dataplane for a pod
// belonging to a built-in Kuma gateway.
func (r *PodReconciler) createorUpdateBuiltinGatewayDataplane(ctx context.Context, pod *kube_core.Pod) error {
services, err := r.findMatchingServices(ctx, pod)
if err != nil {
return errors.Wrap(err, "couldn't find services for gateway pod")
}

dataplane := &mesh_k8s.Dataplane{
ObjectMeta: kube_meta.ObjectMeta{
Namespace: pod.Namespace,
Expand All @@ -30,13 +25,16 @@ func (r *PodReconciler) createorUpdateBuiltinGatewayDataplane(ctx context.Contex
Mesh: k8s_util.MeshFor(pod),
}

if len(services) != 1 {
return errors.Errorf("Gateway should be matched by only 1 Service, found %d", len(services))
}
serviceAnnotation, ok := pod.Annotations[mesh_proto.ServiceTag]

serviceName := k8s_util.ServiceTagFor(services[0], nil)
if !ok {
r.EventRecorder.Eventf(
pod, kube_core.EventTypeWarning, FailedToGenerateKumaDataplaneReason, "Missing %s annotation on Pod serving a builtin Gateway", mesh_proto.ServiceTag,
)
return nil
}

dataplaneProto, err := r.PodConverter.BuiltinGatewayDataplane(pod, serviceName)
dataplaneProto, err := r.PodConverter.BuiltinGatewayDataplane(pod, serviceAnnotation)
if err != nil {
return errors.Wrap(err, "unable to translate a Gateway Pod into a Dataplane")
} else if dataplaneProto == nil {
Expand Down

0 comments on commit b1db0c5

Please sign in to comment.