-
Notifications
You must be signed in to change notification settings - Fork 346
/
meters_linux.go
45 lines (40 loc) · 1.73 KB
/
meters_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//go:build linux
// +build linux
// Copyright 2021 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package openflow
import (
"github.com/blang/semver"
"k8s.io/klog/v2"
"antrea.io/antrea/pkg/util/runtime"
)
func ovsMetersAreSupported() bool {
// According to the OVS documentation, meters are supported in the kernel module since 4.15
// (https://docs.openvswitch.org/en/latest/faq/releases/). However, it turns out that
// because of a bug meters cannot be used with kernel versions older than 4.18, which is
// when this patch was merged: https://github.com/torvalds/linux/commit/25432eba9cd.
// To avoid increasing the minimum required kernel version for Antrea, we will avoid using
// meters altogether if they are not supported, instead of erroring out.
minKernelVersion := semver.MustParse("4.18.0") // patch version is required
kernelVersion, err := runtime.GetKernelVersion()
if err != nil {
klog.Warningf("Cannot retrieve Linux kernel version, cannot use OVS meters: %v", err)
return false
}
if kernelVersion.GTE(minKernelVersion) {
return true
}
klog.Infof("Linux kernel version (%s) is less than %s and therefore the OVS kernel datapath does not support meters", kernelVersion, minKernelVersion)
return false
}