Skip to content

Commit

Permalink
Use random names when copying Secret to test namespace (#3134)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgencur authored Jul 18, 2023
1 parent f622038 commit 00f0dab
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
3 changes: 2 additions & 1 deletion test/rekt/features/broker_deleted_recreated.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,11 @@ func BrokerWithBogusConfig() *feature.Feature {
f := feature.NewFeatureNamed("delete broker with bogus config")

brokerName := feature.MakeRandomK8sName("broker")
secretName := feature.MakeRandomK8sName("sasl-secret")

f.Setup("install bogus configuration", bogus_config.Install)

f.Requirement("Create SASL secret", featuressteps.CopySecretInTestNamespace(system.Namespace(), "strimzi-sasl-secret"))
f.Requirement("Create SASL secret", featuressteps.CopySecretInTestNamespace(system.Namespace(), SASLSecretName, secretName))

f.Setup("install broker", broker.Install(
brokerName,
Expand Down
18 changes: 14 additions & 4 deletions test/rekt/features/featuressteps/copy_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,34 @@ package featuressteps
import (
"context"

"k8s.io/client-go/kubernetes/scheme"
ref "k8s.io/client-go/tools/reference"
"knative.dev/eventing/pkg/utils"
kubeclient "knative.dev/pkg/client/injection/kube/client"
"knative.dev/pkg/logging"
"knative.dev/reconciler-test/pkg/environment"
"knative.dev/reconciler-test/pkg/feature"
)

func CopySecretInTestNamespace(namespace, name string) feature.StepFn {
func CopySecretInTestNamespace(namespace, sourceSecretName, targetSecretName string) feature.StepFn {
return func(ctx context.Context, t feature.T) {
env := environment.FromContext(ctx)
tgtNs := environment.FromContext(ctx).Namespace()
_, err := utils.CopySecret(
secret, err := utils.CopySecretWithName(
kubeclient.Get(ctx).CoreV1(),
namespace,
name,
sourceSecretName,
tgtNs,
targetSecretName,
"default",
)
if err != nil {
t.Fatalf("failed to copy secret %s from %s to %s: %v", name, namespace, tgtNs, err)
t.Fatalf("Failed to copy secret %s from %s to %s: %v", sourceSecretName, namespace, tgtNs, err)
}
reference, err := ref.GetReference(scheme.Scheme, secret)
if err != nil {
logging.FromContext(ctx).Fatalf("Could not construct reference to: '%#v' due to: '%v'", secret, err)
}
env.Reference(*reference)
}
}
25 changes: 13 additions & 12 deletions test/rekt/features/kafka_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ import (
)

const (
saslSecretName = "strimzi-sasl-secret"
tlsSecretName = "strimzi-tls-secret"
SASLSecretName = "strimzi-sasl-secret"
TLSSecretName = "strimzi-tls-secret"
SASLMech = "sasl"
TLSMech = "tls"
PlainMech = "plain"
Expand Down Expand Up @@ -300,6 +300,7 @@ func kafkaSourceFeature(name string,

receiver := feature.MakeRandomK8sName("eventshub-receiver")
sender := feature.MakeRandomK8sName("eventshub-sender")
secretName := feature.MakeRandomK8sName("secret")

f.Setup("install kafka topic", kafkatopic.Install(kafkaSourceCfg.topic))
f.Setup("topic is ready", kafkatopic.IsReady(kafkaSourceCfg.topic))
Expand All @@ -320,23 +321,23 @@ func kafkaSourceFeature(name string,

switch kafkaSourceCfg.authMech {
case TLSMech:
f.Setup("Create TLS secret", featuressteps.CopySecretInTestNamespace(system.Namespace(), tlsSecretName))
f.Setup("Create TLS secret", featuressteps.CopySecretInTestNamespace(system.Namespace(), TLSSecretName, secretName))
kafkaSourceOpts = append(kafkaSourceOpts, kafkasource.WithBootstrapServers(testingpkg.BootstrapServersSslArr),
kafkasource.WithTLSCACert(tlsSecretName, "ca.crt"),
kafkasource.WithTLSCert(tlsSecretName, "user.crt"),
kafkasource.WithTLSKey(tlsSecretName, "user.key"),
kafkasource.WithTLSCACert(secretName, "ca.crt"),
kafkasource.WithTLSCert(secretName, "user.crt"),
kafkasource.WithTLSKey(secretName, "user.key"),
kafkasource.WithTLSEnabled(),
kafkasource.WithTLSCACert(tlsSecretName, "ca.crt"),
kafkasource.WithTLSCACert(secretName, "ca.crt"),
)
case SASLMech:
f.Setup("Create SASL secret", featuressteps.CopySecretInTestNamespace(system.Namespace(), saslSecretName))
f.Setup("Create SASL secret", featuressteps.CopySecretInTestNamespace(system.Namespace(), SASLSecretName, secretName))
kafkaSourceOpts = append(kafkaSourceOpts, kafkasource.WithBootstrapServers(testingpkg.BootstrapServersSslSaslScramArr),
kafkasource.WithSASLEnabled(),
kafkasource.WithSASLUser(saslSecretName, "user"),
kafkasource.WithSASLPassword(saslSecretName, "password"),
kafkasource.WithSASLType(saslSecretName, "saslType"),
kafkasource.WithSASLUser(secretName, "user"),
kafkasource.WithSASLPassword(secretName, "password"),
kafkasource.WithSASLType(secretName, "saslType"),
kafkasource.WithTLSEnabled(),
kafkasource.WithTLSCACert(saslSecretName, "ca.crt"),
kafkasource.WithTLSCACert(secretName, "ca.crt"),
)
default:
kafkaSourceOpts = append(kafkaSourceOpts, kafkasource.WithBootstrapServers(testingpkg.BootstrapServersPlaintextArr))
Expand Down
6 changes: 4 additions & 2 deletions test/rekt/features/kafka_source_create_secrets_after.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func CreateSecretsAfterKafkaSource() *feature.Feature {
topicName := feature.MakeRandomK8sName("topic") // A k8s name is also a valid topic name.
name := feature.MakeRandomK8sName("source")
sink := feature.MakeRandomK8sName("sink")
saslSecretName := feature.MakeRandomK8sName("sasl-secret")
tlsSecretName := feature.MakeRandomK8sName("tls-secret")

f.Setup("install kafka topic", kafkatopic.Install(topicName))
f.Setup("install a service", service.Install(sink,
Expand All @@ -53,8 +55,8 @@ func CreateSecretsAfterKafkaSource() *feature.Feature {
))
f.Setup("KafkaSource is not ready", k8s.IsNotReady(kafkasource.GVR(), name))

f.Requirement("Create TLS secret", featuressteps.CopySecretInTestNamespace(system.Namespace(), tlsSecretName))
f.Requirement("Create SASL secret", featuressteps.CopySecretInTestNamespace(system.Namespace(), saslSecretName))
f.Requirement("Create TLS secret", featuressteps.CopySecretInTestNamespace(system.Namespace(), TLSSecretName, tlsSecretName))
f.Requirement("Create SASL secret", featuressteps.CopySecretInTestNamespace(system.Namespace(), SASLSecretName, saslSecretName))

f.Assert("KafkaSource is ready", kafkasource.IsReady(name))

Expand Down

0 comments on commit 00f0dab

Please sign in to comment.