Skip to content

Commit

Permalink
Enable leader election on managed instances in a sharded deployment (f…
Browse files Browse the repository at this point in the history
…lyteorg#461)

* injecting leader election name if configured

Signed-off-by: Daniel Rammer <[email protected]>

* cleanup

Signed-off-by: Daniel Rammer <[email protected]>

Signed-off-by: Daniel Rammer <[email protected]>
Co-authored-by: Haytham Abuelfutuh <[email protected]>
  • Loading branch information
hamersaw and EngHabu authored Sep 19, 2022
1 parent 3036ace commit b2c0b97
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions flytepropeller/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ func (m *Manager) createPods(ctx context.Context) error {
"app": m.podApplication,
}

// disable leader election on all managed pods
container, err := utils.GetContainer(&podTemplate.Template.Spec, m.podTemplateContainerName)
if err != nil {
return fmt.Errorf("failed to retrieve flytepropeller container from pod template [%v]", err)
}

container.Args = append(container.Args, "--propeller.leader-election.enabled=false")

// retrieve existing pods
listOptions := metav1.ListOptions{
LabelSelector: labels.SelectorFromSet(podLabels).String(),
Expand Down Expand Up @@ -165,6 +157,7 @@ func (m *Manager) createPods(ctx context.Context) error {
errs := stderrors.ErrorCollection{}
for i, podName := range podNames {
if exists := podExists[podName]; !exists {
// initialize pod definition
baseObjectMeta := podTemplate.Template.ObjectMeta.DeepCopy()
objectMeta := metav1.ObjectMeta{
Annotations: podAnnotations,
Expand All @@ -191,6 +184,16 @@ func (m *Manager) createPods(ctx context.Context) error {
continue
}

// override leader election namespaced name on managed flytepropeller instances
container, err := utils.GetContainer(&pod.Spec, m.podTemplateContainerName)
if err != nil {
return fmt.Errorf("failed to retrieve flytepropeller container from pod template [%v]", err)
}

injectLeaderNameArg := fmt.Sprintf("--propeller.leader-election.lock-config-map.Name=propeller-leader-%d", i)
container.Args = append(container.Args, injectLeaderNameArg)

// create pod
_, err = m.kubeClient.CoreV1().Pods(m.podNamespace).Create(ctx, pod, metav1.CreateOptions{})
if err != nil {
errs.Append(fmt.Errorf("failed to create pod '%s' [%v]", podName, err))
Expand Down

0 comments on commit b2c0b97

Please sign in to comment.