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

With sync update, get revision name with latestReadyRevisionName #505

Closed
wants to merge 2 commits into from
Closed
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
58 changes: 30 additions & 28 deletions test/e2e/traffic_split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strconv"
"strings"
"testing"
"time"

"gotest.tools/assert"
"knative.dev/client/pkg/util"
Expand All @@ -33,8 +34,8 @@ var targetFieldsLength = 4
// returns deployed service targets separated by '|' and each target fields seprated by comma
var targetsJsonPath = "jsonpath={range .status.traffic[*]}{.tag}{','}{.revisionName}{','}{.percent}{','}{.latestRevision}{'|'}{end}"

// returns deployed service latest revision name
var latestRevisionJsonPath = "jsonpath={.status.latestCreatedRevisionName}"
// returns latest ready revision name jsonpath
var LRRJsonPath = "jsonpath={.status.latestReadyRevisionName}"

// TargetFields are used in e2e to store expected fields per traffic target
// and actual traffic targets fields of deployed service are converted into struct before comparing
Expand Down Expand Up @@ -88,9 +89,9 @@ func TestTrafficSplit(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
test.serviceCreate(t, serviceName)
test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v1"})
rev1 := test.latestRevisionOfService(t, serviceName)
rev1 := test.latestReadyRevisionOfService(t, serviceName)
test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v2"})
rev2 := test.latestRevisionOfService(t, serviceName)
rev2 := test.latestReadyRevisionOfService(t, serviceName)

tflags := []string{"--tag", fmt.Sprintf("%s=v1,%s=v2", rev1, rev2),
"--traffic", "v1=50,v2=50"}
Expand All @@ -107,9 +108,9 @@ func TestTrafficSplit(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
test.serviceCreate(t, serviceName)
test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v1"})
rev1 := test.latestRevisionOfService(t, serviceName)
rev1 := test.latestReadyRevisionOfService(t, serviceName)
test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v2"})
rev2 := test.latestRevisionOfService(t, serviceName)
rev2 := test.latestReadyRevisionOfService(t, serviceName)

tflags := []string{"--traffic", fmt.Sprintf("%s=20,%s=80", rev1, rev2)} // traffic by revision name
test.serviceUpdateWithOptions(t, serviceName, tflags)
Expand All @@ -123,9 +124,9 @@ func TestTrafficSplit(t *testing.T) {
func(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
test.serviceCreate(t, serviceName)
rev1 := test.latestRevisionOfService(t, serviceName)
rev1 := test.latestReadyRevisionOfService(t, serviceName)
test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v1"})
rev2 := test.latestRevisionOfService(t, serviceName)
rev2 := test.latestReadyRevisionOfService(t, serviceName)

tflags := []string{"--tag", fmt.Sprintf("%s=%s", rev1, "candidate")} // no traffic, append new target with tag in traffic block
test.serviceUpdateWithOptions(t, serviceName, tflags)
Expand All @@ -139,9 +140,9 @@ func TestTrafficSplit(t *testing.T) {
func(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
test.serviceCreate(t, serviceName)
rev1 := test.latestRevisionOfService(t, serviceName)
rev1 := test.latestReadyRevisionOfService(t, serviceName)
test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v1"})
rev2 := test.latestRevisionOfService(t, serviceName)
rev2 := test.latestReadyRevisionOfService(t, serviceName)

tflags := []string{"--tag", fmt.Sprintf("%s=%s", rev1, "candidate"),
"--traffic", "candidate=2%,@latest=98%"} // traffic by tag name and use % at the end
Expand All @@ -157,13 +158,13 @@ func TestTrafficSplit(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
// make available 3 revisions for service first
test.serviceCreate(t, serviceName)
rev1 := test.latestRevisionOfService(t, serviceName)
rev1 := test.latestReadyRevisionOfService(t, serviceName)

test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v2"})
rev2 := test.latestRevisionOfService(t, serviceName)
rev2 := test.latestReadyRevisionOfService(t, serviceName)

test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v3"}) //note that this gives 100% traffic to latest revision (rev3)
rev3 := test.latestRevisionOfService(t, serviceName)
rev3 := test.latestReadyRevisionOfService(t, serviceName)

// make existing state: tag current and candidate exist in traffic block
tflags := []string{"--tag", fmt.Sprintf("%s=current,%s=candidate", rev1, rev2)}
Expand All @@ -184,7 +185,7 @@ func TestTrafficSplit(t *testing.T) {
func(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
test.serviceCreate(t, serviceName)
rev1 := test.latestRevisionOfService(t, serviceName)
rev1 := test.latestReadyRevisionOfService(t, serviceName)

// make existing state: tag @latest as testing
tflags := []string{"--tag", "@latest=testing"}
Expand All @@ -203,10 +204,10 @@ func TestTrafficSplit(t *testing.T) {
func(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
test.serviceCreate(t, serviceName)
rev1 := test.latestRevisionOfService(t, serviceName)
rev1 := test.latestReadyRevisionOfService(t, serviceName)

test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v2"})
rev2 := test.latestRevisionOfService(t, serviceName)
rev2 := test.latestReadyRevisionOfService(t, serviceName)

// make existing state: tag a revision as testing
tflags := []string{"--tag", fmt.Sprintf("%s=testing", rev1)}
Expand All @@ -227,10 +228,10 @@ func TestTrafficSplit(t *testing.T) {
func(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
test.serviceCreate(t, serviceName)
rev1 := test.latestRevisionOfService(t, serviceName)
rev1 := test.latestReadyRevisionOfService(t, serviceName)

test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v2"})
rev2 := test.latestRevisionOfService(t, serviceName)
rev2 := test.latestReadyRevisionOfService(t, serviceName)

// existing state: traffic block having a revision with tag old and some traffic
tflags := []string{"--tag", fmt.Sprintf("%s=old", rev1),
Expand All @@ -250,7 +251,7 @@ func TestTrafficSplit(t *testing.T) {
func(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
test.serviceCreate(t, serviceName)
rev1 := test.latestRevisionOfService(t, serviceName)
rev1 := test.latestReadyRevisionOfService(t, serviceName)

// existing state: traffic block having two targets
test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v2"})
Expand All @@ -269,10 +270,10 @@ func TestTrafficSplit(t *testing.T) {
func(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
test.serviceCreate(t, serviceName)
rev1 := test.latestRevisionOfService(t, serviceName)
rev1 := test.latestReadyRevisionOfService(t, serviceName)

test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v2"})
rev2 := test.latestRevisionOfService(t, serviceName)
rev2 := test.latestReadyRevisionOfService(t, serviceName)

// existing state: latest revision not getting any traffic
tflags := []string{"--traffic", fmt.Sprintf("%s=100", rev1)}
Expand All @@ -292,7 +293,7 @@ func TestTrafficSplit(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
// existing state: latest revision has no tag
test.serviceCreate(t, serviceName)
rev1 := test.latestRevisionOfService(t, serviceName)
rev1 := test.latestReadyRevisionOfService(t, serviceName)

// desired state: tag current to latest ready revision
tflags := []string{"--tag", "@latest=current"}
Expand All @@ -307,10 +308,10 @@ func TestTrafficSplit(t *testing.T) {
func(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
test.serviceCreate(t, serviceName)
rev1 := test.latestRevisionOfService(t, serviceName)
rev1 := test.latestReadyRevisionOfService(t, serviceName)

test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v2"})
rev2 := test.latestRevisionOfService(t, serviceName)
rev2 := test.latestReadyRevisionOfService(t, serviceName)

// existing state: two revision exists with traffic share and
// each revision has tag and traffic portions
Expand All @@ -333,10 +334,10 @@ func TestTrafficSplit(t *testing.T) {
func(t *testing.T) {
serviceName := getServiceNameAndIncrement(serviceBase)
test.serviceCreate(t, serviceName)
rev1 := test.latestRevisionOfService(t, serviceName)
rev1 := test.latestReadyRevisionOfService(t, serviceName)

test.serviceUpdateWithOptions(t, serviceName, []string{"--env", "TARGET=v2"})
rev2 := test.latestRevisionOfService(t, serviceName)
rev2 := test.latestReadyRevisionOfService(t, serviceName)

// existing state: a revision exist with latest tag
tflags := []string{"--tag", fmt.Sprintf("%s=latest", rev1)}
Expand All @@ -360,6 +361,7 @@ func TestTrafficSplit(t *testing.T) {
}

func (test *e2eTest) verifyTargets(t *testing.T, serviceName string, expectedTargets []TargetFields) {
time.Sleep(3 * time.Second)
out := test.serviceDescribeWithJsonPath(t, serviceName, targetsJsonPath)
assert.Check(t, out != "")
actualTargets, err := splitTargets(out, targetsSeparator, len(expectedTargets))
Expand All @@ -368,8 +370,8 @@ func (test *e2eTest) verifyTargets(t *testing.T, serviceName string, expectedTar
assert.DeepEqual(t, expectedTargets, formattedActualTargets)
}

func (test *e2eTest) latestRevisionOfService(t *testing.T, serviceName string) string {
return test.serviceDescribeWithJsonPath(t, serviceName, latestRevisionJsonPath)
func (test *e2eTest) latestReadyRevisionOfService(t *testing.T, serviceName string) string {
return test.serviceDescribeWithJsonPath(t, serviceName, LRRJsonPath)
}

func (test *e2eTest) serviceDescribeWithJsonPath(t *testing.T, serviceName, jsonpath string) string {
Expand Down