Skip to content

Commit

Permalink
WIP: Added the callback shouldRevisionInstall to provide additional c…
Browse files Browse the repository at this point in the history
…onditions for installation

Signed-off-by: jubittajohn <jujohn@redhat.com>
  • Loading branch information
jubittajohn committed Jun 22, 2024
1 parent 4bb4238 commit 02d8fd7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ type InstallerController struct {
clock clock.Clock
installerBackOff func(count int) time.Duration
fallbackBackOff func(count int) time.Duration

shouldRevisionInstall func() (bool, error)
}

// InstallerPodMutationFunc is a function that has a chance at changing the installer pod before it is created
Expand Down Expand Up @@ -128,6 +130,11 @@ func (c *InstallerController) WithStartupMonitorSupport(startupMonitorEnabled fu
return c
}

func (c *InstallerController) WithShouldRevisionInstall(shouldRevisionInstall func() (bool, error)) *InstallerController {
c.shouldRevisionInstall = shouldRevisionInstall
return c
}

// staticPodState is the status of a static pod that has been installed to a node.
type staticPodState int

Expand Down Expand Up @@ -447,6 +454,16 @@ func (c *InstallerController) manageInstallationPods(ctx context.Context, operat
return true, requeueAfter, nil
}

// Check if revision should be installed based on if the quorum is about to be violated
if c.shouldRevisionInstall != nil {
quorumSafe, err := c.shouldRevisionInstall()
if !quorumSafe {
return true, 30 * time.Second, err
} else {
return false, 0, nil
}
}

for l := 0; l < len(operatorStatus.NodeStatuses); l++ {
i := (startNode + l) % len(operatorStatus.NodeStatuses)

Expand Down
11 changes: 11 additions & 0 deletions pkg/operator/staticpod/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type staticPodOperatorControllerBuilder struct {
readyzEndpoint string
pdbUnhealthyPodEvictionPolicy *v1.UnhealthyPodEvictionPolicyType
guardCreateConditionalFunc func() (bool, bool, error)

// should revision install information
shouldRevisionInstall func() (bool, error)
}

func NewBuilder(
Expand Down Expand Up @@ -114,6 +117,7 @@ type Builder interface {
// This can help to drain/maintain a node and recover without a manual intervention when multiple instances of nodes or pods are misbehaving.
// Use this with caution, as this option can disrupt perspective pods that have not yet had a chance to become healthy.
WithPodDisruptionBudgetGuard(operatorNamespace, operatorName, readyzPort, readyzEndpoint string, pdbUnhealthyPodEvictionPolicy *v1.UnhealthyPodEvictionPolicyType, createConditionalFunc func() (bool, bool, error)) Builder
WithShouldRevisionInstall(quorumSafe func() (bool, error)) Builder
ToControllers() (manager.ControllerManager, error)
}

Expand Down Expand Up @@ -196,6 +200,11 @@ func (b *staticPodOperatorControllerBuilder) WithPodDisruptionBudgetGuard(operat
return b
}

func (b *staticPodOperatorControllerBuilder) WithShouldRevisionInstall(quorumSafe func() (bool, error)) Builder {
b.shouldRevisionInstall = quorumSafe
return b
}

func (b *staticPodOperatorControllerBuilder) ToControllers() (manager.ControllerManager, error) {
manager := manager.NewControllerManager()

Expand Down Expand Up @@ -257,6 +266,8 @@ func (b *staticPodOperatorControllerBuilder) ToControllers() (manager.Controller
b.installerPodMutationFunc,
).WithMinReadyDuration(
b.minReadyDuration,
).WithShouldRevisionInstall(
b.shouldRevisionInstall,
), 1)

manager.WithController(installerstate.NewInstallerStateController(
Expand Down

0 comments on commit 02d8fd7

Please sign in to comment.