Skip to content
This repository was archived by the owner on Jun 19, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions pkg/apis/duck/v1alpha1/pubsub_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,46 @@ import (
"knative.dev/pkg/apis"
)

// MarkTopicNotReady sets the condition that the PubSub Topic is not ready and why.
func (s *PubSubStatus) MarkTopicNotReady(cs *apis.ConditionSet, reason, messageFormat string, messageA ...interface{}) {
// MarkTopicFailed sets the condition that the PubSub Topic is False and why.
func (s *PubSubStatus) MarkTopicFailed(cs *apis.ConditionSet, reason, messageFormat string, messageA ...interface{}) {
cs.Manage(s).MarkFalse(TopicReady, reason, messageFormat, messageA...)
}

// MarkTopicUnknown sets the condition that the PubSub Topic is Unknown and why.
func (s *PubSubStatus) MarkTopicUnknown(cs *apis.ConditionSet, reason, messageFormat string, messageA ...interface{}) {
cs.Manage(s).MarkUnknown(TopicReady, reason, messageFormat, messageA...)
}

// MarkTopicReady sets the condition that the PubSub Topic is ready.
func (s *PubSubStatus) MarkTopicReady(cs *apis.ConditionSet) {
cs.Manage(s).MarkTrue(TopicReady)
}

// MarkPullSubscriptionNotReady sets the condition that the PubSub PullSUbscription is
// not ready and why.
func (s *PubSubStatus) MarkPullSubscriptionNotReady(cs *apis.ConditionSet, reason, messageFormat string, messageA ...interface{}) {
// MarkTopicNotConfigured changes the TopicReady condition to be unknown to reflect
// that the Topic does not yet have a Status.
func (s *PubSubStatus) MarkTopicNotConfigured(cs *apis.ConditionSet) {
cs.Manage(s).MarkUnknown(TopicReady, "TopicNotConfigured", "Topic has not yet been reconciled")
Comment thread
nachocano marked this conversation as resolved.
}

// MarkPullSubscriptionFailed sets the condition that the PubSub PullSubscription is
// False and why.
func (s *PubSubStatus) MarkPullSubscriptionFailed(cs *apis.ConditionSet, reason, messageFormat string, messageA ...interface{}) {
cs.Manage(s).MarkFalse(PullSubscriptionReady, reason, messageFormat, messageA...)
}

// MarkPullSubscriptionUnknown sets the condition that the PubSub PullSubscription is Unknown.
func (s *PubSubStatus) MarkPullSubscriptionUnknown(cs *apis.ConditionSet, reason, messageFormat string, messageA ...interface{}) {
cs.Manage(s).MarkUnknown(PullSubscriptionReady, reason, messageFormat, messageA...)
}


// MarkPullSubscriptionReady sets the condition that the PubSub PullSubscription is ready.
func (s *PubSubStatus) MarkPullSubscriptionReady(cs *apis.ConditionSet) {
cs.Manage(s).MarkTrue(PullSubscriptionReady)
}

// MarkPullSubscriptionNotConfigured changes the PullSubscriptionReady condition to be unknown to reflect
// that the PullSubscription does not yet have a Status.
func (s *PubSubStatus) MarkPullSubscriptionNotConfigured(cs *apis.ConditionSet) {
cs.Manage(s).MarkUnknown(PullSubscriptionReady, "PullSubscriptionNotConfigured", "PullSubscription has not yet been reconciled")
}
28 changes: 22 additions & 6 deletions pkg/apis/events/v1alpha1/auditlogs_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func (s *AuditLogsSourceStatus) GetCondition(t apis.ConditionType) *apis.Conditi
return auditLogsSourceCondSet.Manage(s).GetCondition(t)
}

// GetTopLevelCondition returns the top level condition.
func (s *AuditLogsSourceStatus) GetTopLevelCondition() *apis.Condition {
Comment thread
nachocano marked this conversation as resolved.
return auditLogsSourceCondSet.Manage(s).GetTopLevelCondition()
}

// IsReady returns true if the resource is ready overall.
func (s *AuditLogsSourceStatus) IsReady() bool {
return auditLogsSourceCondSet.Manage(s).IsHappy()
Expand All @@ -36,22 +41,33 @@ func (s *AuditLogsSourceStatus) InitializeConditions() {
auditLogsSourceCondSet.Manage(s).InitializeConditions()
}

// MarkPullSubscriptionNotReady sets the condition that the underlying PullSubscription
// source is not ready and why.
func (s *AuditLogsSourceStatus) MarkPullSubscriptionNotReady(reason, messageFormat string, messageA ...interface{}) {
// MarkPullSubscriptionFailed sets the condition that the status of underlying PullSubscription
// is False and why.
func (s *AuditLogsSourceStatus) MarkPullSubscriptionFailed(reason, messageFormat string, messageA ...interface{}) {
auditLogsSourceCondSet.Manage(s).MarkFalse(duckv1alpha1.PullSubscriptionReady, reason, messageFormat, messageA...)
}

// MarkPullSubscriptionReady sets the condition that the underlying PubSub source is ready.
// MarkPullSubscriptionUnknown sets the condition that the status of underlying PullSubscription
// is Unknown and why.
func (s *AuditLogsSourceStatus) MarkPullSubscriptionUnknown(reason, messageFormat string, messageA ...interface{}) {
auditLogsSourceCondSet.Manage(s).MarkUnknown(duckv1alpha1.PullSubscriptionReady, reason, messageFormat, messageA...)
}

// MarkPullSubscriptionReady sets the condition that the underlying PullSubscription is ready.
func (s *AuditLogsSourceStatus) MarkPullSubscriptionReady() {
auditLogsSourceCondSet.Manage(s).MarkTrue(duckv1alpha1.PullSubscriptionReady)
}

// MarkTopicNotReady sets the condition that the PubSub topic was not created and why.
func (s *AuditLogsSourceStatus) MarkTopicNotReady(reason, messageFormat string, messageA ...interface{}) {
// MarkTopicFailed sets the condition that the status of PubSub topic is False and why.
func (s *AuditLogsSourceStatus) MarkTopicFailed(reason, messageFormat string, messageA ...interface{}) {
auditLogsSourceCondSet.Manage(s).MarkFalse(duckv1alpha1.TopicReady, reason, messageFormat, messageA...)
}

// MarkTopicUnknown sets the condition that the status of PubSub topic is Unknown and why.
func (s *AuditLogsSourceStatus) MarkTopicUnknown(reason, messageFormat string, messageA ...interface{}) {
auditLogsSourceCondSet.Manage(s).MarkUnknown(duckv1alpha1.TopicReady, reason, messageFormat, messageA...)
}

// MarkTopicReady sets the condition that the underlying PubSub topic was created successfully.
func (s *AuditLogsSourceStatus) MarkTopicReady() {
auditLogsSourceCondSet.Manage(s).MarkTrue(duckv1alpha1.TopicReady)
Expand Down
101 changes: 73 additions & 28 deletions pkg/apis/events/v1alpha1/auditlogs_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,63 +27,108 @@ import (

func TestAuditLogsSourceStatusIsReady(t *testing.T) {
tests := []struct {
name string
s *AuditLogsSourceStatus
want bool
name string
s *AuditLogsSourceStatus
wantConditionStatus corev1.ConditionStatus
want bool
}{{
name: "uninitialized",
s: &AuditLogsSourceStatus{},
want: false,
}, {
name: "initialized",
s: func() *AuditLogsSourceStatus {
s := &AuditLogsSourceStatus{}
s.InitializeConditions()
return s
}(),
wantConditionStatus: corev1.ConditionUnknown,
want: false,
}, {
name: "topic not ready",
name: "the status of topic is false",
s: func() *AuditLogsSourceStatus {
s := &AuditLogsSourceStatus{}
s.InitializeConditions()
s.MarkPullSubscriptionReady()
s.MarkSinkReady()
s.MarkTopicFailed("test", "the status of topic is false")
return s
}(),
wantConditionStatus: corev1.ConditionFalse,
want: false,
}, {
name: "pullsubscription not ready",
name: "the status of topic is unknown",
s: func() *AuditLogsSourceStatus {
s := &AuditLogsSourceStatus{}
s.InitializeConditions()
s.MarkTopicReady()
s.MarkSinkReady()
return s
}(),
}, {
name: "not ready",
s: func() *AuditLogsSourceStatus {
s := &AuditLogsSourceStatus{}
s.InitializeConditions()
s.MarkTopicReady()
s.MarkPullSubscriptionReady()
return s
}(),
}, {
name: "ready",
s: func() *AuditLogsSourceStatus {
s := &AuditLogsSourceStatus{}
s.InitializeConditions()
s.MarkTopicReady()
s.MarkPullSubscriptionReady()
s.MarkSinkReady()
s.MarkTopicUnknown("test", "the status of topic is unknown")
return s
}(),
want: true,
}}
wantConditionStatus: corev1.ConditionUnknown,
want: false,
},
{
name: "the status of pullsubscription is false",
s: func() *AuditLogsSourceStatus {
s := &AuditLogsSourceStatus{}
s.InitializeConditions()
s.MarkTopicReady()
s.MarkSinkReady()
s.MarkPullSubscriptionFailed("test", "the status of pullsubscription is false")
return s
}(),
wantConditionStatus: corev1.ConditionFalse,
}, {
name: "the status of pullsubscription is unknown",
s: func() *AuditLogsSourceStatus {
s := &AuditLogsSourceStatus{}
s.InitializeConditions()
s.MarkTopicReady()
s.MarkSinkReady()
s.MarkPullSubscriptionUnknown("test", "the status of pullsubscription is unknown")
return s
}(),
wantConditionStatus: corev1.ConditionUnknown,
want: false,
},
{
name: "sink is not ready",
s: func() *AuditLogsSourceStatus {
s := &AuditLogsSourceStatus{}
s.InitializeConditions()
s.MarkTopicReady()
s.MarkPullSubscriptionReady()
s.MarkSinkNotReady("test", "sink is not ready")
return s
}(),
wantConditionStatus: corev1.ConditionFalse,
want: false,
}, {
name: "ready",
s: func() *AuditLogsSourceStatus {
s := &AuditLogsSourceStatus{}
s.InitializeConditions()
s.MarkTopicReady()
s.MarkPullSubscriptionReady()
s.MarkSinkReady()
return s
}(),
wantConditionStatus: corev1.ConditionTrue,
want: true,
}}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if test.wantConditionStatus != "" {
gotConditionStatus := test.s.GetTopLevelCondition().Status
if gotConditionStatus != test.wantConditionStatus {
t.Errorf("unexpected condition status: want %v, got %v", test.wantConditionStatus, gotConditionStatus)
}
}
got := test.s.IsReady()
if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("%s: unexpected condition (-want, +got) = %v", test.name, diff)
if got != test.want {
t.Errorf("unexpected readiness: want %v, got %v", test.want, got)
}
})
}
Expand Down
47 changes: 36 additions & 11 deletions pkg/apis/events/v1alpha1/pubsub_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ limitations under the License.
package v1alpha1

import (
"knative.dev/pkg/apis"

duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1"
"github.com/google/knative-gcp/pkg/apis/pubsub/v1alpha1"
corev1 "k8s.io/api/core/v1"
"knative.dev/pkg/apis"
)

// GetCondition returns the condition currently associated with the given type, or nil.
func (ps *PubSubStatus) GetCondition(t apis.ConditionType) *apis.Condition {
return pubSubCondSet.Manage(ps).GetCondition(t)
}

// GetTopLevelCondition returns the top level condition.
func (ps *PubSubStatus) GetTopLevelCondition() *apis.Condition {
return pubSubCondSet.Manage(ps).GetTopLevelCondition()
}

// IsReady returns true if the resource is ready overall.
func (ps *PubSubStatus) IsReady() bool {
return pubSubCondSet.Manage(ps).IsHappy()
Expand All @@ -37,24 +43,43 @@ func (ps *PubSubStatus) InitializeConditions() {
pubSubCondSet.Manage(ps).InitializeConditions()
}

// MarkPullSubscriptionNotReady sets the condition that the underlying PullSubscription
// source is not ready and why.
func (ps *PubSubStatus) MarkPullSubscriptionNotReady(reason, messageFormat string, messageA ...interface{}) {
// MarkPullSubscriptionFailed sets the condition that the underlying PullSubscription
// is False and why.
func (ps *PubSubStatus) MarkPullSubscriptionFailed(reason, messageFormat string, messageA ...interface{}) {
pubSubCondSet.Manage(ps).MarkFalse(duckv1alpha1.PullSubscriptionReady, reason, messageFormat, messageA...)
}

// MarkPullSubscriptionNotConfigured changes the PullSubscriptionReady condition to be unknown to reflect
// that the PullSubscription does not yet have a Status.
func (ps *PubSubStatus) MarkPullSubscriptionNotConfigured() {
pubSubCondSet.Manage(ps).MarkUnknown(duckv1alpha1.PullSubscriptionReady, "PullSubscriptionNotConfigured", "PullSubscription has not yet been reconciled")
}

// MarkPullSubscriptionReady sets the condition that the underlying PullSubscription is ready.
func (ps *PubSubStatus) MarkPullSubscriptionReady() {
pubSubCondSet.Manage(ps).MarkTrue(duckv1alpha1.PullSubscriptionReady)
}

func (ps *PubSubStatus) PropagatePullSubscriptionStatus(ready *apis.Condition) {
// MarkPullSubscriptionReady sets the condition that the underlying PullSubscription is Unknown and why.
func (ps *PubSubStatus) MarkPullSubscriptionUnknown(reason, messageFormat string, messageA ...interface{}) {
pubSubCondSet.Manage(ps).MarkUnknown(duckv1alpha1.PullSubscriptionReady, reason, messageFormat, messageA...)
}

func (ps *PubSubStatus) PropagatePullSubscriptionStatus(pss *v1alpha1.PullSubscriptionStatus) {
psc := pss.GetTopLevelCondition()
if psc == nil {
ps.MarkPullSubscriptionNotConfigured()
return
}

switch {
case ready == nil:
ps.MarkPullSubscriptionNotReady("PullSubscriptionNotReady", "PullSubscription has no Ready type status")
case ready.IsTrue():
case psc.Status == corev1.ConditionUnknown:
ps.MarkPullSubscriptionUnknown(psc.Reason, psc.Message)
case psc.Status == corev1.ConditionTrue:
ps.MarkPullSubscriptionReady()
case ready.IsFalse():
ps.MarkPullSubscriptionNotReady(ready.Reason, ready.Message)
case psc.Status == corev1.ConditionFalse:
ps.MarkPullSubscriptionFailed(psc.Reason, psc.Message)
default:
ps.MarkPullSubscriptionUnknown("PullSubscriptionUnknown", "The status of PullSubscription is invalid: %v", psc.Status)
}
}
Loading