Skip to content

Commit

Permalink
reuse the consts in resource pkg.
Browse files Browse the repository at this point in the history
Signed-off-by: qicz <[email protected]>
  • Loading branch information
qicz committed Oct 20, 2024
1 parent 7a59d5e commit 295a44b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 58 deletions.
44 changes: 22 additions & 22 deletions internal/gatewayapi/resource/resource_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ package resource
// supportedCacheResourceKinds that are supported cache manager.
// if some resources are supported remove the code slash comment.
var supportedCacheResourceKinds = []string{
"EnvoyProxy",
"Gateway",
"ReferenceGrant",
"Namespace",
"ServiceImport",
"EndpointSlice",
"Secret",
"ConfigMap",
"EnvoyPatchPolicy",
"ClientTrafficPolicy",
"BackendTrafficPolicy",
"SecurityPolicy",
"BackendTLSPolicy",
"EnvoyExtensionPolicy",
"HTTPRouteFilter",
// "Service", // Unsupported
// "Backend", // Unsupported
// "HTTPRoute", // Unsupported
// "GRPCRoute", // Unsupported
// "TLSRoute", // Unsupported
// "TCPRoute", // Unsupported
// "UDPRoute", // Unsupported
KindEnvoyProxy,
KindGateway,
KindReferenceGrant,
KindNamespace,
KindServiceImport,
KindEndpointSlice,
KindSecret,
KindConfigMap,
KindEnvoyPatchPolicy,
KindClientTrafficPolicy,
KindBackendTrafficPolicy,
KindSecurityPolicy,
KindBackendTLSPolicy,
KindEnvoyExtensionPolicy,
KindHTTPRouteFilter,
// KindService, // Unsupported
// KindBackend, // Unsupported
// KindHTTPRoute, // Unsupported
// KindGRPCRoute, // Unsupported
// KindTLSRoute, // Unsupported
// KindTCPRoute, // Unsupported
// KindUDPRoute, // Unsupported
}

// Set holds the resources with the kind.
Expand Down
72 changes: 36 additions & 36 deletions internal/gatewayapi/resource/resource_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,175 +26,175 @@ func TestResourcesCache(t *testing.T) {
resources := []client.Object{
&egv1a1.EnvoyProxy{
TypeMeta: metav1.TypeMeta{
Kind: "EnvoyProxy",
Kind: KindEnvoyProxy,
},
ObjectMeta: metav1.ObjectMeta{
Name: "EnvoyProxy",
},
},
&gwapiv1.Gateway{
TypeMeta: metav1.TypeMeta{
Kind: "Gateway",
Kind: KindGateway,
},
ObjectMeta: metav1.ObjectMeta{
Name: "Gateway",
},
},
&mcsapiv1a1.ServiceImport{
TypeMeta: metav1.TypeMeta{
Kind: "ServiceImport",
Kind: KindServiceImport,
},
ObjectMeta: metav1.ObjectMeta{
Name: "ServiceImport",
},
},
&corev1.Secret{
TypeMeta: metav1.TypeMeta{
Kind: "Secret",
Kind: KindSecret,
},
ObjectMeta: metav1.ObjectMeta{
Name: "Secret",
},
},
&corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
Kind: KindConfigMap,
},
ObjectMeta: metav1.ObjectMeta{
Name: "ConfigMap",
},
},
&gwapiv1b1.ReferenceGrant{
TypeMeta: metav1.TypeMeta{
Kind: "ReferenceGrant",
Kind: KindReferenceGrant,
},
ObjectMeta: metav1.ObjectMeta{
Name: "ReferenceGrant",
},
},
&corev1.Namespace{
TypeMeta: metav1.TypeMeta{
Kind: "Namespace",
Kind: KindNamespace,
},
ObjectMeta: metav1.ObjectMeta{
Name: "Namespace",
},
},
&discoveryv1.EndpointSlice{
TypeMeta: metav1.TypeMeta{
Kind: "EndpointSlice",
Kind: KindEndpointSlice,
},
ObjectMeta: metav1.ObjectMeta{
Name: "endpointSlice",
},
},
&egv1a1.EnvoyPatchPolicy{
TypeMeta: metav1.TypeMeta{
Kind: "EnvoyPatchPolicy",
Kind: KindEnvoyPatchPolicy,
},
ObjectMeta: metav1.ObjectMeta{
Name: "EnvoyPatchPolicy",
},
},
&egv1a1.ClientTrafficPolicy{
TypeMeta: metav1.TypeMeta{
Kind: "ClientTrafficPolicy",
Kind: KindClientTrafficPolicy,
},
ObjectMeta: metav1.ObjectMeta{
Name: "ClientTrafficPolicy",
},
},
&egv1a1.BackendTrafficPolicy{
TypeMeta: metav1.TypeMeta{
Kind: "BackendTrafficPolicy",
Kind: KindBackendTrafficPolicy,
},
ObjectMeta: metav1.ObjectMeta{
Name: "BackendTrafficPolicy",
},
},
&egv1a1.SecurityPolicy{
TypeMeta: metav1.TypeMeta{
Kind: "SecurityPolicy",
Kind: KindSecurityPolicy,
},
ObjectMeta: metav1.ObjectMeta{
Name: "SecurityPolicy",
},
},
&gwapiv1a3.BackendTLSPolicy{
TypeMeta: metav1.TypeMeta{
Kind: "BackendTLSPolicy",
Kind: KindBackendTLSPolicy,
},
ObjectMeta: metav1.ObjectMeta{
Name: "BackendTLSPolicy",
},
},
&egv1a1.EnvoyExtensionPolicy{
TypeMeta: metav1.TypeMeta{
Kind: "EnvoyExtensionPolicy",
Kind: KindEnvoyExtensionPolicy,
},
ObjectMeta: metav1.ObjectMeta{
Name: "EnvoyExtensionPolicy",
},
},
&egv1a1.Backend{
TypeMeta: metav1.TypeMeta{
Kind: "Backend",
Kind: KindBackend,
},
ObjectMeta: metav1.ObjectMeta{
Name: "Backend",
},
},
&egv1a1.HTTPRouteFilter{
TypeMeta: metav1.TypeMeta{
Kind: "HTTPRouteFilter",
Kind: KindHTTPRouteFilter,
},
ObjectMeta: metav1.ObjectMeta{
Name: "HTTPRouteFilter",
},
},
&corev1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
Kind: KindService,
},
ObjectMeta: metav1.ObjectMeta{
Name: "Service",
},
},
&gwapiv1.HTTPRoute{
TypeMeta: metav1.TypeMeta{
Kind: "HTTPRoute",
Kind: KindHTTPRoute,
},
ObjectMeta: metav1.ObjectMeta{
Name: "HTTPRoute",
},
},
&gwapiv1.GRPCRoute{
TypeMeta: metav1.TypeMeta{
Kind: "GRPCRoute",
Kind: KindGRPCRoute,
},
ObjectMeta: metav1.ObjectMeta{
Name: "GRPCRoute",
},
},
&gwapiv1a2.TLSRoute{
TypeMeta: metav1.TypeMeta{
Kind: "TLSRoute",
Kind: KindTLSRoute,
},
ObjectMeta: metav1.ObjectMeta{
Name: "TLSRoute",
},
},
&gwapiv1a2.TCPRoute{
TypeMeta: metav1.TypeMeta{
Kind: "TCPRoute",
Kind: KindTCPRoute,
},
ObjectMeta: metav1.ObjectMeta{
Name: "TCPRoute",
},
},
&gwapiv1a2.UDPRoute{
TypeMeta: metav1.TypeMeta{
Kind: "UDPRoute",
Kind: KindUDPRoute,
},
ObjectMeta: metav1.ObjectMeta{
Name: "UDPRoute",
Expand All @@ -212,31 +212,31 @@ func TestResourcesCache(t *testing.T) {
}
t.Logf("appending resource with kind %v", kind)
switch kind {
case "Namespace":
case KindNamespace:
if r.GetNamespace(name) == nil {
t.Logf("%s is not exist", kind)
}
case "Service":
case KindService:
if r.GetService("", name) == nil {
t.Logf("%s is not exist", kind)
}
case "ServiceImport":
case KindServiceImport:
if r.GetServiceImport("", name) == nil {
t.Logf("%s is not exist", kind)
}
case "Backend":
case KindBackend:
if r.GetBackend("", name) == nil {
t.Logf("%s is not exist", kind)
}
case "Secret":
case KindSecret:
if r.GetSecret("", name) == nil {
t.Logf("%s is not exist", kind)
}
case "ConfigMap":
case KindConfigMap:
if r.GetConfigMap("", name) == nil {
t.Logf("%s is not exist", kind)
}
case "EnvoyProxy":
case KindEnvoyProxy:
if r.GetEnvoyProxy("", name) == nil {
t.Logf("%s is not exist", kind)
}
Expand All @@ -245,31 +245,31 @@ func TestResourcesCache(t *testing.T) {
t.Logf("appends resource with kind %v", kind)
}
switch kind {
case "Namespace":
case KindNamespace:
if r.GetNamespace(name) != nil && r.GetNamespace(name).Name == name {
t.Logf("%s has aleary appended", kind)
}
case "Service":
case KindService:
if r.GetService("", name) != nil && r.GetService("", name).Name == name {
t.Logf("%s has aleary appended", kind)
}
case "ServiceImport":
case KindServiceImport:
if r.GetServiceImport("", name) != nil && r.GetServiceImport("", name).Name == name {
t.Logf("%s has aleary appended", kind)
}
case "Backend":
case KindBackend:
if r.GetBackend("", name) != nil && r.GetBackend("", name).Name == name {
t.Logf("%s has aleary appended", kind)
}
case "Secret":
case KindSecret:
if r.GetSecret("", name) != nil && r.GetSecret("", name).Name == name {
t.Logf("%s has aleary appended", kind)
}
case "ConfigMap":
case KindConfigMap:
if r.GetConfigMap("", name) != nil && r.GetConfigMap("", name).Name == name {
t.Logf("%s has aleary appended", kind)
}
case "EnvoyProxy":
case KindEnvoyProxy:
if r.GetEnvoyProxy("", name) != nil && r.GetEnvoyProxy("", name).Name == name {
t.Logf("%s has aleary appended", kind)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/gatewayapi/resource/supported_kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ const (
KindServiceImport = "ServiceImport"
KindSecret = "Secret"
KindHTTPRouteFilter = "HTTPRouteFilter"
KindReferenceGrant = "ReferenceGrant"
KindEndpointSlice = "EndpointSlice"
)

0 comments on commit 295a44b

Please sign in to comment.