Skip to content

Commit

Permalink
Fix Getting Kubeclient in OpenShift Extension of Pipeline
Browse files Browse the repository at this point in the history
There is an issue introduced in PR: #1530 (https://github.com/tektoncd/operator/pull/1530/files#diff-7f51fd839c96e48ad11d43ad6e8e502cccfb00405087d1c8e116fc6245fad615R92)

```
panic: Unable to fetch k8s.io/client-go/kubernetes.Interface from context. This context is not the application context (which is typically given to constructors via sharedmain).

goroutine 2705 [running]:
go.uber.org/zap/zapcore.CheckWriteAction.OnWrite(0x0?, 0x1e4bde2?, {0x0?, 0x0?, 0xc0023ea000?})
        /go/src/github.com/tektoncd/operator/vendor/go.uber.org/zap/zapcore/entry.go:198 +0x65
go.uber.org/zap/zapcore.(*CheckedEntry).Write(0xc000335ad0, {0x0, 0x0, 0x0})
        /go/src/github.com/tektoncd/operator/vendor/go.uber.org/zap/zapcore/entry.go:264 +0x3ec
go.uber.org/zap.(*SugaredLogger).log(0xc001166940, 0x4, {0x0?, 0x1ac1701?}, {0xc000e25450?, 0x40dc07?, 0x3497c2e1ffdc0d75?}, {0x0, 0x0, 0x0})
        /go/src/github.com/tektoncd/operator/vendor/go.uber.org/zap/sugar.go:295 +0xee
go.uber.org/zap.(*SugaredLogger).Panic(...)
        /go/src/github.com/tektoncd/operator/vendor/go.uber.org/zap/sugar.go:153
knative.dev/pkg/client/injection/kube/client.Get({0x2149358, 0xc0017f2bd0})
        /go/src/github.com/tektoncd/operator/vendor/knative.dev/pkg/client/injection/kube/client/client.go:201 +0x1b7
github.com/tektoncd/operator/pkg/reconciler/openshift/tektonpipeline.openshiftExtension.PreReconcile({0xc0007d4320?}, {0x2149358, 0xc0017f2bd0}, {0x2163a08?, 0xc000d89180?})
        /go/src/github.com/tektoncd/operator/pkg/reconciler/openshift/tektonpipeline/extension.go:92 +0x426
github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektonpipeline.(*Reconciler).ReconcileKind(0xc0009a1100, {0x2149358, 0xc0017f2bd0}, 0xc000d89180)
        /go/src/github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektonpipeline/reconcile.go:87 +0x687
github.com/tektoncd/operator/pkg/client/injection/reconciler/operator/v1alpha1/tektonpipeline.(*reconcilerImpl).Reconcile(0xc000410280, {0x2149358, 0xc0017f2ba0}, {0xc00188d1f8, 0x8})
        /go/src/github.com/tektoncd/operator/pkg/client/injection/reconciler/operator/v1alpha1/tektonpipeline/reconciler.go:236 +0x582
knative.dev/pkg/controller.(*Impl).processNextWorkItem(0xc0008ed1a0)
        /go/src/github.com/tektoncd/operator/vendor/knative.dev/pkg/controller/controller.go:542 +0x58d
knative.dev/pkg/controller.(*Impl).RunContext.func3()
        /go/src/github.com/tektoncd/operator/vendor/knative.dev/pkg/controller/controller.go:491 +0x68
created by knative.dev/pkg/controller.(*Impl).RunContext
        /go/src/github.com/tektoncd/operator/vendor/knative.dev/pkg/controller/controller.go:489 +0x312

```
  • Loading branch information
khrm authored and tekton-robot committed Jun 6, 2023
1 parent 4fa38e7 commit 74febeb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/reconciler/openshift/tektonpipeline/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/tektoncd/operator/pkg/reconciler/common"
"github.com/tektoncd/operator/pkg/reconciler/kubernetes/tektoninstallerset/client"
occommon "github.com/tektoncd/operator/pkg/reconciler/openshift/common"
"k8s.io/client-go/kubernetes"
kubeclient "knative.dev/pkg/client/injection/kube/client"
"knative.dev/pkg/logging"
)
Expand All @@ -50,12 +51,14 @@ func OpenShiftExtension(ctx context.Context) common.Extension {
// value through extension not going to affect execution
installerSetClient: client.NewInstallerSetClient(operatorclient.Get(ctx).OperatorV1alpha1().TektonInstallerSets(),
version, "pipelines-ext", v1alpha1.KindTektonPipeline, nil),
kubeClientSet: kubeclient.Get(ctx),
}
return ext
}

type openshiftExtension struct {
installerSetClient *client.InstallerSetClient
kubeClientSet kubernetes.Interface
}

func (oe openshiftExtension) Transformers(comp v1alpha1.TektonComponent) []mf.Transformer {
Expand Down Expand Up @@ -89,8 +92,7 @@ func (oe openshiftExtension) PreReconcile(ctx context.Context, comp v1alpha1.Tek
}

// reconcile namespace with updated labels
kubeClientSet := kubeclient.Get(ctx)
return common.ReconcileTargetNamespace(ctx, labels, comp, kubeClientSet)
return common.ReconcileTargetNamespace(ctx, labels, comp, oe.kubeClientSet)
}

func (oe openshiftExtension) PostReconcile(ctx context.Context, comp v1alpha1.TektonComponent) error {
Expand Down

0 comments on commit 74febeb

Please sign in to comment.