2020-02-16 17:24:06 +02:00
|
|
|
/*
|
2021-03-03 21:02:06 +02:00
|
|
|
Copyright 2020-2021 The Kubernetes Authors.
|
2020-02-16 17:24:06 +02:00
|
|
|
|
|
|
|
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 rules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-03-03 21:02:06 +02:00
|
|
|
|
2021-08-31 11:07:44 +03:00
|
|
|
nfdv1alpha1 "sigs.k8s.io/node-feature-discovery/pkg/apis/nfd/v1alpha1"
|
2021-03-03 21:02:06 +02:00
|
|
|
"sigs.k8s.io/node-feature-discovery/source"
|
|
|
|
"sigs.k8s.io/node-feature-discovery/source/kernel"
|
2020-02-16 17:24:06 +02:00
|
|
|
)
|
|
|
|
|
2021-06-06 16:25:08 -05:00
|
|
|
// LoadedKModRule matches loaded kernel modules in the system
|
2021-03-04 07:35:17 +02:00
|
|
|
type LoadedKModRule struct {
|
2021-08-31 11:07:44 +03:00
|
|
|
nfdv1alpha1.MatchExpressionSet
|
2021-03-04 07:35:17 +02:00
|
|
|
}
|
2020-02-16 17:24:06 +02:00
|
|
|
|
2020-02-16 17:33:27 +02:00
|
|
|
// Match loaded kernel modules on provided list of kernel modules
|
2021-03-04 07:35:17 +02:00
|
|
|
func (r *LoadedKModRule) Match() (bool, error) {
|
2022-06-14 17:02:49 +03:00
|
|
|
modules, ok := source.GetFeatureSource("kernel").GetFeatures().Flags[kernel.LoadedModuleFeature]
|
2021-03-03 21:02:06 +02:00
|
|
|
if !ok {
|
|
|
|
return false, fmt.Errorf("info about loaded modules not available")
|
2020-02-16 17:24:06 +02:00
|
|
|
}
|
2021-03-03 21:02:06 +02:00
|
|
|
|
2021-03-04 07:35:17 +02:00
|
|
|
return r.MatchKeys(modules.Elements)
|
2020-02-16 17:24:06 +02:00
|
|
|
}
|