Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Commit

Permalink
add safeguards for nil pointer dereference in delivery spec (#2148)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyreddad authored Feb 16, 2021
1 parent 5a19bc2 commit cba6513
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/reconciler/trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
triggerReconciled = "TriggerReconciled"
triggerFinalized = "TriggerFinalized"

defaultMinimumBackoff = 1 * time.Second
// Default maximum backoff duration used in the backoff retry policy for
// pubsub subscriptions. 600 seconds is the longest supported time.
defaultMaximumBackoff = 600 * time.Second
Expand Down Expand Up @@ -284,6 +285,12 @@ func (r *Reconciler) reconcileRetryTopicAndSubscription(ctx context.Context, tri
// getPubsubRetryPolicy gets the eventing retry policy from the Broker delivery
// spec and translates it to a pubsub retry policy.
func getPubsubRetryPolicy(spec *eventingduckv1beta1.DeliverySpec) *pubsub.RetryPolicy {
if spec == nil {
return &pubsub.RetryPolicy{
MinimumBackoff: defaultMinimumBackoff,
MaximumBackoff: defaultMaximumBackoff,
}
}
// The Broker delivery spec is translated to a pubsub retry policy in the
// manner defined in the following post:
// https://github.com/google/knative-gcp/issues/1392#issuecomment-655617873
Expand All @@ -305,7 +312,7 @@ func getPubsubRetryPolicy(spec *eventingduckv1beta1.DeliverySpec) *pubsub.RetryP
// getPubsubDeadLetterPolicy gets the eventing dead letter policy from the
// Broker delivery spec and translates it to a pubsub dead letter policy.
func getPubsubDeadLetterPolicy(projectID string, spec *eventingduckv1beta1.DeliverySpec) *pubsub.DeadLetterPolicy {
if spec.DeadLetterSink == nil {
if spec == nil || spec.DeadLetterSink == nil {
return nil
}
// Translate to the pubsub dead letter policy format.
Expand Down
59 changes: 59 additions & 0 deletions pkg/reconciler/trigger/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,65 @@ func TestAllCasesTrigger(t *testing.T) {
}),
},
},
{
Name: "Check topic config and labels - broker without spec.delivery",
Key: testKey,
Objects: []runtime.Object{
NewBroker(brokerName, testNS,
WithBrokerClass(brokerv1beta1.BrokerClass),
WithInitBrokerConditions,
WithBrokerReady("url"),
WithBrokerSetDefaults,
),
makeSubscriberAddressableAsUnstructured(),
NewTrigger(triggerName, testNS, brokerName,
WithTriggerUID(testUID),
WithTriggerSubscriberRef(subscriberGVK, subscriberName, testNS),
WithTriggerSetDefaults),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewTrigger(triggerName, testNS, brokerName,
WithTriggerUID(testUID),
WithTriggerSubscriberRef(subscriberGVK, subscriberName, testNS),
WithTriggerBrokerReady,
WithTriggerSubscriptionReady,
WithTriggerTopicReady,
WithTriggerDependencyReady,
WithTriggerSubscriberResolvedSucceeded,
WithTriggerStatusSubscriberURI(subscriberURI),
WithTriggerSetDefaults,
),
}},
WantEvents: []string{
triggerFinalizerUpdatedEvent,
topicCreatedEvent,
subscriptionCreatedEvent,
triggerReconciledEvent,
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(testNS, triggerName, finalizerName),
},
OtherTestData: map[string]interface{}{
"dataResidencyConfigMap": NewDataresidencyConfigMapFromRegions([]string{"us-east1"}),
},
PostConditions: []func(*testing.T, *TableRow){
OnlyTopics("cre-tgr_testnamespace_test-trigger_abc123"),
OnlySubscriptions("cre-tgr_testnamespace_test-trigger_abc123"),
SubscriptionHasRetryPolicy("cre-tgr_testnamespace_test-trigger_abc123",
&pubsub.RetryPolicy{
MaximumBackoff: 600 * time.Second,
MinimumBackoff: 1 * time.Second,
}),
TopicExistsWithConfig("cre-tgr_testnamespace_test-trigger_abc123", &pubsub.TopicConfig{
MessageStoragePolicy: pubsub.MessageStoragePolicy{
AllowedPersistenceRegions: []string{"us-east1"},
},
Labels: map[string]string{
"name": "test-trigger", "namespace": "testnamespace", "resource": "triggers",
},
}),
},
},
{
Name: "Trigger created, broker ready, subscriber is addressable, nil pubsub client",
Key: testKey,
Expand Down

0 comments on commit cba6513

Please sign in to comment.