@@ -17,16 +17,17 @@ limitations under the License.
1717package action
1818
1919import (
20+ "context"
2021 "fmt"
2122 "log/slog"
2223
23- "github.com/fluxcd/cli-utils/pkg/kstatus/polling/engine"
2424 helmaction "helm.sh/helm/v4/pkg/action"
25- helmkube "helm.sh/helm/v4/pkg/kube"
2625 helmstorage "helm.sh/helm/v4/pkg/storage"
2726 helmdriver "helm.sh/helm/v4/pkg/storage/driver"
2827 "k8s.io/cli-runtime/pkg/genericclioptions"
2928
29+ "github.com/fluxcd/pkg/ssa"
30+
3031 "github.com/fluxcd/helm-controller/internal/storage"
3132)
3233
@@ -45,15 +46,18 @@ type ConfigFactory struct {
4546 // Getter is the RESTClientGetter used to get the RESTClient for the
4647 // Kubernetes API.
4748 Getter genericclioptions.RESTClientGetter
48- // KubeClient is the (Helm) Kubernetes client, it is Helm-specific and
49+ // KubeClient is the (wrapped) Helm Kubernetes client, it is Helm-specific and
4950 // contains a factory used for lazy-loading.
50- KubeClient * helmkube. Client
51+ KubeClient * Client
5152 // Driver to use for the Helm action.
5253 Driver helmdriver.Driver
5354 // StorageLog is the logger to use for the Helm storage driver.
5455 StorageLog slog.Handler
55- // StatusReader is the status reader used to evaluate custom health checks.
56- StatusReader engine.StatusReader
56+ // NewResourceManager is the resource manager used to evaluate custom health checks.
57+ NewResourceManager func (sr ... NewStatusReaderFunc ) * ssa.ResourceManager
58+ // WaitContext is the context used for waiting operations in the Helm
59+ // Kubernetes client.
60+ WaitContext context.Context
5761}
5862
5963// ConfigFactoryOption is a function that configures a ConfigFactory.
@@ -62,7 +66,7 @@ type ConfigFactoryOption func(*ConfigFactory) error
6266// NewConfigFactory returns a new ConfigFactory configured with the provided
6367// options.
6468func NewConfigFactory (getter genericclioptions.RESTClientGetter , opts ... ConfigFactoryOption ) (* ConfigFactory , error ) {
65- kubeClient := helmkube . New (getter )
69+ kubeClient := NewClient (getter )
6670 factory := & ConfigFactory {
6771 Getter : getter ,
6872 KubeClient : kubeClient ,
@@ -133,10 +137,19 @@ func WithStorageLog(log slog.Handler) ConfigFactoryOption {
133137 }
134138}
135139
136- // WithStatusReader sets the ConfigFactory.StatusReader.
137- func WithStatusReader (reader engine.StatusReader ) ConfigFactoryOption {
140+ // WithResourceManager sets the ConfigFactory.ResourceManager.
141+ func WithResourceManager (mgr func (sr ... NewStatusReaderFunc ) * ssa.ResourceManager ) ConfigFactoryOption {
142+ return func (f * ConfigFactory ) error {
143+ f .NewResourceManager = mgr
144+ return nil
145+ }
146+ }
147+
148+ // WithWaitContext sets the context used for waiting operations in the Helm
149+ // Kubernetes client.
150+ func WithWaitContext (ctx context.Context ) ConfigFactoryOption {
138151 return func (f * ConfigFactory ) error {
139- f .StatusReader = reader
152+ f .WaitContext = ctx
140153 return nil
141154 }
142155}
@@ -156,11 +169,12 @@ func (c *ConfigFactory) NewStorage(observers ...storage.ObserveFunc) *helmstorag
156169// Build returns a new Helm action.Configuration configured with the receiver
157170// values, and the provided logger and observer(s).
158171func (c * ConfigFactory ) Build (log slog.Handler , observers ... storage.ObserveFunc ) * helmaction.Configuration {
159- client := c .KubeClient
172+ client := NewClient (c .Getter )
173+ client .newResourceManager = c .NewResourceManager
174+ client .waitContext = c .WaitContext
160175
161176 var opts []helmaction.ConfigurationOption
162177 if log != nil {
163- client = helmkube .New (c .Getter )
164178 client .SetLogger (log )
165179 opts = append (opts , helmaction .ConfigurationSetLogger (log ))
166180 }
0 commit comments