From edc3ba2141b82e76c7a04e5f3641781a2f4eda4a Mon Sep 17 00:00:00 2001 From: jiangpengcheng Date: Tue, 2 Jul 2024 17:20:35 +0800 Subject: [PATCH] Add pod field --- .ci/clusters/global_backend_config.yaml | 7 ++-- .../mesh-config-kube-system.yaml | 7 ++-- .../mesh-config.yaml | 7 ++-- api/compute/v1alpha1/backendconfig_types.go | 7 ++++ api/compute/v1alpha1/zz_generated.deepcopy.go | 28 +++++++++++++--- ...ompute.functionmesh.io-backendconfigs.yaml | 33 ++++++++++--------- ...ompute.functionmesh.io_backendconfigs.yaml | 33 ++++++++++--------- controllers/spec/common.go | 13 +++++--- 8 files changed, 88 insertions(+), 47 deletions(-) diff --git a/.ci/clusters/global_backend_config.yaml b/.ci/clusters/global_backend_config.yaml index 881748ee..8318b44f 100644 --- a/.ci/clusters/global_backend_config.yaml +++ b/.ci/clusters/global_backend_config.yaml @@ -6,6 +6,7 @@ spec: env: global1: globalvalue1 shared1: fromglobal - liveness: - initialDelaySeconds: 10 - periodSeconds: 30 + pod: + liveness: + initialDelaySeconds: 10 + periodSeconds: 30 diff --git a/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config-kube-system.yaml b/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config-kube-system.yaml index 9b320f75..332f259a 100644 --- a/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config-kube-system.yaml +++ b/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config-kube-system.yaml @@ -7,6 +7,7 @@ spec: env: namespaced1: namespacedvalue1 shared1: fromnamespace - liveness: - initialDelaySeconds: 50 - periodSeconds: 60 + pod: + liveness: + initialDelaySeconds: 50 + periodSeconds: 60 diff --git a/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config.yaml b/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config.yaml index e805921b..e4d48787 100644 --- a/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config.yaml +++ b/.ci/tests/integration/cases/global-and-namespaced-config/mesh-config.yaml @@ -7,6 +7,7 @@ spec: env: namespaced1: namespacedvalue1 shared1: fromnamespace - liveness: - initialDelaySeconds: 30 - periodSeconds: 10 + pod: + liveness: + initialDelaySeconds: 30 + periodSeconds: 10 diff --git a/api/compute/v1alpha1/backendconfig_types.go b/api/compute/v1alpha1/backendconfig_types.go index 888d728a..8b7253de 100644 --- a/api/compute/v1alpha1/backendconfig_types.go +++ b/api/compute/v1alpha1/backendconfig_types.go @@ -34,6 +34,13 @@ type BackendConfigSpec struct { // +kubebuilder:validation:Optional Env map[string]string `json:"env,omitempty"` + // +kubebuilder:validation:Optional + Pod *BackendConfigPodPolicy `json:"pod,omitempty"` +} + +// BackendConfigPodPolicy defines the policy for the pod +// TODO: Support more fields from PodPolicy +type BackendConfigPodPolicy struct { // +kubebuilder:validation:Optional Liveness *Liveness `json:"liveness,omitempty"` } diff --git a/api/compute/v1alpha1/zz_generated.deepcopy.go b/api/compute/v1alpha1/zz_generated.deepcopy.go index 1c58c85e..c0053563 100644 --- a/api/compute/v1alpha1/zz_generated.deepcopy.go +++ b/api/compute/v1alpha1/zz_generated.deepcopy.go @@ -113,6 +113,26 @@ func (in *BackendConfigList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BackendConfigPodPolicy) DeepCopyInto(out *BackendConfigPodPolicy) { + *out = *in + if in.Liveness != nil { + in, out := &in.Liveness, &out.Liveness + *out = new(Liveness) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BackendConfigPodPolicy. +func (in *BackendConfigPodPolicy) DeepCopy() *BackendConfigPodPolicy { + if in == nil { + return nil + } + out := new(BackendConfigPodPolicy) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *BackendConfigSpec) DeepCopyInto(out *BackendConfigSpec) { *out = *in @@ -123,10 +143,10 @@ func (in *BackendConfigSpec) DeepCopyInto(out *BackendConfigSpec) { (*out)[key] = val } } - if in.Liveness != nil { - in, out := &in.Liveness, &out.Liveness - *out = new(Liveness) - **out = **in + if in.Pod != nil { + in, out := &in.Pod, &out.Pod + *out = new(BackendConfigPodPolicy) + (*in).DeepCopyInto(*out) } } diff --git a/charts/function-mesh-operator/charts/admission-webhook/templates/crd-compute.functionmesh.io-backendconfigs.yaml b/charts/function-mesh-operator/charts/admission-webhook/templates/crd-compute.functionmesh.io-backendconfigs.yaml index 981af9aa..bd30e9f0 100644 --- a/charts/function-mesh-operator/charts/admission-webhook/templates/crd-compute.functionmesh.io-backendconfigs.yaml +++ b/charts/function-mesh-operator/charts/admission-webhook/templates/crd-compute.functionmesh.io-backendconfigs.yaml @@ -52,23 +52,26 @@ spec: additionalProperties: type: string type: object - liveness: - properties: - failureThreshold: - format: int32 - type: integer - initialDelaySeconds: - format: int32 - type: integer - periodSeconds: - format: int32 - type: integer - successThreshold: - format: int32 - type: integer - type: object name: type: string + pod: + properties: + liveness: + properties: + failureThreshold: + format: int32 + type: integer + initialDelaySeconds: + format: int32 + type: integer + periodSeconds: + format: int32 + type: integer + successThreshold: + format: int32 + type: integer + type: object + type: object type: object status: type: object diff --git a/config/crd/bases/compute.functionmesh.io_backendconfigs.yaml b/config/crd/bases/compute.functionmesh.io_backendconfigs.yaml index 82b58d82..5db956b8 100644 --- a/config/crd/bases/compute.functionmesh.io_backendconfigs.yaml +++ b/config/crd/bases/compute.functionmesh.io_backendconfigs.yaml @@ -30,23 +30,26 @@ spec: additionalProperties: type: string type: object - liveness: - properties: - failureThreshold: - format: int32 - type: integer - initialDelaySeconds: - format: int32 - type: integer - periodSeconds: - format: int32 - type: integer - successThreshold: - format: int32 - type: integer - type: object name: type: string + pod: + properties: + liveness: + properties: + failureThreshold: + format: int32 + type: integer + initialDelaySeconds: + format: int32 + type: integer + periodSeconds: + format: int32 + type: integer + successThreshold: + format: int32 + type: integer + type: object + type: object type: object status: type: object diff --git a/controllers/spec/common.go b/controllers/spec/common.go index 468f9fb9..25ca428e 100644 --- a/controllers/spec/common.go +++ b/controllers/spec/common.go @@ -20,6 +20,7 @@ package spec import ( "bytes" "context" + // used for template _ "embed" "encoding/json" @@ -306,8 +307,10 @@ func PatchStatefulSet(ctx context.Context, cli client.Client, namespace string, for key, val := range globalBackendConfig.Spec.Env { envData[key] = val } - if globalBackendConfig.Spec.Liveness != nil { - liveness = globalBackendConfig.Spec.Liveness + if globalBackendConfig.Spec.Pod != nil { + if globalBackendConfig.Spec.Pod.Liveness != nil { + liveness = globalBackendConfig.Spec.Pod.Liveness + } } } } @@ -329,8 +332,10 @@ func PatchStatefulSet(ctx context.Context, cli client.Client, namespace string, for key, val := range namespacedBackendConfig.Spec.Env { envData[key] = val } - if namespacedBackendConfig.Spec.Liveness != nil { - liveness = namespacedBackendConfig.Spec.Liveness + if namespacedBackendConfig.Spec.Pod != nil { + if namespacedBackendConfig.Spec.Pod.Liveness != nil { + liveness = namespacedBackendConfig.Spec.Pod.Liveness + } } } }