Skip to content

Commit

Permalink
Add envariables to set config params in share-manager pod.
Browse files Browse the repository at this point in the history
Signed-off-by: James Munson <james.munson@suse.com>
  • Loading branch information
james-munson authored and PhanLe1010 committed Jul 23, 2024
1 parent bf151e7 commit a79c2e8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
2 changes: 2 additions & 0 deletions controller/setting_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ func (sc *SettingController) updateKubernetesClusterAutoscalerEnabled() error {
return nil
}

/*
func (sc *SettingController) cleanupShareManagerServiceAndEndpoints() error {
var err error
defer func() {
Expand Down Expand Up @@ -974,6 +975,7 @@ func (sc *SettingController) cleanupShareManagerServiceAndEndpoints() error {
return nil
}
*/

// updateCNI deletes all system-managed data plane components immediately with the updated CNI annotation.
func (sc *SettingController) updateCNI(funcPreupdate func() error) error {
Expand Down
60 changes: 50 additions & 10 deletions controller/share_manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ import (

const shareManagerLeaseDurationSeconds = 7 // This should be slightly more than twice the share-manager lease renewal interval.

type nfsServerConfig struct {
enableFastFailover bool
leaseLifetime int
gracePeriod int
}

type ShareManagerController struct {
*baseController

Expand Down Expand Up @@ -1089,15 +1095,33 @@ func (c *ShareManagerController) createShareManagerPod(sm *longhorn.ShareManager
return nil, errors.Wrapf(err, "failed to create service and endpoint for share manager %v", sm.Name)
}

// likewise for the lease
if _, err := c.ds.GetLeaseRO(sm.Name); err != nil {
if !apierrors.IsNotFound(err) {
return nil, errors.Wrapf(err, "failed to get lease for share manager %v", sm.Name)
nfsConfig := &nfsServerConfig{
enableFastFailover: false,
leaseLifetime: 60,
gracePeriod: 90,
}

enabled, err := c.ds.GetSettingAsBool(types.SettingNameEnableShareManagerFastFailover)
if err != nil {
return nil, err
}
if enabled {
nfsConfig = &nfsServerConfig{
enableFastFailover: true,
leaseLifetime: 20,
gracePeriod: 30,
}

if _, err = c.ds.CreateLease(c.createLeaseManifest(sm)); err != nil {
return nil, errors.Wrapf(err, "failed to create lease for share manager %v", sm.Name)
if _, err := c.ds.GetLeaseRO(sm.Name); err != nil {
if !apierrors.IsNotFound(err) {
return nil, errors.Wrapf(err, "failed to get lease for share manager %v", sm.Name)
}

if _, err = c.ds.CreateLease(c.createLeaseManifest(sm)); err != nil {
return nil, errors.Wrapf(err, "failed to create lease for share manager %v", sm.Name)
}
}

}

volume, err := c.ds.GetVolume(sm.Name)
Expand Down Expand Up @@ -1171,7 +1195,7 @@ func (c *ShareManagerController) createShareManagerPod(sm *longhorn.ShareManager
}

manifest := c.createPodManifest(sm, annotations, tolerations, affinity, imagePullPolicy, nil, registrySecret,
priorityClass, nodeSelector, fsType, mountOptions, cryptoKey, cryptoParams)
priorityClass, nodeSelector, fsType, mountOptions, cryptoKey, cryptoParams, nfsConfig)

storageNetwork, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNameStorageNetwork)
if err != nil {
Expand Down Expand Up @@ -1290,7 +1314,8 @@ func (c *ShareManagerController) createLeaseManifest(sm *longhorn.ShareManager)

func (c *ShareManagerController) createPodManifest(sm *longhorn.ShareManager, annotations map[string]string, tolerations []corev1.Toleration,
affinity *corev1.Affinity, pullPolicy corev1.PullPolicy, resourceReq *corev1.ResourceRequirements, registrySecret, priorityClass string,
nodeSelector map[string]string, fsType string, mountOptions []string, cryptoKey string, cryptoParams *crypto.EncryptParams) *corev1.Pod {
nodeSelector map[string]string, fsType string, mountOptions []string, cryptoKey string, cryptoParams *crypto.EncryptParams,
nfsConfig *nfsServerConfig) *corev1.Pod {

// command args for the share-manager
args := []string{"--debug", "daemon", "--volume", sm.Name}
Expand Down Expand Up @@ -1345,9 +1370,24 @@ func (c *ShareManagerController) createPodManifest(sm *longhorn.ShareManager, an
},
}

podSpec.Spec.Containers[0].Env = []corev1.EnvVar{
{
Name: "FAST_FAILOVER",
Value: fmt.Sprint(nfsConfig.enableFastFailover),
},
{
Name: "LEASE_LIFETIME",
Value: fmt.Sprint(nfsConfig.leaseLifetime),
},
{
Name: "GRACE_PERIOD",
Value: fmt.Sprint(nfsConfig.gracePeriod),
},
}

// this is an encrypted volume the cryptoKey is base64 encoded
if len(cryptoKey) > 0 {
podSpec.Spec.Containers[0].Env = []corev1.EnvVar{
podSpec.Spec.Containers[0].Env = append(podSpec.Spec.Containers[0].Env, []corev1.EnvVar{
{
Name: "ENCRYPTED",
Value: "True",
Expand All @@ -1372,7 +1412,7 @@ func (c *ShareManagerController) createPodManifest(sm *longhorn.ShareManager, an
Name: "CRYPTOPBKDF",
Value: string(cryptoParams.GetPBKDF()),
},
}
}...)
}

podSpec.Spec.Containers[0].VolumeMounts = []corev1.VolumeMount{
Expand Down
2 changes: 1 addition & 1 deletion types/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ var (
SettingDefinitionEnableShareManagerFastFailover = SettingDefinition{
DisplayName: "Enable Share Manager Fast Failover",
Description: "Turn on logic to detect and move stale RWX volumes quickly (Experimental)",
Category: SettingCategoryDangerZone,
Category: SettingCategoryGeneral,
Type: SettingTypeBool,
Required: true,
ReadOnly: false,
Expand Down

0 comments on commit a79c2e8

Please sign in to comment.