Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Consumer reconciler for scheduling and scaling #1601

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
22 changes: 22 additions & 0 deletions control-plane/pkg/apis/internals/kafka/eventing/data_plane.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2021 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 eventing

const (
// ConfigMapVolumeName is the volume name of the data plane ConfigMap
ConfigMapVolumeName = "kafka-resources"
)
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ func (cgs *ConsumerGroupSpec) Validate(ctx context.Context) *apis.FieldError {
}

func (cts *ConsumerTemplateSpec) Validate(ctx context.Context) *apis.FieldError {
return cts.Spec.Validate(ctx).ViaField("spec")
specCtx := ctx
if apis.IsInUpdate(ctx) {
specCtx = apis.WithinUpdate(ctx, apis.GetBaseline(ctx).(*ConsumerGroup).Spec.Template.Spec)
}
return cts.Spec.Validate(specCtx).ViaField("spec")
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ func TestConsumerGroup_Validate(t *testing.T) {
Topics: []string{"t1"},
Configs: ConsumerConfigs{
Configs: map[string]string{
"group.id": "g1",
"group.id": "g1",
"bootstrap.servers": "kafka:9092",
},
},
Delivery: &DeliverySpec{
Expand All @@ -107,12 +108,276 @@ func TestConsumerGroup_Validate(t *testing.T) {
Host: "127.0.0.1",
},
},
PodBind: &PodBind{
PodName: "p-0",
PodNamespace: "ns",
},
},
},
},
},
wantErr: false,
},
{
name: "invalid no pod name",
ctx: context.Background(),
given: &ConsumerGroup{
Spec: ConsumerGroupSpec{
Replicas: pointer.Int32Ptr(1),
Selector: map[string]string{"app": "app"},
Template: ConsumerTemplateSpec{
Spec: ConsumerSpec{
Topics: []string{"t1"},
Configs: ConsumerConfigs{
Configs: map[string]string{
"group.id": "g1",
"bootstrap.servers": "kafka:9092",
},
},
Delivery: &DeliverySpec{
DeliverySpec: &eventingduck.DeliverySpec{},
},
Subscriber: duckv1.Destination{
URI: &apis.URL{
Scheme: "http",
Host: "127.0.0.1",
},
},
PodBind: &PodBind{
PodNamespace: "ns",
},
},
},
},
},
wantErr: true,
},
{
name: "invalid no pod namespace",
ctx: context.Background(),
given: &ConsumerGroup{
Spec: ConsumerGroupSpec{
Replicas: pointer.Int32Ptr(1),
Selector: map[string]string{"app": "app"},
Template: ConsumerTemplateSpec{
Spec: ConsumerSpec{
Topics: []string{"t1"},
Configs: ConsumerConfigs{
Configs: map[string]string{
"group.id": "g1",
"bootstrap.servers": "kafka:9092",
},
},
Delivery: &DeliverySpec{
DeliverySpec: &eventingduck.DeliverySpec{},
},
Subscriber: duckv1.Destination{
URI: &apis.URL{
Scheme: "http",
Host: "127.0.0.1",
},
},
PodBind: &PodBind{
PodName: "p-0",
},
},
},
},
},
wantErr: true,
},
{
name: "valid - no updates",
ctx: apis.WithinUpdate(context.Background(), &ConsumerGroup{
Spec: ConsumerGroupSpec{
Replicas: pointer.Int32Ptr(1),
Selector: map[string]string{"app": "app"},
Template: ConsumerTemplateSpec{
Spec: ConsumerSpec{
Topics: []string{"t1"},
Configs: ConsumerConfigs{
Configs: map[string]string{
"group.id": "g1",
"bootstrap.servers": "kafka:9092",
},
},
Delivery: &DeliverySpec{
DeliverySpec: &eventingduck.DeliverySpec{},
},
Subscriber: duckv1.Destination{
URI: &apis.URL{
Scheme: "http",
Host: "127.0.0.1",
},
},
PodBind: &PodBind{
PodName: "p-0",
PodNamespace: "ns",
},
},
},
},
}),
given: &ConsumerGroup{
Spec: ConsumerGroupSpec{
Replicas: pointer.Int32Ptr(1),
Selector: map[string]string{"app": "app"},
Template: ConsumerTemplateSpec{
Spec: ConsumerSpec{
Topics: []string{"t1"},
Configs: ConsumerConfigs{
Configs: map[string]string{
"group.id": "g1",
"bootstrap.servers": "kafka:9092",
},
},
Delivery: &DeliverySpec{
DeliverySpec: &eventingduck.DeliverySpec{},
},
Subscriber: duckv1.Destination{
URI: &apis.URL{
Scheme: "http",
Host: "127.0.0.1",
},
},
PodBind: &PodBind{
PodName: "p-0",
PodNamespace: "ns",
},
},
},
},
},
wantErr: false,
},
{
name: "invalid pod name update",
ctx: apis.WithinUpdate(context.Background(), &ConsumerGroup{
Spec: ConsumerGroupSpec{
Replicas: pointer.Int32Ptr(1),
Selector: map[string]string{"app": "app"},
Template: ConsumerTemplateSpec{
Spec: ConsumerSpec{
Topics: []string{"t1"},
Configs: ConsumerConfigs{
Configs: map[string]string{
"group.id": "g1",
"bootstrap.servers": "kafka:9092",
},
},
Delivery: &DeliverySpec{
DeliverySpec: &eventingduck.DeliverySpec{},
},
Subscriber: duckv1.Destination{
URI: &apis.URL{
Scheme: "http",
Host: "127.0.0.1",
},
},
PodBind: &PodBind{
PodName: "p-1",
PodNamespace: "ns",
},
},
},
},
}),
given: &ConsumerGroup{
Spec: ConsumerGroupSpec{
Replicas: pointer.Int32Ptr(1),
Selector: map[string]string{"app": "app"},
Template: ConsumerTemplateSpec{
Spec: ConsumerSpec{
Topics: []string{"t1"},
Configs: ConsumerConfigs{
Configs: map[string]string{
"group.id": "g1",
"bootstrap.servers": "kafka:9092",
},
},
Delivery: &DeliverySpec{
DeliverySpec: &eventingduck.DeliverySpec{},
},
Subscriber: duckv1.Destination{
URI: &apis.URL{
Scheme: "http",
Host: "127.0.0.1",
},
},
PodBind: &PodBind{
PodName: "p-0",
PodNamespace: "ns",
},
},
},
},
},
wantErr: true,
},
{
name: "invalid pod name update",
ctx: apis.WithinUpdate(context.Background(), &ConsumerGroup{
Spec: ConsumerGroupSpec{
Replicas: pointer.Int32Ptr(1),
Selector: map[string]string{"app": "app"},
Template: ConsumerTemplateSpec{
Spec: ConsumerSpec{
Topics: []string{"t1"},
Configs: ConsumerConfigs{
Configs: map[string]string{
"group.id": "g1",
"bootstrap.servers": "kafka:9092",
},
},
Delivery: &DeliverySpec{
DeliverySpec: &eventingduck.DeliverySpec{},
},
Subscriber: duckv1.Destination{
URI: &apis.URL{
Scheme: "http",
Host: "127.0.0.1",
},
},
PodBind: &PodBind{
PodName: "p-0",
PodNamespace: "ns-1",
},
},
},
},
}),
given: &ConsumerGroup{
Spec: ConsumerGroupSpec{
Replicas: pointer.Int32Ptr(1),
Selector: map[string]string{"app": "app"},
Template: ConsumerTemplateSpec{
Spec: ConsumerSpec{
Topics: []string{"t1"},
Configs: ConsumerConfigs{
Configs: map[string]string{
"group.id": "g1",
"bootstrap.servers": "kafka:9092",
},
},
Delivery: &DeliverySpec{
DeliverySpec: &eventingduck.DeliverySpec{},
},
Subscriber: duckv1.Destination{
URI: &apis.URL{
Scheme: "http",
Host: "127.0.0.1",
},
},
PodBind: &PodBind{
PodName: "p-0",
PodNamespace: "ns-2",
},
},
},
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,48 @@
package v1alpha1

import (
"fmt"

"knative.dev/pkg/apis"
"knative.dev/pkg/reconciler"
)

const (
ConsumerConditionContract = "Contract"
ConsumerConditionBind = "Bind"
)

var (
consumerConditionSet = apis.NewLivingConditionSet(
ConsumerConditionContract,
ConsumerConditionBind,
)
)

func (c *Consumer) GetConditionSet() apis.ConditionSet {
return apis.NewLivingConditionSet()
return consumerConditionSet
}

func (c *Consumer) MarkReconcileContractFailed(err error) reconciler.Event {
err = fmt.Errorf("failed to reconcile contract: %w", err)
c.GetConditionSet().Manage(c.GetStatus()).MarkFalse(ConsumerConditionContract, "ReconcileContract", err.Error())
return err
}

func (c *Consumer) MarkReconcileContractSucceeded() {
c.GetConditionSet().Manage(c.GetStatus()).MarkTrue(ConsumerConditionContract)
}

func (c *Consumer) MarkBindFailed(err error) reconciler.Event {
err = fmt.Errorf("failed to bind resource to pod: %w", err)
c.GetConditionSet().Manage(c.GetStatus()).MarkFalse(ConsumerConditionBind, "ConsumerBinding", err.Error())
return err
}

func (c *Consumer) MarkBindInProgress() {
c.GetConditionSet().Manage(c.GetStatus()).MarkFalse(ConsumerConditionBind, "BindInProgress", "")
}

func (c *Consumer) MarkBindSucceeded() {
c.GetConditionSet().Manage(c.GetStatus()).MarkTrue(ConsumerConditionBind)
}
Loading