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

Add BackendConfig crd to provider cluster wide and namespace wide configs #734

Merged
8 changes: 8 additions & 0 deletions .ci/clusters/global_mesh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: compute.functionmesh.io/v1alpha1
kind: MeshConfig
metadata:
name: mesh-global
spec:
env:
global1: globalvalue1
shared1: fromglobal
13 changes: 13 additions & 0 deletions .ci/helm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -596,3 +596,16 @@ function ci::verify_log_topic_with_auth() {
fi
return 1
}

function ci::verify_env() {
pod="$1-function-0"
key=$2
expect=$3
result=$(kubectl exec -n ${NAMESPACE} ${pod} -- env | grep "${key}")
echo "$result"
echo "$expect"
if [[ "$result" = "$expect" ]]; then
return 0
fi
return 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: compute.functionmesh.io/v1alpha1
kind: Function
metadata:
name: function-sample-env
namespace: default
spec:
image: streamnative/pulsar-functions-java-sample:2.9.2.23
className: org.apache.pulsar.functions.api.examples.ExclamationFunction
forwardSourceMessageProperty: true
maxPendingAsyncRequests: 1000
replicas: 1
maxReplicas: 5
logTopic: persistent://public/default/logging-function-logs
input:
topics:
- persistent://public/default/input-java-topic
typeClassName: java.lang.String
output:
topic: persistent://public/default/output-java-topic
typeClassName: java.lang.String
resources:
requests:
cpu: 50m
memory: 1G
limits:
memory: 1.1G
# each secret will be loaded ad an env variable from the `path` secret with the `key` in that secret in the name of `name`
secretsMap:
"name":
path: "test-secret"
key: "username"
"pwd":
path: "test-secret"
key: "password"
pulsar:
pulsarConfig: "test-pulsar"
tlsConfig:
enabled: false
allowInsecure: false
hostnameVerification: true
certSecretName: sn-platform-tls-broker
certSecretKey: ""
#authConfig: "test-auth"
java:
jar: /pulsar/examples/api-examples.jar
# to be delete & use admission hook
clusterName: test
autoAck: true
---
apiVersion: v1
kind: ConfigMap
metadata:
name: 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
#---
#apiVersion: v1
#kind: ConfigMap
#metadata:
# name: test-auth
#data:
# clientAuthenticationPlugin: "abc"
# clientAuthenticationParameters: "xyz"
# tlsTrustCertsFilePath: "uvw"
# useTls: "true"
# tlsAllowInsecureConnection: "false"
# tlsHostnameVerificationEnable: "true"
---
apiVersion: v1
data:
username: YWRtaW4=
password: MWYyZDFlMmU2N2Rm
kind: Secret
metadata:
name: test-secret
type: Opaque
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: compute.functionmesh.io/v1alpha1
kind: MeshConfig
metadata:
name: mesh-namespaced
namespace: kube-system
spec:
env:
namespaced1: namespacedvalue1
shared1: fromnamespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: compute.functionmesh.io/v1alpha1
kind: MeshConfig
metadata:
name: mesh-namespaced
namespace: default
spec:
env:
namespaced1: namespacedvalue1
shared1: fromnamespace
146 changes: 146 additions & 0 deletions .ci/tests/integration/cases/global-and-namespaced-config/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/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/global-and-namespaced-config/manifests.yaml
mesh_config_file="${BASE_DIR}"/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config.yaml
mesh_config_file_in_kube_system="${BASE_DIR}"/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config-kube-system.yaml
global_mesh_config_file="${BASE_DIR}"/.ci/clusters/global_mesh.yaml


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

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

verify_env_result=$(ci::verify_env "function-sample-env" global1 global1=globalvalue1 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

verify_env_result=$(ci::verify_env "function-sample-env" namespaced1 namespaced1=namespacedvalue1 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# if global and namespaced config has same key, the value from namespace should be used
verify_env_result=$(ci::verify_env "function-sample-env" shared1 shared1=fromnamespace 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

# delete the namespaced config, the function should be reconciled without namespaced env injected
kubectl delete -f "${mesh_config_file}" > /dev/null 2>&1
sleep 30

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

verify_env_result=$(ci::verify_env "function-sample-env" global1 global1=globalvalue1 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

verify_env_result=$(ci::verify_env "function-sample-env" shared1 shared1=fromglobal 2>&1)
if [ $? -ne 0 ]; then
echo "$verify_env_result"
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

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

# delete the global config, the function should be reconciled without global env injected
kubectl delete -f "${global_mesh_config_file}" -n $FUNCTION_MESH_NAMESPACE > /dev/null 2>&1 || true
sleep 30

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

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

# config created in an another namespace should not affect functions in other namespaces
kubectl apply -f "${mesh_config_file_in_kube_system}" > /dev/null 2>&1
sleep 30

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

verify_env_result=$(ci::verify_env "function-sample-env" namespaced1 "" 2>&1)
if [ $? -eq 0 ]; then
echo "e2e-test: ok" | yq eval -
else
echo "$verify_env_result"
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
exit 1
fi

kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
9 changes: 8 additions & 1 deletion .ci/tests/integration/e2e_with_tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,17 @@ setup:
image="function-mesh-operator:latest"
IMG=${image} make docker-build-skip-test
kind load docker-image ${image}
helm install ${FUNCTION_MESH_RELEASE_NAME} -n ${FUNCTION_MESH_NAMESPACE} --set operatorImage=${image} --create-namespace charts/function-mesh-operator
helm install ${FUNCTION_MESH_RELEASE_NAME} -n ${FUNCTION_MESH_NAMESPACE} --set operatorImage=${image} --set controllerManager.globalMeshConfig=mesh-global --set controllerManager.globalMeshConfigNamespace=${FUNCTION_MESH_NAMESPACE} --set controllerManager.namespacedMeshConfig=mesh-namespaced --create-namespace charts/function-mesh-operator
wait:
- namespace: function-mesh
resource: pod
label-selector: app.kubernetes.io/name=function-mesh-operator
for: condition=Ready

- name: apply global env config map
command: |
kubectl create -n ${FUNCTION_MESH_NAMESPACE} -f .ci/clusters/global_mesh.yaml

timeout: 60m

cleanup:
Expand Down Expand Up @@ -124,3 +129,5 @@ verify:
expected: expected.data.yaml
- query: bash .ci/tests/integration/cases/crypto-function/verify.sh
expected: expected.data.yaml
- query: timeout 5m bash .ci/tests/integration/cases/global-and-namespaced-config/verify.sh
expected: expected.data.yaml
10 changes: 6 additions & 4 deletions api/compute/v1alpha1/function_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ type FunctionSpec struct {
type FunctionStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Conditions map[Component]ResourceCondition `json:"conditions"`
Replicas int32 `json:"replicas"`
Selector string `json:"selector"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Conditions map[Component]ResourceCondition `json:"conditions"`
Replicas int32 `json:"replicas"`
Selector string `json:"selector"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
GlobalMeshConfigRevision string `json:"globalMeshConfigRevision,omitempty"`
NamespacedMeshConfigRevision string `json:"namespacedMeshConfigRevision,omitempty"`
}

// +genclient
Expand Down
70 changes: 70 additions & 0 deletions api/compute/v1alpha1/meshconfig_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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.

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// MeshConfigSpec defines the desired state of MeshConfig
// +kubebuilder:validation:Optional
type MeshConfigSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
Name string `json:"name,omitempty"`

// +kubebuilder:validation:Optional
Env map[string]string `json:"env,omitempty"`
}

// MeshConfigStatus defines the observed state of MeshConfig
type MeshConfigStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector

// MeshConfig is the Schema of the global configs for all functions, sinks and sources
// +kubebuilder:pruning:PreserveUnknownFields
type MeshConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec MeshConfigSpec `json:"spec,omitempty"`
Status MeshConfigStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// MeshConfigList contains a list of MeshConfig
type MeshConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []MeshConfig `json:"items"`
}

func init() {
SchemeBuilder.Register(&MeshConfig{}, &MeshConfigList{})
}
Loading
Loading