Skip to content

Commit

Permalink
test: adds e2e for arc reconciliation (#679)
Browse files Browse the repository at this point in the history
* feat: adds e2e for arc reconciliation

Signed-off-by: Nilekh Chaudhari <[email protected]>

* test: removes focus test

Signed-off-by: Nilekh Chaudhari <[email protected]>

* chore: fixes template path

Signed-off-by: Nilekh Chaudhari <[email protected]>

* test: removes unused imports

Signed-off-by: Nilekh Chaudhari <[email protected]>

* chore: removes debug

Signed-off-by: Nilekh Chaudhari <[email protected]>

* chore: removes unused import

Signed-off-by: Nilekh Chaudhari <[email protected]>
  • Loading branch information
nilekhc authored Oct 22, 2021
1 parent 2e8d907 commit 68603a6
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .pipelines/templates/e2e-test-kind-arc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,5 @@ jobs:
TENANT_ID: $(TENANT_ID)
CI_KIND_CLUSTER: true
AZURE_ENVIRONMENT_FILEPATH: $(AZURE_ENVIRONMENT_FILEPATH)
# setting IS_SOAK_TEST env var since arc extension manages installation of chart.
IS_SOAK_TEST: true
IS_ARC_TEST: true
- template: teardown.yaml
61 changes: 61 additions & 0 deletions test/e2e/arc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//go:build e2e
// +build e2e

package e2e

import (
"time"

"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework"
"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework/daemonset"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
)

var _ = Describe("When extension arguments are manually overridden", func() {
var (
daemonSet *appsv1.DaemonSet
newRotationPollIntervalValue = "--rotation-poll-interval=1m"
secretStoreCSIDriverName = "secrets-store-csi-driver"
)

It("should reconcile them to original values", func() {
if !config.IsArcTest {
Skip("test case only runs while testing arc extension")
}

daemonSet = daemonset.Get(daemonset.GetInput{
Namespace: framework.NamespaceKubeSystem,
Name: secretStoreCSIDriverName,
Getter: kubeClient,
})
Expect(daemonSet).NotTo(BeNil())

daemonSet.Spec.Template.Spec.Containers[1].Args = append(daemonSet.Spec.Template.Spec.Containers[1].Args, newRotationPollIntervalValue)
daemonSet = daemonset.Update(daemonset.UpdateInput{
Updater: kubeClient,
DaemonSet: daemonSet,
})
Expect(daemonSet).NotTo(BeNil())

// waiting for 300 seconds since 'reconcilerIntervalInSeconds' is set to this value in extension configuration
By("Waiting for arc extension to reconcile the arguments")
time.Sleep(time.Second * 300)

daemonSet = daemonset.Get(daemonset.GetInput{
Namespace: framework.NamespaceKubeSystem,
Name: secretStoreCSIDriverName,
Getter: kubeClient,
})
Expect(daemonSet).NotTo(BeNil())

for _, arg := range daemonSet.Spec.Template.Spec.Containers[1].Args {
if arg == newRotationPollIntervalValue {
// Manually overridden value should be reverted by arc extension reconciliation
Expect(arg).NotTo(Equal(newRotationPollIntervalValue))
}
}
})
})
4 changes: 2 additions & 2 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var _ = BeforeSuite(func() {
By("Creating a Keyvault Client")
kvClient = keyvault.NewClient(config)

if config.IsSoakTest {
if config.IsSoakTest || config.IsArcTest {
return
}

Expand Down Expand Up @@ -107,7 +107,7 @@ var _ = AfterSuite(func() {
// cleanup
defer func() {
// uninstall if it's not Soak Test, not backward compatibility test and if cluster is already upgraded or it's not cluster upgrade test
if !config.IsSoakTest && !config.IsBackwardCompatibilityTest && (!config.IsUpgradeTest || config.IsClusterUpgraded) {
if !config.IsSoakTest && !config.IsArcTest && !config.IsBackwardCompatibilityTest && (!config.IsUpgradeTest || config.IsClusterUpgraded) {
if helm.ReleaseExists() {
By("Uninstalling Secrets Store CSI Driver and Azure Key Vault Provider via Helm")
helm.Uninstall()
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/framework/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Config struct {
IsClusterUpgraded bool `envconfig:"IS_CLUSTER_UPGRADED"`
IsBackwardCompatibilityTest bool `envconfig:"IS_BACKWARD_COMPATIBILITY_TEST"`
AzureEnvironmentFilePath string `envconfig:"AZURE_ENVIRONMENT_FILEPATH"`
IsArcTest bool `envconfig:"IS_ARC_TEST" default:"false"`
}

func (c *Config) DeepCopy() *Config {
Expand Down Expand Up @@ -61,6 +62,7 @@ func (c *Config) DeepCopy() *Config {
copy.IsBackwardCompatibilityTest = c.IsBackwardCompatibilityTest
copy.AzureEnvironmentFilePath = c.AzureEnvironmentFilePath
copy.IsHelmTest = c.IsHelmTest
copy.IsArcTest = c.IsArcTest

return copy
}
Expand Down
53 changes: 53 additions & 0 deletions test/e2e/framework/daemonset/daemonset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//go:build e2e
// +build e2e

package daemonset

import (
"context"
"fmt"

"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/types"
)

// GetInput is the input for Get.
type GetInput struct {
Getter framework.Getter
Name string
Namespace string
}

// Get gets a DaemonSet resource.
func Get(input GetInput) *appsv1.DaemonSet {
Expect(input.Getter).NotTo(BeNil(), "input.Getter is required for DaemonSet.Get")
Expect(input.Name).NotTo(BeEmpty(), "input.Name is required for DaemonSet.Get")
Expect(input.Namespace).NotTo(BeEmpty(), "input.Namespace is required for DaemonSet.Get")

By(fmt.Sprintf("Getting DaemonSet \"%s\"", input.Name))

daemonSet := &appsv1.DaemonSet{}
Expect(input.Getter.Get(context.TODO(), types.NamespacedName{Name: input.Name, Namespace: input.Namespace}, daemonSet)).Should(Succeed())
return daemonSet
}

// UpdateInput is the input for Update.
type UpdateInput struct {
Updater framework.Updater
DaemonSet *appsv1.DaemonSet
}

// Update updates a DaemonSet resource.
func Update(input UpdateInput) *appsv1.DaemonSet {
Expect(input.Updater).NotTo(BeNil(), "input.Updater is required for DaemonSet.Update")
Expect(input.DaemonSet).NotTo(BeNil(), "input.DaemonSet is required for DaemonSet.Update")

By(fmt.Sprintf("Updating DaemonSet \"%s/%s\"", input.DaemonSet.Namespace, input.DaemonSet.Name))

Expect(input.Updater.Update(context.TODO(), input.DaemonSet)).Should(Succeed())
return input.DaemonSet
}

0 comments on commit 68603a6

Please sign in to comment.