Skip to content

Commit f146806

Browse files
committed
Add DirectSourceFetch feature gate to bypass cache for source objects
This feature gate enables fetching source objects (GitRepository, OCIRepository, Bucket) directly from the API server using APIReader, bypassing the controller's cache. This can be useful when immediate consistency is required for source object reads. When enabled via --feature-gates=DirectSourceFetch=true: - Source objects are fetched using r.APIReader instead of r.Client - A log message is emitted at startup indicating the feature is active Changes: - Add DirectSourceFetch field to KustomizationReconciler struct - Update getSource() to use APIReader when feature is enabled - Register feature gate with default value false (opt-in) - Add unit tests for GitRepository, OCIRepository, and Bucket sources - Update pkg/runtime dependency to v0.100.1 - Downgrade pkg/ssa to v0.67.1 Signed-off-by: Dipti Pai <diptipai89@outlook.com>
1 parent d527a7b commit f146806

6 files changed

Lines changed: 359 additions & 35 deletions

File tree

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ require (
2828
github.com/fluxcd/pkg/cache v0.13.0
2929
github.com/fluxcd/pkg/http/fetch v0.22.0
3030
github.com/fluxcd/pkg/kustomize v1.27.0
31-
github.com/fluxcd/pkg/runtime v0.100.0
32-
github.com/fluxcd/pkg/ssa v0.68.0
31+
github.com/fluxcd/pkg/runtime v0.100.1
32+
github.com/fluxcd/pkg/ssa v0.67.1
3333
github.com/fluxcd/pkg/tar v0.17.0
3434
github.com/fluxcd/pkg/testserver v0.13.0
3535
github.com/fluxcd/source-controller/api v1.7.2

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ github.com/fluxcd/pkg/http/fetch v0.22.0 h1:FT8CfstPE/e7+KRxNrx8ZJ1Uj5rkR5wXOtvQ
210210
github.com/fluxcd/pkg/http/fetch v0.22.0/go.mod h1:X+8wF3peP79TyyDSgCJiavz+fAcYaf7CRXSeu7ccsPA=
211211
github.com/fluxcd/pkg/kustomize v1.27.0 h1:bWoWVaHV1ZRo3Ei1JXpY58hJK25WWna+az5jj6zseE0=
212212
github.com/fluxcd/pkg/kustomize v1.27.0/go.mod h1:KKb26vz5EApyOrgencDlvixJnuI6cnkWGks95sK9AFs=
213-
github.com/fluxcd/pkg/runtime v0.100.0 h1:7k2T/zlOLZ+knVr5fGB6cqq3Dr9D1k2jEe6AJo91JlI=
214-
github.com/fluxcd/pkg/runtime v0.100.0/go.mod h1:SctSsHvFwUfiOVP1zirP6mo7I8wQtXeWVl2lNQWal88=
213+
github.com/fluxcd/pkg/runtime v0.100.1 h1:UiPmgY8Yv7UF06MT5T8AG9uDGNszm75/DQtK6JEhnrM=
214+
github.com/fluxcd/pkg/runtime v0.100.1/go.mod h1:SctSsHvFwUfiOVP1zirP6mo7I8wQtXeWVl2lNQWal88=
215215
github.com/fluxcd/pkg/sourceignore v0.17.0 h1:Z72nruRMhC15zIEpWoDrAcJcJ1El6QDnP/aRDfE4WOA=
216216
github.com/fluxcd/pkg/sourceignore v0.17.0/go.mod h1:3e/VmYLId0pI/H5sK7W9Ibif+j0Ahns9RxNjDMtTTfY=
217-
github.com/fluxcd/pkg/ssa v0.68.0 h1:hdRFrBJO9dh04200tNJljpi4TOArHC0nq+LUFZxMgKc=
218-
github.com/fluxcd/pkg/ssa v0.68.0/go.mod h1:PFXVjChubQOiWDxalpwh6PzRsEswGqnKwZB4ScoxDx4=
217+
github.com/fluxcd/pkg/ssa v0.67.1 h1:wmwrznP+USRUtppKRjAiBx3ayriygRx0IeMdX7z/HaM=
218+
github.com/fluxcd/pkg/ssa v0.67.1/go.mod h1:PFXVjChubQOiWDxalpwh6PzRsEswGqnKwZB4ScoxDx4=
219219
github.com/fluxcd/pkg/tar v0.17.0 h1:uNxbFXy8ly8C7fJ8D7w3rjTNJFrb4Hp1aY/30XkfvxY=
220220
github.com/fluxcd/pkg/tar v0.17.0/go.mod h1:b1xyIRYDD0ket4SV5u0UXYv+ZdN/O/HmIO5jZQdHQls=
221221
github.com/fluxcd/pkg/testserver v0.13.0 h1:xEpBcEYtD7bwvZ+i0ZmChxKkDo/wfQEV3xmnzVybSSg=

internal/controller/kustomization_controller.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ import (
7070

7171
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
7272
"github.com/fluxcd/kustomize-controller/internal/decryptor"
73-
"github.com/fluxcd/kustomize-controller/internal/features"
7473
"github.com/fluxcd/kustomize-controller/internal/inventory"
7574
)
7675

@@ -118,6 +117,7 @@ type KustomizationReconciler struct {
118117

119118
AdditiveCELDependencyCheck bool
120119
AllowExternalArtifact bool
120+
DirectSourceFetch bool
121121
FailFast bool
122122
GroupChangeLog bool
123123
StrictSubstitutions bool
@@ -686,13 +686,19 @@ func (r *KustomizationReconciler) getSource(ctx context.Context,
686686
if obj.Spec.SourceRef.Kind == sourcev1.ExternalArtifactKind && !r.AllowExternalArtifact {
687687
return src, acl.AccessDeniedError(
688688
fmt.Sprintf("can't access '%s/%s', %s feature gate is disabled",
689-
obj.Spec.SourceRef.Kind, namespacedName, features.ExternalArtifact))
689+
obj.Spec.SourceRef.Kind, namespacedName, runtimeCtrl.FeatureGateExternalArtifact))
690+
}
691+
692+
// Use APIReader to bypass the cache when DirectSourceFetch is enabled.
693+
var reader client.Reader = r.Client
694+
if r.DirectSourceFetch {
695+
reader = r.APIReader
690696
}
691697

692698
switch obj.Spec.SourceRef.Kind {
693699
case sourcev1.OCIRepositoryKind:
694700
var repository sourcev1.OCIRepository
695-
err := r.Client.Get(ctx, namespacedName, &repository)
701+
err := reader.Get(ctx, namespacedName, &repository)
696702
if err != nil {
697703
if apierrors.IsNotFound(err) {
698704
return src, err
@@ -702,7 +708,7 @@ func (r *KustomizationReconciler) getSource(ctx context.Context,
702708
src = &repository
703709
case sourcev1.GitRepositoryKind:
704710
var repository sourcev1.GitRepository
705-
err := r.Client.Get(ctx, namespacedName, &repository)
711+
err := reader.Get(ctx, namespacedName, &repository)
706712
if err != nil {
707713
if apierrors.IsNotFound(err) {
708714
return src, err
@@ -712,7 +718,7 @@ func (r *KustomizationReconciler) getSource(ctx context.Context,
712718
src = &repository
713719
case sourcev1.BucketKind:
714720
var bucket sourcev1.Bucket
715-
err := r.Client.Get(ctx, namespacedName, &bucket)
721+
err := reader.Get(ctx, namespacedName, &bucket)
716722
if err != nil {
717723
if apierrors.IsNotFound(err) {
718724
return src, err
@@ -722,7 +728,7 @@ func (r *KustomizationReconciler) getSource(ctx context.Context,
722728
src = &bucket
723729
case sourcev1.ExternalArtifactKind:
724730
var ea sourcev1.ExternalArtifact
725-
err := r.Client.Get(ctx, namespacedName, &ea)
731+
err := reader.Get(ctx, namespacedName, &ea)
726732
if err != nil {
727733
if apierrors.IsNotFound(err) {
728734
return src, err

0 commit comments

Comments
 (0)