Skip to content

Commit

Permalink
fix: get node nil exception (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
VaibhavPage authored Apr 1, 2020
1 parent cc42012 commit fd62a59
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
7 changes: 7 additions & 0 deletions controllers/sensor/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func InitializeNode(sensor *v1alpha1.Sensor, nodeName string, nodeType v1alpha1.
// MarkNodePhase marks the node with a phase, returns the node
func MarkNodePhase(sensor *v1alpha1.Sensor, nodeName string, nodeType v1alpha1.NodeType, phase v1alpha1.NodePhase, event *apicommon.Event, logger *logrus.Logger, message ...string) *v1alpha1.NodeStatus {
node := GetNodeByName(sensor, nodeName)
if node == nil {
logger.WithField("node-name", nodeName).Infoln("node is empty, this should not happen...")
return nil
}
if node.Phase != phase {
logger.WithFields(
map[string]interface{}{
Expand Down Expand Up @@ -121,6 +125,9 @@ func AreAllDependenciesResolved(sensor *v1alpha1.Sensor) bool {
// IsDependencyResolved checks whether a dependency is resolved.
func IsDependencyResolved(sensor *v1alpha1.Sensor, nodeName string) bool {
node := GetNodeByName(sensor, nodeName)
if node == nil {
return true
}
if node.Phase == v1alpha1.NodePhaseError {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion examples/event-sources/nats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spec:
nats:
example:
# url of the nats service
url: "nats://nats.argo-events:4222"
url: nats://nats.argo-events.svc:4222
# jsonBody specifies that all event body payload coming from this
# source will be JSON
jsonBody: true
Expand Down
2 changes: 1 addition & 1 deletion examples/gateways/multi-subscribers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ spec:
- "http://webhook-time-filter-sensor.argo-events.svc:9300/"
nats:
- name: webhook-sensor
serverURL: nats://test-nats.argo-events.svc:4222
serverURL: nats://nats.argo-events.svc:4222
subject: webhook-sensor-subject
6 changes: 3 additions & 3 deletions examples/sensors/subscription-over-nats.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
name: webhook-sensor-over-nats
name: webhook-sensor
labels:
sensors.argoproj.io/sensor-controller-instanceid: argo-events
spec:
Expand All @@ -18,8 +18,8 @@ spec:
eventName: example
subscription:
nats:
serverURL: nats://test-nats.argo-events.svc:4222
subject: webhook-sensor-subject
serverURL: nats://nats.argo-events.svc:4222
subject: webhook-events
triggers:
- template:
name: webhook-workflow-trigger
Expand Down
4 changes: 2 additions & 2 deletions sensors/triggers/switches.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ func ApplySwitches(sensor *v1alpha1.Sensor, trigger *v1alpha1.Trigger) bool {
}
if trigger.Template.Switch.Any != nil {
for _, group := range trigger.Template.Switch.Any {
if status := snctrl.GetNodeByName(sensor, group); status.Type == v1alpha1.NodeTypeDependencyGroup && status.Phase == v1alpha1.NodePhaseComplete {
if status := snctrl.GetNodeByName(sensor, group); status != nil && status.Type == v1alpha1.NodeTypeDependencyGroup && status.Phase == v1alpha1.NodePhaseComplete {
return true
}
}
return false
}
if trigger.Template.Switch.All != nil {
for _, group := range trigger.Template.Switch.All {
if status := snctrl.GetNodeByName(sensor, group); status.Type == v1alpha1.NodeTypeDependencyGroup && status.Phase != v1alpha1.NodePhaseComplete {
if status := snctrl.GetNodeByName(sensor, group); status != nil && status.Type == v1alpha1.NodeTypeDependencyGroup && status.Phase != v1alpha1.NodePhaseComplete {
return false
}
}
Expand Down

0 comments on commit fd62a59

Please sign in to comment.