Skip to content

Commit

Permalink
fix(controllers): don't cache secrets as it can consume a lot of memory
Browse files Browse the repository at this point in the history
  • Loading branch information
paullaffitte committed Oct 19, 2023
1 parent 26a2eb2 commit c77d8e6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/cache/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func main() {
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("cachedimage-controller"),
ApiReader: mgr.GetAPIReader(),
ExpiryDelay: time.Duration(expiryDelay*24) * time.Hour,
}).SetupWithManager(mgr, maxConcurrentCachedImageReconciles); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "CachedImage")
Expand Down
3 changes: 2 additions & 1 deletion controllers/cachedimage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type CachedImageReconciler struct {
client.Client
Scheme *runtime.Scheme
Recorder record.EventRecorder
ApiReader client.Reader
ExpiryDelay time.Duration
}

Expand Down Expand Up @@ -128,7 +129,7 @@ func (r *CachedImageReconciler) Reconcile(ctx context.Context, req ctrl.Request)

if !isCached {
r.Recorder.Eventf(&cachedImage, "Normal", "Caching", "Start caching image %s", cachedImage.Spec.SourceImage)
keychain := registry.NewKubernetesKeychain(r.Client, cachedImage.Spec.PullSecretsNamespace, cachedImage.Spec.PullSecretNames)
keychain := registry.NewKubernetesKeychain(r.ApiReader, cachedImage.Spec.PullSecretsNamespace, cachedImage.Spec.PullSecretNames)
if err := registry.CacheImage(cachedImage.Spec.SourceImage, keychain); err != nil {
log.Error(err, "failed to cache image")
r.Recorder.Eventf(&cachedImage, "Warning", "CacheFailed", "Failed to cache image %s, reason: %s", cachedImage.Spec.SourceImage, err)
Expand Down
4 changes: 2 additions & 2 deletions internal/registry/keychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const (
)

type kubernetesKeychain struct {
client client.Client
client client.Reader
mu sync.Mutex
namespace string
pullSecret string
}

func NewKubernetesKeychain(client client.Client, namespace string, pullSecrets []string) authn.Keychain {
func NewKubernetesKeychain(client client.Reader, namespace string, pullSecrets []string) authn.Keychain {
keychains := []authn.Keychain{}
for _, pullSecret := range pullSecrets {
keychains = append(keychains, &kubernetesKeychain{
Expand Down

0 comments on commit c77d8e6

Please sign in to comment.