Skip to content

Commit e70cd85

Browse files
authored
Simplify and speed up "kpt live" e2e tests (#2613)
* Simplify and speed up live e2e tests * Addressed comments
1 parent efade46 commit e70cd85

File tree

26 files changed

+451
-250
lines changed

26 files changed

+451
-250
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ test-fn-eval: build
8787

8888
# target to run e2e tests for "kpt fn eval" command
8989
test-live-apply: build
90-
PATH=$(GOBIN):$(PATH) go test -v -timeout=20m --tags=kind --run=TestLiveApply/testdata/live-apply/$(T) ./e2e/
90+
PATH=$(GOBIN):$(PATH) go test -v -timeout=20m --tags=kind -p 2 --run=TestLiveApply/testdata/live-apply/$(T) ./e2e/
9191

9292
vet:
9393
go vet ./...

e2e/live_test.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
package e2e
1818

1919
import (
20-
"fmt"
2120
"os"
2221
"path/filepath"
2322
"testing"
2423

2524
livetest "github.com/GoogleContainerTools/kpt/pkg/test/live"
25+
"github.com/stretchr/testify/require"
2626
)
2727

2828
func TestLiveApply(t *testing.T) {
@@ -32,18 +32,40 @@ func TestLiveApply(t *testing.T) {
3232
func runTests(t *testing.T, path string) {
3333
testCases := scanTestCases(t, path)
3434

35+
livetest.RemoveKindCluster(t)
36+
livetest.CreateKindCluster(t)
37+
3538
for p := range testCases {
39+
p := p
3640
c := testCases[p]
37-
for format := range c.Output {
38-
testName := fmt.Sprintf("%s#%s", p, format)
39-
t.Run(testName, func(t *testing.T) {
40-
(&livetest.Runner{
41-
Config: c,
42-
Path: p,
43-
Format: format,
44-
}).Run(t)
45-
})
41+
42+
if !c.Parallel {
43+
continue
4644
}
45+
46+
t.Run(p, func(t *testing.T) {
47+
if c.Parallel {
48+
t.Parallel()
49+
}
50+
51+
if c.NoResourceGroup {
52+
require.False(t, c.Parallel, "Parallel tests can not modify the RG CRD")
53+
if livetest.CheckIfResourceGroupInstalled(t) {
54+
livetest.RemoveResourceGroup(t)
55+
}
56+
} else {
57+
livetest.InstallResourceGroup(t)
58+
}
59+
60+
ns := filepath.Base(p)
61+
livetest.CreateNamespace(t, ns)
62+
defer livetest.RemoveNamespace(t, ns)
63+
64+
(&livetest.Runner{
65+
Config: c,
66+
Path: p,
67+
}).Run(t)
68+
})
4769
}
4870
}
4971

@@ -68,4 +90,4 @@ func scanTestCases(t *testing.T, path string) map[string]livetest.TestCaseConfig
6890
t.Fatalf("failed to scan for test cases in %s", path)
6991
}
7092
return testCases
71-
}
93+
}

e2e/testdata/live-apply/apply-depends-on/config.yaml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
preinstallResourceGroup: true
16-
output:
17-
events:
18-
stdOut: |
19-
deployment.apps/first-nginx created
20-
1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed
21-
deployment.apps/second-nginx created
22-
1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed
23-
json:
24-
stdOut: |
25-
{"eventType":"resourceApplied","group":"apps","kind":"Deployment","name":"first-nginx","namespace":"apply-depends-on","operation":"Created","timestamp":"<TIMESTAMP>","type":"apply"}
26-
{"configuredCount":0,"count":1,"createdCount":1,"eventType":"completed","failedCount":0,"serverSideCount":0,"timestamp":"<TIMESTAMP>","type":"apply","unchangedCount":0}
27-
{"eventType":"resourceApplied","group":"apps","kind":"Deployment","name":"second-nginx","namespace":"apply-depends-on","operation":"Created","timestamp":"<TIMESTAMP>","type":"apply"}
28-
{"configuredCount":0,"count":1,"createdCount":1,"eventType":"completed","failedCount":0,"serverSideCount":0,"timestamp":"<TIMESTAMP>","type":"apply","unchangedCount":0}
15+
parallel: true
16+
17+
stdOut: |
18+
deployment.apps/first-nginx created
19+
1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed
20+
deployment.apps/second-nginx created
21+
1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed
22+
2923
inventory:
3024
- group: apps
3125
kind: Deployment

e2e/testdata/live-apply/apply-depends-on/resources/first.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ metadata:
1818
name: first-nginx
1919
namespace: apply-depends-on
2020
spec:
21-
replicas: 2
21+
replicas: 1
2222
selector:
2323
matchLabels:
2424
app: first-nginx

e2e/testdata/live-apply/apply-depends-on/resources/second.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ metadata:
2020
annotations:
2121
config.kubernetes.io/depends-on: apps/namespaces/apply-depends-on/Deployment/first-nginx
2222
spec:
23-
replicas: 2
23+
replicas: 1
2424
selector:
2525
matchLabels:
2626
app: second-nginx

e2e/testdata/live-apply/crd-and-cr/config.yaml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
requiresCleanCluster: true
16-
preinstallResourceGroup: true
17-
output:
18-
events:
19-
stdOut: |
20-
customresourcedefinition.apiextensions.k8s.io/customs.kpt.dev created
21-
1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed
22-
custom.kpt.dev/cr created
23-
1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed
24-
json:
25-
stdOut: |
26-
{"eventType":"resourceApplied","group":"apiextensions.k8s.io","kind":"CustomResourceDefinition","name":"customs.kpt.dev","namespace":"","operation":"Created","timestamp":"<TIMESTAMP>","type":"apply"}
27-
{"configuredCount":0,"count":1,"createdCount":1,"eventType":"completed","failedCount":0,"serverSideCount":0,"timestamp":"<TIMESTAMP>","type":"apply","unchangedCount":0}
28-
{"eventType":"resourceApplied","group":"kpt.dev","kind":"Custom","name":"cr","namespace":"","operation":"Created","timestamp":"<TIMESTAMP>","type":"apply"}
29-
{"configuredCount":0,"count":1,"createdCount":1,"eventType":"completed","failedCount":0,"serverSideCount":0,"timestamp":"<TIMESTAMP>","type":"apply","unchangedCount":0}
15+
parallel: true
16+
stdOut: |
17+
customresourcedefinition.apiextensions.k8s.io/customs.kpt.dev created
18+
1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed
19+
custom.kpt.dev/cr created
20+
1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed
3021
inventory:
3122
- group: apiextensions.k8s.io
3223
kind: CustomResourceDefinition

e2e/testdata/live-apply/dry-run-with-install-rg/config.yaml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
requiresCleanCluster: true
15+
parallel: false
16+
noResourceGroup: true
1617
kptArgs:
1718
- "--dry-run"
1819
- "--install-resource-group"
19-
output:
20-
events:
21-
stdOut: |
22-
deployment.apps/nginx-deployment created (dry-run)
23-
1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed (dry-run)
24-
stdErr: |
25-
installing inventory ResourceGroup CRD.
26-
json:
27-
stdOut: |
28-
{"eventType":"resourceApplied","group":"apps","kind":"Deployment","name":"nginx-deployment","namespace":"dry-run-with-install-rg","operation":"Created","timestamp":"<TIMESTAMP>","type":"apply"}
29-
{"configuredCount":0,"count":1,"createdCount":1,"eventType":"completed","failedCount":0,"serverSideCount":0,"timestamp":"<TIMESTAMP>","type":"apply","unchangedCount":0}
30-
stdErr: |
31-
installing inventory ResourceGroup CRD.
20+
stdOut: |
21+
deployment.apps/nginx-deployment created (dry-run)
22+
1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed (dry-run)
23+
stdErr: |
24+
installing inventory ResourceGroup CRD.
3225
exitCode: 0

e2e/testdata/live-apply/dry-run-with-install-rg/resources/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ spec:
2424
rollingUpdate:
2525
maxUnavailable: 1
2626
maxSurge: 0
27-
replicas: 2
27+
replicas: 1
2828
selector:
2929
matchLabels:
3030
app: nginx-deployment

e2e/testdata/live-apply/dry-run-without-rg/config.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
requiresCleanCluster: true
15+
parallel: false
16+
noResourceGroup: true
1617
kptArgs:
1718
- "--dry-run"
18-
output:
19-
events:
20-
stdErr: |
21-
Error: The ResourceGroup CRD was not found in the cluster. Please install it either by using the '--install-resource-group' flag or the 'kpt live install-resource-group' command.
19+
stdErr: |
20+
Error: The ResourceGroup CRD was not found in the cluster. Please install it either by using the '--install-resource-group' flag or the 'kpt live install-resource-group' command.
2221
exitCode: 1

e2e/testdata/live-apply/install-rg-on-apply/config.yaml

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
requiresCleanCluster: true
16-
output:
17-
events:
18-
stdOut: |
19-
deployment.apps/nginx-deployment created
20-
1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed
21-
stdErr: |
22-
installing inventory ResourceGroup CRD.
23-
json:
24-
stdOut: |
25-
{"eventType":"resourceApplied","group":"apps","kind":"Deployment","name":"nginx-deployment","namespace":"install-rg-on-apply","operation":"Created","timestamp":"<TIMESTAMP>","type":"apply"}
26-
{"configuredCount":0,"count":1,"createdCount":1,"eventType":"completed","failedCount":0,"serverSideCount":0,"timestamp":"<TIMESTAMP>","type":"apply","unchangedCount":0}
27-
stdErr: |
28-
installing inventory ResourceGroup CRD.
15+
parallel: false
16+
noResourceGroup: true
17+
stdOut: |
18+
deployment.apps/nginx-deployment created
19+
1 resource(s) applied. 1 created, 0 unchanged, 0 configured, 0 failed
20+
stdErr: |
21+
installing inventory ResourceGroup CRD.
2922
inventory:
3023
- group: apps
3124
kind: Deployment

0 commit comments

Comments
 (0)