Skip to content

Commit

Permalink
Feat: add new providers (#190)
Browse files Browse the repository at this point in the history
* feat: add new providers

Signed-off-by: FogDong <[email protected]>

* fix: lint

Signed-off-by: FogDong <[email protected]>

* fix: delete useless code

Signed-off-by: FogDong <[email protected]>

* fix: ignore package error

Signed-off-by: FogDong <[email protected]>

* fix: add test -v

Signed-off-by: FogDong <[email protected]>

* fix: set dynamic client

Signed-off-by: FogDong <[email protected]>

* fix: register schema

Signed-off-by: FogDong <[email protected]>

* fix: delete -v

Signed-off-by: FogDong <[email protected]>

* fix: fix test

Signed-off-by: FogDong <[email protected]>

---------

Signed-off-by: FogDong <[email protected]>
  • Loading branch information
FogDong authored Aug 13, 2024
1 parent 7d94489 commit 9d55737
Show file tree
Hide file tree
Showing 41 changed files with 3,497 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
with:
version: 3.1.0
kubebuilderOnly: false
kubernetesVersion: v1.21.2
kubernetesVersion: v1.28.0

- name: Run Make test
run: make test
Expand Down
81 changes: 81 additions & 0 deletions charts/vela-workflow/crds/cue.oam.dev_packages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
name: packages.cue.oam.dev
spec:
group: cue.oam.dev
names:
kind: Package
listKind: PackageList
plural: packages
shortNames:
- pkg
- cpkg
- cuepkg
- cuepackage
singular: package
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .spec.path
name: PATH
type: string
- jsonPath: .spec.provider.protocol
name: PROTO
type: string
- jsonPath: .spec.provider.endpoint
name: ENDPOINT
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: Package is an extension for cuex engine
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: PackageSpec the spec for Package
properties:
path:
type: string
provider:
description: Provider the external Provider in Package for cuex to
run functions
properties:
endpoint:
type: string
protocol:
description: ProviderProtocol the protocol type for external Provider
type: string
required:
- endpoint
- protocol
type: object
templates:
additionalProperties:
type: string
type: object
required:
- path
- templates
type: object
required:
- spec
type: object
served: true
storage: true
subresources: {}
6 changes: 6 additions & 0 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import (
"testing"

"github.com/crossplane/crossplane-runtime/pkg/event"
cuexv1alpha1 "github.com/kubevela/pkg/apis/cue/v1alpha1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic/fake"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -72,13 +74,17 @@ var _ = BeforeSuite(func() {
testScheme = scheme.Scheme
err = v1alpha1.AddToScheme(testScheme)
Expect(err).NotTo(HaveOccurred())
err = cuexv1alpha1.AddToScheme(testScheme)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: testScheme})
Expect(err).NotTo(HaveOccurred())
Expect(k8sClient).NotTo(BeNil())
singleton.KubeClient.Set(k8sClient)
fakeDynamicClient := fake.NewSimpleDynamicClient(testScheme)
singleton.DynamicClient.Set(fakeDynamicClient)

reconciler = &WorkflowRunReconciler{
Client: k8sClient,
Expand Down
20 changes: 11 additions & 9 deletions controllers/testdata/apply-object.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ spec:
cue:
template: |
import (
"vela/op"
"vela/kube"
)
apply: op.#Apply & {
value: parameter.value
cluster: parameter.cluster
apply: kube.#Apply & {
$params: {
value: parameter.value
cluster: parameter.cluster
}
}
parameter: {
// +usage=Specify the value of the object
value: {...}
// +usage=Specify the cluster of the object
cluster: *"" | string
}
// +usage=Specify Kubernetes native resource object to be applied
value: {...}
// +usage=The cluster you want to apply the resource to, default is the current control plane cluster
cluster: *"" | string
}
51 changes: 26 additions & 25 deletions controllers/testdata/suspend-and-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,44 @@ spec:
cue:
template: |
import (
"strconv"
"strings"
"vela/kube"
"vela/op"
)
suspend: op.#Suspend & {duration: "1s"}
output: op.#Apply & {
cluster: parameter.cluster
value: {
apiVersion: "apps/v1"
kind: "Deployment"
metadata: {
name: context.stepName
namespace: context.namespace
}
spec: {
selector: matchLabels: "workflow.oam.dev/step-name": "\(context.name)-\(context.stepName)"
replicas: parameter.replicas
template: {
metadata: labels: "workflow.oam.dev/step-name": "\(context.name)-\(context.stepName)"
spec: containers: [{
name: context.stepName
image: parameter.image
if parameter["cmd"] != _|_ {
command: parameter.cmd
}
}]
output: kube.#Apply & {
$params: {
cluster: parameter.cluster
value: {
apiVersion: "apps/v1"
kind: "Deployment"
metadata: {
name: context.stepName
namespace: context.namespace
}
spec: {
selector: matchLabels: "workflow.oam.dev/step-name": "\(context.name)-\(context.stepName)"
replicas: parameter.replicas
template: {
metadata: labels: "workflow.oam.dev/step-name": "\(context.name)-\(context.stepName)"
spec: containers: [{
name: context.stepName
image: parameter.image
if parameter["cmd"] != _|_ {
command: parameter.cmd
}
}]
}
}
}
}
}
wait: op.#ConditionalWait & {
continue: output.value.status.readyReplicas == parameter.replicas
continue: output.$returns.value.status.readyReplicas == parameter.replicas
}
parameter: {
image: string
replicas: *1 | int
cluster: *"" | string
cmd?: [...string]
}
75 changes: 39 additions & 36 deletions controllers/testdata/test-apply.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,48 @@ spec:
schematic:
cue:
template: |
import ( "vela/op"
import (
"vela/kube"
"vela/op"
)
output: op.#Apply & {
value: {
apiVersion: "apps/v1"
kind: "Deployment"
metadata: {
name: context.stepName
namespace: context.namespace
}
spec: {
selector: matchLabels: wr: context.stepName
template: {
metadata: labels: wr: context.stepName
spec: containers: [{
name: context.stepName
image: parameter.image
if parameter["cmd"] != _|_ {
command: parameter.cmd
}
if parameter["message"] != _|_ {
env: [{
name: "MESSAGE"
value: parameter.message
}]
}
}]
}
}
}
output: kube.#Apply & {
$params: value: {
apiVersion: "apps/v1"
kind: "Deployment"
metadata: {
name: context.stepName
namespace: context.namespace
}
spec: {
selector: matchLabels: wr: context.stepName
template: {
metadata: labels: wr: context.stepName
spec: containers: [{
name: context.stepName
image: parameter.image
if parameter["cmd"] != _|_ {
command: parameter.cmd
}
if parameter["message"] != _|_ {
env: [{
name: "MESSAGE"
value: parameter.message
}]
}
}]
}
}
}
}
wait: op.#ConditionalWait & {
if len(output.value.status) > 0 if output.value.status.readyReplicas == 1 {
continue: true
}
if len(output.$returns.value.status) > 0 if output.$returns.value.status.readyReplicas == 1 {
continue: true
}
}
parameter: {
image: string
cmd?: [...string]
message?: string
}
image: string
cmd?: [...string]
message?: string
}
4 changes: 2 additions & 2 deletions controllers/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ var _ = Describe("Test Workflow", func() {
Outputs: v1alpha1.StepOutputs{
{
Name: "message",
ValueFrom: `"message: " +output.value.status.conditions[0].message`,
ValueFrom: `"message: " +output.$returns.value.status.conditions[0].message`,
},
},
},
Expand Down Expand Up @@ -416,7 +416,7 @@ var _ = Describe("Test Workflow", func() {
Outputs: v1alpha1.StepOutputs{
{
Name: "message",
ValueFrom: `"message: " +output.value.status.conditions[0].message`,
ValueFrom: `"message: " +output.$returns.value.status.conditions[0].message`,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion makefiles/const.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ IMG_TAG ?= latest
OS ?= linux
ARCH ?= amd64
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.24.1
ENVTEST_K8S_VERSION = 1.28.0

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down
39 changes: 0 additions & 39 deletions pkg/cue/model/value/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,45 +109,6 @@ func TestFieldPath(t *testing.T) {
}
}

// func TestValueFix(t *testing.T) {
// testCases := []struct {
// original string
// expected string
// }{
// {
// original: `
// parameter: test: _
// // comment
// y: {
// for k, v in parameter.test.p {
// "\(k)": v
// }
// }`,
// expected: `{
// parameter: {
// test: _
// }
// // comment
// y: {
// for k, v in *parameter.test.p | {} {
// "\(k)": v
// }
// }
// }`,
// },
// }
// for i, tc := range testCases {
// t.Run(fmt.Sprint(i), func(t *testing.T) {
// r := require.New(t)
// v, err := NewValue(tc.original, nil, "")
// r.NoError(err)
// b, err := format.Node(v.CueValue().Syntax(cue.Docs(true)))
// r.NoError(err)
// r.Equal(tc.expected, string(b))
// })
// }
// }

func TestSetByScript(t *testing.T) {
testCases := []struct {
name string
Expand Down
Loading

0 comments on commit 9d55737

Please sign in to comment.