Skip to content

Commit

Permalink
Merge pull request #517 from ash2k/ash2k/reset-mapper
Browse files Browse the repository at this point in the history
fix: remove reflection hack
  • Loading branch information
k8s-ci-robot authored Jan 24, 2022
2 parents afa09f7 + 0af069f commit d45357d
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 83 deletions.
5 changes: 1 addition & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"sigs.k8s.io/cli-utils/cmd/status"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
"sigs.k8s.io/cli-utils/pkg/util/factory"

// This is here rather than in the libraries because of
// https://github.com/kubernetes-sigs/kustomize/issues/2060
Expand All @@ -42,9 +41,7 @@ func main() {
flags := cmd.PersistentFlags()
kubeConfigFlags := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag()
kubeConfigFlags.AddFlags(flags)
matchVersionKubeConfigFlags := util.NewMatchVersionFlags(&factory.CachingRESTClientGetter{
Delegate: kubeConfigFlags,
})
matchVersionKubeConfigFlags := util.NewMatchVersionFlags(kubeConfigFlags)
matchVersionKubeConfigFlags.AddFlags(flags)
flags.AddGoFlagSet(flag.CommandLine)
f := util.NewFactory(matchVersionKubeConfigFlags)
Expand Down
30 changes: 1 addition & 29 deletions pkg/apply/taskrunner/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ package taskrunner

import (
"context"
"fmt"
"reflect"
"sync"
"time"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/restmapper"
"k8s.io/klog/v2"
"sigs.k8s.io/cli-utils/pkg/apply/event"
"sigs.k8s.io/cli-utils/pkg/kstatus/status"
Expand Down Expand Up @@ -304,30 +301,5 @@ func (w *WaitTask) updateRESTMapper(taskContext *TaskContext) {
}

klog.V(5).Infof("resetting RESTMapper")
ddRESTMapper, err := extractDeferredDiscoveryRESTMapper(w.Mapper)
if err != nil {
if klog.V(4).Enabled() {
klog.Errorf("error resetting RESTMapper: %v", err)
}
}
ddRESTMapper.Reset()
}

// extractDeferredDiscoveryRESTMapper unwraps the provided RESTMapper
// interface to get access to the underlying DeferredDiscoveryRESTMapper
// that can be reset.
func extractDeferredDiscoveryRESTMapper(mapper meta.RESTMapper) (
*restmapper.DeferredDiscoveryRESTMapper,
error,
) {
val := reflect.ValueOf(mapper)
if val.Type().Kind() != reflect.Struct {
return nil, fmt.Errorf("unexpected RESTMapper type: %s", val.Type().String())
}
fv := val.FieldByName("RESTMapper")
ddRESTMapper, ok := fv.Interface().(*restmapper.DeferredDiscoveryRESTMapper)
if !ok {
return nil, fmt.Errorf("unexpected RESTMapper field type: %s", fv.Type())
}
return ddRESTMapper, nil
meta.MaybeResetRESTMapper(w.Mapper)
}
46 changes: 0 additions & 46 deletions pkg/util/factory/clientgetter.go

This file was deleted.

5 changes: 1 addition & 4 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"sigs.k8s.io/cli-utils/pkg/apply"
"sigs.k8s.io/cli-utils/pkg/common"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/util/factory"
"sigs.k8s.io/cli-utils/test/e2e/customprovider"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -357,9 +356,7 @@ func newCustomInvDestroyer() *apply.Destroyer {

func newFactory() util.Factory {
kubeConfigFlags := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag()
matchVersionKubeConfigFlags := util.NewMatchVersionFlags(&factory.CachingRESTClientGetter{
Delegate: kubeConfigFlags,
})
matchVersionKubeConfigFlags := util.NewMatchVersionFlags(kubeConfigFlags)
return util.NewFactory(matchVersionKubeConfigFlags)
}

Expand Down

0 comments on commit d45357d

Please sign in to comment.