@@ -23,18 +23,19 @@ import (
23
23
"slices"
24
24
"strings"
25
25
26
- flaggerv1 "github.com/fluxcd/flagger/pkg/apis/flagger/v1beta1"
27
- v1 "github.com/fluxcd/flagger/pkg/apis/gatewayapi/v1"
28
- "github.com/fluxcd/flagger/pkg/apis/gatewayapi/v1beta1"
29
- istiov1beta1 "github.com/fluxcd/flagger/pkg/apis/istio/v1beta1"
30
- clientset "github.com/fluxcd/flagger/pkg/client/clientset/versioned"
31
26
"github.com/google/go-cmp/cmp"
32
27
"github.com/google/go-cmp/cmp/cmpopts"
33
28
"go.uber.org/zap"
34
29
"k8s.io/apimachinery/pkg/api/errors"
35
30
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
36
31
"k8s.io/apimachinery/pkg/runtime/schema"
37
32
"k8s.io/client-go/kubernetes"
33
+
34
+ flaggerv1 "github.com/fluxcd/flagger/pkg/apis/flagger/v1beta1"
35
+ v1 "github.com/fluxcd/flagger/pkg/apis/gatewayapi/v1"
36
+ "github.com/fluxcd/flagger/pkg/apis/gatewayapi/v1beta1"
37
+ istiov1beta1 "github.com/fluxcd/flagger/pkg/apis/istio/v1beta1"
38
+ clientset "github.com/fluxcd/flagger/pkg/client/clientset/versioned"
38
39
)
39
40
40
41
var (
@@ -218,16 +219,26 @@ func (gwr *GatewayAPIRouter) Reconcile(canary *flaggerv1.Canary) error {
218
219
}
219
220
220
221
if httpRoute != nil {
222
+ // Preserve the existing annotations added by other controllers such as AWS Gateway API Controller.
223
+ mergedAnnotations := newMetadata .Annotations
224
+ for key , val := range httpRoute .Annotations {
225
+ if _ , ok := mergedAnnotations [key ]; ! ok {
226
+ mergedAnnotations [key ] = val
227
+ }
228
+ }
229
+
230
+ // Compare the existing HTTPRoute spec and metadata with the desired state.
231
+ // If there are differences, update the HTTPRoute object.
221
232
specDiff := cmp .Diff (
222
233
httpRoute .Spec , httpRouteSpec ,
223
234
ignoreCmpOptions ... ,
224
235
)
225
236
labelsDiff := cmp .Diff (newMetadata .Labels , httpRoute .Labels , cmpopts .EquateEmpty ())
226
- annotationsDiff := cmp .Diff (newMetadata . Annotations , httpRoute .Annotations , cmpopts .EquateEmpty ())
237
+ annotationsDiff := cmp .Diff (mergedAnnotations , httpRoute .Annotations , cmpopts .EquateEmpty ())
227
238
if (specDiff != "" && httpRoute .Name != "" ) || labelsDiff != "" || annotationsDiff != "" {
228
239
hrClone := httpRoute .DeepCopy ()
229
240
hrClone .Spec = httpRouteSpec
230
- hrClone .ObjectMeta .Annotations = newMetadata . Annotations
241
+ hrClone .ObjectMeta .Annotations = mergedAnnotations
231
242
hrClone .ObjectMeta .Labels = newMetadata .Labels
232
243
_ , err := gwr .gatewayAPIClient .GatewayapiV1 ().HTTPRoutes (hrNamespace ).
233
244
Update (context .TODO (), hrClone , metav1.UpdateOptions {})
0 commit comments