2020-08-11 10:57:51 +03:00
|
|
|
/*
|
2021-03-02 15:17:33 +02:00
|
|
|
Copyright 2020-2021 The Kubernetes Authors.
|
2020-08-11 10:57:51 +03: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 (
|
2021-03-02 15:17:33 +02:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"sigs.k8s.io/node-feature-discovery/source"
|
|
|
|
"sigs.k8s.io/node-feature-discovery/source/cpu"
|
2021-03-04 07:35:17 +02:00
|
|
|
"sigs.k8s.io/node-feature-discovery/source/custom/expression"
|
2020-08-11 10:57:51 +03:00
|
|
|
)
|
|
|
|
|
2021-03-02 15:17:33 +02:00
|
|
|
// CpuIDRule implements Rule for the custom source
|
2021-03-04 07:35:17 +02:00
|
|
|
type CpuIDRule struct {
|
|
|
|
expression.MatchExpressionSet
|
|
|
|
}
|
2020-08-11 10:57:51 +03:00
|
|
|
|
2021-03-04 07:35:17 +02:00
|
|
|
func (r *CpuIDRule) Match() (bool, error) {
|
2021-03-02 15:17:33 +02:00
|
|
|
flags, ok := source.GetFeatureSource("cpu").GetFeatures().Keys[cpu.CpuidFeature]
|
|
|
|
if !ok {
|
|
|
|
return false, fmt.Errorf("cpuid information not available")
|
|
|
|
}
|
2021-03-04 07:35:17 +02:00
|
|
|
return r.MatchKeys(flags.Elements)
|
2020-08-11 10:57:51 +03:00
|
|
|
}
|