Skip to content

Commit

Permalink
Add or improve read-only Setting related get/list functions for contr…
Browse files Browse the repository at this point in the history
…oller usage

Signed-off-by: Shuo Wu <shuo.wu@suse.com>
  • Loading branch information
shuo-wu committed Nov 13, 2023
1 parent ecd74f1 commit 4fd20ee
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 68 deletions.
6 changes: 3 additions & 3 deletions controller/backing_image_data_source_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ func (c *BackingImageDataSourceController) generateBackingImageDataSourcePodMani
return nil, err
}

priorityClass, err := c.ds.GetSetting(types.SettingNamePriorityClass)
priorityClass, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNamePriorityClass)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -735,7 +735,7 @@ func (c *BackingImageDataSourceController) generateBackingImageDataSourcePodMani
},
}

registrySecretSetting, err := c.ds.GetSetting(types.SettingNameRegistrySecret)
registrySecretSetting, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNameRegistrySecret)
if err != nil {
return nil, err
}
Expand All @@ -747,7 +747,7 @@ func (c *BackingImageDataSourceController) generateBackingImageDataSourcePodMani
}
}

storageNetwork, err := c.ds.GetSetting(types.SettingNameStorageNetwork)
storageNetwork, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNameStorageNetwork)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions controller/backing_image_manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ func (c *BackingImageManagerController) createBackingImageManagerPod(bim *longho
if err != nil {
return err
}
registrySecretSetting, err := c.ds.GetSetting(types.SettingNameRegistrySecret)
registrySecretSetting, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNameRegistrySecret)
if err != nil {
return err
}
Expand All @@ -802,7 +802,7 @@ func (c *BackingImageManagerController) generateBackingImageManagerPodManifest(b
return nil, err
}

priorityClass, err := c.ds.GetSetting(types.SettingNamePriorityClass)
priorityClass, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNamePriorityClass)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -892,7 +892,7 @@ func (c *BackingImageManagerController) generateBackingImageManagerPodManifest(b
}
}

storageNetwork, err := c.ds.GetSetting(types.SettingNameStorageNetwork)
storageNetwork, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNameStorageNetwork)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion controller/controller_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func GetInstanceManagerCPURequirement(ds *datastore.DataStore, imName string) (*
cpuRequest := lhNode.Spec.InstanceManagerCPURequest
guaranteedCPUSettingName := types.SettingNameGuaranteedInstanceManagerCPU
if cpuRequest == 0 {
guaranteedCPUSetting, err := ds.GetSetting(guaranteedCPUSettingName)
guaranteedCPUSetting, err := ds.GetSettingWithAutoFillingRO(guaranteedCPUSettingName)
if err != nil {
return nil, err
}
Expand Down
11 changes: 4 additions & 7 deletions controller/engine_image_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ func (ic *EngineImageController) syncEngineImage(key string) (err error) {
return err
}

priorityClassSetting, err := ic.ds.GetSetting(types.SettingNamePriorityClass)
priorityClassSetting, err := ic.ds.GetSettingWithAutoFillingRO(types.SettingNamePriorityClass)
if err != nil {
return errors.Wrapf(err, "failed to get priority class setting before creating engine image daemonset")
}
priorityClass := priorityClassSetting.Value

registrySecretSetting, err := ic.ds.GetSetting(types.SettingNameRegistrySecret)
registrySecretSetting, err := ic.ds.GetSettingWithAutoFillingRO(types.SettingNameRegistrySecret)
if err != nil {
return errors.Wrapf(err, "failed to get registry secret setting before creating engine image daemonset")
}
Expand Down Expand Up @@ -646,15 +646,12 @@ func (ic *EngineImageController) cleanupExpiredEngineImage(ei *longhorn.EngineIm
return nil
}
if util.TimestampAfterTimeout(ei.Status.NoRefSince, ExpiredEngineImageTimeout) {
defaultEngineImage, err := ic.ds.GetSetting(types.SettingNameDefaultEngineImage)
defaultEngineImageValue, err := ic.ds.GetSettingValueExisted(types.SettingNameDefaultEngineImage)
if err != nil {
return err
}
if defaultEngineImage.Value == "" {
return fmt.Errorf("default engine image not set")
}
// Don't delete the default image
if ei.Spec.Image == defaultEngineImage.Value {
if ei.Spec.Image == defaultEngineImageValue {
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions controller/instance_manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ func (imc *InstanceManagerController) createInstanceManagerPod(im *longhorn.Inst
return errors.Wrap(err, "failed to get node selector setting before creating instance manager pod")
}

registrySecretSetting, err := imc.ds.GetSetting(types.SettingNameRegistrySecret)
registrySecretSetting, err := imc.ds.GetSettingWithAutoFillingRO(types.SettingNameRegistrySecret)
if err != nil {
return errors.Wrap(err, "failed to get registry secret setting before creating instance manager pod")
}
Expand All @@ -1031,7 +1031,7 @@ func (imc *InstanceManagerController) createInstanceManagerPod(im *longhorn.Inst
return err
}

storageNetwork, err := imc.ds.GetSetting(types.SettingNameStorageNetwork)
storageNetwork, err := imc.ds.GetSettingWithAutoFillingRO(types.SettingNameStorageNetwork)
if err != nil {
return err
}
Expand All @@ -1058,7 +1058,7 @@ func (imc *InstanceManagerController) createGenericManagerPodSpec(im *longhorn.I
return nil, err
}

priorityClass, err := imc.ds.GetSetting(types.SettingNamePriorityClass)
priorityClass, err := imc.ds.GetSettingWithAutoFillingRO(types.SettingNamePriorityClass)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1137,7 +1137,7 @@ func (imc *InstanceManagerController) createInstanceManagerPodSpec(im *longhorn.
podSpec.ObjectMeta.Labels = types.GetInstanceManagerLabels(imc.controllerID, im.Spec.Image, longhorn.InstanceManagerTypeAllInOne)
podSpec.Spec.Containers[0].Name = "instance-manager"

v2DataEngineEnabled, err := imc.ds.GetSetting(types.SettingNameV2DataEngine)
v2DataEngineEnabled, err := imc.ds.GetSettingWithAutoFillingRO(types.SettingNameV2DataEngine)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions controller/recurring_job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,15 +459,15 @@ func (c *RecurringJobController) newCronJob(recurringJob *longhorn.RecurringJob)
if err != nil {
return nil, err
}
priorityClass, err := c.ds.GetSetting(types.SettingNamePriorityClass)
priorityClass, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNamePriorityClass)
if err != nil {
return nil, err
}
nodeSelector, err := c.ds.GetSettingSystemManagedComponentsNodeSelector()
if err != nil {
return nil, err
}
registrySecretSetting, err := c.ds.GetSetting(types.SettingNameRegistrySecret)
registrySecretSetting, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNameRegistrySecret)
if err != nil {
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions controller/setting_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ func (sc *SettingController) syncBackupTarget() (err error) {
}

// Get settings
targetSetting, err := sc.ds.GetSetting(types.SettingNameBackupTarget)
targetSetting, err := sc.ds.GetSettingWithAutoFillingRO(types.SettingNameBackupTarget)
if err != nil {
return err
}

secretSetting, err := sc.ds.GetSetting(types.SettingNameBackupTargetCredentialSecret)
secretSetting, err := sc.ds.GetSettingWithAutoFillingRO(types.SettingNameBackupTargetCredentialSecret)
if err != nil {
return err
}
Expand Down Expand Up @@ -483,7 +483,7 @@ func (sc *SettingController) removePodsAWSIAMRoleAnnotation() error {
}

func (sc *SettingController) updateTaintToleration() error {
setting, err := sc.ds.GetSetting(types.SettingNameTaintToleration)
setting, err := sc.ds.GetSettingWithAutoFillingRO(types.SettingNameTaintToleration)
if err != nil {
return err
}
Expand Down Expand Up @@ -621,7 +621,7 @@ func getLastAppliedTolerationsList(obj runtime.Object) ([]corev1.Toleration, err
}

func (sc *SettingController) updatePriorityClass() error {
setting, err := sc.ds.GetSetting(types.SettingNamePriorityClass)
setting, err := sc.ds.GetSettingWithAutoFillingRO(types.SettingNamePriorityClass)
if err != nil {
return err
}
Expand Down Expand Up @@ -746,7 +746,7 @@ func (sc *SettingController) updateKubernetesClusterAutoscalerEnabled() error {
}

func (sc *SettingController) updateCNI() error {
storageNetwork, err := sc.ds.GetSetting(types.SettingNameStorageNetwork)
storageNetwork, err := sc.ds.GetSettingWithAutoFillingRO(types.SettingNameStorageNetwork)
if err != nil {
return err
}
Expand Down Expand Up @@ -786,7 +786,7 @@ func (sc *SettingController) updateCNI() error {
}

func (sc *SettingController) updateLogLevel() error {
setting, err := sc.ds.GetSetting(types.SettingNameLogLevel)
setting, err := sc.ds.GetSettingWithAutoFillingRO(types.SettingNameLogLevel)
if err != nil {
return err
}
Expand Down Expand Up @@ -857,7 +857,7 @@ func getFinalTolerations(existingTolerations, lastAppliedTolerations, newTolerat
}

func (sc *SettingController) updateNodeSelector() error {
setting, err := sc.ds.GetSetting(types.SettingNameSystemManagedComponentsNodeSelector)
setting, err := sc.ds.GetSettingWithAutoFillingRO(types.SettingNameSystemManagedComponentsNodeSelector)
if err != nil {
return err
}
Expand Down Expand Up @@ -1645,7 +1645,7 @@ func (info *ClusterInfo) collectVolumesInfo() error {

func (info *ClusterInfo) collectSettingInVolume(volumeSpecValue, ignoredValue string, settingName types.SettingName) string {
if volumeSpecValue == ignoredValue {
globalSetting, err := info.ds.GetSetting(settingName)
globalSetting, err := info.ds.GetSettingWithAutoFillingRO(settingName)
if err != nil {
info.logger.WithError(err).Warnf("Failed to get Longhorn Setting %v", settingName)
}
Expand Down
10 changes: 3 additions & 7 deletions controller/share_manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,10 @@ func (c *ShareManagerController) syncShareManagerPod(sm *longhorn.ShareManager)

// createShareManagerPod ensures existence of service, it's assumed that the pvc for this share manager already exists
func (c *ShareManagerController) createShareManagerPod(sm *longhorn.ShareManager) (*corev1.Pod, error) {
setting, err := c.ds.GetSetting(types.SettingNameTaintToleration)
tolerations, err := c.ds.GetSettingTaintToleration()
if err != nil {
return nil, errors.Wrap(err, "failed to get taint toleration setting before creating share manager pod")
}
tolerations, err := types.UnmarshalTolerations(setting.Value)
if err != nil {
return nil, errors.Wrap(err, "failed to unmarshal taint toleration setting before creating share manager pod")
}
nodeSelector, err := c.ds.GetSettingSystemManagedComponentsNodeSelector()
if err != nil {
return nil, errors.Wrap(err, "failed to get node selector setting before creating share manager pod")
Expand All @@ -714,13 +710,13 @@ func (c *ShareManagerController) createShareManagerPod(sm *longhorn.ShareManager
return nil, errors.Wrap(err, "failed to get image pull policy before creating share manager pod")
}

setting, err = c.ds.GetSetting(types.SettingNameRegistrySecret)
setting, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNameRegistrySecret)
if err != nil {
return nil, errors.Wrap(err, "failed to get registry secret setting before creating share manager pod")
}
registrySecret := setting.Value

setting, err = c.ds.GetSetting(types.SettingNamePriorityClass)
setting, err = c.ds.GetSettingWithAutoFillingRO(types.SettingNamePriorityClass)
if err != nil {
return nil, errors.Wrap(err, "failed to get priority class setting before creating share manager pod")
}
Expand Down
6 changes: 3 additions & 3 deletions controller/support_bundle_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,13 +623,13 @@ func (c *SupportBundleController) createSupportBundleManagerDeployment(supportBu
return nil, errors.Wrap(err, "failed to get system pods image pull policy before creating support bundle manager deployment")
}

priorityClassSetting, err := c.ds.GetSetting(types.SettingNamePriorityClass)
priorityClassSetting, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNamePriorityClass)
if err != nil {
return nil, errors.Wrap(err, "failed to get priority class setting before creating support bundle manager deployment")
}
priorityClass := priorityClassSetting.Value

registrySecretSetting, err := c.ds.GetSetting(types.SettingNameRegistrySecret)
registrySecretSetting, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNameRegistrySecret)
if err != nil {
return nil, errors.Wrap(err, "failed to get registry secret setting before creating support bundle manager deployment")
}
Expand All @@ -645,7 +645,7 @@ func (c *SupportBundleController) createSupportBundleManagerDeployment(supportBu
func (c *SupportBundleController) newSupportBundleManager(supportBundle *longhorn.SupportBundle, nodeSelector map[string]string,
imagePullPolicy corev1.PullPolicy, priorityClass, registrySecret string) (*appsv1.Deployment, error) {

tolerationSetting, err := c.ds.GetSetting(types.SettingNameTaintToleration)
tolerationSetting, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNameTaintToleration)
if err != nil {
return nil, errors.Wrapf(err, "failed to get %v setting", types.SettingNameTaintToleration)
}
Expand Down
2 changes: 1 addition & 1 deletion controller/system_rollout_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ func (c *SystemRolloutController) syncController() error {
return errors.Wrapf(err, "failed to get SystemBackup %v", systemRestore.Spec.SystemBackup)
}

currentLonghornVersion, err := c.ds.GetSetting(types.SettingNameCurrentLonghornVersion)
currentLonghornVersion, err := c.ds.GetSettingWithAutoFillingRO(types.SettingNameCurrentLonghornVersion)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion datastore/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ func NewPVCManifest(size int64, pvName, ns, pvcName, storageClassName string, ac
// "dns": {}
// }]
func (s *DataStore) GetStorageIPFromPod(pod *corev1.Pod) string {
storageNetwork, err := s.GetSetting(types.SettingNameStorageNetwork)
storageNetwork, err := s.GetSettingWithAutoFillingRO(types.SettingNameStorageNetwork)
if err != nil {
logrus.Warnf("Failed to get %v setting, use %v pod IP %v", types.SettingNameStorageNetwork, pod.Name, pod.Status.PodIP)
return pod.Status.PodIP
Expand Down
Loading

0 comments on commit 4fd20ee

Please sign in to comment.