-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose a Brokers audience in its status (#7237)
* Provision audience field of Broker * Pass GVK directly to auth.GetAudience() * Add unit test * Add e2e test * Add missing boilerplate
- Loading branch information
Showing
13 changed files
with
278 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Copyright 2023 The Knative Authors | ||
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 auth | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
// GetAudience returns the audience string for the given object in the format <group>/<kind>/<namespace>/<name> | ||
func GetAudience(gvk schema.GroupVersionKind, objectMeta metav1.ObjectMeta) string { | ||
aud := fmt.Sprintf("%s/%s/%s/%s", gvk.Group, gvk.Kind, objectMeta.Namespace, objectMeta.Name) | ||
|
||
return strings.ToLower(aud) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright 2023 The Knative Authors | ||
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 auth | ||
|
||
import ( | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
v1 "knative.dev/eventing/pkg/apis/eventing/v1" | ||
) | ||
|
||
func TestGetAudience(t *testing.T) { | ||
|
||
tests := []struct { | ||
name string | ||
gvk schema.GroupVersionKind | ||
objectMeta metav1.ObjectMeta | ||
want string | ||
}{ | ||
{ | ||
name: "should return audience in correct format", | ||
gvk: schema.GroupVersionKind{ | ||
Group: "group", | ||
Version: "version", | ||
Kind: "kind", | ||
}, | ||
objectMeta: metav1.ObjectMeta{ | ||
Name: "name", | ||
Namespace: "namespace", | ||
}, | ||
want: "group/kind/namespace/name", | ||
}, | ||
{ | ||
name: "should return audience in lower case", | ||
gvk: v1.SchemeGroupVersion.WithKind("Broker"), | ||
objectMeta: metav1.ObjectMeta{ | ||
Name: "my-Broker", | ||
Namespace: "my-Namespace", | ||
}, | ||
want: "eventing.knative.dev/broker/my-namespace/my-broker", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := GetAudience(tt.gvk, tt.objectMeta); got != tt.want { | ||
t.Errorf("GetAudience() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
/* | ||
Copyright 2023 The Knative Authors | ||
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 experimental | ||
|
||
import ( | ||
"testing" | ||
|
||
"knative.dev/pkg/system" | ||
"knative.dev/reconciler-test/pkg/environment" | ||
"knative.dev/reconciler-test/pkg/k8s" | ||
"knative.dev/reconciler-test/pkg/knative" | ||
|
||
"knative.dev/eventing/test/experimental/features/auth" | ||
) | ||
|
||
func TestBrokerAudiencePopulated(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx, env := global.Environment( | ||
knative.WithKnativeNamespace(system.Namespace()), | ||
knative.WithLoggingConfig, | ||
knative.WithTracingConfig, | ||
k8s.WithEventListener, | ||
environment.Managed(t), | ||
) | ||
|
||
env.Test(ctx, t, auth.BrokerGetsAudiencePopulated(env.Namespace())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright 2023 The Knative Authors | ||
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 auth | ||
|
||
import ( | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"knative.dev/eventing/pkg/auth" | ||
"knative.dev/eventing/test/rekt/resources/addressable" | ||
"knative.dev/eventing/test/rekt/resources/broker" | ||
"knative.dev/reconciler-test/pkg/feature" | ||
) | ||
|
||
func BrokerGetsAudiencePopulated(namespace string) *feature.Feature { | ||
f := feature.NewFeature() | ||
|
||
brokerName := feature.MakeRandomK8sName("broker") | ||
|
||
f.Setup("install broker", broker.Install(brokerName, broker.WithEnvConfig()...)) | ||
f.Setup("broker is ready", broker.IsReady(brokerName)) | ||
f.Setup("broker is addressable", broker.IsAddressable(brokerName)) | ||
|
||
expectedAudience := auth.GetAudience(broker.GVR().GroupVersion().WithKind("Broker"), v1.ObjectMeta{ | ||
Name: brokerName, | ||
Namespace: namespace, | ||
}) | ||
|
||
f.Alpha("Broker").Must("have audience set", broker.ValidateAddress(brokerName, addressable.AssertAddressWithAudience(expectedAudience))) | ||
|
||
return f | ||
} |
Oops, something went wrong.