Skip to content

Commit b711e6d

Browse files
committed
s
1 parent 0e8e527 commit b711e6d

File tree

9 files changed

+208
-1665
lines changed

9 files changed

+208
-1665
lines changed

artifacts/flagger/crd.yaml

Lines changed: 34 additions & 532 deletions
Large diffs are not rendered by default.

charts/flagger/crds/crd.yaml

Lines changed: 34 additions & 532 deletions
Large diffs are not rendered by default.

kustomize/base/flagger/crd.yaml

Lines changed: 34 additions & 532 deletions
Large diffs are not rendered by default.

pkg/apis/flagger/v1beta1/canary.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ type CanaryService struct {
214214

215215
// Primary is the metadata to add to the primary service
216216
// +optional
217-
Primary *Custom `json:"primary,omitempty"`
217+
Primary *CustomBackend `json:"primary,omitempty"`
218218

219219
// Canary is the metadata to add to the canary service
220220
// +optional
221-
Canary *Custom `json:"canary,omitempty"`
221+
Canary *CustomBackend `json:"canary,omitempty"`
222222
}
223223

224224
// CanaryAnalysis is used to describe how the analysis should be done
@@ -497,14 +497,36 @@ type CustomMetadata struct {
497497
Annotations map[string]string `json:"annotations,omitempty"`
498498
}
499499

500-
// Custom holds labels, annotations, and proxyRef to set on generated objects.
501-
type Custom struct {
500+
// CustomBackend holds labels, annotations, and proxyRef to set on generated objects.
501+
type CustomBackend struct {
502502
CustomMetadata
503503

504-
// BackendRef is a reference to a backend to forward matched requests to.
504+
// Backend is a reference to a backend to forward matched requests to.
505505
// Defaults to the primary or canary service.
506506
// +optional
507-
BackendRef *v1.HTTPBackendRef `json:"backendRef,omitempty"`
507+
Backend *HTTPBackendRefTemplate `json:"backendRef,omitempty"`
508+
}
509+
510+
// HTTPBackendRefTemplate is a reference to a backend to forward matched requests to.
511+
type HTTPBackendRefTemplate struct {
512+
// Ref references a Kubernetes object.
513+
BackendObjectReference *v1.BackendObjectReference `json:"ref,omitempty"`
514+
515+
// Filters defined at this level should be executed if and only if the
516+
// request is being forwarded to the backend defined here.
517+
//
518+
// Support: Implementation-specific (For broader support of filters, use the
519+
// Filters field in HTTPRouteRule.)
520+
//
521+
// +optional
522+
// +kubebuilder:validation:MaxItems=16
523+
// +kubebuilder:validation:XValidation:message="May specify either httpRouteFilterRequestRedirect or httpRouteFilterRequestRewrite, but not both",rule="!(self.exists(f, f.type == 'RequestRedirect') && self.exists(f, f.type == 'URLRewrite'))"
524+
// +kubebuilder:validation:XValidation:message="May specify either httpRouteFilterRequestRedirect or httpRouteFilterRequestRewrite, but not both",rule="!(self.exists(f, f.type == 'RequestRedirect') && self.exists(f, f.type == 'URLRewrite'))"
525+
// +kubebuilder:validation:XValidation:message="RequestHeaderModifier filter cannot be repeated",rule="self.filter(f, f.type == 'RequestHeaderModifier').size() <= 1"
526+
// +kubebuilder:validation:XValidation:message="ResponseHeaderModifier filter cannot be repeated",rule="self.filter(f, f.type == 'ResponseHeaderModifier').size() <= 1"
527+
// +kubebuilder:validation:XValidation:message="RequestRedirect filter cannot be repeated",rule="self.filter(f, f.type == 'RequestRedirect').size() <= 1"
528+
// +kubebuilder:validation:XValidation:message="URLRewrite filter cannot be repeated",rule="self.filter(f, f.type == 'URLRewrite').size() <= 1"
529+
Filters []v1.HTTPRouteFilter `json:"filters,omitempty"`
508530
}
509531

510532
// HTTPRewrite holds information about how to modify a request URI during

pkg/apis/flagger/v1beta1/zz_generated.deepcopy.go

Lines changed: 37 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/router/gateway_api.go

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,8 @@ func (gwr *GatewayAPIRouter) Reconcile(canary *flaggerv1.Canary) error {
9696
Matches: matches,
9797
Filters: gwr.makeFilters(canary),
9898
BackendRefs: []v1.HTTPBackendRef{
99-
{
100-
BackendRef: gwr.makeBackendRef(primarySvcName, initialPrimaryWeight, canary.Spec.Service.Port, &canary.Spec.Service.Primary.BackendRef.BackendRef),
101-
Filters: canary.Spec.Service.Primary.BackendRef.Filters,
102-
},
103-
{
104-
BackendRef: gwr.makeBackendRef(canarySvcName, initialCanaryWeight, canary.Spec.Service.Port, &canary.Spec.Service.Canary.BackendRef.BackendRef),
105-
Filters: canary.Spec.Service.Canary.BackendRef.Filters,
106-
},
99+
gwr.makeHTTPBackendRef(primarySvcName, initialPrimaryWeight, canary.Spec.Service.Port, canary.Spec.Service.Primary),
100+
gwr.makeHTTPBackendRef(canarySvcName, initialCanaryWeight, canary.Spec.Service.Port, canary.Spec.Service.Canary),
107101
},
108102
},
109103
},
@@ -124,10 +118,7 @@ func (gwr *GatewayAPIRouter) Reconcile(canary *flaggerv1.Canary) error {
124118
Matches: matches,
125119
Filters: gwr.makeFilters(canary),
126120
BackendRefs: []v1.HTTPBackendRef{
127-
{
128-
BackendRef: gwr.makeBackendRef(primarySvcName, initialPrimaryWeight, canary.Spec.Service.Port, &canary.Spec.Service.Primary.BackendRef.BackendRef),
129-
Filters: canary.Spec.Service.Primary.BackendRef.Filters,
130-
},
121+
gwr.makeHTTPBackendRef(primarySvcName, initialPrimaryWeight, canary.Spec.Service.Port, canary.Spec.Service.Primary),
131122
},
132123
})
133124
if canary.Spec.Service.Timeout != "" {
@@ -394,14 +385,8 @@ func (gwr *GatewayAPIRouter) SetRoutes(
394385
Matches: matches,
395386
Filters: gwr.makeFilters(canary),
396387
BackendRefs: []v1.HTTPBackendRef{
397-
{
398-
BackendRef: gwr.makeBackendRef(primarySvcName, pWeight, canary.Spec.Service.Port, &canary.Spec.Service.Primary.BackendRef.BackendRef),
399-
Filters: canary.Spec.Service.Primary.BackendRef.Filters,
400-
},
401-
{
402-
BackendRef: gwr.makeBackendRef(canarySvcName, cWeight, canary.Spec.Service.Port, &canary.Spec.Service.Canary.BackendRef.BackendRef),
403-
Filters: canary.Spec.Service.Canary.BackendRef.Filters,
404-
},
388+
gwr.makeHTTPBackendRef(primarySvcName, pWeight, canary.Spec.Service.Port, canary.Spec.Service.Primary),
389+
gwr.makeHTTPBackendRef(canarySvcName, cWeight, canary.Spec.Service.Port, canary.Spec.Service.Canary),
405390
},
406391
}
407392
if canary.Spec.Service.Timeout != "" {
@@ -455,10 +440,7 @@ func (gwr *GatewayAPIRouter) SetRoutes(
455440
Matches: matches,
456441
Filters: gwr.makeFilters(canary),
457442
BackendRefs: []v1.HTTPBackendRef{
458-
{
459-
BackendRef: gwr.makeBackendRef(primarySvcName, initialPrimaryWeight, canary.Spec.Service.Port, &canary.Spec.Service.Primary.BackendRef.BackendRef),
460-
Filters: canary.Spec.Service.Primary.BackendRef.Filters,
461-
},
443+
gwr.makeHTTPBackendRef(primarySvcName, initialPrimaryWeight, canary.Spec.Service.Port, canary.Spec.Service.Primary),
462444
},
463445
Timeouts: &v1.HTTPRouteTimeouts{
464446
Request: &timeout,
@@ -541,14 +523,8 @@ func (gwr *GatewayAPIRouter) getSessionAffinityRouteRules(canary *flaggerv1.Cana
541523
mergedMatches := gwr.mergeMatchConditions([]v1.HTTPRouteMatch{cookieMatch}, svcMatches)
542524
stickyRouteRule.Matches = mergedMatches
543525
stickyRouteRule.BackendRefs = []v1.HTTPBackendRef{
544-
{
545-
BackendRef: gwr.makeBackendRef(primarySvcName, 0, canary.Spec.Service.Port, &canary.Spec.Service.Primary.BackendRef.BackendRef),
546-
Filters: canary.Spec.Service.Primary.BackendRef.Filters,
547-
},
548-
{
549-
BackendRef: gwr.makeBackendRef(canarySvcName, 100, canary.Spec.Service.Port, &canary.Spec.Service.Canary.BackendRef.BackendRef),
550-
Filters: canary.Spec.Service.Canary.BackendRef.Filters,
551-
},
526+
gwr.makeHTTPBackendRef(primarySvcName, 0, canary.Spec.Service.Port, canary.Spec.Service.Primary),
527+
gwr.makeHTTPBackendRef(canarySvcName, 100, canary.Spec.Service.Port, canary.Spec.Service.Canary),
552528
}
553529
} else {
554530
// If canary weight is 0 and SessionAffinityCookie is non-blank, then it belongs to a previous canary run.
@@ -671,21 +647,28 @@ func (gwr *GatewayAPIRouter) mapRouteMatches(requestMatches []istiov1beta1.HTTPM
671647
return matches, nil
672648
}
673649

674-
func (gwr *GatewayAPIRouter) makeBackendRef(svcName string, weight, port int32, backendRefTemplate *v1.BackendRef) v1.BackendRef {
675-
if backendRefTemplate != nil {
676-
backendRefTemplate.Weight = &weight
677-
return *backendRefTemplate
678-
}
679-
680-
return v1.BackendRef{
681-
BackendObjectReference: v1.BackendObjectReference{
682-
Group: (*v1.Group)(&backendRefGroup),
683-
Kind: (*v1.Kind)(&backendRefKind),
684-
Name: v1.ObjectName(svcName),
685-
Port: (*v1.PortNumber)(&port),
650+
func (gwr *GatewayAPIRouter) makeHTTPBackendRef(svcName string, weight, port int32, customBackend *flaggerv1.CustomBackend) v1.HTTPBackendRef {
651+
httpBackendRef := v1.HTTPBackendRef{
652+
BackendRef: v1.BackendRef{
653+
BackendObjectReference: v1.BackendObjectReference{
654+
Group: (*v1.Group)(&backendRefGroup),
655+
Kind: (*v1.Kind)(&backendRefKind),
656+
Name: v1.ObjectName(svcName),
657+
Port: (*v1.PortNumber)(&port),
658+
},
659+
Weight: &weight,
686660
},
687-
Weight: &weight,
688661
}
662+
if customBackend != nil && customBackend.Backend != nil {
663+
if customBackend.Backend.BackendObjectReference != nil {
664+
httpBackendRef.BackendObjectReference = *customBackend.Backend.BackendObjectReference
665+
}
666+
if customBackend.Backend.Filters != nil {
667+
httpBackendRef.Filters = customBackend.Backend.Filters
668+
}
669+
}
670+
671+
return httpBackendRef
689672
}
690673

691674
func (gwr *GatewayAPIRouter) mergeMatchConditions(analysis, service []v1.HTTPRouteMatch) []v1.HTTPRouteMatch {

pkg/router/gateway_api_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,8 @@ func TestGatewayAPIRouter_getSessionAffinityRouteRules(t *testing.T) {
295295
_, pSvcName, cSvcName := canary.GetServiceNames()
296296
weightedRouteRule := &v1.HTTPRouteRule{
297297
BackendRefs: []v1.HTTPBackendRef{
298-
{
299-
BackendRef: router.makeBackendRef(pSvcName, initialPrimaryWeight, canary.Spec.Service.Port, &canary.Spec.Service.Primary.BackendRef.BackendRef),
300-
},
301-
{
302-
BackendRef: router.makeBackendRef(cSvcName, initialCanaryWeight, canary.Spec.Service.Port, &canary.Spec.Service.Canary.BackendRef.BackendRef),
303-
},
298+
router.makeHTTPBackendRef(pSvcName, initialPrimaryWeight, canary.Spec.Service.Port, canary.Spec.Service.Primary),
299+
router.makeHTTPBackendRef(cSvcName, initialCanaryWeight, canary.Spec.Service.Port, canary.Spec.Service.Canary),
304300
},
305301
}
306302
rules, err := router.getSessionAffinityRouteRules(canary, 10, weightedRouteRule)

pkg/router/kubernetes_default.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,21 @@ func (c *KubernetesDefaultRouter) Initialize(canary *flaggerv1.Canary) error {
5050
_, primaryName, canaryName := canary.GetServiceNames()
5151

5252
// canary svc
53-
err := c.reconcileService(canary, canaryName, c.labelValue, &canary.Spec.Service.Canary.CustomMetadata)
53+
canaryCustomMetadata := &flaggerv1.CustomMetadata{}
54+
if canary.Spec.Service.Canary != nil {
55+
canaryCustomMetadata = &canary.Spec.Service.Canary.CustomMetadata
56+
}
57+
err := c.reconcileService(canary, canaryName, c.labelValue, canaryCustomMetadata)
5458
if err != nil {
5559
return fmt.Errorf("reconcileService failed: %w", err)
5660
}
5761

5862
// primary svc
59-
err = c.reconcileService(canary, primaryName, fmt.Sprintf("%s-primary", c.labelValue), &canary.Spec.Service.Primary.CustomMetadata)
63+
primaryCustomMetadata := &flaggerv1.CustomMetadata{}
64+
if canary.Spec.Service.Primary != nil {
65+
primaryCustomMetadata = &canary.Spec.Service.Primary.CustomMetadata
66+
}
67+
err = c.reconcileService(canary, primaryName, fmt.Sprintf("%s-primary", c.labelValue), primaryCustomMetadata)
6068
if err != nil {
6169
return fmt.Errorf("reconcileService failed: %w", err)
6270
}

pkg/router/kubernetes_default_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func TestServiceRouter_InitializeMetadata(t *testing.T) {
375375
labelSelector: "app",
376376
}
377377

378-
mocks.canary.Spec.Service.Canary = &flaggerv1.Custom{
378+
mocks.canary.Spec.Service.Canary = &flaggerv1.CustomBackend{
379379
CustomMetadata: flaggerv1.CustomMetadata{
380380
Labels: map[string]string{"test": "test"},
381381
Annotations: map[string]string{"test": "test"},

0 commit comments

Comments
 (0)