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

KRV-2815 : Fallback to default configuration files when installed on unsupported versions #23

Merged
merged 3 commits into from
Feb 7, 2022
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
32 changes: 18 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ import (

const (
// K8sMinimumSupportedVersion is the minimum supported version for k8s
K8sMinimumSupportedVersion = "1.19"
K8sMinimumSupportedVersion = "1.21"
// K8sMaximumSupportedVersion is the maximum supported version for k8s
K8sMaximumSupportedVersion = "1.23"
// OpenshiftMinimumSupportedVersion is the minimum supported version for openshift
OpenshiftMinimumSupportedVersion = "4.6"
OpenshiftMinimumSupportedVersion = "4.8"
// OpenshiftMaximumSupportedVersion is the maximum supported version for openshift
OpenshiftMaximumSupportedVersion = "4.7"
OpenshiftMaximumSupportedVersion = "4.9"
)

var (
Expand Down Expand Up @@ -113,34 +113,38 @@ func getOperatorConfig() utils.OperatorConfig {
if err != nil {
log.Info(fmt.Sprintf("kubeVersion %s", kubeVersion))
}
// intialise variable
k8sPath := ""
if currentVersion < minVersion {
log.Info(fmt.Sprintf("version %s is less than minimum supported version of %f", kubeVersion, minVersion))
}
if currentVersion > maxVersion {
log.Info(fmt.Sprintf("version %s is greater than maximum supported version of %f", kubeVersion, maxVersion))

log.Info(fmt.Sprintf("Installed k8s version %s is less than the minimum supported k8s version %f , hence using the default configurations", kubeVersion, minVersion))
k8sPath = fmt.Sprintf("/driverconfig/common/default.yaml")
} else if currentVersion > maxVersion {
log.Info(fmt.Sprintf("Installed k8s version %s is greater than the maximum supported k8s version %f , hence using the latest available configurations", kubeVersion, maxVersion))
k8sPath = fmt.Sprintf("/driverconfig/common/k8s-%s-values.yaml", K8sMaximumSupportedVersion)
} else {
k8sPath = fmt.Sprintf("/driverconfig/common/k8s-%s-values.yaml", kubeVersion)
}

// Get the environment variSable config dir
// Get the environment variable config dir
configDir := os.Getenv("X_CSM_OPERATOR_CONFIG_DIR")
if configDir == "" {
// Set the config dir to the folder pkg/config
configDir = "operatorconfig/"
configDir = "operatorconfig"
k8sPath = fmt.Sprintf("%s%s", configDir, k8sPath)
} else {
k8sPath := fmt.Sprintf("%s/driverconfig/common/k8s-%s-values.yaml", configDir, kubeVersion)
k8sPath = fmt.Sprintf("%s%s", configDir, k8sPath)
_, err := ioutil.ReadFile(k8sPath)
if err != nil {
// This means that the configmap is not mounted
// fall back to the local copy
log.Error(err, "Error reading file from the configmap mount")
log.Info("Falling back to local copy of config files")

configDir = "/etc/config/local/dell-csm-operator"
k8sPath = fmt.Sprintf("%s%s", configDir, k8sPath)
}

}
cfg.ConfigDirectory = configDir

k8sPath := fmt.Sprintf("%s/driverconfig/common/k8s-%s-values.yaml", cfg.ConfigDirectory, kubeVersion)
buf, err := ioutil.ReadFile(k8sPath)
if err != nil {
panic(fmt.Sprintf("reading file, %s, from the configmap mount: %v", k8sPath, err))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

kubeversion: "v1.20"

# IT IS RECOMMENDED YOU DO NOT CHANGE THE IMAGES TO BE DOWNLOADED.
images:
# "images.attacher" defines the container images used for the csi attacher
Expand All @@ -20,4 +17,4 @@ images:

# "images.resizer" defines the container images used for the csi resizer
# container.
resizer: k8s.gcr.io/sig-storage/csi-resizer:v1.2.0
resizer: k8s.gcr.io/sig-storage/csi-resizer:v1.2.0
22 changes: 0 additions & 22 deletions operatorconfig/driverconfig/common/k8s-1.19-values.yaml

This file was deleted.

5 changes: 1 addition & 4 deletions operatorconfig/driverconfig/common/k8s-1.21-values.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

kubeversion: "v1.21"

# IT IS RECOMMENDED YOU DO NOT CHANGE THE IMAGES TO BE DOWNLOADED.
images:
# "images.attacher" defines the container images used for the csi attacher
Expand All @@ -20,4 +17,4 @@ images:

# "images.resizer" defines the container images used for the csi resizer
# container.
resizer: k8s.gcr.io/sig-storage/csi-resizer:v1.2.0
resizer: k8s.gcr.io/sig-storage/csi-resizer:v1.2.0
3 changes: 0 additions & 3 deletions operatorconfig/driverconfig/common/k8s-1.22-values.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

kubeversion: "v1.22"

# IT IS RECOMMENDED YOU DO NOT CHANGE THE IMAGES TO BE DOWNLOADED.
images:
# "images.attacher" defines the container images used for the csi attacher
Expand Down
3 changes: 0 additions & 3 deletions operatorconfig/driverconfig/common/k8s-1.23-values.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

kubeversion: "v1.23"

# IT IS RECOMMENDED YOU DO NOT CHANGE THE IMAGES TO BE DOWNLOADED.
images:
# "images.attacher" defines the container images used for the csi attacher
Expand Down