Skip to content

Commit

Permalink
Fix more build issues (broker.SetAddress())
Browse files Browse the repository at this point in the history
  • Loading branch information
creydr committed Sep 22, 2023
1 parent 1510f58 commit 9bcebcb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package v1alpha1

import (
"knative.dev/pkg/apis"
v1 "knative.dev/pkg/apis/duck/v1"
duckv1 "knative.dev/pkg/apis/duck/v1"
)

const (
Expand All @@ -41,10 +41,9 @@ func (ks *KafkaSinkStatus) GetConditionSet() apis.ConditionSet {

// SetAddress makes this Kafka Sink addressable by setting the URI. It also
// sets the ConditionAddressable to true.
func (ks *KafkaSinkStatus) SetAddress(url *apis.URL) {
ks.AddressStatus.Address = &v1.Addressable{}
ks.AddressStatus.Address.URL = url
if url != nil {
func (ks *KafkaSinkStatus) SetAddress(addr *duckv1.Addressable) {
ks.AddressStatus.Address = addr
if addr != nil {
ks.GetConditionSet().Manage(ks).MarkTrue(ConditionAddressable)
} else {
ks.GetConditionSet().Manage(ks).MarkFalse(ConditionAddressable, "nil URL", "URL is nil")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"k8s.io/utils/pointer"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
)

func TestKafkaSinkStatusSetAddress(t *testing.T) {
status := KafkaSinkStatus{}
status.SetAddress(apis.HTTP("localhost"))
status.SetAddress(&duckv1.Addressable{
Name: pointer.String("http"),
URL: apis.HTTP("localhost"),
})

addressable := status.GetCondition(ConditionAddressable).IsTrue()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ func (kcs *KafkaChannelStatus) InitializeConditions() {
}

// SetAddress sets the address (as part of Addressable contract) and marks the correct condition.
func (kcs *KafkaChannelStatus) SetAddress(url *apis.URL) {
func (kcs *KafkaChannelStatus) SetAddress(addr *duckv1.Addressable) {
if kcs.Address == nil {
kcs.Address = &duckv1.Addressable{}
}
if url != nil {
kcs.Address.URL = url
if addr != nil {
kcs.Address = addr
kcs.GetConditionSet().Manage(kcs).MarkTrue(KafkaChannelConditionAddressable)
} else {
kcs.Address.URL = nil
Expand Down
28 changes: 15 additions & 13 deletions control-plane/pkg/reconciler/base/receiver_condition_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type Object interface {
type StatusConditionManager struct {
Object Object

SetAddress func(u *apis.URL)
SetAddress func(addr *duckv1.Addressable)

Env *config.Env
BootstrapServers string
Expand Down Expand Up @@ -196,18 +196,20 @@ func (manager *StatusConditionManager) FailedToGetBrokerAuthSecret(err error) re
}

func (manager *StatusConditionManager) Addressable(address *url.URL) {
manager.SetAddress(&apis.URL{
Scheme: address.Scheme,
Opaque: address.Opaque,
User: address.User,
Host: address.Host,
Path: address.Path,
RawPath: address.RawPath,
ForceQuery: address.ForceQuery,
RawQuery: address.RawQuery,
Fragment: address.Fragment,
RawFragment: address.RawFragment,
})
manager.SetAddress(&duckv1.Addressable{
Name: &address.Scheme,
URL: &apis.URL{
Scheme: address.Scheme,
Opaque: address.Opaque,
User: address.User,
Host: address.Host,
Path: address.Path,
RawPath: address.RawPath,
ForceQuery: address.ForceQuery,
RawQuery: address.RawQuery,
Fragment: address.Fragment,
RawFragment: address.RawFragment,
}})

Check warning on line 212 in control-plane/pkg/reconciler/base/receiver_condition_set.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/reconciler/base/receiver_condition_set.go#L199-L212

Added lines #L199 - L212 were not covered by tests
manager.Object.GetConditionSet().Manage(manager.Object.GetStatus()).MarkTrue(ConditionAddressable)
manager.ProbesStatusReady()
}
Expand Down
8 changes: 5 additions & 3 deletions test/lib/resources/kafkachannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"

v1 "knative.dev/eventing/pkg/apis/duck/v1"

Expand All @@ -34,6 +35,7 @@ import (
"knative.dev/eventing-kafka-broker/control-plane/pkg/reconciler/channel/apis/messaging"

"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
)

// KafkaChannelOption enables further configuration of a KafkaChannel.
Expand Down Expand Up @@ -127,9 +129,9 @@ func WithKafkaChannelEndpointsReady() KafkaChannelOption {

func WithKafkaChannelAddress(a string) KafkaChannelOption {
return func(nc *v1beta1.KafkaChannel) {
nc.Status.SetAddress(&apis.URL{
Scheme: "http",
Host: a,
nc.Status.SetAddress(&duckv1.Addressable{
Name: pointer.String("http"),
URL: apis.HTTP(a),
})
}
}
Expand Down

0 comments on commit 9bcebcb

Please sign in to comment.