Remove namespace inheritance of opaque ports annotation (#5739)

This change removes the namespace inheritance of the opaque ports annotation.
Now when setting opaque port related fields in destination profile responses, we
only look at the pod annotations.

This prepares for #5736 where the proxy-injector will add the annotation from
the namespace if the pod does not have it already.

Closes #5735

Signed-off-by: Kevin Leimkuhler <kevin@kleimkuhler.com>
This commit is contained in:
Kevin Leimkuhler 2021-02-15 10:21:20 -05:00 committed by GitHub
parent d2a4027610
commit 5dc662ae97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 21 deletions

View File

@ -210,7 +210,6 @@ func (s *server) GetProfile(dest *pb.GetDestination, stream pb.Destination_GetPr
Namespace: pod.Namespace,
Name: pod.Name,
}
err := watcher.SetPodOpaquePortAnnotation(s.k8sAPI, pod, pod.Namespace)
if err != nil {
log.Errorf("failed to set opaque port annotation on pod: %s", err)
}

View File

@ -805,7 +805,6 @@ func (pp *portPublisher) endpointsToAddresses(endpoints *corev1.Endpoints) Addre
pp.log.Errorf("Unable to create new address:%v", err)
continue
}
err = SetPodOpaquePortAnnotation(pp.k8sAPI, address.Pod, endpoints.Namespace)
if err != nil {
pp.log.Errorf("failed to set opaque port annotation on pod: %s", err)
}
@ -1091,22 +1090,3 @@ func isValidSlice(es *discovery.EndpointSlice) bool {
return true
}
// SetPodOpaquePortAnnotation ensures that if there is no opaque port
// annotation on the pod, then it inherits the annotation from the namespace.
// If there is also no annotation on the namespace, then it remains unset.
func SetPodOpaquePortAnnotation(k8sAPI *k8s.API, pod *corev1.Pod, ns string) error {
if _, ok := pod.Annotations[consts.ProxyOpaquePortsAnnotation]; !ok {
ns, err := k8sAPI.NS().Lister().Get(ns)
if err != nil {
return fmt.Errorf("failed to get namespace annotation: %s", err)
}
if annotation, ok := ns.Annotations[consts.ProxyOpaquePortsAnnotation]; ok {
if pod.Annotations == nil {
pod.Annotations = make(map[string]string)
}
pod.Annotations[consts.ProxyOpaquePortsAnnotation] = annotation
}
}
return nil
}