Skip to content

Commit

Permalink
fix: add missing nil checks
Browse files Browse the repository at this point in the history
  • Loading branch information
pb82 committed Oct 18, 2021
1 parent a5808a2 commit ceb0588
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions controllers/model/grafanaDeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,23 @@ func getVolumes(cr *v1alpha1.Grafana) []v13.Volume { // nolint
}

// Volume to store the plugins
appendIfContainsPlugin := func(slice []v13.VolumeMount) bool {
appendIfContainsPlugin := func() bool {
var foundGrafanaPluginsPath bool
if cr.Spec.Deployment.ExtraVolumeMounts != nil {
for _, item := range slice {
if cr.Spec.Deployment != nil {
for _, item := range cr.Spec.Deployment.ExtraVolumeMounts {
if item.MountPath == config.GrafanaPluginsPath {
foundGrafanaPluginsPath = true
break
}
}
}
volumes = append(volumes, cr.Spec.Deployment.ExtraVolumes...)

if cr.Spec.Deployment != nil {
volumes = append(volumes, cr.Spec.Deployment.ExtraVolumes...)
}
return foundGrafanaPluginsPath
}
if !appendIfContainsPlugin(cr.Spec.Deployment.ExtraVolumeMounts) {
if !appendIfContainsPlugin() {
volumes = append(volumes, v13.Volume{
Name: constants.GrafanaPluginsVolumeName,
VolumeSource: v13.VolumeSource{
Expand Down Expand Up @@ -343,20 +346,23 @@ func getVolumeMounts(cr *v1alpha1.Grafana) []v13.VolumeMount {
MountPath: config.GrafanaDataPath,
})

appendIfContainsPlugin := func(slice []v13.VolumeMount) bool {
appendIfContainsPlugin := func() bool {
var foundGrafanaPluginsPath bool
if cr.Spec.Deployment.ExtraVolumeMounts != nil {
for _, item := range slice {
if cr.Spec.Deployment != nil {
for _, item := range cr.Spec.Deployment.ExtraVolumeMounts {
if item.MountPath == config.GrafanaPluginsPath {
foundGrafanaPluginsPath = true
break
}
}
}
mounts = append(mounts, cr.Spec.Deployment.ExtraVolumeMounts...)

if cr.Spec.Deployment != nil {
mounts = append(mounts, cr.Spec.Deployment.ExtraVolumeMounts...)
}
return foundGrafanaPluginsPath
}
if !appendIfContainsPlugin(cr.Spec.Deployment.ExtraVolumeMounts) {
if !appendIfContainsPlugin() {
mounts = append(mounts, v13.VolumeMount{
Name: constants.GrafanaPluginsVolumeName,
MountPath: config.GrafanaPluginsPath,
Expand Down Expand Up @@ -573,9 +579,12 @@ func getInitContainers(cr *v1alpha1.Grafana, plugins string) []v13.Container {
}

var volumeName = constants.GrafanaPluginsVolumeName
for _, item := range cr.Spec.Deployment.ExtraVolumeMounts {
if item.MountPath == config.GrafanaPluginsPath {
volumeName = item.Name

if cr.Spec.Deployment != nil {
for _, item := range cr.Spec.Deployment.ExtraVolumeMounts {
if item.MountPath == config.GrafanaPluginsPath {
volumeName = item.Name
}
}
}

Expand Down

0 comments on commit ceb0588

Please sign in to comment.