mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-15 04:57:56 +00:00
commit
a006459078
30 changed files with 90 additions and 90 deletions
|
@ -1,4 +1,5 @@
|
||||||
FROM golang:1.18-buster as builder
|
ARG BUILDER_IMAGE
|
||||||
|
FROM ${BUILDER_IMAGE} as builder
|
||||||
|
|
||||||
# Install tools
|
# Install tools
|
||||||
RUN go install github.com/vektra/mockery/v2@v2.13.0 && \
|
RUN go install github.com/vektra/mockery/v2@v2.13.0 && \
|
||||||
|
|
5
Makefile
5
Makefile
|
@ -127,7 +127,10 @@ templates:
|
||||||
@rm nfd-worker.conf.tmp
|
@rm nfd-worker.conf.tmp
|
||||||
|
|
||||||
.generator.image.stamp: Dockerfile_generator
|
.generator.image.stamp: Dockerfile_generator
|
||||||
$(IMAGE_BUILD_CMD) -t nfd-generator -f Dockerfile_generator .
|
$(IMAGE_BUILD_CMD) \
|
||||||
|
--build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \
|
||||||
|
-t nfd-generator \
|
||||||
|
-f Dockerfile_generator .
|
||||||
|
|
||||||
generate: .generator.image.stamp
|
generate: .generator.image.stamp
|
||||||
$(CONTAINER_RUN_CMD) --rm \
|
$(CONTAINER_RUN_CMD) --rm \
|
||||||
|
|
|
@ -78,8 +78,8 @@ spec:
|
||||||
the input and an array of values that the operator
|
the input and an array of values that the operator
|
||||||
evaluates the input against. \n NB: CreateMatchExpression
|
evaluates the input against. \n NB: CreateMatchExpression
|
||||||
or MustCreateMatchExpression() should be used
|
or MustCreateMatchExpression() should be used
|
||||||
for creating new instances. NB: Validate() must
|
for creating new instances. \n NB: Validate()
|
||||||
be called if Op or Value fields are modified
|
must be called if Op or Value fields are modified
|
||||||
or if a new instance is created from scratch
|
or if a new instance is created from scratch
|
||||||
without using the helper functions."
|
without using the helper functions."
|
||||||
properties:
|
properties:
|
||||||
|
@ -144,8 +144,8 @@ spec:
|
||||||
and an array of values that the operator evaluates
|
and an array of values that the operator evaluates
|
||||||
the input against. \n NB: CreateMatchExpression or
|
the input against. \n NB: CreateMatchExpression or
|
||||||
MustCreateMatchExpression() should be used for creating
|
MustCreateMatchExpression() should be used for creating
|
||||||
new instances. NB: Validate() must be called if Op
|
new instances. \n NB: Validate() must be called if
|
||||||
or Value fields are modified or if a new instance
|
Op or Value fields are modified or if a new instance
|
||||||
is created from scratch without using the helper functions."
|
is created from scratch without using the helper functions."
|
||||||
properties:
|
properties:
|
||||||
op:
|
op:
|
||||||
|
|
|
@ -78,8 +78,8 @@ spec:
|
||||||
the input and an array of values that the operator
|
the input and an array of values that the operator
|
||||||
evaluates the input against. \n NB: CreateMatchExpression
|
evaluates the input against. \n NB: CreateMatchExpression
|
||||||
or MustCreateMatchExpression() should be used
|
or MustCreateMatchExpression() should be used
|
||||||
for creating new instances. NB: Validate() must
|
for creating new instances. \n NB: Validate()
|
||||||
be called if Op or Value fields are modified
|
must be called if Op or Value fields are modified
|
||||||
or if a new instance is created from scratch
|
or if a new instance is created from scratch
|
||||||
without using the helper functions."
|
without using the helper functions."
|
||||||
properties:
|
properties:
|
||||||
|
@ -144,8 +144,8 @@ spec:
|
||||||
and an array of values that the operator evaluates
|
and an array of values that the operator evaluates
|
||||||
the input against. \n NB: CreateMatchExpression or
|
the input against. \n NB: CreateMatchExpression or
|
||||||
MustCreateMatchExpression() should be used for creating
|
MustCreateMatchExpression() should be used for creating
|
||||||
new instances. NB: Validate() must be called if Op
|
new instances. \n NB: Validate() must be called if
|
||||||
or Value fields are modified or if a new instance
|
Op or Value fields are modified or if a new instance
|
||||||
is created from scratch without using the helper functions."
|
is created from scratch without using the helper functions."
|
||||||
properties:
|
properties:
|
||||||
op:
|
op:
|
||||||
|
|
|
@ -490,6 +490,7 @@ func (in *valueRegexpCache) DeepCopy() *valueRegexpCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopyInto is a stub to augment the auto-generated code
|
// DeepCopyInto is a stub to augment the auto-generated code
|
||||||
|
//
|
||||||
//nolint:staticcheck // re.Copy is deprecated but we want to use it here
|
//nolint:staticcheck // re.Copy is deprecated but we want to use it here
|
||||||
func (in *valueRegexpCache) DeepCopyInto(out *valueRegexpCache) {
|
func (in *valueRegexpCache) DeepCopyInto(out *valueRegexpCache) {
|
||||||
*out = make(valueRegexpCache, len(*in))
|
*out = make(valueRegexpCache, len(*in))
|
||||||
|
|
|
@ -120,9 +120,10 @@ type MatchExpressionSet map[string]*MatchExpression
|
||||||
// an array of values that the operator evaluates the input against.
|
// an array of values that the operator evaluates the input against.
|
||||||
//
|
//
|
||||||
// NB: CreateMatchExpression or MustCreateMatchExpression() should be used for
|
// NB: CreateMatchExpression or MustCreateMatchExpression() should be used for
|
||||||
// creating new instances.
|
// creating new instances.
|
||||||
|
//
|
||||||
// NB: Validate() must be called if Op or Value fields are modified or if a new
|
// NB: Validate() must be called if Op or Value fields are modified or if a new
|
||||||
// instance is created from scratch without using the helper functions.
|
// instance is created from scratch without using the helper functions.
|
||||||
type MatchExpression struct {
|
type MatchExpression struct {
|
||||||
// Op is the operator to be applied.
|
// Op is the operator to be applied.
|
||||||
Op MatchOp `json:"op"`
|
Op MatchOp `json:"op"`
|
||||||
|
|
|
@ -37,14 +37,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{
|
||||||
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
|
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
|
||||||
// of clientsets, like in:
|
// of clientsets, like in:
|
||||||
//
|
//
|
||||||
// import (
|
// import (
|
||||||
// "k8s.io/client-go/kubernetes"
|
// "k8s.io/client-go/kubernetes"
|
||||||
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
|
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
|
||||||
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
|
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
|
||||||
// )
|
// )
|
||||||
//
|
//
|
||||||
// kclientset, _ := kubernetes.NewForConfig(c)
|
// kclientset, _ := kubernetes.NewForConfig(c)
|
||||||
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
|
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
|
||||||
//
|
//
|
||||||
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
|
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
|
||||||
// correctly.
|
// correctly.
|
||||||
|
|
|
@ -37,14 +37,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{
|
||||||
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
|
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
|
||||||
// of clientsets, like in:
|
// of clientsets, like in:
|
||||||
//
|
//
|
||||||
// import (
|
// import (
|
||||||
// "k8s.io/client-go/kubernetes"
|
// "k8s.io/client-go/kubernetes"
|
||||||
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
|
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
|
||||||
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
|
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
|
||||||
// )
|
// )
|
||||||
//
|
//
|
||||||
// kclientset, _ := kubernetes.NewForConfig(c)
|
// kclientset, _ := kubernetes.NewForConfig(c)
|
||||||
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
|
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
|
||||||
//
|
//
|
||||||
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
|
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
|
||||||
// correctly.
|
// correctly.
|
||||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
package kubeconf
|
package kubeconf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
|
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
// GetKubeletConfigFromLocalFile returns KubeletConfiguration loaded from the node local config
|
// GetKubeletConfigFromLocalFile returns KubeletConfiguration loaded from the node local config
|
||||||
func GetKubeletConfigFromLocalFile(kubeletConfigPath string) (*kubeletconfigv1beta1.KubeletConfiguration, error) {
|
func GetKubeletConfigFromLocalFile(kubeletConfigPath string) (*kubeletconfigv1beta1.KubeletConfiguration, error) {
|
||||||
kubeletBytes, err := ioutil.ReadFile(kubeletConfigPath)
|
kubeletBytes, err := os.ReadFile(kubeletConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -105,7 +104,7 @@ func (w *NfdBaseClient) Connect() error {
|
||||||
return fmt.Errorf("failed to load client certificate: %v", err)
|
return fmt.Errorf("failed to load client certificate: %v", err)
|
||||||
}
|
}
|
||||||
// Load CA cert for server cert verification
|
// Load CA cert for server cert verification
|
||||||
caCert, err := ioutil.ReadFile(w.args.CaFile)
|
caCert, err := os.ReadFile(w.args.CaFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to read root certificate file: %v", err)
|
return fmt.Errorf("failed to read root certificate file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||||
package worker
|
package worker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -129,7 +128,7 @@ func TestConfigParse(t *testing.T) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
// Create a temporary config file
|
// Create a temporary config file
|
||||||
f, err := ioutil.TempFile("", "nfd-test-")
|
f, err := os.CreateTemp("", "nfd-test-")
|
||||||
defer os.Remove(f.Name())
|
defer os.Remove(f.Name())
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
_, err = f.WriteString(`
|
_, err = f.WriteString(`
|
||||||
|
@ -197,7 +196,7 @@ sources:
|
||||||
|
|
||||||
func TestDynamicConfig(t *testing.T) {
|
func TestDynamicConfig(t *testing.T) {
|
||||||
Convey("When running nfd-worker", t, func() {
|
Convey("When running nfd-worker", t, func() {
|
||||||
tmpDir, err := ioutil.TempDir("", "*.nfd-test")
|
tmpDir, err := os.MkdirTemp("", "*.nfd-test")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ package worker
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -401,7 +400,7 @@ func (w *nfdWorker) configure(filepath string, overrides string) error {
|
||||||
|
|
||||||
// Try to read and parse config file
|
// Try to read and parse config file
|
||||||
if filepath != "" {
|
if filepath != "" {
|
||||||
data, err := ioutil.ReadFile(filepath)
|
data, err := os.ReadFile(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
klog.Infof("config file %q not found, using defaults", filepath)
|
klog.Infof("config file %q not found, using defaults", filepath)
|
||||||
|
|
|
@ -18,7 +18,7 @@ package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -44,7 +44,7 @@ type MemoryResourceInfo map[v1.ResourceName]int64
|
||||||
|
|
||||||
// GetNumaMemoryResources returns total amount of memory and hugepages under NUMA nodes
|
// GetNumaMemoryResources returns total amount of memory and hugepages under NUMA nodes
|
||||||
func GetNumaMemoryResources() (NumaMemoryResources, error) {
|
func GetNumaMemoryResources() (NumaMemoryResources, error) {
|
||||||
nodes, err := ioutil.ReadDir(sysBusNodeBasepath)
|
nodes, err := os.ReadDir(sysBusNodeBasepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func GetNumaMemoryResources() (NumaMemoryResources, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHugepagesBytes(path string) (MemoryResourceInfo, error) {
|
func getHugepagesBytes(path string) (MemoryResourceInfo, error) {
|
||||||
entries, err := ioutil.ReadDir(path)
|
entries, err := os.ReadDir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ func getHugepagesBytes(path string) (MemoryResourceInfo, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(filepath.Join(path, entry.Name(), "nr_hugepages"))
|
data, err := os.ReadFile(filepath.Join(path, entry.Name(), "nr_hugepages"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ func getHugepagesBytes(path string) (MemoryResourceInfo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func readTotalMemoryFromMeminfo(path string) (int64, error) {
|
func readTotalMemoryFromMeminfo(path string) (int64, error) {
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ func (c *TlsConfig) UpdateConfig(certFile, keyFile, caFile string) error {
|
||||||
return fmt.Errorf("failed to load server certificate: %v", err)
|
return fmt.Errorf("failed to load server certificate: %v", err)
|
||||||
}
|
}
|
||||||
// Load CA cert for client cert verification
|
// Load CA cert for client cert verification
|
||||||
caCert, err := ioutil.ReadFile(caFile)
|
caCert, err := os.ReadFile(caFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to read root certificate file: %v", err)
|
return fmt.Errorf("failed to read root certificate file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# Install deps
|
# Install deps
|
||||||
gobinpath="$(go env GOPATH)/bin"
|
gobinpath="$(go env GOPATH)/bin"
|
||||||
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b "$gobinpath" v1.45.2
|
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b "$gobinpath" v1.49.0
|
||||||
export PATH=$PATH:$(go env GOPATH)/bin
|
export PATH=$PATH:$(go env GOPATH)/bin
|
||||||
|
|
||||||
curl -sfL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash -s -- --version v3.7.1
|
curl -sfL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash -s -- --version v3.7.1
|
||||||
|
@ -12,8 +12,13 @@ curl -L https://dl.k8s.io/release/v1.22.1/bin/linux/amd64/kubectl -o "$kubectl"
|
||||||
chmod 755 "$kubectl"
|
chmod 755 "$kubectl"
|
||||||
|
|
||||||
# Run verify steps
|
# Run verify steps
|
||||||
|
echo "Checking gofmt"
|
||||||
make gofmt-verify
|
make gofmt-verify
|
||||||
|
|
||||||
|
echo "Running golangci-lint"
|
||||||
make ci-lint
|
make ci-lint
|
||||||
|
|
||||||
|
echo "Running Helm lint"
|
||||||
make helm-lint
|
make helm-lint
|
||||||
|
|
||||||
# Check that repo is clean
|
# Check that repo is clean
|
||||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
@ -282,14 +282,14 @@ func discoverTopology() map[string]string {
|
||||||
// Check if any (online) CPUs have thread siblings
|
// Check if any (online) CPUs have thread siblings
|
||||||
func haveThreadSiblings() (bool, error) {
|
func haveThreadSiblings() (bool, error) {
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(source.SysfsDir.Path("bus/cpu/devices"))
|
files, err := os.ReadDir(source.SysfsDir.Path("bus/cpu/devices"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
// Try to read siblings from topology
|
// Try to read siblings from topology
|
||||||
siblings, err := ioutil.ReadFile(source.SysfsDir.Path("bus/cpu/devices", file.Name(), "topology/thread_siblings_list"))
|
siblings, err := os.ReadFile(source.SysfsDir.Path("bus/cpu/devices", file.Name(), "topology/thread_siblings_list"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ package cpu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -45,7 +44,7 @@ func detectCstate() (map[string]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the intel_idle driver is in use (default), check setting of max_cstates
|
// When the intel_idle driver is in use (default), check setting of max_cstates
|
||||||
driver, err := ioutil.ReadFile(filepath.Join(cpuidleDir, "current_driver"))
|
driver, err := os.ReadFile(filepath.Join(cpuidleDir, "current_driver"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cstate, fmt.Errorf("cannot get driver for cpuidle: %w", err)
|
return cstate, fmt.Errorf("cannot get driver for cpuidle: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -56,7 +55,7 @@ func detectCstate() (map[string]string, error) {
|
||||||
return cstate, nil
|
return cstate, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(source.SysfsDir.Path("module/intel_idle/parameters/max_cstate"))
|
data, err := os.ReadFile(source.SysfsDir.Path("module/intel_idle/parameters/max_cstate"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cstate, fmt.Errorf("cannot determine cstate from max_cstates: %w", err)
|
return cstate, fmt.Errorf("cannot determine cstate from max_cstates: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ package cpu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -52,7 +51,7 @@ func discoverSSTBF() (bool, error) {
|
||||||
nominalBaseFrequency := int(freqInfo.EAX)
|
nominalBaseFrequency := int(freqInfo.EAX)
|
||||||
|
|
||||||
// Loop over all CPUs in the system
|
// Loop over all CPUs in the system
|
||||||
files, err := ioutil.ReadDir(source.SysfsDir.Path("bus/cpu/devices"))
|
files, err := os.ReadDir(source.SysfsDir.Path("bus/cpu/devices"))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -60,7 +59,7 @@ func discoverSSTBF() (bool, error) {
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
// Try to read effective base frequency of each cpu in the system
|
// Try to read effective base frequency of each cpu in the system
|
||||||
filePath := source.SysfsDir.Path("bus/cpu/devices", file.Name(), "cpufreq/base_frequency")
|
filePath := source.SysfsDir.Path("bus/cpu/devices", file.Name(), "cpufreq/base_frequency")
|
||||||
data, err := ioutil.ReadFile(filePath)
|
data, err := os.ReadFile(filePath)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
// Ignore missing file and continue to check other CPUs
|
// Ignore missing file and continue to check other CPUs
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -18,7 +18,6 @@ package cpu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -42,7 +41,7 @@ func detectPstate() (map[string]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get global pstate status
|
// Get global pstate status
|
||||||
data, err := ioutil.ReadFile(filepath.Join(pstateDir, "status"))
|
data, err := os.ReadFile(filepath.Join(pstateDir, "status"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not read pstate status: %w", err)
|
return nil, fmt.Errorf("could not read pstate status: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -55,7 +54,7 @@ func detectPstate() (map[string]string, error) {
|
||||||
features := map[string]string{"status": status}
|
features := map[string]string{"status": status}
|
||||||
|
|
||||||
// Check turbo boost
|
// Check turbo boost
|
||||||
bytes, err := ioutil.ReadFile(filepath.Join(pstateDir, "no_turbo"))
|
bytes, err := os.ReadFile(filepath.Join(pstateDir, "no_turbo"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("can't detect whether turbo boost is enabled: %s", err.Error())
|
klog.Errorf("can't detect whether turbo boost is enabled: %s", err.Error())
|
||||||
} else {
|
} else {
|
||||||
|
@ -72,7 +71,7 @@ func detectPstate() (map[string]string, error) {
|
||||||
|
|
||||||
// Determine scaling governor that is being used
|
// Determine scaling governor that is being used
|
||||||
cpufreqDir := filepath.Join(sysfsBase, "cpufreq")
|
cpufreqDir := filepath.Join(sysfsBase, "cpufreq")
|
||||||
policies, err := ioutil.ReadDir(cpufreqDir)
|
policies, err := os.ReadDir(cpufreqDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("failed to read cpufreq directory: %s", err.Error())
|
klog.Errorf("failed to read cpufreq directory: %s", err.Error())
|
||||||
return features, nil
|
return features, nil
|
||||||
|
@ -81,7 +80,7 @@ func detectPstate() (map[string]string, error) {
|
||||||
scaling := ""
|
scaling := ""
|
||||||
for _, policy := range policies {
|
for _, policy := range policies {
|
||||||
// Ensure at least one cpu is using this policy
|
// Ensure at least one cpu is using this policy
|
||||||
cpus, err := ioutil.ReadFile(filepath.Join(cpufreqDir, policy.Name(), "affected_cpus"))
|
cpus, err := os.ReadFile(filepath.Join(cpufreqDir, policy.Name(), "affected_cpus"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("could not read cpufreq policy %s affected_cpus", policy.Name())
|
klog.Errorf("could not read cpufreq policy %s affected_cpus", policy.Name())
|
||||||
continue
|
continue
|
||||||
|
@ -91,7 +90,7 @@ func detectPstate() (map[string]string, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(filepath.Join(cpufreqDir, policy.Name(), "scaling_governor"))
|
data, err := os.ReadFile(filepath.Join(cpufreqDir, policy.Name(), "scaling_governor"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("could not read cpufreq policy %s scaling_governor", policy.Name())
|
klog.Errorf("could not read cpufreq policy %s scaling_governor", policy.Name())
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||||
package custom
|
package custom
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -41,7 +40,7 @@ func readDir(dirName string, recursive bool) []CustomRule {
|
||||||
features := make([]CustomRule, 0)
|
features := make([]CustomRule, 0)
|
||||||
|
|
||||||
klog.V(1).Infof("getting files in %s", dirName)
|
klog.V(1).Infof("getting files in %s", dirName)
|
||||||
files, err := ioutil.ReadDir(dirName)
|
files, err := os.ReadDir(dirName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
klog.V(1).Infof("custom config directory %q does not exist", dirName)
|
klog.V(1).Infof("custom config directory %q does not exist", dirName)
|
||||||
|
@ -69,7 +68,7 @@ func readDir(dirName string, recursive bool) []CustomRule {
|
||||||
}
|
}
|
||||||
klog.V(2).Infof("processing file %q", fileName)
|
klog.V(2).Infof("processing file %q", fileName)
|
||||||
|
|
||||||
bytes, err := ioutil.ReadFile(fileName)
|
bytes, err := os.ReadFile(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("could not read custom config file %q, %v", fileName, err)
|
klog.Errorf("could not read custom config file %q, %v", fileName, err)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -44,7 +44,7 @@ func readKconfigGzip(filename string) ([]byte, error) {
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
return ioutil.ReadAll(r)
|
return io.ReadAll(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseKconfig reads Linux kernel configuration and returns all set options
|
// parseKconfig reads Linux kernel configuration and returns all set options
|
||||||
|
@ -88,7 +88,7 @@ func parseKconfig(configPath string) (realKconfig, legacyKconfig map[string]stri
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if raw, err = ioutil.ReadFile(path); err == nil {
|
if raw, err = os.ReadFile(path); err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,14 @@ package kernel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const kmodProcfsPath = "/proc/modules"
|
const kmodProcfsPath = "/proc/modules"
|
||||||
|
|
||||||
func getLoadedModules() ([]string, error) {
|
func getLoadedModules() ([]string, error) {
|
||||||
out, err := ioutil.ReadFile(kmodProcfsPath)
|
out, err := os.ReadFile(kmodProcfsPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read file %s: %s", kmodProcfsPath, err.Error())
|
return nil, fmt.Errorf("failed to read file %s: %s", kmodProcfsPath, err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ package kernel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ func SelinuxEnabled() (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err := ioutil.ReadFile(filepath.Join(selinuxBase, "enforce"))
|
status, err := os.ReadFile(filepath.Join(selinuxBase, "enforce"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("failed to detect the status of selinux: %w", err)
|
return false, fmt.Errorf("failed to detect the status of selinux: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
package kernel
|
package kernel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -53,7 +53,7 @@ func parseVersion() (map[string]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVersion() (string, error) {
|
func getVersion() (string, error) {
|
||||||
unameRaw, err := ioutil.ReadFile("/proc/sys/kernel/osrelease")
|
unameRaw, err := os.ReadFile("/proc/sys/kernel/osrelease")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ package local
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -135,7 +134,7 @@ func parseFeatures(lines [][]byte) map[string]string {
|
||||||
func getFeaturesFromHooks() (map[string]string, error) {
|
func getFeaturesFromHooks() (map[string]string, error) {
|
||||||
features := make(map[string]string)
|
features := make(map[string]string)
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(hookDir)
|
files, err := os.ReadDir(hookDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
klog.Infof("hook directory %v does not exist", hookDir)
|
klog.Infof("hook directory %v does not exist", hookDir)
|
||||||
|
@ -212,7 +211,7 @@ func runHook(file string) ([][]byte, error) {
|
||||||
func getFeaturesFromFiles() (map[string]string, error) {
|
func getFeaturesFromFiles() (map[string]string, error) {
|
||||||
features := make(map[string]string)
|
features := make(map[string]string)
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(featureFilesDir)
|
files, err := os.ReadDir(featureFilesDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
klog.Infof("features directory %v does not exist", featureFilesDir)
|
klog.Infof("features directory %v does not exist", featureFilesDir)
|
||||||
|
@ -256,7 +255,7 @@ func getFileContent(fileName string) ([][]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if filestat.Mode().IsRegular() {
|
if filestat.Mode().IsRegular() {
|
||||||
fileContent, err := ioutil.ReadFile(path)
|
fileContent, err := os.ReadFile(path)
|
||||||
|
|
||||||
// Do not return any lines if an error occurred
|
// Do not return any lines if an error occurred
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -18,7 +18,6 @@ package memory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -117,7 +116,7 @@ func (s *memorySource) GetFeatures() *feature.DomainFeatures {
|
||||||
func detectNuma() (map[string]string, error) {
|
func detectNuma() (map[string]string, error) {
|
||||||
sysfsBasePath := source.SysfsDir.Path("bus/node/devices")
|
sysfsBasePath := source.SysfsDir.Path("bus/node/devices")
|
||||||
|
|
||||||
nodes, err := ioutil.ReadDir(sysfsBasePath)
|
nodes, err := os.ReadDir(sysfsBasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to list numa nodes: %w", err)
|
return nil, fmt.Errorf("failed to list numa nodes: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -133,7 +132,7 @@ func detectNv() ([]feature.InstanceFeature, error) {
|
||||||
sysfsBasePath := source.SysfsDir.Path("bus/nd/devices")
|
sysfsBasePath := source.SysfsDir.Path("bus/nd/devices")
|
||||||
info := make([]feature.InstanceFeature, 0)
|
info := make([]feature.InstanceFeature, 0)
|
||||||
|
|
||||||
devices, err := ioutil.ReadDir(sysfsBasePath)
|
devices, err := os.ReadDir(sysfsBasePath)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
klog.V(1).Info("No NVDIMM devices present")
|
klog.V(1).Info("No NVDIMM devices present")
|
||||||
return info, nil
|
return info, nil
|
||||||
|
@ -156,7 +155,7 @@ var ndDevAttrs = []string{"devtype", "mode"}
|
||||||
func readNdDeviceInfo(path string) feature.InstanceFeature {
|
func readNdDeviceInfo(path string) feature.InstanceFeature {
|
||||||
attrs := map[string]string{"name": filepath.Base(path)}
|
attrs := map[string]string{"name": filepath.Base(path)}
|
||||||
for _, attrName := range ndDevAttrs {
|
for _, attrName := range ndDevAttrs {
|
||||||
data, err := ioutil.ReadFile(filepath.Join(path, attrName))
|
data, err := os.ReadFile(filepath.Join(path, attrName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.V(3).Infof("failed to read nd device attribute %s: %w", attrName, err)
|
klog.V(3).Infof("failed to read nd device attribute %s: %w", attrName, err)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -18,7 +18,6 @@ package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -115,7 +114,7 @@ func (s *networkSource) GetFeatures() *feature.DomainFeatures {
|
||||||
func detectNetDevices() ([]feature.InstanceFeature, error) {
|
func detectNetDevices() ([]feature.InstanceFeature, error) {
|
||||||
sysfsBasePath := source.SysfsDir.Path(sysfsBaseDir)
|
sysfsBasePath := source.SysfsDir.Path(sysfsBaseDir)
|
||||||
|
|
||||||
ifaces, err := ioutil.ReadDir(sysfsBasePath)
|
ifaces, err := os.ReadDir(sysfsBasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to list network interfaces: %w", err)
|
return nil, fmt.Errorf("failed to list network interfaces: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -137,7 +136,7 @@ func detectNetDevices() ([]feature.InstanceFeature, error) {
|
||||||
func readIfaceInfo(path string) feature.InstanceFeature {
|
func readIfaceInfo(path string) feature.InstanceFeature {
|
||||||
attrs := map[string]string{"name": filepath.Base(path)}
|
attrs := map[string]string{"name": filepath.Base(path)}
|
||||||
for _, attrName := range ifaceAttrs {
|
for _, attrName := range ifaceAttrs {
|
||||||
data, err := ioutil.ReadFile(filepath.Join(path, attrName))
|
data, err := os.ReadFile(filepath.Join(path, attrName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
klog.Errorf("failed to read net iface attribute %s: %v", attrName, err)
|
klog.Errorf("failed to read net iface attribute %s: %v", attrName, err)
|
||||||
|
@ -148,7 +147,7 @@ func readIfaceInfo(path string) feature.InstanceFeature {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, attrName := range devAttrs {
|
for _, attrName := range devAttrs {
|
||||||
data, err := ioutil.ReadFile(filepath.Join(path, "device", attrName))
|
data, err := os.ReadFile(filepath.Join(path, "device", attrName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
klog.Errorf("failed to read net device attribute %s: %v", attrName, err)
|
klog.Errorf("failed to read net device attribute %s: %v", attrName, err)
|
||||||
|
|
|
@ -18,7 +18,7 @@ package pci
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ var optionalDevAttrs = []string{"sriov_totalvfs", "iommu_group/type", "iommu/int
|
||||||
// Read a single PCI device attribute
|
// Read a single PCI device attribute
|
||||||
// A PCI attribute in this context, maps to the corresponding sysfs file
|
// A PCI attribute in this context, maps to the corresponding sysfs file
|
||||||
func readSinglePciAttribute(devPath string, attrName string) (string, error) {
|
func readSinglePciAttribute(devPath string, attrName string) (string, error) {
|
||||||
data, err := ioutil.ReadFile(filepath.Join(devPath, attrName))
|
data, err := os.ReadFile(filepath.Join(devPath, attrName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to read device attribute %s: %v", attrName, err)
|
return "", fmt.Errorf("failed to read device attribute %s: %v", attrName, err)
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ func readPciDevInfo(devPath string) (*feature.InstanceFeature, error) {
|
||||||
func detectPci() ([]feature.InstanceFeature, error) {
|
func detectPci() ([]feature.InstanceFeature, error) {
|
||||||
sysfsBasePath := source.SysfsDir.Path("bus/pci/devices")
|
sysfsBasePath := source.SysfsDir.Path("bus/pci/devices")
|
||||||
|
|
||||||
devices, err := ioutil.ReadDir(sysfsBasePath)
|
devices, err := os.ReadDir(sysfsBasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ func (s *storageSource) GetFeatures() *feature.DomainFeatures {
|
||||||
func detectBlock() ([]feature.InstanceFeature, error) {
|
func detectBlock() ([]feature.InstanceFeature, error) {
|
||||||
sysfsBasePath := source.SysfsDir.Path("block")
|
sysfsBasePath := source.SysfsDir.Path("block")
|
||||||
|
|
||||||
blockdevices, err := ioutil.ReadDir(sysfsBasePath)
|
blockdevices, err := os.ReadDir(sysfsBasePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to list block devices: %w", err)
|
return nil, fmt.Errorf("failed to list block devices: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ func detectBlock() ([]feature.InstanceFeature, error) {
|
||||||
func readBlockDevQueueInfo(path string) *feature.InstanceFeature {
|
func readBlockDevQueueInfo(path string) *feature.InstanceFeature {
|
||||||
attrs := map[string]string{"name": filepath.Base(path)}
|
attrs := map[string]string{"name": filepath.Base(path)}
|
||||||
for _, attrName := range queueAttrs {
|
for _, attrName := range queueAttrs {
|
||||||
data, err := ioutil.ReadFile(filepath.Join(path, "queue", attrName))
|
data, err := os.ReadFile(filepath.Join(path, "queue", attrName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.V(3).Infof("failed to read block device queue attribute %s: %w", attrName, err)
|
klog.V(3).Infof("failed to read block device queue attribute %s: %w", attrName, err)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -18,7 +18,7 @@ package usb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -40,7 +40,7 @@ var devAttrFileMap = map[string]string{
|
||||||
}
|
}
|
||||||
|
|
||||||
func readSingleUsbSysfsAttribute(path string) (string, error) {
|
func readSingleUsbSysfsAttribute(path string) (string, error) {
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to read device attribute %s: %v", filepath.Base(path), err)
|
return "", fmt.Errorf("failed to read device attribute %s: %v", filepath.Base(path), err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue