mirror of https://github.com/k3s-io/k3s
teach kubenet to use annotation instead of pod object for traffic shaper
parent
947e0e1bf5
commit
f006c8bcd3
|
@ -307,7 +307,7 @@ func (plugin *kubenetNetworkPlugin) Capabilities() utilsets.Int {
|
||||||
// setup sets up networking through CNI using the given ns/name and sandbox ID.
|
// setup sets up networking through CNI using the given ns/name and sandbox ID.
|
||||||
// TODO: Don't pass the pod to this method, it only needs it for bandwidth
|
// TODO: Don't pass the pod to this method, it only needs it for bandwidth
|
||||||
// shaping and hostport management.
|
// shaping and hostport management.
|
||||||
func (plugin *kubenetNetworkPlugin) setup(namespace string, name string, id kubecontainer.ContainerID, pod *v1.Pod) error {
|
func (plugin *kubenetNetworkPlugin) setup(namespace string, name string, id kubecontainer.ContainerID, pod *v1.Pod, annotations map[string]string) error {
|
||||||
// Bring up container loopback interface
|
// Bring up container loopback interface
|
||||||
if _, err := plugin.addContainerToNetwork(plugin.loConfig, "lo", namespace, name, id); err != nil {
|
if _, err := plugin.addContainerToNetwork(plugin.loConfig, "lo", namespace, name, id); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -359,23 +359,22 @@ func (plugin *kubenetNetworkPlugin) setup(namespace string, name string, id kube
|
||||||
|
|
||||||
plugin.podIPs[id] = ip4.String()
|
plugin.podIPs[id] = ip4.String()
|
||||||
|
|
||||||
|
// The first SetUpPod call creates the bridge; get a shaper for the sake of initialization
|
||||||
|
// TODO: replace with CNI traffic shaper plugin
|
||||||
|
shaper := plugin.shaper()
|
||||||
|
ingress, egress, err := bandwidth.ExtractPodBandwidthResources(annotations)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error reading pod bandwidth annotations: %v", err)
|
||||||
|
}
|
||||||
|
if egress != nil || ingress != nil {
|
||||||
|
if err := shaper.ReconcileCIDR(fmt.Sprintf("%s/32", ip4.String()), egress, ingress); err != nil {
|
||||||
|
return fmt.Errorf("Failed to add pod to shaper: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The host can choose to not support "legacy" features. The remote
|
// The host can choose to not support "legacy" features. The remote
|
||||||
// shim doesn't support it (#35457), but the kubelet does.
|
// shim doesn't support it (#35457), but the kubelet does.
|
||||||
if plugin.host.SupportsLegacyFeatures() {
|
if plugin.host.SupportsLegacyFeatures() {
|
||||||
// The first SetUpPod call creates the bridge; get a shaper for the sake of
|
|
||||||
// initialization
|
|
||||||
shaper := plugin.shaper()
|
|
||||||
|
|
||||||
ingress, egress, err := bandwidth.ExtractPodBandwidthResources(pod.Annotations)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Error reading pod bandwidth annotations: %v", err)
|
|
||||||
}
|
|
||||||
if egress != nil || ingress != nil {
|
|
||||||
if err := shaper.ReconcileCIDR(fmt.Sprintf("%s/32", ip4.String()), egress, ingress); err != nil {
|
|
||||||
return fmt.Errorf("Failed to add pod to shaper: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open any hostport the pod's containers want
|
// Open any hostport the pod's containers want
|
||||||
activePodPortMappings, err := plugin.getPodPortMappings()
|
activePodPortMappings, err := plugin.getPodPortMappings()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -387,6 +386,7 @@ func (plugin *kubenetNetworkPlugin) setup(namespace string, name string, id kube
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// TODO: replace with CNI port-forwarding plugin
|
||||||
portMappings, err := plugin.host.GetPodPortMappings(id.ID)
|
portMappings, err := plugin.host.GetPodPortMappings(id.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -425,7 +425,7 @@ func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id k
|
||||||
return fmt.Errorf("Kubenet cannot SetUpPod: %v", err)
|
return fmt.Errorf("Kubenet cannot SetUpPod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := plugin.setup(namespace, name, id, pod); err != nil {
|
if err := plugin.setup(namespace, name, id, pod, annotations); err != nil {
|
||||||
// Make sure everything gets cleaned up on errors
|
// Make sure everything gets cleaned up on errors
|
||||||
podIP, _ := plugin.podIPs[id]
|
podIP, _ := plugin.podIPs[id]
|
||||||
if err := plugin.teardown(namespace, name, id, podIP); err != nil {
|
if err := plugin.teardown(namespace, name, id, podIP); err != nil {
|
||||||
|
|
|
@ -36,6 +36,9 @@ func validateBandwidthIsReasonable(rsrc *resource.Quantity) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExtractPodBandwidthResources(podAnnotations map[string]string) (ingress, egress *resource.Quantity, err error) {
|
func ExtractPodBandwidthResources(podAnnotations map[string]string) (ingress, egress *resource.Quantity, err error) {
|
||||||
|
if podAnnotations == nil {
|
||||||
|
return nil, nil, nil
|
||||||
|
}
|
||||||
str, found := podAnnotations["kubernetes.io/ingress-bandwidth"]
|
str, found := podAnnotations["kubernetes.io/ingress-bandwidth"]
|
||||||
if found {
|
if found {
|
||||||
ingressValue, err := resource.ParseQuantity(str)
|
ingressValue, err := resource.ParseQuantity(str)
|
||||||
|
|
Loading…
Reference in New Issue