Skip to content

Commit

Permalink
Include drift end-to-end tests in CI workflows (#2531)
Browse files Browse the repository at this point in the history
* Include drift end-to-end tests in CI workflows

This includes drift tests, previously omitted, in our CI workflows
running single-cluster end-to-end tests.

* Fix drift tests

This fixes expectations and ensures that a valid patch is applied
to make drift detection tests pass.
  • Loading branch information
weyfonk authored Jun 19, 2024
1 parent 6dacb0d commit 9f6d9b3
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
FLEET_E2E_NS: fleet-local
run: |
export KUBECONFIG="$GITHUB_WORKSPACE/kubeconfig-fleet-ci"
ginkgo --github-output --label-filter="!infra-setup" e2e/single-cluster e2e/keep-resources
ginkgo --github-output --label-filter='!infra-setup' e2e/single-cluster e2e/keep-resources e2e/drift
-
name: Acceptance Tests for Examples
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
export CI_OCI_CERTS_DIR="$(git rev-parse --show-toplevel)/FleetCI-RootCA"
# 1. Run test cases not needing infra
ginkgo --github-output --label-filter='!infra-setup' e2e/single-cluster e2e/keep-resources
ginkgo --github-output --label-filter='!infra-setup' e2e/single-cluster e2e/keep-resources e2e/drift
# 2. Run tests for metrics
ginkgo --github-output e2e/metrics
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ jobs:
env:
FLEET_E2E_NS: fleet-local
run: |
ginkgo --github-output --label-filter="!infra-setup" e2e/single-cluster e2e/keep-resources
ginkgo --github-output --label-filter='!infra-setup' e2e/single-cluster e2e/keep-resources e2e/drift
-
name: Acceptance Tests for Examples
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
export CI_OCI_CERTS_DIR="$(git rev-parse --show-toplevel)/FleetCI-RootCA"
# 1. Run test cases not needing infra
ginkgo --github-output --label-filter='!infra-setup' e2e/single-cluster e2e/keep-resources
ginkgo --github-output --label-filter='!infra-setup' e2e/single-cluster e2e/keep-resources e2e/drift
# 2. Run tests for metrics
ginkgo --github-output e2e/metrics
Expand Down
1 change: 0 additions & 1 deletion e2e/assets/drift/correction-disabled/gitrepo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ kind: GitRepo
apiVersion: fleet.cattle.io/v1alpha1
metadata:
name: drift-test
namespace: fleet-default
spec:
repo: https://github.com/rancher/fleet-test-data
branch: master
Expand Down
1 change: 0 additions & 1 deletion e2e/assets/drift/correction-enabled/gitrepo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ kind: GitRepo
apiVersion: fleet.cattle.io/v1alpha1
metadata:
name: drift-correction-test
namespace: fleet-default
spec:
repo: https://github.com/rancher/fleet-test-data
branch: master
Expand Down
1 change: 0 additions & 1 deletion e2e/assets/drift/force/gitrepo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ kind: GitRepo
apiVersion: fleet.cattle.io/v1alpha1
metadata:
name: drift-force-test
namespace: fleet-default
spec:
repo: https://github.com/rancher/fleet-test-data
branch: master
Expand Down
22 changes: 14 additions & 8 deletions e2e/drift/drift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
corev1 "k8s.io/api/core/v1"
)

var _ = Describe("Drift", func() {
var _ = Describe("Drift", Ordered, func() {
var (
asset string
k kubectl.Command
Expand Down Expand Up @@ -134,7 +134,7 @@ var _ = Describe("Drift", func() {
out, err := kw.Patch(
"configmap", "configmap",
"--type=json",
"-p", `[{"op": "replace", "path": "data/foo", "value": "modified"}]`,
"-p", `[{"op": "replace", "path": "/data/foo", "value": "modified"}]`,
)
Expect(err).ToNot(HaveOccurred(), out)
})
Expand All @@ -151,11 +151,15 @@ var _ = Describe("Drift", func() {
_ = json.Unmarshal([]byte(out), &configMap)
return configMap.Data["foo"] == "bar"
}).Should(BeTrue())
Expect(func() string {
kw := k.Namespace(namespace)
n, _ := kw.Get("secrets", "--field-selector=type=helm.sh/release.v1", `-o=go-template='{{printf "%d\n" (len .items)}}'`)
return n
}).Should(Equal("2")) // Max Helm history

kw := k.Namespace(namespace)
out, err := kw.Get(
"secrets",
"--field-selector=type=helm.sh/release.v1",
`-o=go-template={{printf "%d" (len .items)}}`,
)
Expect(err).ToNot(HaveOccurred(), out)
Expect(out).To(Equal("2")) // Max Helm history
})
})

Expand All @@ -175,7 +179,9 @@ var _ = Describe("Drift", func() {
Eventually(func() string {
out, _ := k.Namespace(env.Namespace).Get("bundles", bundleName, "-o=jsonpath={.status.conditions[*].message}")
return out
}).Should(ContainSubstring(`error reconciling drift: cannot patch "nginx-service" with kind Service: Service "nginx-service" is invalid: spec.ports[1].name: Duplicate value: "http"]; service.v1 drift/nginx-service modified {"spec":{"ports":[{"name":"http","port":80,"protocol":"TCP","targetPort":"http-web-svc"},{"name":"http","port":1234,"protocol":"TCP","targetPort":"http-web-svc"}]}}`))
}).Should(ContainSubstring(`service.v1 drift/nginx-service modified {"spec":{"ports":[` +
`{"name":"http","port":80,"protocol":"TCP","targetPort":"http-web-svc"},` +
`{"name":"http","port":1234,"protocol":"TCP","targetPort":"http-web-svc"}]}}`))
})
})
})
Expand Down
2 changes: 2 additions & 0 deletions e2e/drift/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package examples_test

import (
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -19,6 +20,7 @@ var (

var _ = BeforeSuite(func() {
SetDefaultEventuallyTimeout(testenv.Timeout)
SetDefaultEventuallyPollingInterval(time.Second)
testenv.SetRoot("../..")

env = testenv.New()
Expand Down

0 comments on commit 9f6d9b3

Please sign in to comment.