Skip to content

Commit

Permalink
changed license header for scripts, fixed flaky e2e tests, removed de…
Browse files Browse the repository at this point in the history
…precated method usage
  • Loading branch information
unmarshall committed Apr 16, 2024
1 parent 856a2d9 commit 92dddad
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .ci/set_dependency_version
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0

"$(dirname "$0")"/hack/set_dependency_version
1 change: 0 additions & 1 deletion hack/addlicenseheaders.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ sed 's|^// *||' hack/boilerplate.go.txt > $temp_file

addlicense \
-f $temp_file \
-ignore "vendor/**" \
-ignore "**/*.md" \
-ignore "**/*.yaml" \
-ignore "**/Dockerfile" \
Expand Down
2 changes: 1 addition & 1 deletion hack/ci-e2e-kind.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0

set -o errexit
set -o nounset
set -o pipefail
Expand Down
2 changes: 1 addition & 1 deletion hack/deploy-localstack.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0

set -o errexit
set -o nounset
set -o pipefail
Expand Down
1 change: 0 additions & 1 deletion hack/get-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#
# SPDX-License-Identifier: Apache-2.0


# The test-machinery testrunner injects two environment variables into test runs to specify which version should be
# tested (TM_GIT_SHA and TM_GIT_REF, see https://github.com/gardener/test-infra/blob/master/docs/testmachinery/GetStarted.md#input-contract)
# Use those to calculate the terraformer version in order to tell the e2e test (via ldflags), which terraformer image
Expand Down
1 change: 0 additions & 1 deletion hack/kind-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#
# SPDX-License-Identifier: Apache-2.0


set -o errexit
set -o nounset
set -o pipefail
Expand Down
1 change: 0 additions & 1 deletion hack/print-content.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
#
# SPDX-License-Identifier: Apache-2.0


cat docs/proposals/multi-node/README.md | gh-md-toc - | sed 's/\*/-/g' | sed 's/ / /g' | sed 's/^ //'
1 change: 0 additions & 1 deletion hack/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0
Expand Down
1 change: 0 additions & 1 deletion hack/update-codegen.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
#
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0
Expand Down
18 changes: 9 additions & 9 deletions test/e2e/etcd_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var _ = Describe("Etcd Backup", func() {

By("Check initial snapshot is available")

latestSnapshotsBeforePopulate, err := getLatestSnapshots(kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
latestSnapshotsBeforePopulate, err := getLatestSnapshots(ctx, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
Expect(err).ShouldNot(HaveOccurred())
// We don't expect any delta snapshot as the cluster
Expect(latestSnapshotsBeforePopulate.DeltaSnapshots).To(HaveLen(0))
Expand All @@ -94,15 +94,15 @@ var _ = Describe("Etcd Backup", func() {
"toKey", fmt.Sprintf("%s-10", etcdKeyPrefix), "toValue", fmt.Sprintf("%s-10", etcdValuePrefix))

// populate 10 keys in etcd, finishing in 10 seconds
err = populateEtcd(logger, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, etcdKeyPrefix, etcdValuePrefix, 1, 10, time.Second*1)
err = populateEtcd(ctx, logger, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, etcdKeyPrefix, etcdValuePrefix, 1, 10, time.Second*1)
Expect(err).ShouldNot(HaveOccurred())

By("Check snapshot after putting data into etcd")
latestSnapshotsAfterPopulate, err := getLatestSnapshots(kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
latestSnapshotsAfterPopulate, err := getLatestSnapshots(ctx, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
Expect(err).ShouldNot(HaveOccurred())

Eventually(func() int {
latestSnapshotsAfterPopulate, err = getLatestSnapshots(kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
latestSnapshotsAfterPopulate, err = getLatestSnapshots(ctx, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
Expect(err).NotTo(HaveOccurred())
return len(latestSnapshotsAfterPopulate.DeltaSnapshots)
}, singleNodeEtcdTimeout, pollingInterval).Should(BeNumerically(">", len(latestSnapshotsBeforePopulate.DeltaSnapshots)))
Expand All @@ -116,7 +116,7 @@ var _ = Describe("Etcd Backup", func() {
Expect(latestSnapshotAfterPopulate.CreatedOn.After(latestSnapshotBeforePopulate.CreatedOn)).To(BeTrue())

By("Trigger on-demand full snapshot")
fullSnapshot, err := triggerOnDemandSnapshot(kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080, brtypes.SnapshotKindFull)
fullSnapshot, err := triggerOnDemandSnapshot(ctx, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080, brtypes.SnapshotKindFull)
Expect(err).ShouldNot(HaveOccurred())
Expect(fullSnapshot.LastRevision).To(Equal(10 + latestSnapshotBeforePopulate.LastRevision))

Expand All @@ -125,15 +125,15 @@ var _ = Describe("Etcd Backup", func() {
"fromKey", fmt.Sprintf("%s-11", etcdKeyPrefix), "fromValue", fmt.Sprintf("%s-11", etcdValuePrefix),
"toKey", fmt.Sprintf("%s-15", etcdKeyPrefix), "toValue", fmt.Sprintf("%s-15", etcdValuePrefix))
// populate 5 keys in etcd, finishing in 5 seconds
err = populateEtcd(logger, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, etcdKeyPrefix, etcdValuePrefix, 11, 15, time.Second*1)
err = populateEtcd(ctx, logger, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, etcdKeyPrefix, etcdValuePrefix, 11, 15, time.Second*1)
Expect(err).ShouldNot(HaveOccurred())

By("Trigger on-demand delta snapshot")
_, err = triggerOnDemandSnapshot(kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080, brtypes.SnapshotKindDelta)
_, err = triggerOnDemandSnapshot(ctx, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080, brtypes.SnapshotKindDelta)
Expect(err).ShouldNot(HaveOccurred())

By("Test cluster restoration by deleting data directory")
Expect(deleteDir(kubeconfigPath, namespace, debugPod.Name, debugPod.Spec.Containers[0].Name, "/var/etcd/data/new.etcd/member")).To(Succeed())
Expect(deleteDir(ctx, kubeconfigPath, namespace, debugPod.Name, debugPod.Spec.Containers[0].Name, "/var/etcd/data/new.etcd/member")).To(Succeed())

logger.Info("waiting for sts to become unready", "statefulSetName", etcdName)
Eventually(func() error {
Expand Down Expand Up @@ -169,7 +169,7 @@ var _ = Describe("Etcd Backup", func() {

// verify existence and correctness of keys 1 to 30
logger.Info("fetching etcd key-value pairs")
keyValueMap, err := getEtcdKeys(logger, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, etcdKeyPrefix, 1, 15)
keyValueMap, err := getEtcdKeys(ctx, logger, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, etcdKeyPrefix, 1, 15)
Expect(err).ShouldNot(HaveOccurred())

for i := 1; i <= 15; i++ {
Expand Down
20 changes: 10 additions & 10 deletions test/e2e/etcd_compaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var _ = Describe("Etcd Compaction", func() {

By("Check initial snapshot is available")

latestSnapshotsBeforePopulate, err := getLatestSnapshots(kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
latestSnapshotsBeforePopulate, err := getLatestSnapshots(ctx, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
Expect(err).ShouldNot(HaveOccurred())
// We don't expect any delta snapshot as the cluster
Expect(latestSnapshotsBeforePopulate.DeltaSnapshots).To(HaveLen(0))
Expand All @@ -87,16 +87,16 @@ var _ = Describe("Etcd Compaction", func() {
"toKey", fmt.Sprintf("%s-10", etcdKeyPrefix), "toValue", fmt.Sprintf("%s-10", etcdValuePrefix))

// populate 10 keys in etcd, finishing in 10 seconds
err = populateEtcd(logger, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, etcdKeyPrefix, etcdValuePrefix, 1, 10, time.Second*1)
err = populateEtcd(ctx, logger, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, etcdKeyPrefix, etcdValuePrefix, 1, 10, time.Second*1)
Expect(err).ShouldNot(HaveOccurred())

By("Check snapshot after putting data into etcd")

latestSnapshotsAfterPopulate, err := getLatestSnapshots(kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
latestSnapshotsAfterPopulate, err := getLatestSnapshots(ctx, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
Expect(err).ShouldNot(HaveOccurred())

Eventually(func() int {
latestSnapshotsAfterPopulate, err = getLatestSnapshots(kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
latestSnapshotsAfterPopulate, err = getLatestSnapshots(ctx, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
Expect(err).NotTo(HaveOccurred())
return len(latestSnapshotsAfterPopulate.DeltaSnapshots)
}, singleNodeEtcdTimeout, pollingInterval).Should(BeNumerically(">", len(latestSnapshotsBeforePopulate.DeltaSnapshots)))
Expand All @@ -114,11 +114,11 @@ var _ = Describe("Etcd Compaction", func() {
"fromKey", fmt.Sprintf("%s-11", etcdKeyPrefix), "fromValue", fmt.Sprintf("%s-11", etcdValuePrefix),
"toKey", fmt.Sprintf("%s-15", etcdKeyPrefix), "toValue", fmt.Sprintf("%s-15", etcdValuePrefix))
// populate 5 keys in etcd, finishing in 5 seconds
err = populateEtcd(logger, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, etcdKeyPrefix, etcdValuePrefix, 11, 15, time.Second*1)
err = populateEtcd(ctx, logger, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, etcdKeyPrefix, etcdValuePrefix, 11, 15, time.Second*1)
Expect(err).ShouldNot(HaveOccurred())

By("Trigger on-demand delta snapshot")
_, err = triggerOnDemandSnapshot(kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080, brtypes.SnapshotKindDelta)
_, err = triggerOnDemandSnapshot(ctx, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080, brtypes.SnapshotKindDelta)
Expect(err).ShouldNot(HaveOccurred())

logger.Info("waiting for compaction job to become successful")
Expand All @@ -145,7 +145,7 @@ var _ = Describe("Etcd Compaction", func() {
logger.Info("compaction job is successful")

By("Verify that all the delta snapshots are compacted to full snapshots by compaction triggerred at first 15th revision")
latestSnapshotsAfterPopulate, err = getLatestSnapshots(kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
latestSnapshotsAfterPopulate, err = getLatestSnapshots(ctx, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
Expect(err).ShouldNot(HaveOccurred())

Expect(len(latestSnapshotsAfterPopulate.DeltaSnapshots)).Should(BeNumerically("==", 0))
Expand All @@ -155,15 +155,15 @@ var _ = Describe("Etcd Compaction", func() {
"fromKey", fmt.Sprintf("%s-16", etcdKeyPrefix), "fromValue", fmt.Sprintf("%s-16", etcdValuePrefix),
"toKey", fmt.Sprintf("%s-20", etcdKeyPrefix), "toValue", fmt.Sprintf("%s-20", etcdValuePrefix))
// populate 5 keys in etcd, finishing in 5 seconds
err = populateEtcd(logger, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, etcdKeyPrefix, etcdValuePrefix, 16, 20, time.Second*1)
err = populateEtcd(ctx, logger, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, etcdKeyPrefix, etcdValuePrefix, 16, 20, time.Second*1)
Expect(err).ShouldNot(HaveOccurred())

By("Trigger on-demand delta snapshot")
_, err = triggerOnDemandSnapshot(kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080, brtypes.SnapshotKindDelta)
_, err = triggerOnDemandSnapshot(ctx, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080, brtypes.SnapshotKindDelta)
Expect(err).ShouldNot(HaveOccurred())

By("Verify that there are new delta snapshots as compaction is not triggered yet because delta events have not reached next 15 revision")
latestSnapshotsAfterPopulate, err = getLatestSnapshots(kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
latestSnapshotsAfterPopulate, err = getLatestSnapshots(ctx, kubeconfigPath, namespace, etcdName, debugPod.Name, debugPod.Spec.Containers[0].Name, 8080)
Expect(err).ShouldNot(HaveOccurred())

Expect(len(latestSnapshotsAfterPopulate.DeltaSnapshots)).Should(BeNumerically(">", 0))
Expand Down
16 changes: 14 additions & 2 deletions test/e2e/etcd_multi_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ var _ = Describe("Etcd", func() {
})

func deleteMemberDir(ctx context.Context, cl client.Client, logger logr.Logger, etcd *v1alpha1.Etcd, podName, containerName string) {
ExpectWithOffset(1, deleteDir(kubeconfigPath, namespace, podName, containerName, "/var/etcd/data/new.etcd/member")).To(Succeed())
ExpectWithOffset(1, deleteDir(ctx, kubeconfigPath, namespace, podName, containerName, "/var/etcd/data/new.etcd/member")).To(Succeed())
checkUnreadySts(ctx, cl, logger, etcd)
}

Expand Down Expand Up @@ -312,7 +312,19 @@ func hibernateAndCheckEtcd(ctx context.Context, cl client.Client, logger logr.Lo
etcd.Spec.Replicas = 0
return cl.Update(ctx, etcd)
})).ToNot(HaveOccurred())
logger.Info("Waiting to hibernate")

logger.Info("Waiting for statefulset spec to reflect change in replicas to 0")
EventuallyWithOffset(1, func() error {
sts := &appsv1.StatefulSet{}
ExpectWithOffset(2, cl.Get(ctx, client.ObjectKeyFromObject(etcd), sts)).To(Succeed())
if sts.Spec.Replicas == nil {
return fmt.Errorf("etcd %q replicas is empty", etcd.Name)
}
if *sts.Spec.Replicas != 0 {
return fmt.Errorf("etcd %q replicas is %d, but expected to be 0", etcd.Name, *sts.Spec.Replicas)
}
return nil
}, timeout, pollingInterval).Should(BeNil())

logger.Info("Checking etcd")
EventuallyWithOffset(1, func() error {
Expand Down
Loading

0 comments on commit 92dddad

Please sign in to comment.