-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jorge Turrado <jorge_turrado@hotmail.es>
- Loading branch information
Showing
2 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
package assets | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
. "github.com/kedacore/keda/v2/tests/helper" | ||
) | ||
|
||
func TestRemoveKEDA(t *testing.T) { | ||
out, err := ExecuteCommandWithDir("make undeploy", "..") | ||
require.NoErrorf(t, err, "error removing KEDA - %s", err) | ||
|
||
t.Log(string(out)) | ||
t.Log("KEDA removed successfully using 'make undeploy' command") | ||
} | ||
|
||
func TestRemoveWorkloadIdentityComponents(t *testing.T) { | ||
if AzureRunWorkloadIdentityTests == "" || AzureRunWorkloadIdentityTests == "false" { | ||
t.Skip("skipping as workload identity tests are disabled") | ||
} | ||
|
||
_, err := ExecuteCommand(fmt.Sprintf("helm uninstall workload-identity-webhook --namespace %s", AzureWorkloadIdentityNamespace)) | ||
require.NoErrorf(t, err, "cannot uninstall workload identity webhook - %s", err) | ||
|
||
Kc = GetKubernetesClient(t) | ||
|
||
DeleteNamespace(t, Kc, AzureWorkloadIdentityNamespace) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
package assets | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os/exec" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
. "github.com/kedacore/keda/v2/tests/helper" | ||
) | ||
|
||
func TestVerifyCommands(t *testing.T) { | ||
commands := []string{"kubectl"} | ||
for _, cmd := range commands { | ||
_, err := exec.LookPath(cmd) | ||
require.NoErrorf(t, err, "%s is required for setup - %s", cmd, err) | ||
} | ||
} | ||
|
||
func TestKubernetesConnection(t *testing.T) { | ||
Kc = GetKubernetesClient(t) | ||
} | ||
|
||
func TestKubernetesVersion(t *testing.T) { | ||
out, err := ExecuteCommand("kubectl version") | ||
require.NoErrorf(t, err, "error getting kubernetes version - %s", err) | ||
|
||
t.Logf("kubernetes version: %s", string(out)) | ||
} | ||
|
||
func TestSetupHelm(t *testing.T) { | ||
_, err := exec.LookPath("helm") | ||
if err == nil { | ||
t.Skip("helm is already installed. skipping setup.") | ||
} | ||
|
||
_, err = ExecuteCommand("curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3") | ||
require.NoErrorf(t, err, "cannot download helm installation shell script - %s", err) | ||
|
||
_, err = ExecuteCommand("chmod 700 get_helm.sh") | ||
require.NoErrorf(t, err, "cannot change permissions for helm installation script - %s", err) | ||
|
||
_, err = ExecuteCommand("./get_helm.sh") | ||
require.NoErrorf(t, err, "cannot download helm - %s", err) | ||
|
||
_, err = ExecuteCommand("helm version") | ||
require.NoErrorf(t, err, "cannot get helm version - %s", err) | ||
} | ||
|
||
func TestSetupWorkloadIdentityComponents(t *testing.T) { | ||
if AzureRunWorkloadIdentityTests == "" || AzureRunWorkloadIdentityTests == "false" { | ||
t.Skip("skipping as workload identity tests are disabled") | ||
} | ||
|
||
_, err := ExecuteCommand("helm version") | ||
require.NoErrorf(t, err, "helm is not installed - %s", err) | ||
|
||
_, err = ExecuteCommand("helm repo add azure-workload-identity https://azure.github.io/azure-workload-identity/charts") | ||
require.NoErrorf(t, err, "cannot add workload identity helm repo - %s", err) | ||
|
||
_, err = ExecuteCommand("helm repo update azure-workload-identity") | ||
require.NoErrorf(t, err, "cannot update workload identity helm repo - %s", err) | ||
|
||
Kc = GetKubernetesClient(t) | ||
CreateNamespace(t, Kc, AzureWorkloadIdentityNamespace) | ||
|
||
_, err = ExecuteCommand(fmt.Sprintf("helm upgrade --install workload-identity-webhook azure-workload-identity/workload-identity-webhook --namespace %s --set azureTenantID=%s", | ||
AzureWorkloadIdentityNamespace, AzureADTenantID)) | ||
require.NoErrorf(t, err, "cannot install workload identity webhook - %s", err) | ||
|
||
workloadIdentityDeploymentName := "azure-wi-webhook-controller-manager" | ||
success := false | ||
for i := 0; i < 20; i++ { | ||
deployment, err := Kc.AppsV1().Deployments(AzureWorkloadIdentityNamespace).Get(context.Background(), workloadIdentityDeploymentName, v1.GetOptions{}) | ||
require.NoErrorf(t, err, "unable to get workload identity webhook deployment - %s", err) | ||
|
||
readyReplicas := deployment.Status.ReadyReplicas | ||
if readyReplicas != 2 { | ||
t.Log("workload identity webhook is not ready. sleeping") | ||
time.Sleep(5 * time.Second) | ||
} else { | ||
t.Log("workload identity webhook is ready") | ||
success = true | ||
|
||
time.Sleep(2 * time.Minute) // sleep for some time for webhook to setup properly | ||
break | ||
} | ||
} | ||
|
||
require.True(t, success, "expected workload identity webhook deployment to start 2 pods successfully") | ||
} | ||
|
||
func TestDeployKEDA(t *testing.T) { | ||
out, err := ExecuteCommandWithDir("make deploy", "..") | ||
require.NoErrorf(t, err, "error deploying KEDA - %s", err) | ||
|
||
t.Log(string(out)) | ||
t.Log("KEDA deployed successfully using 'make deploy' command") | ||
} | ||
|
||
func TestVerifyKEDA(t *testing.T) { | ||
success := false | ||
for i := 0; i < 20; i++ { | ||
operatorDeployment, err := Kc.AppsV1().Deployments(KEDANamespace).Get(context.Background(), KEDAOperator, v1.GetOptions{}) | ||
require.NoErrorf(t, err, "unable to get %s deployment - %s", KEDAOperator, err) | ||
|
||
metricsServerDeployment, err := Kc.AppsV1().Deployments(KEDANamespace).Get(context.Background(), KEDAMetricsAPIServer, v1.GetOptions{}) | ||
require.NoErrorf(t, err, "unable to get %s deployment - %s", KEDAMetricsAPIServer, err) | ||
|
||
operatorReadyReplicas := operatorDeployment.Status.ReadyReplicas | ||
metricsServerReadyReplicas := metricsServerDeployment.Status.ReadyReplicas | ||
|
||
if operatorReadyReplicas != 1 || metricsServerReadyReplicas != 1 { | ||
t.Log("KEDA is not ready. sleeping") | ||
time.Sleep(5 * time.Second) | ||
} else { | ||
t.Logf("KEDA is running 1 pod for %s and 1 pod for %s", KEDAOperator, KEDAMetricsAPIServer) | ||
success = true | ||
|
||
break | ||
} | ||
} | ||
|
||
require.True(t, success, "expected KEDA deployments to start 2 pods successfully") | ||
} |