-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>
- Loading branch information
Showing
25 changed files
with
572 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package broker | ||
|
||
import ( | ||
"fmt" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func PathFromObject(obj metav1.Object) string { | ||
return Path(obj.GetNamespace(), obj.GetName()) | ||
} | ||
|
||
func Path(namespace, name string) string { | ||
return fmt.Sprintf("/%s/%s", namespace, name) | ||
} | ||
|
||
func Topic(prefix string, obj metav1.Object) string { | ||
return fmt.Sprintf("%s%s-%s", prefix, obj.GetNamespace(), obj.GetName()) | ||
} | ||
|
167 changes: 167 additions & 0 deletions
167
control-plane/pkg/reconciler/base/broker/condition_set.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
package broker | ||
|
||
import ( | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/tools/record" | ||
"knative.dev/eventing/pkg/reconciler/names" | ||
"knative.dev/pkg/apis" | ||
duckv1 "knative.dev/pkg/apis/duck/v1" | ||
"knative.dev/pkg/reconciler" | ||
) | ||
|
||
const ( | ||
ConditionAddressable apis.ConditionType = "Addressable" | ||
ConditionTopicReady apis.ConditionType = "TopicReady" | ||
ConditionConfigMapUpdated apis.ConditionType = "ConfigMapUpdated" | ||
ConditionConfigParsed apis.ConditionType = "ConfigParsed" | ||
) | ||
|
||
var ConditionSet = apis.NewLivingConditionSet( | ||
ConditionAddressable, | ||
ConditionTopicReady, | ||
ConditionConfigMapUpdated, | ||
ConditionConfigParsed, | ||
) | ||
|
||
type Object interface { | ||
duckv1.KRShaped | ||
runtime.Object | ||
} | ||
|
||
type StatusConditionManager struct { | ||
Object Object | ||
|
||
SetAddress func(u *apis.URL) | ||
|
||
Configs *EnvConfigs | ||
|
||
Recorder record.EventRecorder | ||
} | ||
|
||
func (manager *StatusConditionManager) FailedToGetBrokersTriggersConfigMap(err error) reconciler.Event { | ||
|
||
manager.Object.GetConditionSet().Manage(manager.Object.GetStatus()).MarkFalse( | ||
ConditionConfigMapUpdated, | ||
fmt.Sprintf( | ||
"Failed to get ConfigMap: %s", | ||
manager.Configs.DataPlaneConfigMapAsString(), | ||
), | ||
"%v", | ||
err, | ||
) | ||
|
||
return fmt.Errorf("failed to get brokers and triggers config map %s: %w", manager.Configs.DataPlaneConfigMapAsString(), err) | ||
} | ||
|
||
func (manager *StatusConditionManager) FailedToGetBrokersTriggersDataFromConfigMap(err error) reconciler.Event { | ||
|
||
manager.Object.GetConditionSet().Manage(manager.Object.GetStatus()).MarkFalse( | ||
ConditionConfigMapUpdated, | ||
fmt.Sprintf( | ||
"Failed to get brokers and trigger data from ConfigMap: %s", | ||
manager.Configs.DataPlaneConfigMapAsString(), | ||
), | ||
"%v", | ||
err, | ||
) | ||
|
||
return fmt.Errorf("failed to get broker and triggers data from config map %s: %w", manager.Configs.DataPlaneConfigMapAsString(), err) | ||
} | ||
|
||
func (manager *StatusConditionManager) FailedToUpdateBrokersTriggersConfigMap(err error) reconciler.Event { | ||
|
||
manager.Object.GetConditionSet().Manage(manager.Object.GetStatus()).MarkFalse( | ||
ConditionConfigMapUpdated, | ||
fmt.Sprintf("Failed to update ConfigMap: %s", manager.Configs.DataPlaneConfigMapAsString()), | ||
"%s", | ||
err, | ||
) | ||
|
||
return fmt.Errorf("failed to update brokers and triggers config map %s: %w", manager.Configs.DataPlaneConfigMapAsString(), err) | ||
} | ||
|
||
func (manager *StatusConditionManager) BrokersTriggersConfigMapUpdated() { | ||
|
||
manager.Object.GetConditionSet().Manage(manager.Object.GetStatus()).MarkTrueWithReason( | ||
ConditionConfigMapUpdated, | ||
fmt.Sprintf("Config map %s updated", manager.Configs.DataPlaneConfigMapAsString()), | ||
"", | ||
) | ||
} | ||
|
||
func (manager *StatusConditionManager) FailedToCreateTopic(topic string, err error) reconciler.Event { | ||
|
||
manager.Object.GetConditionSet().Manage(manager.Object.GetStatus()).MarkFalse( | ||
ConditionTopicReady, | ||
fmt.Sprintf("Failed to create topic: %s", topic), | ||
"%v", | ||
err, | ||
) | ||
|
||
return fmt.Errorf("failed to create topic: %s: %w", topic, err) | ||
} | ||
|
||
func (manager *StatusConditionManager) TopicCreated(topic string) { | ||
|
||
manager.Object.GetConditionSet().Manage(manager.Object.GetStatus()).MarkTrueWithReason( | ||
ConditionTopicReady, | ||
fmt.Sprintf("Topic %s created", topic), | ||
"", | ||
) | ||
} | ||
|
||
func (manager *StatusConditionManager) Reconciled() reconciler.Event { | ||
|
||
object := manager.Object | ||
|
||
manager.SetAddress(&apis.URL{ | ||
Scheme: "http", | ||
Host: names.ServiceHostName(manager.Configs.BrokerIngressName, manager.Configs.SystemNamespace), | ||
Path: fmt.Sprintf("/%s/%s", object.GetNamespace(), object.GetName()), | ||
}) | ||
object.GetConditionSet().Manage(object.GetStatus()).MarkTrue(ConditionAddressable) | ||
|
||
return nil | ||
} | ||
|
||
func (manager *StatusConditionManager) FailedToUpdateDispatcherPodsAnnotation(err error) { | ||
|
||
// We don't set status conditions for dispatcher pods updates. | ||
|
||
// Record the event. | ||
manager.Recorder.Eventf( | ||
manager.Object, | ||
corev1.EventTypeWarning, | ||
"failed to update dispatcher pods annotation", | ||
"%v", | ||
err, | ||
) | ||
} | ||
|
||
func (manager *StatusConditionManager) FailedToUpdateReceiverPodsAnnotation(err error) reconciler.Event { | ||
|
||
return fmt.Errorf("failed to update receiver pods annotation: %w", err) | ||
} | ||
|
||
func (manager *StatusConditionManager) FailedToGetBrokerConfig(err error) reconciler.Event { | ||
|
||
return fmt.Errorf("failed to get broker configuration: %w", err) | ||
} | ||
|
||
func (manager *StatusConditionManager) FailedToResolveBrokerConfig(err error) reconciler.Event { | ||
|
||
manager.Object.GetConditionSet().Manage(manager.Object.GetStatus()).MarkFalse( | ||
ConditionConfigParsed, | ||
fmt.Sprintf("%v", err), | ||
"", | ||
) | ||
|
||
return fmt.Errorf("failed to get broker configuration: %w", err) | ||
} | ||
|
||
func (manager *StatusConditionManager) BrokerConfigResolved() { | ||
manager.Object.GetConditionSet().Manage(manager.Object.GetStatus()).MarkTrue(ConditionConfigParsed) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package broker | ||
|
||
import "fmt" | ||
|
||
type EnvConfigs struct { | ||
DataPlaneConfigMapNamespace string `required:"true" split_words:"true"` | ||
DataPlaneConfigMapName string `required:"true" split_words:"true"` | ||
GeneralConfigMapName string `required:"true" split_words:"true"` | ||
BrokerIngressName string `required:"true" split_words:"true"` | ||
SystemNamespace string `required:"true" split_words:"true"` | ||
DataPlaneConfigFormat string `required:"true" split_words:"true"` | ||
} | ||
|
||
func (c *EnvConfigs) DataPlaneConfigMapAsString() string { | ||
return fmt.Sprintf("%s/%s", c.DataPlaneConfigMapNamespace, c.DataPlaneConfigMapName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.