Skip to content

Commit

Permalink
Wrap error for malformatted EventMesh secrets and let them set the st…
Browse files Browse the repository at this point in the history
…attus to warning instead of error
  • Loading branch information
friedrichwilken committed Mar 6, 2024
1 parent ad63af5 commit dc73dea
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,123 @@ func Test_WatcherEventingCRK8sObjects(t *testing.T) {
}
}

func Test_EventMesh_MalformattedSecret(t *testing.T) {
testCases := []struct {
name string
givenSecretData map[string][]byte
wantMatcher gomegatypes.GomegaMatcher
}{
{
name: "should have ready state when EventMesh secret is malformatted",
givenSecretData: map[string][]byte{
"management": []byte("foo"),
"messaging": []byte(`[
{
"broker": {
"type": "bar"
},
"oa2": {
"clientid": "foo",
"clientsecret": "foo",
"granttype": "client_credentials",
"tokenendpoint": "bar"
},
"protocol": [
"amqp10ws"
],
"uri": "foo"
},
{
"broker": {
"type": "foo"
},
"oa2": {
"clientid": "bar",
"clientsecret": "bar",
"granttype": "client_credentials",
"tokenendpoint": "foo"
},
"protocol": [
"bar"
],
"uri": "bar"
},
{
"broker": {
"type": "foo"
},
"oa2": {
"clientid": "foo",
"clientsecret": "bar",
"granttype": "client_credentials",
"tokenendpoint": "foo"
},
"protocol": [
"httprest"
],
"uri": "bar"
}
]`),
"namespace": []byte("bar"),
"serviceinstanceid": []byte("foo"),
"xsappname": []byte("bar"),
},
wantMatcher: gomega.And(
matchers.HaveStatusReady(),
),
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
g := gomega.NewWithT(t)

// Given:
// Make the Deployment always beeing ready.
eventingcontroller.IsDeploymentReady = func(deployment *kappsv1.Deployment) bool {
return true
}

// Create an Eventing CR. We do not care about the details in this test.
givenEventingCR := utils.NewEventingCR(
utils.WithEventMeshBackend("test-secret-name"),
utils.WithEventingPublisherData(1, 1, "199m", "99Mi", "399m", "199Mi"),
utils.WithEventingEventTypePrefix("test-prefix"),
)

// Create an unique Namespace for this test run.
givenNamespace := givenEventingCR.Namespace
testEnvironment.EnsureNamespaceCreation(t, givenNamespace)

// // Create an EventMesh Secret. This is the crucial part of the test;
// // if the Secret is malformatted, Eventing should have the warning status.
// // Frist we need to extract the Secret name and namespace from the given Eventing CR.
// subArray := strings.Split(givenEventingCR.Spec.Backend.Config.EventMeshSecret, "/")
// secretName, secretNameSpace := subArray[1], subArray[0]
// // Now we can assemble the Secret.
// secret := kcorev1.Secret{
// ObjectMeta: kmetav1.ObjectMeta{
// Name: secretName,
// Namespace: secretNameSpace,
// },
// Data: tc.givenSecretData,
// Type: "Opaque",
// }
// // Finally, we create the Secret in the K8s cluster.
// testEnvironment.EnsureEventMeshSecretCreated(t, &secret)
testEnvironment.EnsureDefaultEventMeshSecretCreated(t, givenEventingCR)

Check failure on line 684 in internal/controller/operator/eventing/integrationtests/controller/integration_test.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint / unit

testEnvironment.EnsureDefaultEventMeshSecretCreated undefined (type *integration.TestEnvironment has no field or method EnsureDefaultEventMeshSecretCreated)

Check failure on line 684 in internal/controller/operator/eventing/integrationtests/controller/integration_test.go

View workflow job for this annotation

GitHub Actions / unit-test / unit

testEnvironment.EnsureDefaultEventMeshSecretCreated undefined (type *integration.TestEnvironment has no field or method EnsureDefaultEventMeshSecretCreated)

// When:
// Create the Eventing CR with the given EventMesh Secret.
testEnvironment.EnsureK8sResourceCreated(t, givenEventingCR)

// Then:
// Check the Eventing CR status against the expected status.
testEnvironment.GetEventingAssert(g, givenEventingCR).Should(tc.wantMatcher)
})
}
}

func Test_CreateEventingCR_EventMesh(t *testing.T) {
testCases := []struct {
name string
Expand Down Expand Up @@ -662,16 +779,15 @@ func Test_CreateEventingCR_EventMesh(t *testing.T) {
}

// create unique namespace for this test run.
givenNamespace := testcase.givenEventing.Namespace

givenNamespace := tc.givenEventing.Namespace
testEnvironment.EnsureNamespaceCreation(t, givenNamespace)

// create eventing-webhook-auth secret.
testEnvironment.EnsureOAuthSecretCreated(t, testcase.givenEventing)

if !testcase.shouldEventMeshSecretNotFound {
// create EventMesh secret.
testEnvironment.EnsureEventMeshSecretCreated(t, testcase.givenEventing)
testEnvironment.EnsureDefaultEventMeshSecretCreated(t, tc.givenEventing)

Check failure on line 790 in internal/controller/operator/eventing/integrationtests/controller/integration_test.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint / unit

testEnvironment.EnsureDefaultEventMeshSecretCreated undefined (type *integration.TestEnvironment has no field or method EnsureDefaultEventMeshSecretCreated)

Check failure on line 790 in internal/controller/operator/eventing/integrationtests/controller/integration_test.go

View workflow job for this annotation

GitHub Actions / unit-test / unit

testEnvironment.EnsureDefaultEventMeshSecretCreated undefined (type *integration.TestEnvironment has no field or method EnsureDefaultEventMeshSecretCreated)
}

originalKubeClient := testEnvironment.KubeClient
Expand Down Expand Up @@ -804,8 +920,8 @@ func Test_DeleteEventingCR(t *testing.T) {
testEnvironment.EnsureNATSResourceStateReady(t, nats)
} else {
// create eventing-webhook-auth secret.
testEnvironment.EnsureOAuthSecretCreated(t, testcase.givenEventing)
testEnvironment.EnsureEventMeshSecretCreated(t, testcase.givenEventing)
testEnvironment.EnsureOAuthSecretCreated(t, tc.givenEventing)
testEnvironment.EnsureDefaultEventMeshSecretCreated(t, tc.givenEventing)

Check failure on line 924 in internal/controller/operator/eventing/integrationtests/controller/integration_test.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint / unit

testEnvironment.EnsureDefaultEventMeshSecretCreated undefined (type *integration.TestEnvironment has no field or method EnsureDefaultEventMeshSecretCreated)

Check failure on line 924 in internal/controller/operator/eventing/integrationtests/controller/integration_test.go

View workflow job for this annotation

GitHub Actions / unit-test / unit

testEnvironment.EnsureDefaultEventMeshSecretCreated undefined (type *integration.TestEnvironment has no field or method EnsureDefaultEventMeshSecretCreated)
}
testEnvironment.EnsureK8sResourceCreated(t, testcase.givenEventing)

Expand Down Expand Up @@ -936,7 +1052,7 @@ func Test_WatcherNATSResource(t *testing.T) {
)
// create necessary EventMesh secrets
testEnvironment.EnsureOAuthSecretCreated(t, eventingResource)
testEnvironment.EnsureEventMeshSecretCreated(t, eventingResource)
testEnvironment.EnsureDefaultEventMeshSecretCreated(t, eventingResource)

Check failure on line 1055 in internal/controller/operator/eventing/integrationtests/controller/integration_test.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint / unit

testEnvironment.EnsureDefaultEventMeshSecretCreated undefined (type *integration.TestEnvironment has no field or method EnsureDefaultEventMeshSecretCreated) (typecheck)

Check failure on line 1055 in internal/controller/operator/eventing/integrationtests/controller/integration_test.go

View workflow job for this annotation

GitHub Actions / unit-test / unit

testEnvironment.EnsureDefaultEventMeshSecretCreated undefined (type *integration.TestEnvironment has no field or method EnsureDefaultEventMeshSecretCreated)
} else {
eventingResource = utils.NewEventingCR(
utils.WithEventingCRNamespace(givenNamespace),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ func Test_Switching(t *testing.T) {
// create eventing-webhook-auth secret.
testEnvironment.EnsureOAuthSecretCreated(t, testcase.givenEventing)
// create EventMesh secret.
if testcase.givenEventing.Spec.Backend.Type == operatorv1alpha1.EventMeshBackendType {
testEnvironment.EnsureEventMeshSecretCreated(t, testcase.givenEventing)
} else if testcase.givenSwitchedEventing.Spec.Backend.Type == operatorv1alpha1.EventMeshBackendType {
testEnvironment.EnsureEventMeshSecretCreated(t, testcase.givenSwitchedEventing)
if tc.givenEventing.Spec.Backend.Type == operatorv1alpha1.EventMeshBackendType {
testEnvironment.EnsureDefaultEventMeshSecretCreated(t, tc.givenEventing)

Check failure on line 170 in internal/controller/operator/eventing/integrationtests/controllerswitching/integration_test.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint / unit

testEnvironment.EnsureDefaultEventMeshSecretCreated undefined (type *integration.TestEnvironment has no field or method EnsureDefaultEventMeshSecretCreated)

Check failure on line 170 in internal/controller/operator/eventing/integrationtests/controllerswitching/integration_test.go

View workflow job for this annotation

GitHub Actions / unit-test / unit

testEnvironment.EnsureDefaultEventMeshSecretCreated undefined (type *integration.TestEnvironment has no field or method EnsureDefaultEventMeshSecretCreated)
} else if tc.givenSwitchedEventing.Spec.Backend.Type == operatorv1alpha1.EventMeshBackendType {
testEnvironment.EnsureDefaultEventMeshSecretCreated(t, tc.givenSwitchedEventing)

Check failure on line 172 in internal/controller/operator/eventing/integrationtests/controllerswitching/integration_test.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint / unit

testEnvironment.EnsureDefaultEventMeshSecretCreated undefined (type *integration.TestEnvironment has no field or method EnsureDefaultEventMeshSecretCreated) (typecheck)

Check failure on line 172 in internal/controller/operator/eventing/integrationtests/controllerswitching/integration_test.go

View workflow job for this annotation

GitHub Actions / unit-test / unit

testEnvironment.EnsureDefaultEventMeshSecretCreated undefined (type *integration.TestEnvironment has no field or method EnsureDefaultEventMeshSecretCreated)
}

// create Eventing CR.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func Test_EventMesh_APIRule_Dependency_Check(t *testing.T) {
testEnvironment.EnsureOAuthSecretCreated(t, testcase.givenEventing)

// create EventMesh secret.
testEnvironment.EnsureEventMeshSecretCreated(t, testcase.givenEventing)
testEnvironment.EnsureDefaultEventMeshSecretCreated(t, tc.givenEventing)

Check failure on line 94 in internal/controller/operator/eventing/integrationtests/without_apirule_crd/integration_test.go

View workflow job for this annotation

GitHub Actions / unit-test / unit

testEnvironment.EnsureDefaultEventMeshSecretCreated undefined (type *integration.TestEnvironment has no field or method EnsureDefaultEventMeshSecretCreated)

// when
// create Eventing CR.
Expand Down

0 comments on commit dc73dea

Please sign in to comment.