Skip to content

Commit 5b3b26b

Browse files
committed
add custom alter components func and expose to outside projects
Signed-off-by: Carlos Salas <[email protected]>
1 parent ec8c0bd commit 5b3b26b

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

controller/alias.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,6 @@ type ProviderMapper = providercontroller.ProviderMapper
6666

6767
// WithProviderMapper is an alias for the internal WithProviderMapper function.
6868
var WithProviderMapper = providercontroller.WithProviderMapper
69+
70+
// WithCustomAlterComponentsFuncs is an alias for the internal WithCustomAlterComponentsFuncs function.
71+
var WithCustomAlterComponentsFuncs = providercontroller.WithCustomAlterComponentsFuncs

internal/controller/phases.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,18 @@ type PhaseReconciler struct {
7979
providerLister ProviderLister
8080
providerConverter ProviderConverter
8181

82-
ctrlClient client.Client
83-
ctrlConfig *rest.Config
84-
repo repository.Repository
85-
contract string
86-
options repository.ComponentsOptions
87-
providerConfig configclient.Provider
88-
configClient configclient.Client
89-
overridesClient configclient.Client
90-
components repository.Components
91-
clusterctlProvider *clusterctlv1.Provider
92-
needsCompression bool
82+
ctrlClient client.Client
83+
ctrlConfig *rest.Config
84+
repo repository.Repository
85+
contract string
86+
options repository.ComponentsOptions
87+
providerConfig configclient.Provider
88+
configClient configclient.Client
89+
overridesClient configclient.Client
90+
components repository.Components
91+
clusterctlProvider *clusterctlv1.Provider
92+
needsCompression bool
93+
customAlterComponentsFuncs []repository.ComponentsAlterFn
9394
}
9495

9596
// PhaseReconcilerOption is a function that configures the reconciler.
@@ -123,6 +124,13 @@ func WithProviderMapper(providerMapper ProviderMapper) PhaseReconcilerOption {
123124
}
124125
}
125126

127+
// WithCustomAlterComponentsFuncs configures the reconciler to use the given custom alter components functions.
128+
func WithCustomAlterComponentsFuncs(fns []repository.ComponentsAlterFn) PhaseReconcilerOption {
129+
return func(r *PhaseReconciler) {
130+
r.customAlterComponentsFuncs = fns
131+
}
132+
}
133+
126134
// PhaseFn is a function that represent a phase of the reconciliation.
127135
type PhaseFn func(context.Context) (*Result, error)
128136

@@ -616,6 +624,12 @@ func (p *PhaseReconciler) Fetch(ctx context.Context) (*Result, error) {
616624
return &Result{}, wrapPhaseError(err, operatorv1.ComponentsImageOverrideErrorReason, operatorv1.ProviderInstalledCondition)
617625
}
618626

627+
for _, fn := range p.customAlterComponentsFuncs {
628+
if err := repository.AlterComponents(p.components, fn); err != nil {
629+
return &Result{}, wrapPhaseError(err, operatorv1.ComponentsCustomizationErrorReason, operatorv1.ProviderInstalledCondition)
630+
}
631+
}
632+
619633
return &Result{}, nil
620634
}
621635

0 commit comments

Comments
 (0)