Skip to content

Commit

Permalink
added notifications for openapi3 provider (#178)
Browse files Browse the repository at this point in the history
* added notifications for openapi3 provider

* added nolint:unparam to bypass golint
  • Loading branch information
Devaansh-Kumar authored Nov 22, 2024
1 parent 1a6031b commit e9621a1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/i2gw/providers/openapi3/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))
}
}

Expand Down
27 changes: 27 additions & 0 deletions pkg/i2gw/providers/openapi3/notification.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit e9621a1

Please sign in to comment.