-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* KafkaChannel v1 API Signed-off-by: Pierangelo Di Pilato <[email protected]> * Update codegen Signed-off-by: Pierangelo Di Pilato <[email protected]> * v1beta1 remains the stored version Signed-off-by: Pierangelo Di Pilato <[email protected]> * Fix service name in CRD Signed-off-by: Pierangelo Di Pilato <[email protected]> * Update codegen Signed-off-by: Pierangelo Di Pilato <[email protected]> --------- Signed-off-by: Pierangelo Di Pilato <[email protected]>
- Loading branch information
Showing
36 changed files
with
2,680 additions
and
6 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
297 changes: 296 additions & 1 deletion
297
control-plane/config/eventing-kafka-broker/100-channel/100-kafka-channel.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
/* | ||
Copyright 2020 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package v1 is the v1 version of the API. | ||
// +k8s:deepcopy-gen=package | ||
// +groupName=messaging.knative.dev | ||
package v1 |
34 changes: 34 additions & 0 deletions
34
control-plane/pkg/apis/messaging/v1/kafka_channel_conversion.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,34 @@ | ||
/* | ||
Copyright 2020 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"knative.dev/pkg/apis" | ||
) | ||
|
||
// ConvertTo implements apis.Convertible | ||
func (channel *KafkaChannel) ConvertTo(_ context.Context, sink apis.Convertible) error { | ||
return fmt.Errorf("v1 is the highest known version, got: %T", sink) | ||
} | ||
|
||
// ConvertFrom implements apis.Convertible | ||
func (sink *KafkaChannel) ConvertFrom(_ context.Context, channel apis.Convertible) error { | ||
return fmt.Errorf("v1 is the highest known version, got: %T", channel) | ||
} |
73 changes: 73 additions & 0 deletions
73
control-plane/pkg/apis/messaging/v1/kafka_channel_defaults.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,73 @@ | ||
/* | ||
Copyright 2020 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1 | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"knative.dev/eventing/pkg/apis/messaging" | ||
"knative.dev/pkg/apis" | ||
) | ||
|
||
const ( | ||
// DefaultNumPartitions is the KafkaChannel Spec default for the number of partitions | ||
DefaultNumPartitions = 1 | ||
|
||
// DefaultReplicationFactor is the KafkaChannel Spec default for the replication factor | ||
DefaultReplicationFactor = 1 | ||
|
||
// DefaultRetentionISO8601Duration is the KafkaChannel Spec default for the retention duration as an ISO-8601 string | ||
DefaultRetentionISO8601Duration = "PT168H" // Precise 7 Days | ||
|
||
// DefaultRetentionDuration is the time.Duration equivalent of the DefaultRetentionISO8601Duration | ||
DefaultRetentionDuration = 7 * 24 * time.Hour // Precise 7 Days | ||
|
||
// KafkaTopicConfigRetentionMs is the key in the Sarama TopicDetail ConfigEntries map for retention time (in ms) | ||
KafkaTopicConfigRetentionMs = "retention.ms" | ||
) | ||
|
||
func (kc *KafkaChannel) SetDefaults(ctx context.Context) { | ||
// Set the duck subscription to the stored version of the duck | ||
// we support. Reason for this is that the stored version will | ||
// not get a chance to get modified, but for newer versions | ||
// conversion webhook will be able to take a crack at it and | ||
// can modify it to match the duck shape. | ||
if kc.Annotations == nil { | ||
kc.Annotations = make(map[string]string) | ||
} | ||
|
||
if _, ok := kc.Annotations[messaging.SubscribableDuckVersionAnnotation]; !ok { | ||
kc.Annotations[messaging.SubscribableDuckVersionAnnotation] = "v1" | ||
} | ||
|
||
ctx = apis.WithinParent(ctx, kc.ObjectMeta) | ||
kc.Spec.SetDefaults(ctx) | ||
} | ||
|
||
func (kcs *KafkaChannelSpec) SetDefaults(ctx context.Context) { | ||
if kcs.NumPartitions == 0 { | ||
kcs.NumPartitions = DefaultNumPartitions | ||
} | ||
if kcs.ReplicationFactor == 0 { | ||
kcs.ReplicationFactor = DefaultReplicationFactor | ||
} | ||
if len(kcs.RetentionDuration) <= 0 { | ||
kcs.RetentionDuration = DefaultRetentionISO8601Duration | ||
} | ||
kcs.Delivery.SetDefaults(ctx) | ||
} |
149 changes: 149 additions & 0 deletions
149
control-plane/pkg/apis/messaging/v1/kafka_channel_lifecycle.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,149 @@ | ||
/* | ||
Copyright 2020 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1 | ||
|
||
import ( | ||
"sync" | ||
|
||
"knative.dev/pkg/apis" | ||
duckv1 "knative.dev/pkg/apis/duck/v1" | ||
) | ||
|
||
// The consolidated and distributed KafkaChannel implementations require | ||
// differentiated ConditionSets in order to accurately reflect their varied | ||
// runtime architectures. One of the channel specific "Register..." functions | ||
// in pkg/channel/<type>/apis/messaging/kafka_channel_lifecycle.go should be | ||
// called via an init() in the main() of associated components. | ||
var kc apis.ConditionSet | ||
var channelCondSetLock = sync.RWMutex{} | ||
|
||
// Shared / Common Conditions Used By All Channel Implementations | ||
const ( | ||
|
||
// KafkaChannelConditionReady has status True when all sub-conditions below have been set to True. | ||
KafkaChannelConditionReady = apis.ConditionReady | ||
|
||
// KafkaChannelConditionAddressable has status true when this KafkaChannel meets | ||
// the Addressable contract and has a non-empty URL. | ||
KafkaChannelConditionAddressable apis.ConditionType = "Addressable" | ||
|
||
// KafkaChannelConditionConfigReady has status True when the Kafka configuration to use by the channel | ||
// exists and is valid (i.e. the connection has been established). | ||
KafkaChannelConditionConfigReady apis.ConditionType = "ConfigurationReady" | ||
|
||
// KafkaChannelConditionTopicReady has status True when the Kafka topic to use by the channel exists. | ||
KafkaChannelConditionTopicReady apis.ConditionType = "TopicReady" | ||
|
||
// KafkaChannelConditionChannelServiceReady has status True when the K8S Service representing the channel | ||
// is ready. Because this uses ExternalName, there are no endpoints to check. | ||
KafkaChannelConditionChannelServiceReady apis.ConditionType = "ChannelServiceReady" | ||
|
||
ConditionEventPoliciesReady apis.ConditionType = "EventPoliciesReady" | ||
) | ||
|
||
// RegisterAlternateKafkaChannelConditionSet register a different apis.ConditionSet. | ||
func RegisterAlternateKafkaChannelConditionSet(conditionSet apis.ConditionSet) { | ||
channelCondSetLock.Lock() | ||
defer channelCondSetLock.Unlock() | ||
|
||
kc = conditionSet | ||
} | ||
|
||
// GetConditionSet retrieves the condition set for this resource. Implements the KRShaped interface. | ||
func (*KafkaChannel) GetConditionSet() apis.ConditionSet { | ||
channelCondSetLock.RLock() | ||
defer channelCondSetLock.RUnlock() | ||
|
||
return kc | ||
} | ||
|
||
// GetConditionSet retrieves the condition set for this resource. | ||
func (*KafkaChannelStatus) GetConditionSet() apis.ConditionSet { | ||
channelCondSetLock.RLock() | ||
defer channelCondSetLock.RUnlock() | ||
|
||
return kc | ||
} | ||
|
||
// GetCondition returns the condition currently associated with the given type, or nil. | ||
func (kcs *KafkaChannelStatus) GetCondition(t apis.ConditionType) *apis.Condition { | ||
return kcs.GetConditionSet().Manage(kcs).GetCondition(t) | ||
} | ||
|
||
// IsReady returns true if the resource is ready overall. | ||
func (kcs *KafkaChannelStatus) IsReady() bool { | ||
return kcs.GetConditionSet().Manage(kcs).IsHappy() | ||
} | ||
|
||
// InitializeConditions sets relevant unset conditions to Unknown state. | ||
func (kcs *KafkaChannelStatus) InitializeConditions() { | ||
kcs.GetConditionSet().Manage(kcs).InitializeConditions() | ||
} | ||
|
||
// SetAddress sets the address (as part of Addressable contract) and marks the correct condition. | ||
func (kcs *KafkaChannelStatus) SetAddress(addr *duckv1.Addressable) { | ||
if kcs.Address == nil { | ||
kcs.Address = &duckv1.Addressable{} | ||
} | ||
if addr != nil { | ||
kcs.Address = addr | ||
kcs.GetConditionSet().Manage(kcs).MarkTrue(KafkaChannelConditionAddressable) | ||
} else { | ||
kcs.Address.URL = nil | ||
kcs.GetConditionSet().Manage(kcs).MarkFalse(KafkaChannelConditionAddressable, "EmptyURL", "URL is nil") | ||
} | ||
} | ||
|
||
func (kcs *KafkaChannelStatus) MarkConfigTrue() { | ||
kcs.GetConditionSet().Manage(kcs).MarkTrue(KafkaChannelConditionConfigReady) | ||
} | ||
|
||
func (kcs *KafkaChannelStatus) MarkConfigFailed(reason, messageFormat string, messageA ...interface{}) { | ||
kcs.GetConditionSet().Manage(kcs).MarkFalse(KafkaChannelConditionConfigReady, reason, messageFormat, messageA...) | ||
} | ||
|
||
func (kcs *KafkaChannelStatus) MarkTopicTrue() { | ||
kcs.GetConditionSet().Manage(kcs).MarkTrue(KafkaChannelConditionTopicReady) | ||
} | ||
|
||
func (kcs *KafkaChannelStatus) MarkTopicFailed(reason, messageFormat string, messageA ...interface{}) { | ||
kcs.GetConditionSet().Manage(kcs).MarkFalse(KafkaChannelConditionTopicReady, reason, messageFormat, messageA...) | ||
} | ||
|
||
func (kcs *KafkaChannelStatus) MarkChannelServiceFailed(reason, messageFormat string, messageA ...interface{}) { | ||
kcs.GetConditionSet().Manage(kcs).MarkFalse(KafkaChannelConditionChannelServiceReady, reason, messageFormat, messageA...) | ||
} | ||
|
||
func (kcs *KafkaChannelStatus) MarkChannelServiceTrue() { | ||
kcs.GetConditionSet().Manage(kcs).MarkTrue(KafkaChannelConditionChannelServiceReady) | ||
} | ||
|
||
func (kcs *KafkaChannelStatus) MarkEventPoliciesTrue() { | ||
kcs.GetConditionSet().Manage(kcs).MarkTrue(ConditionEventPoliciesReady) | ||
} | ||
|
||
func (kcs *KafkaChannelStatus) MarkEventPoliciesTrueWithReason(reason, messageFormat string, messageA ...interface{}) { | ||
kcs.GetConditionSet().Manage(kcs).MarkTrueWithReason(ConditionEventPoliciesReady, reason, messageFormat, messageA...) | ||
} | ||
|
||
func (kcs *KafkaChannelStatus) MarkEventPoliciesFailed(reason, messageFormat string, messageA ...interface{}) { | ||
kcs.GetConditionSet().Manage(kcs).MarkFalse(ConditionEventPoliciesReady, reason, messageFormat, messageA...) | ||
} | ||
|
||
func (kcs *KafkaChannelStatus) MarkEventPoliciesUnknown(reason, messageFormat string, messageA ...interface{}) { | ||
kcs.GetConditionSet().Manage(kcs).MarkUnknown(ConditionEventPoliciesReady, reason, messageFormat, messageA...) | ||
} |
Oops, something went wrong.