1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-28 10:47:23 +00:00

Merge pull request #845 from marquiz/devel/nfd-api-cleanup

Revert type hack in api
This commit is contained in:
Kubernetes Prow Robot 2022-08-10 06:34:36 -07:00 committed by GitHub
commit f26064c54f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 148 additions and 154 deletions

View file

@ -2,9 +2,9 @@ FROM golang:1.18-buster as builder
# Install tools
RUN go install github.com/vektra/mockery/v2@v2.13.0 && \
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0 && \
git clone https://github.com/kubernetes/code-generator -b v0.20.7 --depth 1 && \
go install k8s.io/code-generator/cmd/...@v0.20.7 && \
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.2 && \
git clone https://github.com/kubernetes/code-generator -b v0.24.3 --depth 1 && \
go install k8s.io/code-generator/cmd/...@v0.24.3 && \
go install golang.org/x/tools/cmd/goimports@v0.1.1 && \
go install github.com/golang/protobuf/protoc-gen-go@v1.4.3

View file

@ -1,10 +1,9 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.7.0
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: nodefeaturerules.nfd.k8s-sigs.io
spec:
@ -79,9 +78,9 @@ spec:
the input and an array of values that the operator
evaluates the input against. \n NB: CreateMatchExpression
or MustCreateMatchExpression() should be used
for creating new instances. NB: Validate()
must be called if Op or Value fields are modified
or if a new instance is created from scratch
for creating new instances. 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."
properties:
op:
@ -144,9 +143,9 @@ spec:
an operator that is applied when matching the input
and an array of values that the operator evaluates
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
or Value fields are modified or if a new instance
or Value fields are modified or if a new instance
is created from scratch without using the helper functions."
properties:
op:
@ -215,9 +214,3 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []

View file

@ -1,10 +1,9 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.7.0
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: nodefeaturerules.nfd.k8s-sigs.io
spec:
@ -79,9 +78,9 @@ spec:
the input and an array of values that the operator
evaluates the input against. \n NB: CreateMatchExpression
or MustCreateMatchExpression() should be used
for creating new instances. NB: Validate()
must be called if Op or Value fields are modified
or if a new instance is created from scratch
for creating new instances. 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."
properties:
op:
@ -144,9 +143,9 @@ spec:
an operator that is applied when matching the input
and an array of values that the operator evaluates
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
or Value fields are modified or if a new instance
or Value fields are modified or if a new instance
is created from scratch without using the helper functions."
properties:
op:
@ -215,9 +214,3 @@ spec:
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []

View file

@ -230,38 +230,38 @@ func init() { proto.RegisterFile("feature/generated.proto", fileDescriptor_870e6
var fileDescriptor_870e6eafce4d2482 = []byte{
// 503 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0xc1, 0x6e, 0xd3, 0x40,
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0xc1, 0x6e, 0xd3, 0x40,
0x10, 0x86, 0xbd, 0x71, 0x5b, 0xea, 0x49, 0x9b, 0x94, 0x15, 0x02, 0xcb, 0x48, 0xdb, 0x10, 0x50,
0x95, 0x03,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 0x83, 0xda, 0x32, 0xe7, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x83,
0x7e, 0xe5, 0x1f, 0xef, 0x04, 0x00, 0x00,
}
func (m *DomainFeatures) Marshal() (dAtA []byte, err error) {

View file

@ -45,16 +45,6 @@ var matchOps = map[MatchOp]struct{}{
type valueRegexpCache []*regexp.Regexp
// NewMatchExpressionSet returns a new MatchExpressionSet instance.
func NewMatchExpressionSet() *MatchExpressionSet {
return &MatchExpressionSet{Expressions: make(Expressions)}
}
// Len returns the number of expressions.
func (e *Expressions) Len() int {
return len(*e)
}
// CreateMatchExpression creates a new MatchExpression instance. Returns an
// error if validation fails.
func CreateMatchExpression(op MatchOp, values ...string) (*MatchExpression, error) {
@ -329,9 +319,9 @@ type MatchedKey struct {
// an empty MatchExpressionSet and an empty set of keys returns an empty slice
// which is not nil and is treated as a match.
func (m *MatchExpressionSet) MatchGetKeys(keys map[string]feature.Nil) (bool, []MatchedKey, error) {
ret := make([]MatchedKey, 0, m.Len())
ret := make([]MatchedKey, 0, len(*m))
for n, e := range (*m).Expressions {
for n, e := range *m {
match, err := e.MatchKeys(n, keys)
if err != nil {
return false, nil, err
@ -364,9 +354,9 @@ type MatchedValue struct {
// MatchExpressionSet and an empty set of values returns an empty non-nil map
// which is treated as a match.
func (m *MatchExpressionSet) MatchGetValues(values map[string]string) (bool, []MatchedValue, error) {
ret := make([]MatchedValue, 0, m.Len())
ret := make([]MatchedValue, 0, len(*m))
for n, e := range (*m).Expressions {
for n, e := range *m {
match, err := e.MatchValues(n, values)
if err != nil {
return false, nil, err
@ -411,7 +401,7 @@ func (m *MatchExpressionSet) MatchGetInstances(instances []feature.InstanceFeatu
// UnmarshalJSON implements the Unmarshaler interface of "encoding/json".
func (m *MatchExpressionSet) UnmarshalJSON(data []byte) error {
*m = *NewMatchExpressionSet()
*m = MatchExpressionSet{}
names := make([]string, 0)
if err := json.Unmarshal(data, &names); err == nil {
@ -419,9 +409,9 @@ func (m *MatchExpressionSet) UnmarshalJSON(data []byte) error {
for _, name := range names {
split := strings.SplitN(name, "=", 2)
if len(split) == 1 {
(*m).Expressions[split[0]] = newMatchExpression(MatchExists)
(*m)[split[0]] = newMatchExpression(MatchExists)
} else {
(*m).Expressions[split[0]] = newMatchExpression(MatchIn, split[1])
(*m)[split[0]] = newMatchExpression(MatchIn, split[1])
}
}
} else {
@ -432,9 +422,9 @@ func (m *MatchExpressionSet) UnmarshalJSON(data []byte) error {
}
for k, v := range expressions {
if v != nil {
(*m).Expressions[k] = v
(*m)[k] = v
} else {
(*m).Expressions[k] = newMatchExpression(MatchExists)
(*m)[k] = newMatchExpression(MatchExists)
}
}
}

View file

@ -33,7 +33,7 @@ func TestRule(t *testing.T) {
FeatureMatcherTerm{
Feature: "domain-1.kf-1",
MatchExpressions: MatchExpressionSet{
Expressions: Expressions{"key-1": MustCreateMatchExpression(MatchExists)},
"key-1": MustCreateMatchExpression(MatchExists),
},
},
},
@ -111,7 +111,7 @@ func TestRule(t *testing.T) {
FeatureMatcherTerm{
Feature: "domain-1.vf-1",
MatchExpressions: MatchExpressionSet{
Expressions: Expressions{"key-1": MustCreateMatchExpression(MatchIn, "val-1")},
"key-1": MustCreateMatchExpression(MatchIn, "val-1"),
},
},
},
@ -132,7 +132,7 @@ func TestRule(t *testing.T) {
FeatureMatcherTerm{
Feature: "domain-1.if-1",
MatchExpressions: MatchExpressionSet{
Expressions: Expressions{"attr-1": MustCreateMatchExpression(MatchIn, "val-1")},
"attr-1": MustCreateMatchExpression(MatchIn, "val-1"),
},
},
},
@ -153,13 +153,13 @@ func TestRule(t *testing.T) {
FeatureMatcherTerm{
Feature: "domain-1.vf-1",
MatchExpressions: MatchExpressionSet{
Expressions: Expressions{"key-1": MustCreateMatchExpression(MatchIn, "val-x")},
"key-1": MustCreateMatchExpression(MatchIn, "val-x"),
},
},
FeatureMatcherTerm{
Feature: "domain-1.if-1",
MatchExpressions: MatchExpressionSet{
Expressions: Expressions{"attr-1": MustCreateMatchExpression(MatchIn, "val-1")},
"attr-1": MustCreateMatchExpression(MatchIn, "val-1"),
},
},
},
@ -168,7 +168,7 @@ func TestRule(t *testing.T) {
assert.Nilf(t, err, "unexpected error: %v", err)
assert.Nil(t, m.Labels, "instances should not have matched")
r5.MatchFeatures[0].MatchExpressions.Expressions["key-1"] = MustCreateMatchExpression(MatchIn, "val-1")
r5.MatchFeatures[0].MatchExpressions["key-1"] = MustCreateMatchExpression(MatchIn, "val-1")
m, err = r5.Execute(f)
assert.Nilf(t, err, "unexpected error: %v", err)
assert.Equal(t, r5.Labels, m.Labels, "instances should have matched")
@ -180,7 +180,7 @@ func TestRule(t *testing.T) {
FeatureMatcherTerm{
Feature: "domain-1.kf-1",
MatchExpressions: MatchExpressionSet{
Expressions: Expressions{"key-na": MustCreateMatchExpression(MatchExists)},
"key-na": MustCreateMatchExpression(MatchExists),
},
},
},
@ -196,12 +196,12 @@ func TestRule(t *testing.T) {
FeatureMatcherTerm{
Feature: "domain-1.kf-1",
MatchExpressions: MatchExpressionSet{
Expressions: Expressions{"key-1": MustCreateMatchExpression(MatchExists)},
"key-1": MustCreateMatchExpression(MatchExists),
},
},
},
})
r5.MatchFeatures[0].MatchExpressions.Expressions["key-1"] = MustCreateMatchExpression(MatchIn, "val-1")
r5.MatchFeatures[0].MatchExpressions["key-1"] = MustCreateMatchExpression(MatchIn, "val-1")
m, err = r5.Execute(f)
assert.Nilf(t, err, "unexpected error: %v", err)
assert.Equal(t, r5.Labels, m.Labels, "instances should have matched")
@ -275,27 +275,24 @@ var-2=
MatchFeatures: FeatureMatcher{
FeatureMatcherTerm{
Feature: "domain_1.kf_1",
MatchExpressions: MatchExpressionSet{Expressions: Expressions{
MatchExpressions: MatchExpressionSet{
"key-a": MustCreateMatchExpression(MatchExists),
"key-c": MustCreateMatchExpression(MatchExists),
"foo": MustCreateMatchExpression(MatchDoesNotExist),
},
},
},
FeatureMatcherTerm{
Feature: "domain_1.vf_1",
MatchExpressions: MatchExpressionSet{Expressions: Expressions{
MatchExpressions: MatchExpressionSet{
"key-1": MustCreateMatchExpression(MatchIn, "val-1", "val-2"),
"bar": MustCreateMatchExpression(MatchDoesNotExist),
},
},
},
FeatureMatcherTerm{
Feature: "domain_1.if_1",
MatchExpressions: MatchExpressionSet{Expressions: Expressions{
MatchExpressions: MatchExpressionSet{
"attr-1": MustCreateMatchExpression(MatchLt, "100"),
},
},
},
},
}
@ -337,10 +334,9 @@ var-2=
// Use a simple empty matchexpression set to match anything.
FeatureMatcherTerm{
Feature: "domain_1.kf_1",
MatchExpressions: MatchExpressionSet{Expressions: Expressions{
MatchExpressions: MatchExpressionSet{
"key-a": MustCreateMatchExpression(MatchExists),
},
},
},
},
}

View file

@ -111,12 +111,9 @@ type FeatureMatcherTerm struct {
// MatchExpressionSet contains a set of MatchExpressions, each of which is
// evaluated against a set of input values.
type MatchExpressionSet struct {
Expressions `json:",inline"`
}
type MatchExpressionSet map[string]*MatchExpression
// Expressions is a helper type to work around issues with k8s deepcopy-gen
type Expressions map[string]*MatchExpression
// MatchExpression specifies an expression to evaluate against a set of input
// values. It contains an operator that is applied when matching the input and

View file

@ -9,35 +9,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in Expressions) DeepCopyInto(out *Expressions) {
{
in := &in
*out = make(Expressions, len(*in))
for key, val := range *in {
var outVal *MatchExpression
if val == nil {
(*out)[key] = nil
} else {
in, out := &val, &outVal
*out = new(MatchExpression)
(*in).DeepCopyInto(*out)
}
(*out)[key] = outVal
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Expressions.
func (in Expressions) DeepCopy() Expressions {
if in == nil {
return nil
}
out := new(Expressions)
in.DeepCopyInto(out)
return *out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in FeatureMatcher) DeepCopyInto(out *FeatureMatcher) {
{
@ -62,7 +33,21 @@ func (in FeatureMatcher) DeepCopy() FeatureMatcher {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *FeatureMatcherTerm) DeepCopyInto(out *FeatureMatcherTerm) {
*out = *in
in.MatchExpressions.DeepCopyInto(&out.MatchExpressions)
if in.MatchExpressions != nil {
in, out := &in.MatchExpressions, &out.MatchExpressions
*out = make(MatchExpressionSet, len(*in))
for key, val := range *in {
var outVal *MatchExpression
if val == nil {
(*out)[key] = nil
} else {
in, out := &val, &outVal
*out = new(MatchExpression)
(*in).DeepCopyInto(*out)
}
(*out)[key] = outVal
}
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FeatureMatcherTerm.
@ -119,11 +104,10 @@ func (in *MatchExpression) DeepCopy() *MatchExpression {
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *MatchExpressionSet) DeepCopyInto(out *MatchExpressionSet) {
*out = *in
if in.Expressions != nil {
in, out := &in.Expressions, &out.Expressions
*out = make(Expressions, len(*in))
func (in MatchExpressionSet) DeepCopyInto(out *MatchExpressionSet) {
{
in := &in
*out = make(MatchExpressionSet, len(*in))
for key, val := range *in {
var outVal *MatchExpression
if val == nil {
@ -139,13 +123,13 @@ func (in *MatchExpressionSet) DeepCopyInto(out *MatchExpressionSet) {
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MatchExpressionSet.
func (in *MatchExpressionSet) DeepCopy() *MatchExpressionSet {
func (in MatchExpressionSet) DeepCopy() MatchExpressionSet {
if in == nil {
return nil
}
out := new(MatchExpressionSet)
in.DeepCopyInto(out)
return out
return *out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

View file

@ -20,6 +20,7 @@ package versioned
import (
"fmt"
"net/http"
discovery "k8s.io/client-go/discovery"
rest "k8s.io/client-go/rest"
@ -55,22 +56,45 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface {
// NewForConfig creates a new Clientset for the given config.
// If config's RateLimiter is not set and QPS and Burst are acceptable,
// NewForConfig will generate a rate-limiter in configShallowCopy.
// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient),
// where httpClient was generated with rest.HTTPClientFor(c).
func NewForConfig(c *rest.Config) (*Clientset, error) {
configShallowCopy := *c
if configShallowCopy.UserAgent == "" {
configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent()
}
// share the transport between all clients
httpClient, err := rest.HTTPClientFor(&configShallowCopy)
if err != nil {
return nil, err
}
return NewForConfigAndClient(&configShallowCopy, httpClient)
}
// NewForConfigAndClient creates a new Clientset for the given config and http client.
// Note the http client provided takes precedence over the configured transport values.
// If config's RateLimiter is not set and QPS and Burst are acceptable,
// NewForConfigAndClient will generate a rate-limiter in configShallowCopy.
func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, error) {
configShallowCopy := *c
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
if configShallowCopy.Burst <= 0 {
return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0")
}
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
}
var cs Clientset
var err error
cs.nfdV1alpha1, err = nfdv1alpha1.NewForConfig(&configShallowCopy)
cs.nfdV1alpha1, err = nfdv1alpha1.NewForConfigAndClient(&configShallowCopy, httpClient)
if err != nil {
return nil, err
}
cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy)
cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient)
if err != nil {
return nil, err
}
@ -80,11 +104,11 @@ func NewForConfig(c *rest.Config) (*Clientset, error) {
// NewForConfigOrDie creates a new Clientset for the given config and
// panics if there is an error in the config.
func NewForConfigOrDie(c *rest.Config) *Clientset {
var cs Clientset
cs.nfdV1alpha1 = nfdv1alpha1.NewForConfigOrDie(c)
cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c)
return &cs
cs, err := NewForConfig(c)
if err != nil {
panic(err)
}
return cs
}
// New creates a new Clientset for the given RESTClient.

View file

@ -74,7 +74,10 @@ func (c *Clientset) Tracker() testing.ObjectTracker {
return c.tracker
}
var _ clientset.Interface = &Clientset{}
var (
_ clientset.Interface = &Clientset{}
_ testing.FakeClient = &Clientset{}
)
// NfdV1alpha1 retrieves the NfdV1alpha1Client
func (c *Clientset) NfdV1alpha1() nfdv1alpha1.NfdV1alpha1Interface {

View file

@ -99,7 +99,7 @@ func (c *FakeNodeFeatureRules) Update(ctx context.Context, nodeFeatureRule *v1al
// Delete takes name of the nodeFeatureRule and deletes it. Returns an error if one occurs.
func (c *FakeNodeFeatureRules) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewRootDeleteAction(nodefeaturerulesResource, name), &v1alpha1.NodeFeatureRule{})
Invokes(testing.NewRootDeleteActionWithOptions(nodefeaturerulesResource, name, opts), &v1alpha1.NodeFeatureRule{})
return err
}

View file

@ -19,6 +19,8 @@ limitations under the License.
package v1alpha1
import (
"net/http"
rest "k8s.io/client-go/rest"
v1alpha1 "sigs.k8s.io/node-feature-discovery/pkg/apis/nfd/v1alpha1"
"sigs.k8s.io/node-feature-discovery/pkg/generated/clientset/versioned/scheme"
@ -39,12 +41,28 @@ func (c *NfdV1alpha1Client) NodeFeatureRules() NodeFeatureRuleInterface {
}
// NewForConfig creates a new NfdV1alpha1Client for the given config.
// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient),
// where httpClient was generated with rest.HTTPClientFor(c).
func NewForConfig(c *rest.Config) (*NfdV1alpha1Client, error) {
config := *c
if err := setConfigDefaults(&config); err != nil {
return nil, err
}
client, err := rest.RESTClientFor(&config)
httpClient, err := rest.HTTPClientFor(&config)
if err != nil {
return nil, err
}
return NewForConfigAndClient(&config, httpClient)
}
// NewForConfigAndClient creates a new NfdV1alpha1Client for the given config and http client.
// Note the http client provided takes precedence over the configured transport values.
func NewForConfigAndClient(c *rest.Config, h *http.Client) (*NfdV1alpha1Client, error) {
config := *c
if err := setConfigDefaults(&config); err != nil {
return nil, err
}
client, err := rest.RESTClientForConfigAndClient(&config, h)
if err != nil {
return nil, err
}

View file

@ -32,9 +32,7 @@ func getStaticFeatureConfig() []CustomRule {
{
PciID: &rules.PciIDRule{
MatchExpressionSet: nfdv1alpha1.MatchExpressionSet{
Expressions: nfdv1alpha1.Expressions{
"vendor": nfdv1alpha1.MustCreateMatchExpression(nfdv1alpha1.MatchIn, "15b3"),
},
"vendor": nfdv1alpha1.MustCreateMatchExpression(nfdv1alpha1.MatchIn, "15b3"),
},
},
},
@ -48,10 +46,8 @@ func getStaticFeatureConfig() []CustomRule {
{
LoadedKMod: &rules.LoadedKModRule{
MatchExpressionSet: nfdv1alpha1.MatchExpressionSet{
Expressions: nfdv1alpha1.Expressions{
"ib_uverbs": nfdv1alpha1.MustCreateMatchExpression(nfdv1alpha1.MatchExists),
"rdma_ucm": nfdv1alpha1.MustCreateMatchExpression(nfdv1alpha1.MatchExists),
},
"ib_uverbs": nfdv1alpha1.MustCreateMatchExpression(nfdv1alpha1.MatchExists),
"rdma_ucm": nfdv1alpha1.MustCreateMatchExpression(nfdv1alpha1.MatchExists),
},
},
},