Skip to content

Commit 95d5e4d

Browse files
added notifications for nginx provider (#177)
1 parent 35fef10 commit 95d5e4d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

pkg/i2gw/providers/ingressnginx/canary.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"strconv"
2222

2323
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
24+
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/notifications"
2425
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/common"
2526
networkingv1 "k8s.io/api/networking/v1"
2627
"k8s.io/apimachinery/pkg/types"
@@ -86,9 +87,10 @@ func getPathsByMatchGroups(rg common.IngressRuleGroup) (map[pathMatchKey][]ingre
8687
}
8788

8889
func patchHTTPRouteWithBackendRefs(httpRoute *gatewayv1.HTTPRoute, backendRefs []gatewayv1.HTTPBackendRef) {
90+
var ruleExists bool
8991
for _, backendRef := range backendRefs {
9092

91-
ruleExists := false
93+
ruleExists = false
9294

9395
for j, rule := range httpRoute.Spec.Rules {
9496
foundBackendRef := false
@@ -112,6 +114,9 @@ func patchHTTPRouteWithBackendRefs(httpRoute *gatewayv1.HTTPRoute, backendRefs [
112114
})
113115
}
114116
}
117+
if ruleExists {
118+
notify(notifications.InfoNotification, fmt.Sprintf("parsed canary annotations of ingress and patched %v fields", field.NewPath("httproute", "spec", "rules").Key("").Child("backendRefs")), httpRoute)
119+
}
115120
}
116121

117122
func calculateBackendRefWeight(paths []ingressPath) ([]gatewayv1.HTTPBackendRef, field.ErrorList) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package ingressnginx
18+
19+
import (
20+
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/notifications"
21+
"sigs.k8s.io/controller-runtime/pkg/client"
22+
)
23+
24+
func notify(mType notifications.MessageType, message string, callingObject ...client.Object) {
25+
newNotification := notifications.NewNotification(mType, message, callingObject...)
26+
notifications.NotificationAggr.DispatchNotification(newNotification, string(Name))
27+
}

0 commit comments

Comments
 (0)