Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: protocol missing in ambassador canary mapping creation. Fixes #3593 #3603

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions rollout/trafficrouting/ambassador/ambassador.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -218,7 +217,8 @@ func (r *Reconciler) createCanaryMapping(ctx context.Context,
}

canarySvc := r.Rollout.Spec.Strategy.Canary.CanaryService
canaryMapping := buildCanaryMapping(baseMapping, canarySvc, desiredWeight)
stableService := r.Rollout.Spec.Strategy.Canary.StableService
canaryMapping := buildCanaryMapping(baseMapping, canarySvc, stableService, desiredWeight)
_, err = client.Create(ctx, canaryMapping, metav1.CreateOptions{})
if err != nil {
msg := fmt.Sprintf("Error creating canary mapping: %s", err)
Expand All @@ -227,9 +227,9 @@ func (r *Reconciler) createCanaryMapping(ctx context.Context,
return err
}

func buildCanaryMapping(baseMapping *unstructured.Unstructured, canarySvc string, desiredWeight int32) *unstructured.Unstructured {
func buildCanaryMapping(baseMapping *unstructured.Unstructured, canarySvc string, stableService string, desiredWeight int32) *unstructured.Unstructured {
canaryMapping := baseMapping.DeepCopy()
svc := buildCanaryService(baseMapping, canarySvc)
svc := buildCanaryService(baseMapping, canarySvc, stableService)
unstructured.RemoveNestedField(canaryMapping.Object, "metadata")
cMappingName := buildCanaryMappingName(baseMapping.GetName())
canaryMapping.SetName(cMappingName)
Expand All @@ -239,19 +239,9 @@ func buildCanaryMapping(baseMapping *unstructured.Unstructured, canarySvc string
return canaryMapping
}

func buildCanaryService(baseMapping *unstructured.Unstructured, canarySvc string) string {
func buildCanaryService(baseMapping *unstructured.Unstructured, canarySvc string, stableService string) string {
curSvc := GetMappingService(baseMapping)
parts := strings.Split(curSvc, ":")
if len(parts) < 2 {
return canarySvc
}
// Check if the last part is a valid int that can be used as the port
port := parts[len(parts)-1]
if _, err := strconv.Atoi(port); err != nil {
return canarySvc

}
return fmt.Sprintf("%s:%s", canarySvc, port)
return strings.Replace(curSvc, stableService, canarySvc, 1)
}

func (r *Reconciler) VerifyWeight(desiredWeight int32, additionalDestinations ...v1alpha1.WeightDestination) (*bool, error) {
Expand Down
12 changes: 6 additions & 6 deletions rollout/trafficrouting/ambassador/ambassador_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ metadata:
spec:
prefix: /myapp/
rewrite: /myapp/
service: myapp:8080`
service: main-service:8080`

baseMappingNoPort = `
apiVersion: getambassador.io/v2
Expand All @@ -42,7 +42,7 @@ metadata:
spec:
prefix: /myapp/
rewrite: /myapp/
service: myapp`
service: main-service`

baseMappingWithWeight = `
apiVersion: getambassador.io/v2
Expand All @@ -53,7 +53,7 @@ metadata:
spec:
prefix: /myapp/
rewrite: /myapp/
service: myapp:8080
service: main-service:8080
weight: 20`

baseV3Mapping = `
Expand All @@ -66,7 +66,7 @@ spec:
hostname: 'example.com'
prefix: /myapp/
rewrite: /myapp/
service: myapp:8080`
service: main-service:8080`

canaryMapping = `
apiVersion: getambassador.io/v2
Expand All @@ -77,7 +77,7 @@ metadata:
spec:
prefix: /myapp/
rewrite: /myapp/
service: myapp:8080
service: main-service:8080
weight: 20`

canaryMappingWithZeroWeight = `
Expand All @@ -89,7 +89,7 @@ metadata:
spec:
prefix: /myapp/
rewrite: /myapp/
service: myapp:8080
service: main-service:8080
weight: 0`
)

Expand Down
Loading