Skip to content

Commit

Permalink
fix assignment to entry in nil map
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Zimin <alexandr.zimin@flant.com>
  • Loading branch information
AleksZimin committed Apr 14, 2024
1 parent a5bdb01 commit 8efe695
Showing 1 changed file with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,28 @@ import (
"context"
"errors"
"fmt"
"reflect"
v1alpha1 "sds-local-volume-controller/api/v1alpha1"
"sds-local-volume-controller/pkg/config"
"sds-local-volume-controller/pkg/logger"
"sds-local-volume-controller/pkg/monitoring"
"strings"
"time"

corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/storage/v1"
errors2 "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/strings/slices"
"reflect"
v1alpha1 "sds-local-volume-controller/api/v1alpha1"
"sds-local-volume-controller/pkg/config"
"sds-local-volume-controller/pkg/logger"
"sds-local-volume-controller/pkg/monitoring"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
"sigs.k8s.io/yaml"
"strings"
"time"

"sigs.k8s.io/controller-runtime/pkg/manager"
)
Expand Down Expand Up @@ -443,13 +444,19 @@ func reconcileLSCUpdateFunc(
}

func patchSCByLSC(sc *v1.StorageClass, lsc *v1alpha1.LocalStorageClass) *v1.StorageClass {
lscDefault := "false"

if lsc.Spec.IsDefault {
lscDefault = "true"
if sc.Annotations == nil {
sc.Annotations = make(map[string]string)
}
sc.Annotations[DefaultStorageClassAnnotationKey] = "true"
} else {
_, isDefault := sc.Annotations[DefaultStorageClassAnnotationKey]
if isDefault {
delete(sc.Annotations, DefaultStorageClassAnnotationKey)
}
}

sc.Annotations[DefaultStorageClassAnnotationKey] = lscDefault

return sc
}

Expand Down

0 comments on commit 8efe695

Please sign in to comment.