Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use reconciliation context in kubeconfig provider #69

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/controller/gardener_cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewGardenerClusterController(mgr ctrl.Manager, kubeconfigProvider Kubeconfi

//go:generate mockery --name=KubeconfigProvider
type KubeconfigProvider interface {
Fetch(shootName string) (string, error)
Fetch(ctx context.Context, shootName string) (string, error)
}

//+kubebuilder:rbac:groups=infrastructuremanager.kyma-project.io,resources=gardenerclusters,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -226,7 +226,7 @@ func (controller *GardenerClusterController) handleKubeconfig(ctx context.Contex
return ksZero, err
}

kubeconfig, err := controller.KubeconfigProvider.Fetch(cluster.Spec.Shoot.Name)
kubeconfig, err := controller.KubeconfigProvider.Fetch(ctx, cluster.Spec.Shoot.Name)
if err != nil {
cluster.UpdateConditionForErrorState(imv1.ConditionTypeKubeconfigManagement, imv1.ConditionReasonFailedToGetKubeconfig, metav1.ConditionTrue, err)
return ksZero, err
Expand Down
26 changes: 15 additions & 11 deletions internal/controller/mocks/KubeconfigProvider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
. "github.com/stretchr/testify/mock"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -45,6 +46,7 @@ var (
testEnv *envtest.Environment //nolint:gochecknoglobals
suiteCtx context.Context //nolint:gochecknoglobals
cancelSuiteCtx context.CancelFunc //nolint:gochecknoglobals
anyContext = MatchedBy(func(ctx context.Context) bool { return true })
)

const TestKubeconfigValidityTime = 24 * time.Hour
Expand Down Expand Up @@ -102,12 +104,12 @@ var _ = BeforeSuite(func() {
})

func setupKubeconfigProviderMock(kpMock *mocks.KubeconfigProvider) {
kpMock.On("Fetch", "shootName1").Return("kubeconfig1", nil)
kpMock.On("Fetch", "shootName2").Return("kubeconfig2", nil)
kpMock.On("Fetch", "shootName3").Return("", errors.New("failed to get kubeconfig"))
kpMock.On("Fetch", "shootName6").Return("kubeconfig6", nil)
kpMock.On("Fetch", "shootName4").Return("kubeconfig4", nil)
kpMock.On("Fetch", "shootName5").Return("kubeconfig5", nil)
kpMock.On("Fetch", anyContext, "shootName1").Return("kubeconfig1", nil)
kpMock.On("Fetch", anyContext, "shootName2").Return("kubeconfig2", nil)
kpMock.On("Fetch", anyContext, "shootName3").Return("", errors.New("failed to get kubeconfig"))
kpMock.On("Fetch", anyContext, "shootName6").Return("kubeconfig6", nil)
kpMock.On("Fetch", anyContext, "shootName4").Return("kubeconfig4", nil)
kpMock.On("Fetch", anyContext, "shootName5").Return("kubeconfig5", nil)
}

var _ = AfterSuite(func() {
Expand Down
4 changes: 2 additions & 2 deletions internal/gardener/KubeConfigProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func NewKubeconfigProvider(
}
}

func (kp KubeconfigProvider) Fetch(shootName string) (string, error) {
shoot, err := kp.shootClient.Get(context.Background(), shootName, v1.GetOptions{})
func (kp KubeconfigProvider) Fetch(ctx context.Context, shootName string) (string, error) {
shoot, err := kp.shootClient.Get(ctx, shootName, v1.GetOptions{})
if err != nil {
return "", errors.Wrap(err, "failed to get shoot")
}
Expand Down
Loading