Created
January 10, 2022 22:35
-
-
Save jpeach/7d0e13bd2312204de3d4be8dcf564605 to your computer and use it in GitHub Desktop.
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
package reference | |
import ( | |
"fmt" | |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |
"k8s.io/apimachinery/pkg/types" | |
"sigs.k8s.io/gateway-api/apis/v1alpha2" | |
) | |
var ( | |
DefaultParentKind = metav1.GroupKind{ | |
Group: "gateway.networking.k8s.io", | |
Kind: "Gateway", | |
} | |
DefaultSecretKind = metav1.GroupKind{ | |
Group: "", | |
Kind: "Secret", | |
} | |
DefaultBackendObjectKind = metav1.GroupKind{ | |
Group: "", | |
Kind: "Service", | |
} | |
) | |
type Ref interface { | |
Name() string | |
Namespace() string | |
Kind() metav1.GroupKind | |
} | |
type localRef struct { | |
ref *v1alpha2.LocalObjectReference | |
} | |
func (l *localRef) Name() string { | |
return string(l.ref.Name) | |
} | |
func (l *localRef) Namespace() string { | |
return "" | |
} | |
func (l *localRef) Kind() metav1.GroupKind { | |
return metav1.GroupKind{Group: string(l.ref.Group), Kind: string(l.ref.Kind)} | |
} | |
func Local(ref *v1alpha2.LocalObjectReference) Ref { | |
return &localRef{ref} | |
} | |
type parentRef struct { | |
ref *v1alpha2.ParentRef | |
} | |
func (p *parentRef) Name() string { | |
return string(p.ref.Name) | |
} | |
func (p *parentRef) Namespace() string { | |
return "" | |
} | |
func (p *parentRef) Kind() metav1.GroupKind { | |
k := metav1.GroupKind{ | |
Group: "gateway.networking.k8s.io", | |
Kind: "Gateway", | |
} | |
if p.ref.Group != nil { | |
k.Group = string(*p.ref.Group) | |
} | |
if p.ref.Kind != nil { | |
k.Kind = string(*p.ref.Kind) | |
} | |
return k | |
} | |
func Parent(ref *v1alpha2.ParentRef) Ref { | |
return &parentRef{ref} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment