mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-14 11:57:51 +00:00
pkg/api/feature: rename types
Sync type names with NFD documentation. Aims at making the codebase easier to follow.
This commit is contained in:
parent
906aad6717
commit
abdbd420d1
17 changed files with 142 additions and 142 deletions
|
@ -20,26 +20,26 @@ package feature
|
|||
// features to empty values
|
||||
func NewDomainFeatures() *DomainFeatures {
|
||||
return &DomainFeatures{
|
||||
Keys: make(map[string]KeyFeatureSet),
|
||||
Values: make(map[string]ValueFeatureSet),
|
||||
Instances: make(map[string]InstanceFeatureSet)}
|
||||
Flags: make(map[string]FlagFeatureSet),
|
||||
Attributes: make(map[string]AttributeFeatureSet),
|
||||
Instances: make(map[string]InstanceFeatureSet)}
|
||||
}
|
||||
|
||||
// NewKeyFeatures creates a new instance of KeyFeatureSet.
|
||||
func NewKeyFeatures(keys ...string) KeyFeatureSet {
|
||||
// NewFlagFeatures creates a new instance of KeyFeatureSet.
|
||||
func NewFlagFeatures(keys ...string) FlagFeatureSet {
|
||||
e := make(map[string]Nil, len(keys))
|
||||
for _, k := range keys {
|
||||
e[k] = Nil{}
|
||||
}
|
||||
return KeyFeatureSet{Elements: e}
|
||||
return FlagFeatureSet{Elements: e}
|
||||
}
|
||||
|
||||
// NewValueFeatures creates a new instance of ValueFeatureSet.
|
||||
func NewValueFeatures(values map[string]string) ValueFeatureSet {
|
||||
// NewAttributeFeatures creates a new instance of ValueFeatureSet.
|
||||
func NewAttributeFeatures(values map[string]string) AttributeFeatureSet {
|
||||
if values == nil {
|
||||
values = make(map[string]string)
|
||||
}
|
||||
return ValueFeatureSet{Elements: values}
|
||||
return AttributeFeatureSet{Elements: values}
|
||||
}
|
||||
|
||||
// NewInstanceFeatures creates a new instance of InstanceFeatureSet.
|
||||
|
@ -55,17 +55,17 @@ func NewInstanceFeature(attrs map[string]string) *InstanceFeature {
|
|||
return &InstanceFeature{Attributes: attrs}
|
||||
}
|
||||
|
||||
// InsertFeatureValues inserts new values into a specific feature.
|
||||
func InsertFeatureValues(f Features, domain, feature string, values map[string]string) {
|
||||
// InsertAttributeFeatures inserts new values into a specific feature.
|
||||
func InsertAttributeFeatures(f Features, domain, feature string, values map[string]string) {
|
||||
if _, ok := f[domain]; !ok {
|
||||
f[domain] = NewDomainFeatures()
|
||||
}
|
||||
if _, ok := f[domain].Values[feature]; !ok {
|
||||
f[domain].Values[feature] = NewValueFeatures(values)
|
||||
if _, ok := f[domain].Attributes[feature]; !ok {
|
||||
f[domain].Attributes[feature] = NewAttributeFeatures(values)
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range values {
|
||||
f[domain].Values[feature].Elements[k] = v
|
||||
f[domain].Attributes[feature].Elements[k] = v
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,15 +127,15 @@ func (m *InstanceFeatureSet) XXX_DiscardUnknown() {
|
|||
|
||||
var xxx_messageInfo_InstanceFeatureSet proto.InternalMessageInfo
|
||||
|
||||
func (m *KeyFeatureSet) Reset() { *m = KeyFeatureSet{} }
|
||||
func (*KeyFeatureSet) ProtoMessage() {}
|
||||
func (*KeyFeatureSet) Descriptor() ([]byte, []int) {
|
||||
func (m *FlagFeatureSet) Reset() { *m = FlagFeatureSet{} }
|
||||
func (*FlagFeatureSet) ProtoMessage() {}
|
||||
func (*FlagFeatureSet) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_870e6eafce4d2482, []int{3}
|
||||
}
|
||||
func (m *KeyFeatureSet) XXX_Unmarshal(b []byte) error {
|
||||
func (m *FlagFeatureSet) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *KeyFeatureSet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
func (m *FlagFeatureSet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
|
@ -143,13 +143,13 @@ func (m *KeyFeatureSet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error
|
|||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
func (m *KeyFeatureSet) XXX_Merge(src proto.Message) {
|
||||
func (m *FlagFeatureSet) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_KeyFeatureSet.Merge(m, src)
|
||||
}
|
||||
func (m *KeyFeatureSet) XXX_Size() int {
|
||||
func (m *FlagFeatureSet) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *KeyFeatureSet) XXX_DiscardUnknown() {
|
||||
func (m *FlagFeatureSet) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_KeyFeatureSet.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
|
@ -183,15 +183,15 @@ func (m *Nil) XXX_DiscardUnknown() {
|
|||
|
||||
var xxx_messageInfo_Nil proto.InternalMessageInfo
|
||||
|
||||
func (m *ValueFeatureSet) Reset() { *m = ValueFeatureSet{} }
|
||||
func (*ValueFeatureSet) ProtoMessage() {}
|
||||
func (*ValueFeatureSet) Descriptor() ([]byte, []int) {
|
||||
func (m *AttributeFeatureSet) Reset() { *m = AttributeFeatureSet{} }
|
||||
func (*AttributeFeatureSet) ProtoMessage() {}
|
||||
func (*AttributeFeatureSet) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_870e6eafce4d2482, []int{5}
|
||||
}
|
||||
func (m *ValueFeatureSet) XXX_Unmarshal(b []byte) error {
|
||||
func (m *AttributeFeatureSet) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *ValueFeatureSet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
func (m *AttributeFeatureSet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
|
@ -199,13 +199,13 @@ func (m *ValueFeatureSet) XXX_Marshal(b []byte, deterministic bool) ([]byte, err
|
|||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
func (m *ValueFeatureSet) XXX_Merge(src proto.Message) {
|
||||
func (m *AttributeFeatureSet) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_ValueFeatureSet.Merge(m, src)
|
||||
}
|
||||
func (m *ValueFeatureSet) XXX_Size() int {
|
||||
func (m *AttributeFeatureSet) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *ValueFeatureSet) XXX_DiscardUnknown() {
|
||||
func (m *AttributeFeatureSet) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_ValueFeatureSet.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
|
@ -214,15 +214,15 @@ var xxx_messageInfo_ValueFeatureSet proto.InternalMessageInfo
|
|||
func init() {
|
||||
proto.RegisterType((*DomainFeatures)(nil), "feature.DomainFeatures")
|
||||
proto.RegisterMapType((map[string]InstanceFeatureSet)(nil), "feature.DomainFeatures.InstancesEntry")
|
||||
proto.RegisterMapType((map[string]KeyFeatureSet)(nil), "feature.DomainFeatures.KeysEntry")
|
||||
proto.RegisterMapType((map[string]ValueFeatureSet)(nil), "feature.DomainFeatures.ValuesEntry")
|
||||
proto.RegisterMapType((map[string]FlagFeatureSet)(nil), "feature.DomainFeatures.KeysEntry")
|
||||
proto.RegisterMapType((map[string]AttributeFeatureSet)(nil), "feature.DomainFeatures.ValuesEntry")
|
||||
proto.RegisterType((*InstanceFeature)(nil), "feature.InstanceFeature")
|
||||
proto.RegisterMapType((map[string]string)(nil), "feature.InstanceFeature.AttributesEntry")
|
||||
proto.RegisterType((*InstanceFeatureSet)(nil), "feature.InstanceFeatureSet")
|
||||
proto.RegisterType((*KeyFeatureSet)(nil), "feature.KeyFeatureSet")
|
||||
proto.RegisterType((*FlagFeatureSet)(nil), "feature.KeyFeatureSet")
|
||||
proto.RegisterMapType((map[string]Nil)(nil), "feature.KeyFeatureSet.ElementsEntry")
|
||||
proto.RegisterType((*Nil)(nil), "feature.Nil")
|
||||
proto.RegisterType((*ValueFeatureSet)(nil), "feature.ValueFeatureSet")
|
||||
proto.RegisterType((*AttributeFeatureSet)(nil), "feature.ValueFeatureSet")
|
||||
proto.RegisterMapType((map[string]string)(nil), "feature.ValueFeatureSet.ElementsEntry")
|
||||
}
|
||||
|
||||
|
@ -313,14 +313,14 @@ func (m *DomainFeatures) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
|||
dAtA[i] = 0x1a
|
||||
}
|
||||
}
|
||||
if len(m.Values) > 0 {
|
||||
keysForValues := make([]string, 0, len(m.Values))
|
||||
for k := range m.Values {
|
||||
if len(m.Attributes) > 0 {
|
||||
keysForValues := make([]string, 0, len(m.Attributes))
|
||||
for k := range m.Attributes {
|
||||
keysForValues = append(keysForValues, string(k))
|
||||
}
|
||||
github_com_gogo_protobuf_sortkeys.Strings(keysForValues)
|
||||
for iNdEx := len(keysForValues) - 1; iNdEx >= 0; iNdEx-- {
|
||||
v := m.Values[string(keysForValues[iNdEx])]
|
||||
v := m.Attributes[string(keysForValues[iNdEx])]
|
||||
baseI := i
|
||||
{
|
||||
size, err := (&v).MarshalToSizedBuffer(dAtA[:i])
|
||||
|
@ -342,14 +342,14 @@ func (m *DomainFeatures) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
|||
dAtA[i] = 0x12
|
||||
}
|
||||
}
|
||||
if len(m.Keys) > 0 {
|
||||
keysForKeys := make([]string, 0, len(m.Keys))
|
||||
for k := range m.Keys {
|
||||
if len(m.Flags) > 0 {
|
||||
keysForKeys := make([]string, 0, len(m.Flags))
|
||||
for k := range m.Flags {
|
||||
keysForKeys = append(keysForKeys, string(k))
|
||||
}
|
||||
github_com_gogo_protobuf_sortkeys.Strings(keysForKeys)
|
||||
for iNdEx := len(keysForKeys) - 1; iNdEx >= 0; iNdEx-- {
|
||||
v := m.Keys[string(keysForKeys[iNdEx])]
|
||||
v := m.Flags[string(keysForKeys[iNdEx])]
|
||||
baseI := i
|
||||
{
|
||||
size, err := (&v).MarshalToSizedBuffer(dAtA[:i])
|
||||
|
@ -458,7 +458,7 @@ func (m *InstanceFeatureSet) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
|||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *KeyFeatureSet) Marshal() (dAtA []byte, err error) {
|
||||
func (m *FlagFeatureSet) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
|
@ -468,12 +468,12 @@ func (m *KeyFeatureSet) Marshal() (dAtA []byte, err error) {
|
|||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *KeyFeatureSet) MarshalTo(dAtA []byte) (int, error) {
|
||||
func (m *FlagFeatureSet) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *KeyFeatureSet) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
func (m *FlagFeatureSet) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
|
@ -533,7 +533,7 @@ func (m *Nil) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
|||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *ValueFeatureSet) Marshal() (dAtA []byte, err error) {
|
||||
func (m *AttributeFeatureSet) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
|
@ -543,12 +543,12 @@ func (m *ValueFeatureSet) Marshal() (dAtA []byte, err error) {
|
|||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *ValueFeatureSet) MarshalTo(dAtA []byte) (int, error) {
|
||||
func (m *AttributeFeatureSet) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *ValueFeatureSet) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
func (m *AttributeFeatureSet) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
|
@ -597,8 +597,8 @@ func (m *DomainFeatures) Size() (n int) {
|
|||
}
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Keys) > 0 {
|
||||
for k, v := range m.Keys {
|
||||
if len(m.Flags) > 0 {
|
||||
for k, v := range m.Flags {
|
||||
_ = k
|
||||
_ = v
|
||||
l = v.Size()
|
||||
|
@ -606,8 +606,8 @@ func (m *DomainFeatures) Size() (n int) {
|
|||
n += mapEntrySize + 1 + sovGenerated(uint64(mapEntrySize))
|
||||
}
|
||||
}
|
||||
if len(m.Values) > 0 {
|
||||
for k, v := range m.Values {
|
||||
if len(m.Attributes) > 0 {
|
||||
for k, v := range m.Attributes {
|
||||
_ = k
|
||||
_ = v
|
||||
l = v.Size()
|
||||
|
@ -659,7 +659,7 @@ func (m *InstanceFeatureSet) Size() (n int) {
|
|||
return n
|
||||
}
|
||||
|
||||
func (m *KeyFeatureSet) Size() (n int) {
|
||||
func (m *FlagFeatureSet) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
|
@ -686,7 +686,7 @@ func (m *Nil) Size() (n int) {
|
|||
return n
|
||||
}
|
||||
|
||||
func (m *ValueFeatureSet) Size() (n int) {
|
||||
func (m *AttributeFeatureSet) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
|
@ -713,24 +713,24 @@ func (this *DomainFeatures) String() string {
|
|||
if this == nil {
|
||||
return "nil"
|
||||
}
|
||||
keysForKeys := make([]string, 0, len(this.Keys))
|
||||
for k := range this.Keys {
|
||||
keysForKeys := make([]string, 0, len(this.Flags))
|
||||
for k := range this.Flags {
|
||||
keysForKeys = append(keysForKeys, k)
|
||||
}
|
||||
github_com_gogo_protobuf_sortkeys.Strings(keysForKeys)
|
||||
mapStringForKeys := "map[string]KeyFeatureSet{"
|
||||
for _, k := range keysForKeys {
|
||||
mapStringForKeys += fmt.Sprintf("%v: %v,", k, this.Keys[k])
|
||||
mapStringForKeys += fmt.Sprintf("%v: %v,", k, this.Flags[k])
|
||||
}
|
||||
mapStringForKeys += "}"
|
||||
keysForValues := make([]string, 0, len(this.Values))
|
||||
for k := range this.Values {
|
||||
keysForValues := make([]string, 0, len(this.Attributes))
|
||||
for k := range this.Attributes {
|
||||
keysForValues = append(keysForValues, k)
|
||||
}
|
||||
github_com_gogo_protobuf_sortkeys.Strings(keysForValues)
|
||||
mapStringForValues := "map[string]ValueFeatureSet{"
|
||||
for _, k := range keysForValues {
|
||||
mapStringForValues += fmt.Sprintf("%v: %v,", k, this.Values[k])
|
||||
mapStringForValues += fmt.Sprintf("%v: %v,", k, this.Attributes[k])
|
||||
}
|
||||
mapStringForValues += "}"
|
||||
keysForInstances := make([]string, 0, len(this.Instances))
|
||||
|
@ -786,7 +786,7 @@ func (this *InstanceFeatureSet) String() string {
|
|||
}, "")
|
||||
return s
|
||||
}
|
||||
func (this *KeyFeatureSet) String() string {
|
||||
func (this *FlagFeatureSet) String() string {
|
||||
if this == nil {
|
||||
return "nil"
|
||||
}
|
||||
|
@ -815,7 +815,7 @@ func (this *Nil) String() string {
|
|||
}, "")
|
||||
return s
|
||||
}
|
||||
func (this *ValueFeatureSet) String() string {
|
||||
func (this *AttributeFeatureSet) String() string {
|
||||
if this == nil {
|
||||
return "nil"
|
||||
}
|
||||
|
@ -901,11 +901,11 @@ func (m *DomainFeatures) Unmarshal(dAtA []byte) error {
|
|||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if m.Keys == nil {
|
||||
m.Keys = make(map[string]KeyFeatureSet)
|
||||
if m.Flags == nil {
|
||||
m.Flags = make(map[string]FlagFeatureSet)
|
||||
}
|
||||
var mapkey string
|
||||
mapvalue := &KeyFeatureSet{}
|
||||
mapvalue := &FlagFeatureSet{}
|
||||
for iNdEx < postIndex {
|
||||
entryPreIndex := iNdEx
|
||||
var wire uint64
|
||||
|
@ -979,7 +979,7 @@ func (m *DomainFeatures) Unmarshal(dAtA []byte) error {
|
|||
if postmsgIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
mapvalue = &KeyFeatureSet{}
|
||||
mapvalue = &FlagFeatureSet{}
|
||||
if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -999,7 +999,7 @@ func (m *DomainFeatures) Unmarshal(dAtA []byte) error {
|
|||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
m.Keys[mapkey] = *mapvalue
|
||||
m.Flags[mapkey] = *mapvalue
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
|
@ -1030,11 +1030,11 @@ func (m *DomainFeatures) Unmarshal(dAtA []byte) error {
|
|||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if m.Values == nil {
|
||||
m.Values = make(map[string]ValueFeatureSet)
|
||||
if m.Attributes == nil {
|
||||
m.Attributes = make(map[string]AttributeFeatureSet)
|
||||
}
|
||||
var mapkey string
|
||||
mapvalue := &ValueFeatureSet{}
|
||||
mapvalue := &AttributeFeatureSet{}
|
||||
for iNdEx < postIndex {
|
||||
entryPreIndex := iNdEx
|
||||
var wire uint64
|
||||
|
@ -1108,7 +1108,7 @@ func (m *DomainFeatures) Unmarshal(dAtA []byte) error {
|
|||
if postmsgIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
mapvalue = &ValueFeatureSet{}
|
||||
mapvalue = &AttributeFeatureSet{}
|
||||
if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1128,7 +1128,7 @@ func (m *DomainFeatures) Unmarshal(dAtA []byte) error {
|
|||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
m.Values[mapkey] = *mapvalue
|
||||
m.Attributes[mapkey] = *mapvalue
|
||||
iNdEx = postIndex
|
||||
case 3:
|
||||
if wireType != 2 {
|
||||
|
@ -1541,7 +1541,7 @@ func (m *InstanceFeatureSet) Unmarshal(dAtA []byte) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
func (m *KeyFeatureSet) Unmarshal(dAtA []byte) error {
|
||||
func (m *FlagFeatureSet) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
|
@ -1770,7 +1770,7 @@ func (m *Nil) Unmarshal(dAtA []byte) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
func (m *ValueFeatureSet) Unmarshal(dAtA []byte) error {
|
||||
func (m *AttributeFeatureSet) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
|
|
|
@ -24,18 +24,18 @@ type Features map[string]*DomainFeatures
|
|||
|
||||
// DomainFeatures is the collection of all discovered features of one domain.
|
||||
type DomainFeatures struct {
|
||||
Keys map[string]KeyFeatureSet `protobuf:"bytes,1,rep,name=keys"`
|
||||
Values map[string]ValueFeatureSet `protobuf:"bytes,2,rep,name=values"`
|
||||
Instances map[string]InstanceFeatureSet `protobuf:"bytes,3,rep,name=instances"`
|
||||
Flags map[string]FlagFeatureSet `protobuf:"bytes,1,rep,name=flags"`
|
||||
Attributes map[string]AttributeFeatureSet `protobuf:"bytes,2,rep,name=vattributes"`
|
||||
Instances map[string]InstanceFeatureSet `protobuf:"bytes,3,rep,name=instances"`
|
||||
}
|
||||
|
||||
// KeyFeatureSet is a set of simple features only containing names without values.
|
||||
type KeyFeatureSet struct {
|
||||
// FlagFeatureSet is a set of simple features only containing names without values.
|
||||
type FlagFeatureSet struct {
|
||||
Elements map[string]Nil `protobuf:"bytes,1,rep,name=elements"`
|
||||
}
|
||||
|
||||
// ValueFeatureSet is a set of features having string value.
|
||||
type ValueFeatureSet struct {
|
||||
// AttributeFeatureSet is a set of features having string value.
|
||||
type AttributeFeatureSet struct {
|
||||
Elements map[string]string `protobuf:"bytes,1,rep,name=elements"`
|
||||
}
|
||||
|
||||
|
|
|
@ -178,12 +178,12 @@ func (m *FeatureMatcher) match(features map[string]*feature.DomainFeatures) (boo
|
|||
|
||||
var isMatch bool
|
||||
var err error
|
||||
if f, ok := domainFeatures.Keys[featureName]; ok {
|
||||
if f, ok := domainFeatures.Flags[featureName]; ok {
|
||||
m, v, e := term.MatchExpressions.MatchGetKeys(f.Elements)
|
||||
isMatch = m
|
||||
err = e
|
||||
matches[domain][featureName] = v
|
||||
} else if f, ok := domainFeatures.Values[featureName]; ok {
|
||||
} else if f, ok := domainFeatures.Attributes[featureName]; ok {
|
||||
m, v, e := term.MatchExpressions.MatchGetValues(f.Elements)
|
||||
isMatch = m
|
||||
err = e
|
||||
|
|
|
@ -60,8 +60,8 @@ func TestRule(t *testing.T) {
|
|||
assert.Error(t, err, "matching against a missing feature type should have returned an error")
|
||||
|
||||
// Test empty feature sets
|
||||
d.Keys["kf-1"] = feature.NewKeyFeatures()
|
||||
d.Values["vf-1"] = feature.NewValueFeatures(nil)
|
||||
d.Flags["kf-1"] = feature.NewFlagFeatures()
|
||||
d.Attributes["vf-1"] = feature.NewAttributeFeatures(nil)
|
||||
d.Instances["if-1"] = feature.NewInstanceFeatures(nil)
|
||||
|
||||
m, err = r1.Execute(f)
|
||||
|
@ -73,8 +73,8 @@ func TestRule(t *testing.T) {
|
|||
assert.Nil(t, m.Labels, "unexpected match")
|
||||
|
||||
// Test non-empty feature sets
|
||||
d.Keys["kf-1"].Elements["key-x"] = feature.Nil{}
|
||||
d.Values["vf-1"].Elements["key-1"] = "val-x"
|
||||
d.Flags["kf-1"].Elements["key-x"] = feature.Nil{}
|
||||
d.Attributes["vf-1"].Elements["key-1"] = "val-x"
|
||||
d.Instances["if-1"] = feature.NewInstanceFeatures([]feature.InstanceFeature{
|
||||
*feature.NewInstanceFeature(map[string]string{"attr-1": "val-x"})})
|
||||
|
||||
|
@ -98,7 +98,7 @@ func TestRule(t *testing.T) {
|
|||
assert.Nilf(t, err, "unexpected error: %v", err)
|
||||
assert.Nil(t, m.Labels, "keys should not have matched")
|
||||
|
||||
d.Keys["kf-1"].Elements["key-1"] = feature.Nil{}
|
||||
d.Flags["kf-1"].Elements["key-1"] = feature.Nil{}
|
||||
m, err = r2.Execute(f)
|
||||
assert.Nilf(t, err, "unexpected error: %v", err)
|
||||
assert.Equal(t, r2.Labels, m.Labels, "keys should have matched")
|
||||
|
@ -120,7 +120,7 @@ func TestRule(t *testing.T) {
|
|||
assert.Nilf(t, err, "unexpected error: %v", err)
|
||||
assert.Nil(t, m.Labels, "values should not have matched")
|
||||
|
||||
d.Values["vf-1"].Elements["key-1"] = "val-1"
|
||||
d.Attributes["vf-1"].Elements["key-1"] = "val-1"
|
||||
m, err = r3.Execute(f)
|
||||
assert.Nilf(t, err, "unexpected error: %v", err)
|
||||
assert.Equal(t, r3.Labels, m.Labels, "values should have matched")
|
||||
|
@ -210,8 +210,8 @@ func TestRule(t *testing.T) {
|
|||
func TestTemplating(t *testing.T) {
|
||||
f := map[string]*feature.DomainFeatures{
|
||||
"domain_1": &feature.DomainFeatures{
|
||||
Keys: map[string]feature.KeyFeatureSet{
|
||||
"kf_1": feature.KeyFeatureSet{
|
||||
Flags: map[string]feature.FlagFeatureSet{
|
||||
"kf_1": feature.FlagFeatureSet{
|
||||
Elements: map[string]feature.Nil{
|
||||
"key-a": feature.Nil{},
|
||||
"key-b": feature.Nil{},
|
||||
|
@ -219,8 +219,8 @@ func TestTemplating(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
Values: map[string]feature.ValueFeatureSet{
|
||||
"vf_1": feature.ValueFeatureSet{
|
||||
Attributes: map[string]feature.AttributeFeatureSet{
|
||||
"vf_1": feature.AttributeFeatureSet{
|
||||
Elements: map[string]string{
|
||||
"key-1": "val-1",
|
||||
"keu-2": "val-2",
|
||||
|
|
|
@ -534,8 +534,8 @@ func (m *nfdMaster) crLabels(r *pb.SetLabelsRequest) map[string]string {
|
|||
}
|
||||
|
||||
// Feed back rule output to features map for subsequent rules to match
|
||||
feature.InsertFeatureValues(r.Features, nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Labels)
|
||||
feature.InsertFeatureValues(r.Features, nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Vars)
|
||||
feature.InsertAttributeFeatures(r.Features, nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Labels)
|
||||
feature.InsertAttributeFeatures(r.Features, nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Vars)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -140,54 +140,54 @@ func (s *cpuSource) GetLabels() (source.FeatureLabels, error) {
|
|||
features := s.GetFeatures()
|
||||
|
||||
// CPUID
|
||||
for f := range features.Keys[CpuidFeature].Elements {
|
||||
for f := range features.Flags[CpuidFeature].Elements {
|
||||
if s.cpuidFilter.unmask(f) {
|
||||
labels["cpuid."+f] = true
|
||||
}
|
||||
}
|
||||
|
||||
// CPU model
|
||||
for k, v := range features.Values[Cpumodel].Elements {
|
||||
for k, v := range features.Attributes[Cpumodel].Elements {
|
||||
labels["model."+k] = v
|
||||
}
|
||||
|
||||
// Cstate
|
||||
for k, v := range features.Values[CstateFeature].Elements {
|
||||
for k, v := range features.Attributes[CstateFeature].Elements {
|
||||
labels["cstate."+k] = v
|
||||
}
|
||||
|
||||
// Pstate
|
||||
for k, v := range features.Values[PstateFeature].Elements {
|
||||
for k, v := range features.Attributes[PstateFeature].Elements {
|
||||
labels["pstate."+k] = v
|
||||
}
|
||||
|
||||
// RDT
|
||||
for k := range features.Keys[RdtFeature].Elements {
|
||||
for k := range features.Flags[RdtFeature].Elements {
|
||||
labels["rdt."+k] = true
|
||||
}
|
||||
|
||||
// Security
|
||||
for k, v := range features.Values[SecurityFeature].Elements {
|
||||
for k, v := range features.Attributes[SecurityFeature].Elements {
|
||||
labels["security."+k] = v
|
||||
}
|
||||
|
||||
// SGX
|
||||
for k, v := range features.Values[SgxFeature].Elements {
|
||||
for k, v := range features.Attributes[SgxFeature].Elements {
|
||||
labels["sgx."+k] = v
|
||||
}
|
||||
|
||||
// Secure Execution
|
||||
for k, v := range features.Values[SeFeature].Elements {
|
||||
for k, v := range features.Attributes[SeFeature].Elements {
|
||||
labels["se."+k] = v
|
||||
}
|
||||
|
||||
// SST
|
||||
for k, v := range features.Values[SstFeature].Elements {
|
||||
for k, v := range features.Attributes[SstFeature].Elements {
|
||||
labels["power.sst_"+k] = v
|
||||
}
|
||||
|
||||
// Hyperthreading
|
||||
if v, ok := features.Values[TopologyFeature].Elements["hardware_multithreading"]; ok {
|
||||
if v, ok := features.Attributes[TopologyFeature].Elements["hardware_multithreading"]; ok {
|
||||
labels["hardware_multithreading"] = v
|
||||
}
|
||||
|
||||
|
@ -199,17 +199,17 @@ func (s *cpuSource) Discover() error {
|
|||
s.features = feature.NewDomainFeatures()
|
||||
|
||||
// Detect CPUID
|
||||
s.features.Keys[CpuidFeature] = feature.NewKeyFeatures(getCpuidFlags()...)
|
||||
s.features.Flags[CpuidFeature] = feature.NewFlagFeatures(getCpuidFlags()...)
|
||||
|
||||
// Detect CPU model
|
||||
s.features.Values[Cpumodel] = feature.NewValueFeatures(getCPUModel())
|
||||
s.features.Attributes[Cpumodel] = feature.NewAttributeFeatures(getCPUModel())
|
||||
|
||||
// Detect cstate configuration
|
||||
cstate, err := detectCstate()
|
||||
if err != nil {
|
||||
klog.Errorf("failed to detect cstate: %v", err)
|
||||
} else {
|
||||
s.features.Values[CstateFeature] = feature.NewValueFeatures(cstate)
|
||||
s.features.Attributes[CstateFeature] = feature.NewAttributeFeatures(cstate)
|
||||
}
|
||||
|
||||
// Detect pstate features
|
||||
|
@ -217,33 +217,33 @@ func (s *cpuSource) Discover() error {
|
|||
if err != nil {
|
||||
klog.Error(err)
|
||||
}
|
||||
s.features.Values[PstateFeature] = feature.NewValueFeatures(pstate)
|
||||
s.features.Attributes[PstateFeature] = feature.NewAttributeFeatures(pstate)
|
||||
|
||||
// Detect RDT features
|
||||
s.features.Keys[RdtFeature] = feature.NewKeyFeatures(discoverRDT()...)
|
||||
s.features.Flags[RdtFeature] = feature.NewFlagFeatures(discoverRDT()...)
|
||||
|
||||
// Detect SGX features
|
||||
s.features.Values[SecurityFeature] = feature.NewValueFeatures(discoverSecurity())
|
||||
s.features.Attributes[SecurityFeature] = feature.NewAttributeFeatures(discoverSecurity())
|
||||
|
||||
// Detect SGX features
|
||||
//
|
||||
// DEPRECATED in v0.12: will be removed in the future
|
||||
if val, ok := s.features.Values[SecurityFeature].Elements["sgx.enabled"]; ok {
|
||||
s.features.Values[SgxFeature] = feature.NewValueFeatures(map[string]string{"enabled": val})
|
||||
if val, ok := s.features.Attributes[SecurityFeature].Elements["sgx.enabled"]; ok {
|
||||
s.features.Attributes[SgxFeature] = feature.NewAttributeFeatures(map[string]string{"enabled": val})
|
||||
}
|
||||
|
||||
// Detect Secure Execution features
|
||||
//
|
||||
// DEPRECATED in v0.12: will be removed in the future
|
||||
if val, ok := s.features.Values[SecurityFeature].Elements["se.enabled"]; ok {
|
||||
s.features.Values[SeFeature] = feature.NewValueFeatures(map[string]string{"enabled": val})
|
||||
if val, ok := s.features.Attributes[SecurityFeature].Elements["se.enabled"]; ok {
|
||||
s.features.Attributes[SeFeature] = feature.NewAttributeFeatures(map[string]string{"enabled": val})
|
||||
}
|
||||
|
||||
// Detect SST features
|
||||
s.features.Values[SstFeature] = feature.NewValueFeatures(discoverSST())
|
||||
s.features.Attributes[SstFeature] = feature.NewAttributeFeatures(discoverSST())
|
||||
|
||||
// Detect hyper-threading
|
||||
s.features.Values[TopologyFeature] = feature.NewValueFeatures(discoverTopology())
|
||||
s.features.Attributes[TopologyFeature] = feature.NewAttributeFeatures(discoverTopology())
|
||||
|
||||
utils.KlogDump(3, "discovered cpu features:", " ", s.features)
|
||||
|
||||
|
|
|
@ -129,8 +129,8 @@ func (s *customSource) GetLabels() (source.FeatureLabels, error) {
|
|||
labels[n] = v
|
||||
}
|
||||
// Feed back rule output to features map for subsequent rules to match
|
||||
feature.InsertFeatureValues(domainFeatures, nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Labels)
|
||||
feature.InsertFeatureValues(domainFeatures, nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Vars)
|
||||
feature.InsertAttributeFeatures(domainFeatures, nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Labels)
|
||||
feature.InsertAttributeFeatures(domainFeatures, nfdv1alpha1.RuleBackrefDomain, nfdv1alpha1.RuleBackrefFeature, ruleOut.Vars)
|
||||
}
|
||||
return labels, nil
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ type CpuIDRule struct {
|
|||
|
||||
// Match checks if CpuId rule matches.
|
||||
func (r *CpuIDRule) Match() (bool, error) {
|
||||
flags, ok := source.GetFeatureSource("cpu").GetFeatures().Keys[cpu.CpuidFeature]
|
||||
flags, ok := source.GetFeatureSource("cpu").GetFeatures().Flags[cpu.CpuidFeature]
|
||||
if !ok {
|
||||
return false, fmt.Errorf("cpuid information not available")
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ type LoadedKModRule struct {
|
|||
|
||||
// Match loaded kernel modules on provided list of kernel modules
|
||||
func (r *LoadedKModRule) Match() (bool, error) {
|
||||
modules, ok := source.GetFeatureSource("kernel").GetFeatures().Keys[kernel.LoadedModuleFeature]
|
||||
modules, ok := source.GetFeatureSource("kernel").GetFeatures().Flags[kernel.LoadedModuleFeature]
|
||||
if !ok {
|
||||
return false, fmt.Errorf("info about loaded modules not available")
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ type NodenameRule struct {
|
|||
|
||||
// Match checks if node name matches the rule.
|
||||
func (r *NodenameRule) Match() (bool, error) {
|
||||
nodeName, ok := source.GetFeatureSource("system").GetFeatures().Values[system.NameFeature].Elements["nodename"]
|
||||
nodeName, ok := source.GetFeatureSource("system").GetFeatures().Attributes[system.NameFeature].Elements["nodename"]
|
||||
if !ok || nodeName == "" {
|
||||
return false, fmt.Errorf("node name not available")
|
||||
}
|
||||
|
|
|
@ -118,8 +118,8 @@ func (s *fakeSource) SetConfig(conf source.Config) {
|
|||
func (s *fakeSource) Discover() error {
|
||||
s.features = feature.NewDomainFeatures()
|
||||
|
||||
s.features.Keys[FlagFeature] = feature.NewKeyFeatures(s.config.FlagFeatures...)
|
||||
s.features.Values[AttributeFeature] = feature.NewValueFeatures(s.config.AttributeFeatures)
|
||||
s.features.Flags[FlagFeature] = feature.NewFlagFeatures(s.config.FlagFeatures...)
|
||||
s.features.Attributes[AttributeFeature] = feature.NewAttributeFeatures(s.config.AttributeFeatures)
|
||||
|
||||
instances := make([]feature.InstanceFeature, len(s.config.InstanceFeatures))
|
||||
for i, instanceAttributes := range s.config.InstanceFeatures {
|
||||
|
|
|
@ -98,7 +98,7 @@ func (s *kernelSource) GetLabels() (source.FeatureLabels, error) {
|
|||
labels := source.FeatureLabels{}
|
||||
features := s.GetFeatures()
|
||||
|
||||
for k, v := range features.Values[VersionFeature].Elements {
|
||||
for k, v := range features.Attributes[VersionFeature].Elements {
|
||||
labels[VersionFeature+"."+k] = v
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ func (s *kernelSource) GetLabels() (source.FeatureLabels, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if enabled, ok := features.Values[SelinuxFeature].Elements["enabled"]; ok && enabled == "true" {
|
||||
if enabled, ok := features.Attributes[SelinuxFeature].Elements["enabled"]; ok && enabled == "true" {
|
||||
labels["selinux.enabled"] = "true"
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ func (s *kernelSource) Discover() error {
|
|||
if version, err := parseVersion(); err != nil {
|
||||
klog.Errorf("failed to get kernel version: %s", err)
|
||||
} else {
|
||||
s.features.Values[VersionFeature] = feature.NewValueFeatures(version)
|
||||
s.features.Attributes[VersionFeature] = feature.NewAttributeFeatures(version)
|
||||
}
|
||||
|
||||
// Read kconfig
|
||||
|
@ -131,21 +131,21 @@ func (s *kernelSource) Discover() error {
|
|||
s.legacyKconfig = nil
|
||||
klog.Errorf("failed to read kconfig: %s", err)
|
||||
} else {
|
||||
s.features.Values[ConfigFeature] = feature.NewValueFeatures(realKconfig)
|
||||
s.features.Attributes[ConfigFeature] = feature.NewAttributeFeatures(realKconfig)
|
||||
s.legacyKconfig = legacyKconfig
|
||||
}
|
||||
|
||||
if kmods, err := getLoadedModules(); err != nil {
|
||||
klog.Errorf("failed to get loaded kernel modules: %v", err)
|
||||
} else {
|
||||
s.features.Keys[LoadedModuleFeature] = feature.NewKeyFeatures(kmods...)
|
||||
s.features.Flags[LoadedModuleFeature] = feature.NewFlagFeatures(kmods...)
|
||||
}
|
||||
|
||||
if selinux, err := SelinuxEnabled(); err != nil {
|
||||
klog.Warning(err)
|
||||
} else {
|
||||
s.features.Values[SelinuxFeature] = feature.NewValueFeatures(nil)
|
||||
s.features.Values[SelinuxFeature].Elements["enabled"] = strconv.FormatBool(selinux)
|
||||
s.features.Attributes[SelinuxFeature] = feature.NewAttributeFeatures(nil)
|
||||
s.features.Attributes[SelinuxFeature].Elements["enabled"] = strconv.FormatBool(selinux)
|
||||
}
|
||||
|
||||
utils.KlogDump(3, "discovered kernel features:", " ", s.features)
|
||||
|
|
|
@ -88,7 +88,7 @@ func (s *localSource) GetLabels() (source.FeatureLabels, error) {
|
|||
labels := make(source.FeatureLabels)
|
||||
features := s.GetFeatures()
|
||||
|
||||
for k, v := range features.Values[LabelFeature].Elements {
|
||||
for k, v := range features.Attributes[LabelFeature].Elements {
|
||||
labels[k] = v
|
||||
}
|
||||
return labels, nil
|
||||
|
@ -129,7 +129,7 @@ func (s *localSource) Discover() error {
|
|||
}
|
||||
}
|
||||
|
||||
s.features.Values[LabelFeature] = feature.NewValueFeatures(featuresFromFiles)
|
||||
s.features.Attributes[LabelFeature] = feature.NewAttributeFeatures(featuresFromFiles)
|
||||
|
||||
utils.KlogDump(3, "discovered local features:", " ", s.features)
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ func (s *memorySource) GetLabels() (source.FeatureLabels, error) {
|
|||
features := s.GetFeatures()
|
||||
|
||||
// NUMA
|
||||
if isNuma, ok := features.Values[NumaFeature].Elements["is_numa"]; ok && isNuma == "true" {
|
||||
if isNuma, ok := features.Attributes[NumaFeature].Elements["is_numa"]; ok && isNuma == "true" {
|
||||
labels["numa"] = true
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ func (s *memorySource) Discover() error {
|
|||
if numa, err := detectNuma(); err != nil {
|
||||
klog.Errorf("failed to detect NUMA nodes: %v", err)
|
||||
} else {
|
||||
s.features.Values[NumaFeature] = feature.ValueFeatureSet{Elements: numa}
|
||||
s.features.Attributes[NumaFeature] = feature.AttributeFeatureSet{Elements: numa}
|
||||
}
|
||||
|
||||
// Detect NVDIMM
|
||||
|
|
|
@ -73,8 +73,8 @@ func TestFeatureSources(t *testing.T) {
|
|||
|
||||
f := s.GetFeatures()
|
||||
assert.NotNil(t, f, msg)
|
||||
assert.Empty(t, (*f).Keys, msg)
|
||||
assert.Empty(t, (*f).Values, msg)
|
||||
assert.Empty(t, (*f).Flags, msg)
|
||||
assert.Empty(t, (*f).Attributes, msg)
|
||||
assert.Empty(t, (*f).Instances, msg)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ func (s *systemSource) GetLabels() (source.FeatureLabels, error) {
|
|||
features := s.GetFeatures()
|
||||
|
||||
for _, key := range osReleaseFields {
|
||||
if value, exists := features.Values[OsReleaseFeature].Elements[key]; exists {
|
||||
if value, exists := features.Attributes[OsReleaseFeature].Elements[key]; exists {
|
||||
feature := "os_release." + key
|
||||
labels[feature] = value
|
||||
}
|
||||
|
@ -80,21 +80,21 @@ func (s *systemSource) Discover() error {
|
|||
s.features = feature.NewDomainFeatures()
|
||||
|
||||
// Get node name
|
||||
s.features.Values[NameFeature] = feature.NewValueFeatures(nil)
|
||||
s.features.Values[NameFeature].Elements["nodename"] = os.Getenv("NODE_NAME")
|
||||
s.features.Attributes[NameFeature] = feature.NewAttributeFeatures(nil)
|
||||
s.features.Attributes[NameFeature].Elements["nodename"] = os.Getenv("NODE_NAME")
|
||||
|
||||
// Get os-release information
|
||||
release, err := parseOSRelease()
|
||||
if err != nil {
|
||||
klog.Errorf("failed to get os-release: %s", err)
|
||||
} else {
|
||||
s.features.Values[OsReleaseFeature] = feature.NewValueFeatures(release)
|
||||
s.features.Attributes[OsReleaseFeature] = feature.NewAttributeFeatures(release)
|
||||
|
||||
if v, ok := release["VERSION_ID"]; ok {
|
||||
versionComponents := splitVersion(v)
|
||||
for subKey, subValue := range versionComponents {
|
||||
if subValue != "" {
|
||||
s.features.Values[OsReleaseFeature].Elements["VERSION_ID."+subKey] = subValue
|
||||
s.features.Attributes[OsReleaseFeature].Elements["VERSION_ID."+subKey] = subValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue