Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/minimal CRD #318

Merged
merged 5 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions service/envvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ const (
// EnvConfigFilePath is an env variable which contains the full path for the config file
EnvConfigFilePath = "X_CSI_POWERMAX_CONFIG_PATH"

// EnvArrayConfigPath is an env variable which contains the full path for the config file
EnvArrayConfigPath = "X_CSI_POWERMAX_ARRAY_CONFIG_PATH"

// EnvMaxVolumesPerNode specifies maximum number of volumes that controller can publish to the node.
EnvMaxVolumesPerNode = "X_CSI_MAX_VOLUMES_PER_NODE"

Expand Down
51 changes: 51 additions & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package service

import (
"context"
"errors"
"fmt"
"math/rand"
"net"
Expand Down Expand Up @@ -66,6 +67,10 @@ const (
CSILogFormatParam = "CSI_LOG_FORMAT"
ArrayStatus = "/array-status"
DefaultPodmonPollRate = 60
PortGroups = "X_CSI_POWERMAX_PORTGROUPS"
Protocol = "X_CSI_TRANSPORT_PROTOCOL"
// PmaxEndPoint = "X_CSI_POWERMAX_ENDPOINT"
ManagedArrays = "X_CSI_MANAGED_ARRAYS"
)

type contextKey string // specific string type used for context keys
Expand Down Expand Up @@ -310,6 +315,8 @@ func (s *service) BeforeServe(

log.WithFields(fields).Infof("configured %s", s.getDriverName())
}()
// setting array related data to envs. by reading it from config-map - Needs refactoring
setArrayConfigEnvs(ctx)

configFilePath, ok := csictx.LookupEnv(ctx, EnvConfigFilePath)
if !ok {
Expand Down Expand Up @@ -874,3 +881,47 @@ func (s *service) SetPollingFrequency(ctx context.Context) int64 {
log.Debugf("use default pollingFrequency as %d seconds", DefaultPodmonPollRate)
return DefaultPodmonPollRate
}

func setArrayConfigEnvs(ctx context.Context) error {
log.Info("---------inside setArrayConfig function----------")
// set additional driver configs moved from envs.
configFilePath, ok := csictx.LookupEnv(ctx, EnvArrayConfigPath)
if !ok {
return errors.New("unable to read X_CSI_POWERMAX_ARRAY_CONFIG_PATH from env")
}

paramsViper := viper.New()
paramsViper.SetConfigFile(configFilePath)
paramsViper.SetConfigType("yaml")

err := paramsViper.ReadInConfig()
// if unable to read configuration file, set defaults
if err != nil {
log.WithError(err).Error("unable to read array config file")
setLogFormatAndLevel(&log.TextFormatter{
DisableColors: true,
FullTimestamp: true,
}, log.DebugLevel)
}
portgroups := paramsViper.GetString(PortGroups)
if portgroups != "" {
log.Info("Read PortGroups from config file:", portgroups)
_ = os.Setenv(PortGroups, portgroups)
}
protocol := paramsViper.GetString(Protocol)
if protocol != "" {
log.Info("Read protocol from config file:", protocol)
_ = os.Setenv(Protocol, protocol)
}
endpoint := paramsViper.GetString(EnvEndpoint)
if endpoint != "" {
log.Info("Read endpoint from config file:", endpoint)
_ = os.Setenv(EnvEndpoint, endpoint)
}
managedArrays := paramsViper.GetString(ManagedArrays)
if managedArrays != "" {
log.Info("Managed arrays from config file:", managedArrays)
_ = os.Setenv(ManagedArrays, managedArrays)
}
return nil
}
Loading