Skip to content

Commit

Permalink
Fix missing map initialization in ParseData()
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Feb 25, 2022
1 parent a00dd2a commit fc9e79c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions controllers/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func reconcileInternal(params reconcileParameters) error {
if err != nil {
return err
}
log.Info("ntoficationtimes map", "value", data.LastNotificationTimes)
profilesStr, ok := node.Labels[constants.ProfileLabelKey]
if !ok {
profilesStr = constants.DefaultProfileName
Expand Down
5 changes: 4 additions & 1 deletion state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func ParseData(node *v1.Node) (Data, error) {
return Data{}, fmt.Errorf("failed to parse json value in data annotation: %w", err)
}
}
if data.LastNotificationTimes == nil {
data.LastNotificationTimes = make(map[string]time.Time)
}
return data, nil
}

Expand Down Expand Up @@ -164,7 +167,7 @@ func Apply(state NodeState, node *v1.Node, data *Data, params plugin.Parameters)
return state.Label(), nil
}

// notifyDefault is a default NodeState.Transition implementation that checks
// transitionDefault is a default NodeState.Transition implementation that checks
// each specified transition in order and returns the next state. If len(trans)
// is 0, the current state is returned.
func transitionDefault(params plugin.Parameters, current NodeStateLabel, trans []Transition) (NodeStateLabel, error) {
Expand Down
13 changes: 13 additions & 0 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/go-logr/logr"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/sapcc/maintenance-controller/constants"
"github.com/sapcc/maintenance-controller/plugin"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/record"
Expand Down Expand Up @@ -246,3 +247,15 @@ var _ = Describe("Apply", func() {
})

})

var _ = Describe("ParseData", func() {

It("should initialize the notification times map", func() {
var node v1.Node
node.Annotations = map[string]string{constants.DataAnnotationKey: "{}"}
data, err := ParseData(&node)
Expect(err).To(Succeed())
Expect(data.LastNotificationTimes).ToNot(BeNil())
})

})

0 comments on commit fc9e79c

Please sign in to comment.