Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generic cr in mesh #750

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
apiVersion: compute.functionmesh.io/v1alpha1
kind: FunctionMesh
metadata:
name: functionmesh-generic-sample
spec:
genericResources:
- apiVersion: "compute.functionmesh.io/v1alpha1"
kind: "Function"
name: java-function
spec:
name: java-function
image: streamnative/pulsar-functions-java-sample:3.2.2.1
className: org.apache.pulsar.functions.api.examples.ExclamationFunction
replicas: 1
maxReplicas: 1
input:
topics:
- persistent://public/default/functionmesh-generic-resource-input-topic
typeClassName: java.lang.String
output:
topic: persistent://public/default/functionmesh-generic-resource-java-topic
typeClassName: java.lang.String
pulsar:
pulsarConfig: "mesh-test-pulsar"
java:
jar: /pulsar/examples/api-examples.jar
forwardSourceMessageProperty: true
autoAck: true
resources:
requests:
cpu: "0.1"
memory: 1G
limits:
cpu: "0.2"
memory: 1.1G
clusterName: test
readyFields:
- "StatefulSet"
- "Service"
- apiVersion: "compute.functionmesh.io/v1alpha1"
kind: "Function"
name: golang-function
spec:
name: golang-function
image: streamnative/pulsar-functions-go-sample:3.2.2.1
replicas: 1
maxReplicas: 1
input:
topics:
- persistent://public/default/functionmesh-generic-resource-java-topic
typeClassName: java.lang.String
output:
topic: persistent://public/default/functionmesh-generic-resource-golang-topic
typeClassName: java.lang.String
pulsar:
pulsarConfig: "mesh-test-pulsar"
golang:
go: /pulsar/examples/go-exclamation-func
forwardSourceMessageProperty: true
autoAck: true
resources:
requests:
cpu: "0.1"
memory: 1G
limits:
cpu: "0.2"
memory: 1.1G
clusterName: test
readyFields:
- "StatefulSet"
- "Service"
- apiVersion: "compute.functionmesh.io/v1alpha1"
kind: "Function"
name: python-function
spec:
name: python-function
image: streamnative/pulsar-functions-python-sample:3.2.2.1
className: exclamation_function.ExclamationFunction
replicas: 1
maxReplicas: 1
input:
topics:
- persistent://public/default/functionmesh-generic-resource-golang-topic
typeClassName: java.lang.String
output:
topic: persistent://public/default/functionmesh-generic-resource-python-topic
typeClassName: java.lang.String
pulsar:
pulsarConfig: "mesh-test-pulsar"
python:
py: /pulsar/examples/python-examples/exclamation_function.py
forwardSourceMessageProperty: true
autoAck: true
resources:
requests:
cpu: "0.1"
memory: 1G
limits:
cpu: "0.2"
memory: 1.1G
clusterName: test
readyFields:
- "StatefulSet"
- "Service"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mesh-test-pulsar
data:
webServiceURL: http://sn-platform-pulsar-broker.default.svc.cluster.local:8080
brokerServiceURL: pulsar://sn-platform-pulsar-broker.default.svc.cluster.local:6650
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

set -e

E2E_DIR=$(dirname "$0")
BASE_DIR=$(cd "${E2E_DIR}"/../../../../..;pwd)
PULSAR_NAMESPACE=${PULSAR_NAMESPACE:-"default"}
PULSAR_RELEASE_NAME=${PULSAR_RELEASE_NAME:-"sn-platform"}
E2E_KUBECONFIG=${E2E_KUBECONFIG:-"/tmp/e2e-k8s.config"}

source "${BASE_DIR}"/.ci/helm.sh

if [ ! "$KUBECONFIG" ]; then
export KUBECONFIG=${E2E_KUBECONFIG}
fi

manifests_file="${BASE_DIR}"/.ci/tests/integration/cases/functionmesh-with-generic-resources/manifests.yaml

kubectl apply -f "${manifests_file}" > /dev/null 2>&1

verify_fm_result=$(ci::verify_function_mesh functionmesh-generic-sample-java-function 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_fm_result"
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

verify_fm_result=$(ci::verify_function_mesh functionmesh-generic-sample-golang-function 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_fm_result"
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

verify_fm_result=$(ci::verify_function_mesh functionmesh-generic-sample-python-function 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_fm_result"
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

verify_fm_result=$(NAMESPACE=${PULSAR_NAMESPACE} CLUSTER=${PULSAR_RELEASE_NAME} ci::verify_exclamation_function "persistent://public/default/functionmesh-generic-resource-input-topic" "persistent://public/default/functionmesh-generic-resource-python-topic" "test-message" "test-message!!!" 10 2>&1)
if [ $? -eq 0 ]; then
echo "e2e-test: ok" | yq eval -
else
echo "$verify_fm_result"
fi
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
2 changes: 2 additions & 0 deletions .ci/tests/integration/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ verify:
expected: expected.data.yaml
- query: timeout 5m bash .ci/tests/integration/cases/functionmesh/verify.sh
expected: expected.data.yaml
- query: timeout 5m bash .ci/tests/integration/cases/functionmesh-with-generic-resources/verify.sh
expected: expected.data.yaml
- query: timeout 5m bash .ci/tests/integration/cases/hpa/verify.sh
expected: expected.data.yaml
- query: timeout 5m bash .ci/tests/integration/cases/builtin-hpa/verify.sh
Expand Down
17 changes: 10 additions & 7 deletions api/compute/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,20 +369,23 @@ const (

// ResourceCondition The `Status` of a given `Condition` and the `Action` needed to reach the `Status`
type ResourceCondition struct {
Condition ResourceConditionType `json:"condition,omitempty"`
Status metav1.ConditionStatus `json:"status,omitempty"`
Action ReconcileAction `json:"action,omitempty"`
Condition ResourceConditionType `json:"condition,omitempty"`
Status metav1.ConditionStatus `json:"status,omitempty"`
Action ReconcileAction `json:"action,omitempty"`
APIVersion string `json:"apiVersion,omitempty"`
Kind string `json:"kind,omitempty"`
}

type ResourceConditionType string

const (
Orphaned ResourceConditionType = "Orphaned"

MeshReady ResourceConditionType = "MeshReady"
FunctionReady ResourceConditionType = "FunctionReady"
SourceReady ResourceConditionType = "SourceReady"
SinkReady ResourceConditionType = "SinkReady"
MeshReady ResourceConditionType = "MeshReady"
FunctionReady ResourceConditionType = "FunctionReady"
SourceReady ResourceConditionType = "SourceReady"
SinkReady ResourceConditionType = "SinkReady"
GenericResourceReady ResourceConditionType = "GenericResourceReady"

StatefulSetReady ResourceConditionType = "StatefulSetReady"
ServiceReady ResourceConditionType = "ServiceReady"
Expand Down
46 changes: 38 additions & 8 deletions api/compute/v1alpha1/functionmesh_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,50 @@ type FunctionMeshSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

Sources []SourceSpec `json:"sources,omitempty"`
Sinks []SinkSpec `json:"sinks,omitempty"`
Functions []FunctionSpec `json:"functions,omitempty"`
Sources []SourceSpec `json:"sources,omitempty"`
Sinks []SinkSpec `json:"sinks,omitempty"`
Functions []FunctionSpec `json:"functions,omitempty"`
GenericResources []GenericResourceSpec `json:"genericResources,omitempty"`
}

type GenericResourceSpec struct {
// +kubebuilder:validation:Required
APIVersion string `json:"apiVersion"`

// +kubebuilder:validation:Required
Kind string `json:"kind"`

// +kubebuilder:validation:Required
Name string `json:"name"`

// the field in the resource used to get the spec, default to "spec"
// +kubebuilder:validation:Optional
SpecFieldName string `json:"specFieldName,omitempty"`

// the field in the resource used to get the status, default to "status"
// +kubebuilder:validation:Optional
StatusFieldName string `json:"statusFieldName,omitempty"`

// the spec fields of the resource
// +kubebuilder:validation:Optional
// +kubebuilder:pruning:PreserveUnknownFields
Spec *Config `json:"spec,omitempty"`

// The fields in the `Status` field of Resource used to check whether the resource is ready
// should equal to ConditionTrue when it's ready
ReadyFields []string `json:"readyFields,omitempty"`
}

// FunctionMeshStatus defines the observed state of FunctionMesh
type FunctionMeshStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
SourceConditions map[string]ResourceCondition `json:"sourceConditions,omitempty"`
SinkConditions map[string]ResourceCondition `json:"sinkConditions,omitempty"`
FunctionConditions map[string]ResourceCondition `json:"functionConditions,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Condition *ResourceCondition `json:"condition,omitempty"`
SourceConditions map[string]ResourceCondition `json:"sourceConditions,omitempty"`
SinkConditions map[string]ResourceCondition `json:"sinkConditions,omitempty"`
FunctionConditions map[string]ResourceCondition `json:"functionConditions,omitempty"`
GenericResourceConditions map[string]ResourceCondition `json:"genericResourceConditions,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Condition *ResourceCondition `json:"condition,omitempty"`
}

// +genclient
Expand Down
39 changes: 38 additions & 1 deletion api/compute/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
{{- if eq .Values.admissionWebhook.certificate.provider "cert-manager" }}
{{- include "function-mesh-operator.certManager.annotation" . | nindent 4 -}}
{{- end }}
controller-gen.kubebuilder.io/version: v0.9.2
controller-gen.kubebuilder.io/version: v0.15.0
name: backendconfigs.compute.functionmesh.io
spec:
conversion:
Expand Down
Loading
Loading