Skip to content

Commit

Permalink
fix: passthrough unified LE settings to all controllers
Browse files Browse the repository at this point in the history
Signed-off-by: jakobmoellerdev <jmoller@redhat.com>
  • Loading branch information
jakobmoellerdev committed Aug 7, 2023
1 parent 6f10571 commit 2554fc1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
7 changes: 6 additions & 1 deletion controllers/lvmcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import (
"context"
"fmt"
v1 "github.com/openshift/api/config/v1"
"os"
"time"

Expand Down Expand Up @@ -77,6 +78,10 @@ type LVMClusterReconciler struct {
SecurityClient secv1client.SecurityV1Interface
Namespace string
ImageName string

// TopoLVMLeaderElectionPassthrough uses the given leaderElection when initializing TopoLVM to synchronize
// leader election configuration
TopoLVMLeaderElectionPassthrough v1.LeaderElection
}

//+kubebuilder:rbac:groups=lvm.topolvm.io,resources=lvmclusters,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -190,7 +195,7 @@ func (r *LVMClusterReconciler) reconcile(ctx context.Context, instance *lvmv1alp

resourceCreationList := []resourceManager{
&csiDriver{},
&topolvmController{},
&topolvmController{r.TopoLVMLeaderElectionPassthrough},
&openshiftSccs{},
&topolvmNode{},
&vgManager{},
Expand Down
41 changes: 30 additions & 11 deletions controllers/topolvm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import (
"context"
"fmt"
v1 "github.com/openshift/api/config/v1"
"path/filepath"

lvmv1alpha1 "github.com/openshift/lvm-operator/api/v1alpha1"
Expand All @@ -37,7 +38,9 @@ const (
controllerName = "topolvm-controller"
)

type topolvmController struct{}
type topolvmController struct {
topoLVMLeaderElectionPassthrough v1.LeaderElection
}

// topolvmController unit satisfies resourceManager interface
var _ resourceManager = topolvmController{}
Expand All @@ -51,7 +54,7 @@ func (c topolvmController) getName() string {
func (c topolvmController) ensureCreated(r *LVMClusterReconciler, ctx context.Context, lvmCluster *lvmv1alpha1.LVMCluster) error {

// get the desired state of topolvm controller deployment
desiredDeployment := getControllerDeployment(lvmCluster, r.Namespace, r.ImageName)
desiredDeployment := getControllerDeployment(lvmCluster, r.Namespace, r.ImageName, c.topoLVMLeaderElectionPassthrough)
existingDeployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: desiredDeployment.Name,
Expand Down Expand Up @@ -124,7 +127,7 @@ func (c topolvmController) setTopolvmControllerDesiredState(existing, desired *a
return nil
}

func getControllerDeployment(lvmCluster *lvmv1alpha1.LVMCluster, namespace string, initImage string) *appsv1.Deployment {
func getControllerDeployment(lvmCluster *lvmv1alpha1.LVMCluster, namespace string, initImage string, topoLVMLeaderElectionPassthrough v1.LeaderElection) *appsv1.Deployment {
// Topolvm CSI Controller Deployment
var replicas int32 = 1
volumes := []corev1.Volume{
Expand All @@ -138,11 +141,11 @@ func getControllerDeployment(lvmCluster *lvmv1alpha1.LVMCluster, namespace strin

// get all containers that are part of csi controller deployment
containers := []corev1.Container{
controllerContainer(),
csiProvisionerContainer(),
csiResizerContainer(),
controllerContainer(topoLVMLeaderElectionPassthrough),
csiProvisionerContainer(topoLVMLeaderElectionPassthrough),
csiResizerContainer(topoLVMLeaderElectionPassthrough),
livenessProbeContainer(),
csiSnapshotterContainer(),
csiSnapshotterContainer(topoLVMLeaderElectionPassthrough),
}

annotations := map[string]string{
Expand Down Expand Up @@ -212,12 +215,16 @@ func initContainer(initImage string) corev1.Container {
}
}

func controllerContainer() corev1.Container {
func controllerContainer(topoLVMLeaderElectionPassthrough v1.LeaderElection) corev1.Container {

// topolvm controller plugin container
command := []string{
"/topolvm-controller",
"--cert-dir=/certs",
fmt.Sprintf("--leader-election-namespace=%s", topoLVMLeaderElectionPassthrough.Namespace),
fmt.Sprintf("--leader-election-lease-duration=%s", topoLVMLeaderElectionPassthrough.LeaseDuration),
fmt.Sprintf("--leader-election-renew-deadline=%s", topoLVMLeaderElectionPassthrough.RenewDeadline),
fmt.Sprintf("--leader-election-retry-period=%s", topoLVMLeaderElectionPassthrough.RetryPeriod),
}

resourceRequirements := corev1.ResourceRequirements{
Expand Down Expand Up @@ -271,7 +278,7 @@ func controllerContainer() corev1.Container {
}
}

func csiProvisionerContainer() corev1.Container {
func csiProvisionerContainer(topoLVMLeaderElectionPassthrough v1.LeaderElection) corev1.Container {

// csi provisioner container
args := []string{
Expand All @@ -280,6 +287,10 @@ func csiProvisionerContainer() corev1.Container {
"--capacity-ownerref-level=2",
"--capacity-poll-interval=30s",
"--feature-gates=Topology=true",
fmt.Sprintf("--leader-election-namespace=%s", topoLVMLeaderElectionPassthrough.Namespace),
fmt.Sprintf("--leader-election-lease-duration=%s", topoLVMLeaderElectionPassthrough.LeaseDuration),
fmt.Sprintf("--leader-election-renew-deadline=%s", topoLVMLeaderElectionPassthrough.RenewDeadline),
fmt.Sprintf("--leader-election-retry-period=%s", topoLVMLeaderElectionPassthrough.RetryPeriod),
}

resourceRequirements := corev1.ResourceRequirements{
Expand Down Expand Up @@ -322,11 +333,15 @@ func csiProvisionerContainer() corev1.Container {
}
}

func csiResizerContainer() corev1.Container {
func csiResizerContainer(topoLVMLeaderElectionPassthrough v1.LeaderElection) corev1.Container {

// csi resizer container
args := []string{
fmt.Sprintf("--csi-address=%s", DefaultCSISocket),
fmt.Sprintf("--leader-election-namespace=%s", topoLVMLeaderElectionPassthrough.Namespace),
fmt.Sprintf("--leader-election-lease-duration=%s", topoLVMLeaderElectionPassthrough.LeaseDuration),
fmt.Sprintf("--leader-election-renew-deadline=%s", topoLVMLeaderElectionPassthrough.RenewDeadline),
fmt.Sprintf("--leader-election-retry-period=%s", topoLVMLeaderElectionPassthrough.RetryPeriod),
}

volumeMounts := []corev1.VolumeMount{
Expand All @@ -349,10 +364,14 @@ func csiResizerContainer() corev1.Container {
}
}

func csiSnapshotterContainer() corev1.Container {
func csiSnapshotterContainer(topoLVMLeaderElectionPassthrough v1.LeaderElection) corev1.Container {

args := []string{
fmt.Sprintf("--csi-address=%s", DefaultCSISocket),
fmt.Sprintf("--leader-election-namespace=%s", topoLVMLeaderElectionPassthrough.Namespace),
fmt.Sprintf("--leader-election-lease-duration=%s", topoLVMLeaderElectionPassthrough.LeaseDuration),
fmt.Sprintf("--leader-election-renew-deadline=%s", topoLVMLeaderElectionPassthrough.RenewDeadline),
fmt.Sprintf("--leader-election-retry-period=%s", topoLVMLeaderElectionPassthrough.RetryPeriod),
}

volumeMounts := []corev1.VolumeMount{
Expand Down
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ func main() {

// register controllers
if err = (&controllers.LVMClusterReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
SecurityClient: secv1client.NewForConfigOrDie(mgr.GetConfig()),
Namespace: operatorNamespace,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
SecurityClient: secv1client.NewForConfigOrDie(mgr.GetConfig()),
Namespace: operatorNamespace,
TopoLVMLeaderElectionPassthrough: leaderElectionConfig,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "LVMCluster")
os.Exit(1)
Expand Down

0 comments on commit 2554fc1

Please sign in to comment.