@@ -53,6 +53,14 @@ const (
5353//go:embed manifests/installer-pod.yaml
5454var podTemplate []byte
5555
56+ type OperatorClient interface {
57+ GetStaticPodOperatorState () (spec * operatorv1.StaticPodOperatorSpec , status * operatorv1.StaticPodOperatorStatus , resourceVersion string , err error )
58+ GetStaticPodOperatorStateWithQuorum (ctx context.Context ) (spec * operatorv1.StaticPodOperatorSpec , status * operatorv1.StaticPodOperatorStatus , resourceVersion string , err error )
59+ ApplyStaticPodOperatorStatus (ctx context.Context , fieldManager string , applyConfiguration * applyoperatorv1.StaticPodOperatorStatusApplyConfiguration ) (err error )
60+ }
61+
62+ var _ OperatorClient = v1helpers .StaticPodOperatorClient (nil )
63+
5664// InstallerController is a controller that watches the currentRevision and targetRevision fields for each node and spawn
5765// installer pods to update the static pods on the master nodes.
5866type InstallerController struct {
@@ -81,7 +89,7 @@ type InstallerController struct {
8189 certSecrets []UnrevisionedResource
8290 certDir string
8391
84- operatorClient v1helpers. StaticPodOperatorClient
92+ operatorClient OperatorClient
8593
8694 configMapsGetter corev1client.ConfigMapsGetter
8795 secretsGetter corev1client.SecretsGetter
@@ -92,7 +100,9 @@ type InstallerController struct {
92100 // installerPodImageFn returns the image name for the installer pod
93101 installerPodImageFn func () string
94102 // ownerRefsFn sets the ownerrefs on the pruner pod
95- ownerRefsFn func (ctx context.Context , revision int32 ) ([]metav1.OwnerReference , error )
103+ ownerRefsFn func (ctx context.Context , revision int32 ) ([]metav1.OwnerReference , error )
104+ ensureRequiredResourcesExistFn func (ctx context.Context , revisionNumber int32 ) error
105+ manageInstallationPodsFn func (ctx context.Context , operatorSpec * operatorv1.StaticPodOperatorSpec , originalOperatorStatus * operatorv1.StaticPodOperatorStatus ) (bool , time.Duration , * operatorv1.NodeStatus , func (), error )
96106
97107 installerPodMutationFns []InstallerPodMutationFunc
98108
@@ -200,6 +210,8 @@ func NewInstallerController(
200210 }
201211
202212 c .ownerRefsFn = c .setOwnerRefs
213+ c .ensureRequiredResourcesExistFn = c .ensureRequiredResourcesExist
214+ c .manageInstallationPodsFn = c .manageInstallationPods
203215 c .factory = factory .New ().
204216 WithInformers (
205217 operatorClient .Informer (),
@@ -1111,7 +1123,7 @@ func (c InstallerController) ensureRequiredResourcesExist(ctx context.Context, r
11111123 return fmt .Errorf ("missing required resources: %v" , aggregatedErr )
11121124}
11131125
1114- func (c InstallerController ) Sync (ctx context.Context , syncCtx factory.SyncContext ) error {
1126+ func (c * InstallerController ) Sync (ctx context.Context , syncCtx factory.SyncContext ) error {
11151127 operatorSpec , originalOperatorStatus , operatorResourceVersion , err := c .operatorClient .GetStaticPodOperatorState ()
11161128 if err != nil {
11171129 return err
@@ -1123,7 +1135,7 @@ func (c InstallerController) Sync(ctx context.Context, syncCtx factory.SyncConte
11231135 // Apply response.
11241136 if c .podOperatorStatusApplied {
11251137 if c .lastPodOperatorAppliedRV == 0 {
1126- _ , _ , resourceVersion , err := c .operatorClient .GetOperatorStateWithQuorum (ctx )
1138+ _ , _ , resourceVersion , err := c .operatorClient .GetStaticPodOperatorStateWithQuorum (ctx )
11271139 if err != nil {
11281140 return err
11291141 }
@@ -1152,7 +1164,7 @@ func (c InstallerController) Sync(ctx context.Context, syncCtx factory.SyncConte
11521164 return nil
11531165 }
11541166
1155- err = c .ensureRequiredResourcesExist (ctx , originalOperatorStatus .LatestAvailableRevision )
1167+ err = c .ensureRequiredResourcesExistFn (ctx , originalOperatorStatus .LatestAvailableRevision )
11561168
11571169 // Only manage installation pods when all required certs are present.
11581170 var updatedNode * operatorv1.NodeStatus
@@ -1161,7 +1173,7 @@ func (c InstallerController) Sync(ctx context.Context, syncCtx factory.SyncConte
11611173 var requeue bool
11621174 var after time.Duration
11631175 var syncErr error
1164- requeue , after , updatedNode , updatedNodeReportOnSuccessfulUpdateFn , syncErr = c .manageInstallationPods (ctx , operatorSpec , operatorStatus )
1176+ requeue , after , updatedNode , updatedNodeReportOnSuccessfulUpdateFn , syncErr = c .manageInstallationPodsFn (ctx , operatorSpec , operatorStatus )
11651177 if requeue && syncErr == nil {
11661178 syncCtx .Queue ().AddAfter (syncCtx .QueueKey (), after )
11671179 return nil
0 commit comments