forked from rook/rook
userSecretRef and passwordSecretRef fields are added to allow the Kafka endpoint username and password to be supplied from a Kubernetes Secret, rather than exposed as plaintext as part of the endpoint URI. If the endpoint URI has HTTP basic auth user-id and user-pass components, they are overridden by userSecretRef and passwordSecretRef. Squid added bucket topic attributes for configuring the user-name and password for pushing notifications to Kafka as an alternative to encoding credentials into the URI. However, these attributes are not supported under Reef. Thus, this initial implementation relies on URI mangling for compatible with both Reef and Squid. Future work could using Ceph version detection and switch to the new attributes to be used with Squid and/or the implementation could be converted exclusively to use the new attributes once Rook has dropped support for Reef. Signed-off-by: Joshua Hoblitt <josh@hoblitt.com>
150 lines
3.9 KiB
Go
150 lines
3.9 KiB
Go
/*
|
|
Copyright 2022 The Rook Authors. All rights reserved.
|
|
|
|
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 topic to manage a rook bucket topics.
|
|
package topic
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/coreos/pkg/capnslog"
|
|
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
func TestTopicAttributesCreation(t *testing.T) {
|
|
capnslog.SetGlobalLogLevel(capnslog.DEBUG)
|
|
os.Setenv("ROOK_LOG_LEVEL", "DEBUG")
|
|
falseString := "false"
|
|
trueString := "true"
|
|
emptyString := ""
|
|
|
|
t.Run("test HTTP attributes", func(t *testing.T) {
|
|
uri := "http://localhost"
|
|
expectedAttrs := map[string]*string{
|
|
"OpaqueData": &emptyString,
|
|
"cloudevents": &falseString,
|
|
"persistent": &falseString,
|
|
"push-endpoint": &uri,
|
|
"verify-ssl": &trueString,
|
|
}
|
|
bucketTopic := &cephv1.CephBucketTopic{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: name,
|
|
Namespace: namespace,
|
|
},
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "CephBucketTopic",
|
|
},
|
|
Spec: cephv1.BucketTopicSpec{
|
|
ObjectStoreName: store,
|
|
ObjectStoreNamespace: namespace,
|
|
Endpoint: cephv1.TopicEndpointSpec{
|
|
HTTP: &cephv1.HTTPEndpointSpec{
|
|
URI: uri,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
attrs, _, err := createTopicAttributes(provisioner{}, bucketTopic)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, expectedAttrs, attrs)
|
|
})
|
|
|
|
t.Run("test AMQP attributes", func(t *testing.T) {
|
|
uri := "amqp://my-rabbitmq-service:5672/vhost1"
|
|
ackLevel := "broker"
|
|
exchange := "ex1"
|
|
expectedAttrs := map[string]*string{
|
|
"OpaqueData": &emptyString,
|
|
"persistent": &falseString,
|
|
"push-endpoint": &uri,
|
|
"verify-ssl": &trueString,
|
|
"amqp-exchange": &exchange,
|
|
"amqp-ack-level": &ackLevel,
|
|
}
|
|
bucketTopic := &cephv1.CephBucketTopic{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: name,
|
|
Namespace: namespace,
|
|
},
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "CephBucketTopic",
|
|
},
|
|
Spec: cephv1.BucketTopicSpec{
|
|
ObjectStoreName: store,
|
|
ObjectStoreNamespace: namespace,
|
|
Endpoint: cephv1.TopicEndpointSpec{
|
|
AMQP: &cephv1.AMQPEndpointSpec{
|
|
URI: uri,
|
|
AckLevel: ackLevel,
|
|
Exchange: exchange,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
attrs, _, err := createTopicAttributes(provisioner{}, bucketTopic)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, expectedAttrs, attrs)
|
|
})
|
|
|
|
t.Run("test Kafka attributes", func(t *testing.T) {
|
|
uri := "kafka://my-kafka-service:9092"
|
|
ackLevel := "broker"
|
|
mechanism := "SCRAM-SHA-512"
|
|
expectedAttrs := map[string]*string{
|
|
"OpaqueData": &emptyString,
|
|
"persistent": &falseString,
|
|
"push-endpoint": &uri,
|
|
"verify-ssl": &trueString,
|
|
"kafka-ack-level": &ackLevel,
|
|
"use-ssl": &trueString,
|
|
"mechanism": &mechanism,
|
|
}
|
|
bucketTopic := &cephv1.CephBucketTopic{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: name,
|
|
Namespace: namespace,
|
|
},
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "CephBucketTopic",
|
|
},
|
|
Spec: cephv1.BucketTopicSpec{
|
|
ObjectStoreName: store,
|
|
ObjectStoreNamespace: namespace,
|
|
Endpoint: cephv1.TopicEndpointSpec{
|
|
Kafka: &cephv1.KafkaEndpointSpec{
|
|
URI: uri,
|
|
AckLevel: ackLevel,
|
|
UseSSL: true,
|
|
Mechanism: mechanism,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
attrs, _, err := createTopicAttributes(provisioner{}, bucketTopic)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, expectedAttrs, attrs)
|
|
})
|
|
}
|