diff --git a/pkg/nfd-worker/nfd-worker-internal_test.go b/pkg/nfd-worker/nfd-worker-internal_test.go index 8b2943ad5..2d2b13a6b 100644 --- a/pkg/nfd-worker/nfd-worker-internal_test.go +++ b/pkg/nfd-worker/nfd-worker-internal_test.go @@ -17,7 +17,6 @@ limitations under the License. package nfdworker import ( - "fmt" "io/ioutil" "os" "path/filepath" @@ -36,7 +35,6 @@ import ( "sigs.k8s.io/node-feature-discovery/source/cpu" "sigs.k8s.io/node-feature-discovery/source/fake" "sigs.k8s.io/node-feature-discovery/source/kernel" - "sigs.k8s.io/node-feature-discovery/source/panic_fake" "sigs.k8s.io/node-feature-discovery/source/pci" ) @@ -358,12 +356,12 @@ func TestNewNfdWorker(t *testing.T) { func TestCreateFeatureLabels(t *testing.T) { Convey("When creating feature labels from the configured sources", t, func() { + fakeFeatureSource := source.FeatureSource(new(fake.Source)) + fakeFeatureSource.SetConfig(fakeFeatureSource.NewConfig()) + sources := []source.FeatureSource{fakeFeatureSource} + Convey("When fake feature source is configured", func() { emptyLabelWL := regexp.MustCompile("") - fakeFeatureSource := source.FeatureSource(new(fake.Source)) - fakeFeatureSource.SetConfig(fakeFeatureSource.NewConfig()) - sources := []source.FeatureSource{} - sources = append(sources, fakeFeatureSource) labels := createFeatureLabels(sources, *emptyLabelWL) Convey("Proper fake labels are returned", func() { @@ -374,9 +372,6 @@ func TestCreateFeatureLabels(t *testing.T) { }) }) Convey("When fake feature source is configured with a whitelist that doesn't match", func() { - fakeFeatureSource := source.FeatureSource(new(fake.Source)) - sources := []source.FeatureSource{} - sources = append(sources, fakeFeatureSource) labels := createFeatureLabels(sources, *regexp.MustCompile(".*rdt.*")) Convey("fake labels are not returned", func() { @@ -389,21 +384,6 @@ func TestCreateFeatureLabels(t *testing.T) { }) } -func TestGetFeatureLabels(t *testing.T) { - Convey("When I get feature labels and panic occurs during discovery of a feature source", t, func() { - fakePanicFeatureSource := source.FeatureSource(new(panicfake.Source)) - - returnedLabels, err := getFeatureLabels(fakePanicFeatureSource, *regexp.MustCompile("")) - Convey("No label is returned", func() { - So(len(returnedLabels), ShouldEqual, 0) - }) - Convey("Error is produced and panic error is returned", func() { - So(err, ShouldResemble, fmt.Errorf("fake panic error")) - }) - - }) -} - func TestAdvertiseFeatureLabels(t *testing.T) { Convey("When advertising labels", t, func() { mockClient := &labeler.MockLabelerClient{} diff --git a/pkg/nfd-worker/nfd-worker.go b/pkg/nfd-worker/nfd-worker.go index 1ad42adde..81bf0be33 100644 --- a/pkg/nfd-worker/nfd-worker.go +++ b/pkg/nfd-worker/nfd-worker.go @@ -48,7 +48,6 @@ import ( "sigs.k8s.io/node-feature-discovery/source/local" "sigs.k8s.io/node-feature-discovery/source/memory" "sigs.k8s.io/node-feature-discovery/source/network" - "sigs.k8s.io/node-feature-discovery/source/panic_fake" "sigs.k8s.io/node-feature-discovery/source/pci" "sigs.k8s.io/node-feature-discovery/source/storage" "sigs.k8s.io/node-feature-discovery/source/system" @@ -146,7 +145,6 @@ func NewNfdWorker(args *Args) (NfdWorker, error) { }, testSources: []source.FeatureSource{ &fake.Source{}, - &panicfake.Source{}, }, stop: make(chan struct{}, 1), } @@ -527,13 +525,6 @@ func createFeatureLabels(sources []source.FeatureSource, labelWhiteList regexp.R // getFeatureLabels returns node labels for features discovered by the // supplied source. func getFeatureLabels(source source.FeatureSource, labelWhiteList regexp.Regexp) (labels Labels, err error) { - defer func() { - if r := recover(); r != nil { - klog.Errorf("panic occurred during discovery of source [%s]: %v", source.Name(), r) - err = fmt.Errorf("%v", r) - } - }() - labels = Labels{} features, err := source.Discover() if err != nil { diff --git a/source/panic_fake/fake_panic.go b/source/panic_fake/fake_panic.go deleted file mode 100644 index 741dd71b7..000000000 --- a/source/panic_fake/fake_panic.go +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. - -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 panicfake - -import "sigs.k8s.io/node-feature-discovery/source" - -// Source implements FeatureSource. -type Source struct{} - -// Name returns an identifier string for this feature source. -func (s Source) Name() string { return "panic_fake" } - -// NewConfig method of the FeatureSource interface -func (s *Source) NewConfig() source.Config { return nil } - -// GetConfig method of the FeatureSource interface -func (s *Source) GetConfig() source.Config { return nil } - -// SetConfig method of the FeatureSource interface -func (s *Source) SetConfig(source.Config) {} - -// Discover calls panic(). -func (s Source) Discover() (source.Features, error) { - panic("fake panic error") -}