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

Removes secret type for brokerConfig #773

Merged
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
3 changes: 1 addition & 2 deletions pkg/apis/eventing/v1/broker_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ func (b *RabbitBroker) Validate(ctx context.Context) *apis.FieldError {
gvk := fmt.Sprintf("%s.%s", b.Spec.Config.Kind, b.Spec.Config.APIVersion)

switch gvk {
case "Secret.v1":
case "RabbitmqCluster.rabbitmq.com/v1beta1":
default:
errs = errs.Also(apis.ErrGeneric("Configuration not supported, only [kind: Secret, apiVersion: v1 or kind: RabbitmqCluster, apiVersion: rabbitmq.com/v1beta1]")).ViaField("spec").ViaField("config")
errs = errs.Also(apis.ErrGeneric("Configuration not supported, only [kind: RabbitmqCluster, apiVersion: rabbitmq.com/v1beta1]")).ViaField("spec").ViaField("config")
}
}
if errs.Error() == "" {
Expand Down
53 changes: 4 additions & 49 deletions pkg/apis/eventing/v1/broker_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func TestValidate(t *testing.T) {
},
},
}},
want: apis.ErrGeneric("Configuration not supported, only [kind: Secret, apiVersion: v1 or kind: RabbitmqCluster, apiVersion: rabbitmq.com/v1beta1]").ViaField("spec").ViaField("config"),
want: apis.ErrGeneric("Configuration not supported, only [kind: RabbitmqCluster, apiVersion: rabbitmq.com/v1beta1]").ViaField("spec").ViaField("config"),
}, {
name: "invalid config, no namespace",
b: RabbitBroker{eventingv1.Broker{
Expand All @@ -195,8 +195,8 @@ func TestValidate(t *testing.T) {
Spec: eventingv1.BrokerSpec{
Config: &duckv1.KReference{
Name: "name",
Kind: "Secret",
APIVersion: "v1",
Kind: "RabbitmqCluster",
APIVersion: "rabbitmq.com/v1beta1",
},
},
}},
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestValidate(t *testing.T) {
Config: &duckv1.KReference{
Namespace: "namespace",
Name: "name",
Kind: "Secret",
Kind: "RabbitmqCluster",
},
},
}},
Expand All @@ -246,21 +246,6 @@ func TestValidate(t *testing.T) {
},
}},
want: apis.ErrMissingField("spec.config.kind"),
}, {
name: "valid config, secret",
b: RabbitBroker{eventingv1.Broker{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{"eventing.knative.dev/broker.class": "RabbitMQBroker"},
},
Spec: eventingv1.BrokerSpec{
Config: &duckv1.KReference{
Namespace: "namespace",
Name: "name",
Kind: "Secret",
APIVersion: "v1",
},
},
}},
}, {
name: "valid config, rabbitmqcluster",
b: RabbitBroker{eventingv1.Broker{
Expand Down Expand Up @@ -306,9 +291,6 @@ func TestValidateFunc(t *testing.T) {
}, {
name: "valid with RabbitmqCluster",
b: createRabbitMQBrokerValidRabbitMQCluster(),
}, {
name: "valid with Secret",
b: createRabbitMQBrokerValidSecret(),
}}

for _, test := range tests {
Expand Down Expand Up @@ -381,33 +363,6 @@ func createRabbitMQBrokerInvalid() *unstructured.Unstructured {
}
}

func createRabbitMQBrokerValidSecret() *unstructured.Unstructured {
annotations := map[string]interface{}{
"eventing.knative.dev/broker.class": "RabbitMQBroker",
}

return &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "eventing.knative.dev/v1",
"kind": "Broker",
"metadata": map[string]interface{}{
"creationTimestamp": nil,
"namespace": "namespace",
"name": "broker",
"annotations": annotations,
},
"spec": map[string]interface{}{
"config": map[string]interface{}{
"namespace": "namespace",
"name": "name",
"kind": "Secret",
"apiVersion": "v1",
},
},
},
}
}

func createRabbitMQBrokerValidRabbitMQCluster() *unstructured.Unstructured {
annotations := map[string]interface{}{
"eventing.knative.dev/broker.class": "RabbitMQBroker",
Expand Down
24 changes: 1 addition & 23 deletions pkg/reconciler/broker/broker_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import (
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/logging"
"knative.dev/pkg/network"

"knative.dev/eventing-rabbitmq/pkg/reconciler/broker/resources"
)

// This file contains the logic dealing with how to handle Broker.Spec.Config.
Expand Down Expand Up @@ -68,39 +66,19 @@ func (r *Reconciler) rabbitmqURL(ctx context.Context, b *eventingv1.Broker) (*ur
gvk := fmt.Sprintf("%s.%s", b.Spec.Config.Kind, b.Spec.Config.APIVersion)

switch gvk {
case "Secret.v1":
u, err := r.rabbitmqURLFromSecret(ctx, b.Spec.Config)
if err != nil {
logging.FromContext(ctx).Errorw("Unable to load RabbitMQ Broker URL from Broker.Spec.Config as v1:Secret.", zap.Error(err))
}
return u, err
case "RabbitmqCluster.rabbitmq.com/v1beta1":
u, err := r.rabbitmqURLFromRabbit(ctx, b.Spec.Config)
if err != nil {
logging.FromContext(ctx).Errorw("Unable to load RabbitMQ Broker URL from Broker.Spec.Config as rabbitmq.com/v1beta1:RabbitmqCluster.", zap.Error(err))
}
return u, err
default:
return nil, errors.New("Broker.Spec.Config configuration not supported, only [kind: Secret, apiVersion: v1 or kind: RabbitmqCluster, apiVersion: rabbitmq.com/v1beta1]")
return nil, errors.New("Broker.Spec.Config configuration not supported, only [kind: RabbitmqCluster, apiVersion: rabbitmq.com/v1beta1]")
}
}
return nil, errors.New("Broker.Spec.Config is required")
}

func (r *Reconciler) rabbitmqURLFromSecret(ctx context.Context, ref *duckv1.KReference) (*url.URL, error) {
s, err := r.kubeClientSet.CoreV1().Secrets(ref.Namespace).Get(ctx, ref.Name, metav1.GetOptions{})

if err != nil {
return nil, err
}
val := s.Data[resources.BrokerURLSecretKey]
if val == nil {
return nil, fmt.Errorf("secret missing key %s", resources.BrokerURLSecretKey)
}

return url.Parse(string(val))
}

func (r *Reconciler) rabbitmqURLFromRabbit(ctx context.Context, ref *duckv1.KReference) (*url.URL, error) {
// TODO: make this better.

Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/broker/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ func TestReconcile(t *testing.T) {
WithBrokerClass(brokerClass),
WithInitBrokerConditions,
WithBrokerConfig(invalidConfigForRabbitOperator()),
WithExchangeFailed("ExchangeCredentialsUnavailable", `Failed to get arguments for creating exchange: Broker.Spec.Config configuration not supported, only [kind: Secret, apiVersion: v1 or kind: RabbitmqCluster, apiVersion: rabbitmq.com/v1beta1]`)),
WithExchangeFailed("ExchangeCredentialsUnavailable", `Failed to get arguments for creating exchange: Broker.Spec.Config configuration not supported, only [kind: RabbitmqCluster, apiVersion: rabbitmq.com/v1beta1]`)),
}},
WantEvents: []string{
Eventf(corev1.EventTypeWarning, "InternalError", `Broker.Spec.Config configuration not supported, only [kind: Secret, apiVersion: v1 or kind: RabbitmqCluster, apiVersion: rabbitmq.com/v1beta1]`),
Eventf(corev1.EventTypeWarning, "InternalError", `Broker.Spec.Config configuration not supported, only [kind: RabbitmqCluster, apiVersion: rabbitmq.com/v1beta1]`),
},
}, {
Name: "Broker does not exist",
Expand Down
5 changes: 0 additions & 5 deletions test/conformance/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
_ "knative.dev/pkg/system/testing"

"knative.dev/eventing-rabbitmq/test/conformance/features/rabbitmqcluster"
"knative.dev/eventing-rabbitmq/test/conformance/features/secret"
"knative.dev/eventing/test/rekt/features/broker"
b "knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/reconciler-test/pkg/environment"
Expand All @@ -48,8 +47,6 @@ func TestBrokerControlPlaneConformance(t *testing.T) {
)

env.Prerequisite(ctx, t, rabbitmqcluster.GoesReady("rabbitbroker", b.WithEnvConfig()...))
// env.Prerequisite(ctx, t, secret.Install("rabbitbrokersecret", "rabbitbroker", ctx, b.WithEnvConfig()...))
env.Prerequisite(ctx, t, secret.Created("rabbitbroker-secret", "rabbitbroker", ctx, b.WithEnvConfig()...))
// Install and wait for a Ready Broker.
env.Prerequisite(ctx, t, broker.GoesReady("default", b.WithEnvConfig()...))
env.TestSet(ctx, t, broker.ControlPlaneConformance("default"))
Expand All @@ -65,8 +62,6 @@ func TestBrokerDataPlaneConformance(t *testing.T) {
)

env.Prerequisite(ctx, t, rabbitmqcluster.GoesReady("rabbitbroker", b.WithEnvConfig()...))
// env.Prerequisite(ctx, t, secret.Install("rabbitbrokersecret", "rabbitbroker", ctx, b.WithEnvConfig()...))
env.Prerequisite(ctx, t, secret.Created("rabbitbroker-secret", "rabbitbroker", ctx, b.WithEnvConfig()...))
// Install and wait for a Ready Broker.
env.Prerequisite(ctx, t, broker.GoesReady("default3", b.WithEnvConfig()...))

Expand Down
35 changes: 0 additions & 35 deletions test/conformance/features/secret/created.go

This file was deleted.

55 changes: 0 additions & 55 deletions test/conformance/resources/secret/secret.go

This file was deleted.

7 changes: 0 additions & 7 deletions test/conformance/resources/secret/secret.yaml

This file was deleted.