mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-18 03:56:36 +00:00
Chore: Add workflow addon testing (#6911)
* Chore: Add workflow addon testing Signed-off-by: Chaitanyareddy0702 <chaitanyareddy0702@gmail.com> * Feat(tests): Update addon tests to use correct command and deployment name Signed-off-by: Reetika Malhotra <malhotra.reetika25@gmail.com> * Feat(tests): Enhance addon tests with debugging information for deployment not found Signed-off-by: Reetika Malhotra <malhotra.reetika25@gmail.com> * Feat(tests): Add debugging output for listing WorkflowRuns in addon tests Signed-off-by: Reetika Malhotra <malhotra.reetika25@gmail.com> * Feat(tests): Improve debugging output for WorkflowRuns in addon tests Signed-off-by: Reetika Malhotra <malhotra.reetika25@gmail.com> * Feat(tests): Update addon test command path for enabling Workflow Signed-off-by: Reetika Malhotra <malhotra.reetika25@gmail.com> * Refactor: Clean up unused imports and commented-out code in addon tests Signed-off-by: Chaitanyareddy0702 <chaitanyareddy0702@gmail.com> * Feat(tests): Add debugging steps for addon registry in e2e tests Signed-off-by: Vishal Kumar <vishal210893@gmail.com> * Feat: Update vela-workflow version to v0.6.2 in mock server and tests Signed-off-by: Vishal Kumar <vishal210893@gmail.com> * Refactor: Remove debug commands from e2e tests and clean up addon test assertions Signed-off-by: Vishal Kumar <vishal210893@gmail.com> * Fix: run make reviewable Signed-off-by: Vishal Kumar <vishal210893@gmail.com> * Fix: Update assertions in addon tests to check for successful WorkflowRun phase Signed-off-by: Vishal Kumar <vishal210893@gmail.com> --------- Signed-off-by: Chaitanyareddy0702 <chaitanyareddy0702@gmail.com> Signed-off-by: Reetika Malhotra <malhotra.reetika25@gmail.com> Signed-off-by: Vishal Kumar <vishal210893@gmail.com> Co-authored-by: Vishal Kumar <vishal210893@gmail.com>
This commit is contained in:
co-authored by
Vishal Kumar
parent
707ae396ce
commit
af1ce628d1
@@ -32,8 +32,8 @@ entries:
|
||||
icon: https://static.kubevela.net/images/logos/KubeVela%20-03.png
|
||||
name: vela-workflow
|
||||
urls:
|
||||
- http://127.0.0.1:9098/helm/vela-workflow-v0.3.5.tgz
|
||||
version: v0.3.5
|
||||
- http://127.0.0.1:9098/helm/vela-workflow-v0.6.2.tgz
|
||||
version: v0.6.2
|
||||
foo:
|
||||
- created: "2022-10-29T09:11:16.865230605Z"
|
||||
description: Vela test addon named foo
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -125,8 +125,8 @@ var helmHandler http.HandlerFunc = func(rw http.ResponseWriter, req *http.Reques
|
||||
_, _ = rw.Write([]byte(err.Error()))
|
||||
}
|
||||
rw.Write(file)
|
||||
case strings.Contains(req.URL.Path, "vela-workflow-v0.3.5.tgz"):
|
||||
file, err := os.ReadFile("./e2e/addon/mock/testrepo/helm-repo/vela-workflow-v0.3.5.tgz")
|
||||
case strings.Contains(req.URL.Path, "vela-workflow-v0.6.2.tgz"):
|
||||
file, err := os.ReadFile("./e2e/addon/mock/testrepo/helm-repo/vela-workflow-v0.6.2.tgz")
|
||||
if err != nil {
|
||||
_, _ = rw.Write([]byte(err.Error()))
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func setupMockServer() *httptest.Server {
|
||||
"index.yaml",
|
||||
"fluxcd-test-version-1.0.0.tgz",
|
||||
"fluxcd-test-version-2.0.0.tgz",
|
||||
"vela-workflow-v0.3.5.tgz",
|
||||
"vela-workflow-v0.6.2.tgz",
|
||||
"foo-v1.0.0.tgz",
|
||||
"bar-v1.0.0.tgz",
|
||||
"bar-v2.0.0.tgz",
|
||||
|
||||
@@ -21,17 +21,22 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"os/exec"
|
||||
"strconv"
|
||||
|
||||
"time"
|
||||
|
||||
terraformv1beta1 "github.com/oam-dev/terraform-controller/api/v1beta1"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
workflowv1alpha1 "github.com/kubevela/workflow/api/v1alpha1"
|
||||
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||
"github.com/oam-dev/kubevela/pkg/oam/util"
|
||||
"github.com/oam-dev/kubevela/pkg/utils/common"
|
||||
@@ -132,4 +137,41 @@ var _ = Describe("Addon tests", func() {
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(string(output)).Should(ContainSubstring("enabled successfully"))
|
||||
})
|
||||
|
||||
It("Addon Workflow is successfully enabled and WorkflowRun creates Deployment", func() {
|
||||
By("Install Addon Workflow")
|
||||
|
||||
output, err := exec.Command("bash", "-c", "/tmp/vela addon enable vela-workflow").Output()
|
||||
var ee *exec.ExitError
|
||||
if errors.As(err, &ee) {
|
||||
fmt.Println("exit code error:", string(ee.Stderr))
|
||||
}
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(string(output)).Should(ContainSubstring("enabled successfully"))
|
||||
|
||||
By("Apply a WorkflowRun which creates a Deployment")
|
||||
var wr workflowv1alpha1.WorkflowRun
|
||||
Expect(common.ReadYamlToObject("./testdata/workflow/workflowrun_nginx.yaml", &wr)).Should(BeNil())
|
||||
// set namespace to dynamically created test namespace
|
||||
wr.Namespace = namespaceName
|
||||
Eventually(func() error { return k8sClient.Create(ctx, wr.DeepCopy()) }, 20*time.Second, 500*time.Millisecond).Should(Succeed())
|
||||
|
||||
By("Verify the Deployment is created by WorkflowRun")
|
||||
Eventually(func() error {
|
||||
var deploy appsv1.Deployment
|
||||
return k8sClient.Get(ctx, client.ObjectKey{Name: "apply-nginx-deployment", Namespace: namespaceName}, &deploy)
|
||||
}, 180*time.Second, 2*time.Second).Should(Succeed())
|
||||
|
||||
By("Check the WorkflowRun reaches a succeeded phase")
|
||||
Eventually(func() error {
|
||||
var latest workflowv1alpha1.WorkflowRun
|
||||
if err := k8sClient.Get(ctx, client.ObjectKey{Name: wr.Name, Namespace: namespaceName}, &latest); err != nil {
|
||||
return err
|
||||
}
|
||||
if latest.Status.Phase == workflowv1alpha1.WorkflowStateSucceeded {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("workflowrun not finished, current phase: %s", latest.Status.Phase)
|
||||
}, 300*time.Second, 2*time.Second).Should(Succeed())
|
||||
})
|
||||
})
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
workflowv1alpha1 "github.com/kubevela/workflow/api/v1alpha1"
|
||||
terraformv1beta1 "github.com/oam-dev/terraform-controller/api/v1beta1"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
@@ -57,6 +58,8 @@ var _ = BeforeSuite(func() {
|
||||
Expect(err).Should(BeNil())
|
||||
err = terraformv1beta1.AddToScheme(scheme)
|
||||
Expect(err).Should(BeNil())
|
||||
err = workflowv1alpha1.AddToScheme(scheme)
|
||||
Expect(err).Should(BeNil())
|
||||
By("Setting up kubernetes client")
|
||||
k8sClient, err = client.New(config.GetConfigOrDie(), client.Options{Scheme: scheme})
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: terraform-pod-sample
|
||||
spec:
|
||||
components:
|
||||
- name: sample-pod
|
||||
type: terraform-k8s-pod
|
||||
properties:
|
||||
name: tf-sample-pod
|
||||
namespace: ___NAMESPACE___
|
||||
image: nginx:1.25-alpine
|
||||
@@ -0,0 +1,65 @@
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: ComponentDefinition
|
||||
metadata:
|
||||
name: terraform-k8s-pod
|
||||
namespace: vela-system
|
||||
annotations:
|
||||
definition.oam.dev/description: Terraform configuration to create a Kubernetes Pod via the kubernetes provider
|
||||
labels:
|
||||
type: terraform
|
||||
spec:
|
||||
workload:
|
||||
definition:
|
||||
apiVersion: terraform.core.oam.dev/v1beta1
|
||||
kind: Configuration
|
||||
schematic:
|
||||
terraform:
|
||||
configuration: |
|
||||
terraform {
|
||||
required_providers {
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
version = "~> 2.27"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# In-cluster provider auth (terraform-controller should run in cluster and inject)
|
||||
provider "kubernetes" {}
|
||||
|
||||
resource "kubernetes_pod" "example" {
|
||||
metadata {
|
||||
name = var.name
|
||||
namespace = var.namespace
|
||||
labels = {
|
||||
app = "tf-sample"
|
||||
}
|
||||
}
|
||||
spec {
|
||||
container {
|
||||
image = var.image
|
||||
name = "nginx"
|
||||
port {
|
||||
container_port = 80
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output "POD_NAME" {
|
||||
value = kubernetes_pod.example.metadata[0].name
|
||||
}
|
||||
|
||||
variable "name" {
|
||||
type = string
|
||||
description = "Name of the Pod to create"
|
||||
}
|
||||
variable "namespace" {
|
||||
type = string
|
||||
description = "Namespace in which to create the Pod"
|
||||
}
|
||||
variable "image" {
|
||||
type = string
|
||||
default = "nginx:1.25-alpine"
|
||||
description = "Container image"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
apiVersion: core.oam.dev/v1alpha1
|
||||
kind: WorkflowRun
|
||||
metadata:
|
||||
name: deploy-nginx
|
||||
namespace: default
|
||||
spec:
|
||||
workflowSpec:
|
||||
steps:
|
||||
- name: apply-nginx-deployment
|
||||
type: apply-deployment
|
||||
properties:
|
||||
image: nginx:latest
|
||||
replicas: 1
|
||||
Reference in New Issue
Block a user