-
Notifications
You must be signed in to change notification settings - Fork 225
Refactor k8s source to use the sdk. #123
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,9 +50,14 @@ const ( | |
// KubernetesEventSourceConditionReady has status True when the | ||
// source is ready to send events. | ||
KubernetesEventSourceConditionReady = duckv1alpha1.ConditionReady | ||
|
||
// KubernetesEventSourceContainerSourceReady has status True when the | ||
// container source produced as a result of this resource is ready. | ||
KubernetesEventSourceContainerSourceReady = "ContainerSourceReady" | ||
) | ||
|
||
var kubernetesEventSourceCondSet = duckv1alpha1.NewLivingConditionSet() | ||
var kubernetesEventSourceCondSet = duckv1alpha1.NewLivingConditionSet( | ||
KubernetesEventSourceContainerSourceReady) | ||
|
||
// KubernetesEventSourceStatus defines the observed state of the source. | ||
type KubernetesEventSourceStatus struct { | ||
|
@@ -82,16 +87,57 @@ func (s *KubernetesEventSourceStatus) InitializeConditions() { | |
kubernetesEventSourceCondSet.Manage(s).InitializeConditions() | ||
} | ||
|
||
// MarkReady sets the condition that the ContainerSource owned by | ||
// the source has Ready status True. | ||
func (s *KubernetesEventSourceStatus) MarkReady() { | ||
kubernetesEventSourceCondSet.Manage(s).MarkTrue(KubernetesEventSourceConditionReady) | ||
// PropagateContainerSourceStatus examines the given container source and synchronizes the conditions that matter to | ||
// the kubernetes event source status. | ||
func (ss *KubernetesEventSourceStatus) MarkContainerSourceReadyStatus(cs ContainerSourceStatus) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we expect people to use func PropagateContainerSourceStatus(cm ConditionManager, cs ContainerSourceStatus) Then in this file: func PropagateContainerSourceStatus(cs ContainerSourceStatus) {
containersource.PropagateConatinerSourceStatus(kubernetesEventSourceCondSet.Manage(s), cs)
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if cs.IsReady() { | ||
kubernetesEventSourceCondSet.Manage(ss).MarkTrue(KubernetesEventSourceContainerSourceReady) | ||
return | ||
} | ||
|
||
sinkProvided := cs.GetCondition(ContainerConditionSinkProvided) | ||
deployed := cs.GetCondition(ContainerConditionDeployed) | ||
|
||
reason := "" | ||
message := "" | ||
isFalse := false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about |
||
|
||
if sinkProvided == nil { | ||
reason = reason + "SinkProvided" | ||
message = appendMessage(message, "SinkProvided status is nil") | ||
} else if sinkProvided.IsUnknown() { | ||
reason = reason + sinkProvided.Reason | ||
message = appendMessage(message, sinkProvided.Message) | ||
} else if sinkProvided.IsFalse() { | ||
reason = reason + sinkProvided.Reason | ||
message = appendMessage(message, sinkProvided.Message) | ||
isFalse = true | ||
} | ||
|
||
if deployed == nil { | ||
reason = reason + "Deploy" | ||
message = appendMessage(message, "Deploy status is nil") | ||
} else if deployed.IsUnknown() { | ||
reason = reason + deployed.Reason | ||
message = appendMessage(message, deployed.Message) | ||
} else if deployed.IsFalse() { | ||
reason = reason + deployed.Reason | ||
message = appendMessage(message, deployed.Message) | ||
isFalse = true | ||
} | ||
|
||
if isFalse { | ||
kubernetesEventSourceCondSet.Manage(ss).MarkFalse(KubernetesEventSourceContainerSourceReady, reason, message) | ||
} else { | ||
kubernetesEventSourceCondSet.Manage(ss).MarkUnknown(KubernetesEventSourceContainerSourceReady, reason, message) | ||
} | ||
} | ||
|
||
// MarkUnready sets the condition that the ContainerSource owned by | ||
// the source does not have Ready status True. | ||
func (s *KubernetesEventSourceStatus) MarkUnready(reason, messageFormat string, messageA ...interface{}) { | ||
kubernetesEventSourceCondSet.Manage(s).MarkFalse(KubernetesEventSourceConditionReady, reason, messageFormat, messageA...) | ||
func appendMessage(a string, b string) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using Above would change to something like: messages := make([]string)
...
messages = append(messages, "SinkProvided status is nil")
...
MarkUnknown(..., reason, strings.Join(messages, "; ")) |
||
if a != "" { | ||
a += "; " | ||
} | ||
return a + b | ||
} | ||
|
||
// +genclient | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment starts with
PropagateContainerSourceStatus
, which seems like what this method does, but the method is namedMarkContainerSourceReadyStatus
.