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

Changes to beforeserve to pick up storage array labels and parameters if provided #486

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ type Opts struct {
PodmonPort string // to indicates the port to be used for exposing podmon API health
PodmonPollingFreq string // indicates the polling frequency to check array connectivity
TLSCertDir string
StorageArrays []StorageArrayConfig
}

// StorageArrayConfig represents the configuration of a storage array in the config file
type StorageArrayConfig struct {
Labels map[string]interface{} `yaml:"labels,omitempty"`
Parameters map[string]interface{} `yaml:"parameters,omitempty"`
}

// NodeConfig defines rules for given node
Expand Down Expand Up @@ -430,6 +437,29 @@ func (s *service) BeforeServe(
} else {
log.Println("No management servers found.")
}

// Access the storagearrays key (which is a slice of maps)
storageArrays := secretParams.Get("storagearrays").([]interface{})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this panic if "storagearrays" is missing in the secret?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like it, thanks for that. will fix.

// Ensure there's at least one server and extract labels and parameters if any
if len(storageArrays) == 0 {
log.Println("No storage arrays found.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We start log messages in lowercase.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it only applied to error messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following the same syntax as on line 438: log.Println("No management servers found.")

} else {
// cycle through each storage array and extract Labels and Parameters maps
for _, storageArray := range storageArrays {
storageArrayMap := storageArray.(map[string]interface{})
if storageArrayMap["labels"] == nil {
storageArrayMap["labels"] = make(map[string]interface{})
}
if storageArrayMap["parameters"] == nil {
storageArrayMap["parameters"] = make(map[string]interface{})
}
storageArrayConfig := StorageArrayConfig{
Labels: storageArrayMap["labels"].(map[string]interface{}),
Parameters: storageArrayMap["parameters"].(map[string]interface{}),
}
opts.StorageArrays = append(opts.StorageArrays, storageArrayConfig)
}
}
Comment on lines +444 to +462
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you extract this block into a utility function then you make unit testing easier. You can test a lot of use cases. The you can just do something like:

opts.StorageArrays = getStorageArrayInfo() or similar.

}

if chapuser, ok := csictx.LookupEnv(ctx, EnvISCSICHAPUserName); ok {
Expand Down