From e9621a1722d17f2363f5bd447716751cda424453 Mon Sep 17 00:00:00 2001 From: Devaansh Kumar <97400489+Devaansh-Kumar@users.noreply.github.com> Date: Fri, 22 Nov 2024 14:58:57 +0530 Subject: [PATCH] added notifications for openapi3 provider (#178) * added notifications for openapi3 provider * added nolint:unparam to bypass golint --- pkg/i2gw/providers/openapi3/converter.go | 5 ++++ pkg/i2gw/providers/openapi3/notification.go | 27 +++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 pkg/i2gw/providers/openapi3/notification.go diff --git a/pkg/i2gw/providers/openapi3/converter.go b/pkg/i2gw/providers/openapi3/converter.go index af701314..75ee1f77 100644 --- a/pkg/i2gw/providers/openapi3/converter.go +++ b/pkg/i2gw/providers/openapi3/converter.go @@ -36,6 +36,7 @@ import ( "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw" "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/intermediate" + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/notifications" "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/common" ) @@ -121,17 +122,21 @@ func (c *resourcesToIRConverter) Convert(storage Storage) (intermediate.IR, fiel httpRoutes, gateways := c.toHTTPRoutesAndGateways(spec, resourcesNamePrefix, errors) for _, httpRoute := range httpRoutes { ir.HTTPRoutes[types.NamespacedName{Name: httpRoute.GetName(), Namespace: httpRoute.GetNamespace()}] = intermediate.HTTPRouteContext{HTTPRoute: httpRoute} + notify(notifications.InfoNotification, fmt.Sprintf("successfully created HTTPRoute \"%v/%v\" from OpenAPI spec \"%v\"", httpRoute.Namespace, httpRoute.Name, spec.Info.Title)) } // build reference grants for the resources if referenceGrant := c.buildHTTPRouteBackendReferenceGrant(); referenceGrant != nil { ir.ReferenceGrants[types.NamespacedName{Name: referenceGrant.GetName(), Namespace: referenceGrant.GetNamespace()}] = *referenceGrant + notify(notifications.InfoNotification, fmt.Sprintf("successfully created ReferenceGrant \"%v/%v\" from OpenAPI spec \"%v\"", referenceGrant.Namespace, referenceGrant.Name, spec.Info.Title)) } for _, gateway := range gateways { ir.Gateways[types.NamespacedName{Name: gateway.GetName(), Namespace: gateway.GetNamespace()}] = intermediate.GatewayContext{Gateway: gateway} if referenceGrant := c.buildGatewayTLSSecretReferenceGrant(gateway); referenceGrant != nil { ir.ReferenceGrants[types.NamespacedName{Name: referenceGrant.GetName(), Namespace: referenceGrant.GetNamespace()}] = *referenceGrant + notify(notifications.InfoNotification, fmt.Sprintf("successfully created ReferenceGrant \"%v/%v\" from OpenAPI spec \"%v\"", referenceGrant.Namespace, referenceGrant.Name, spec.Info.Title)) } + notify(notifications.InfoNotification, fmt.Sprintf("successfully created Gateway \"%v/%v\" from OpenAPI spec \"%v\"", gateway.Namespace, gateway.Name, spec.Info.Title)) } } diff --git a/pkg/i2gw/providers/openapi3/notification.go b/pkg/i2gw/providers/openapi3/notification.go new file mode 100644 index 00000000..8e7ed59d --- /dev/null +++ b/pkg/i2gw/providers/openapi3/notification.go @@ -0,0 +1,27 @@ +/* +Copyright 2024 The Kubernetes 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 openapi3 + +import ( + "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/notifications" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +func notify(mType notifications.MessageType, message string, callingObject ...client.Object) { //nolint:unparam + newNotification := notifications.NewNotification(mType, message, callingObject...) + notifications.NotificationAggr.DispatchNotification(newNotification, string(ProviderName)) +}