Skip to content

Commit

Permalink
add kref uid as avaiable template field
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelvillard committed Oct 13, 2021
1 parent fcf6738 commit 98ec545
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/core/configmaps/kreference-mapping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ data:
# - Name: reference name
# - Namespace: reference namespace
# - SystemNamespace: knative namespace
# - UID: reference UID
#
# Pod.v1: https://addressable-pod.{{ .SystemNamespace }}.svc.cluster.local/{{ .Name }}
3 changes: 3 additions & 0 deletions pkg/resolver/mapping_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"knative.dev/eventing/pkg/apis/feature"
"knative.dev/pkg/apis"
"knative.dev/pkg/configmap"
Expand All @@ -46,6 +47,7 @@ type MappingResolverTemplateValues struct {
Name string
Namespace string
SystemNamespace string
UID types.UID
}

func NewMappingResolver(ctx context.Context, cmw configmap.Watcher, t tracker.Interface) *MappingResolver {
Expand Down Expand Up @@ -90,6 +92,7 @@ func (mr *MappingResolver) MappingURIFromObjectReference(ctx context.Context, re
data := MappingResolverTemplateValues{
Name: ref.Name,
Namespace: ref.Namespace,
UID: ref.UID,
SystemNamespace: system.Namespace(),
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/resolver/mapping_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func TestMappingResolver(t *testing.T) {
Namespace: testingNamespace,
},
Data: map[string]string{
"Service.v1": "https://{{ .Name }}.{{ .Namespace }}.svc.cluster.local",
"Service.v1": "https://{{ .Name }}.{{ .Namespace }}.svc.cluster.local/{{ .UID }}",
},
},
wantHandled: true,
wantURI: "https://aservice.testns.svc.cluster.local",
wantURI: "https://aservice.testns.svc.cluster.local/e23097c8-15a8-487b-b5a3-76fdc4a48c46",
},
"enabled, handled, with error (broken template)": {
enabled: true,
Expand Down Expand Up @@ -159,5 +159,6 @@ func serviceObjRef(ns string) *corev1.ObjectReference {
Name: "aservice",
APIVersion: "v1",
Namespace: ns,
UID: "e23097c8-15a8-487b-b5a3-76fdc4a48c46",
}
}

0 comments on commit 98ec545

Please sign in to comment.