Skip to content

Commit

Permalink
Add persistentVolumeClaimRetentionPolicy field (#633)
Browse files Browse the repository at this point in the history
* Add persistentVolumeClaimRetentionPolicy field

* Add if
  • Loading branch information
jiangpengcheng authored May 8, 2023
1 parent 5dfa387 commit 8f16303
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 7 deletions.
4 changes: 4 additions & 0 deletions api/compute/v1alpha1/function_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package v1alpha1

import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -101,6 +102,9 @@ type FunctionSpec struct {

// +kubebuilder:validation:Optional
VolumeClaimTemplates []corev1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty"`

// +kubebuilder:validation:Optional
PersistentVolumeClaimRetentionPolicy *appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy `json:"persistentVolumeClaimRetentionPolicy,omitempty"`
}

// FunctionStatus defines the observed state of Function
Expand Down
6 changes: 6 additions & 0 deletions 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 @@ -295,6 +295,13 @@ spec:
typeClassName:
type: string
type: object
persistentVolumeClaimRetentionPolicy:
properties:
whenDeleted:
type: string
whenScaled:
type: string
type: object
pod:
properties:
affinity:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ spec:
typeClassName:
type: string
type: object
persistentVolumeClaimRetentionPolicy:
properties:
whenDeleted:
type: string
whenScaled:
type: string
type: object
pod:
properties:
affinity:
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/compute.functionmesh.io_functionmeshes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@ spec:
typeClassName:
type: string
type: object
persistentVolumeClaimRetentionPolicy:
properties:
whenDeleted:
type: string
whenScaled:
type: string
type: object
pod:
properties:
affinity:
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/compute.functionmesh.io_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ spec:
typeClassName:
type: string
type: object
persistentVolumeClaimRetentionPolicy:
properties:
whenDeleted:
type: string
whenScaled:
type: string
type: object
pod:
properties:
affinity:
Expand Down
12 changes: 9 additions & 3 deletions controllers/spec/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ func MakeStatefulSet(objectMeta *metav1.ObjectMeta, replicas *int32, downloaderI
volumes []corev1.Volume, labels map[string]string, policy v1alpha1.PodPolicy, pulsar v1alpha1.PulsarMessaging,
javaRuntime *v1alpha1.JavaRuntime, pythonRuntime *v1alpha1.PythonRuntime,
goRuntime *v1alpha1.GoRuntime, definedVolumeMounts []corev1.VolumeMount,
volumeClaimTemplates []corev1.PersistentVolumeClaim) *appsv1.StatefulSet {
volumeClaimTemplates []corev1.PersistentVolumeClaim,
persistentVolumeClaimRetentionPolicy *appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy) *appsv1.StatefulSet {

volumeMounts := generateDownloaderVolumeMountsForDownloader(javaRuntime, pythonRuntime, goRuntime)
var downloaderContainer *corev1.Container
Expand Down Expand Up @@ -323,13 +324,15 @@ func MakeStatefulSet(objectMeta *metav1.ObjectMeta, replicas *int32, downloaderI
},
ObjectMeta: *objectMeta,
Spec: *MakeStatefulSetSpec(replicas, container, podVolumes, labels, policy,
MakeHeadlessServiceName(objectMeta.Name), downloaderContainer, volumeClaimTemplates),
MakeHeadlessServiceName(objectMeta.Name), downloaderContainer, volumeClaimTemplates,
persistentVolumeClaimRetentionPolicy),
}
}

func MakeStatefulSetSpec(replicas *int32, container *corev1.Container,
volumes []corev1.Volume, labels map[string]string, policy v1alpha1.PodPolicy,
serviceName string, downloaderContainer *corev1.Container, volumeClaimTemplates []corev1.PersistentVolumeClaim) *appsv1.StatefulSetSpec {
serviceName string, downloaderContainer *corev1.Container, volumeClaimTemplates []corev1.PersistentVolumeClaim,
persistentVolumeClaimRetentionPolicy *appsv1.StatefulSetPersistentVolumeClaimRetentionPolicy) *appsv1.StatefulSetSpec {
spec := &appsv1.StatefulSetSpec{
Replicas: replicas,
Selector: &metav1.LabelSelector{
Expand All @@ -345,6 +348,9 @@ func MakeStatefulSetSpec(replicas *int32, container *corev1.Container,
if len(volumeClaimTemplates) > 0 {
spec.VolumeClaimTemplates = volumeClaimTemplates
}
if persistentVolumeClaimRetentionPolicy != nil {
spec.PersistentVolumeClaimRetentionPolicy = persistentVolumeClaimRetentionPolicy
}
return spec
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/spec/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func MakeFunctionStatefulSet(function *v1alpha1.Function) *appsv1.StatefulSet {
return MakeStatefulSet(objectMeta, function.Spec.Replicas, function.Spec.DownloaderImage,
makeFunctionContainer(function), makeFunctionVolumes(function, function.Spec.Pulsar.AuthConfig), makeFunctionLabels(function), function.Spec.Pod,
*function.Spec.Pulsar, function.Spec.Java, function.Spec.Python, function.Spec.Golang,
function.Spec.VolumeMounts, function.Spec.VolumeClaimTemplates)
function.Spec.VolumeMounts, function.Spec.VolumeClaimTemplates, function.Spec.PersistentVolumeClaimRetentionPolicy)
}

func MakeFunctionObjectMeta(function *v1alpha1.Function) *metav1.ObjectMeta {
Expand Down
2 changes: 1 addition & 1 deletion controllers/spec/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func MakeSinkStatefulSet(sink *v1alpha1.Sink) *appsv1.StatefulSet {
objectMeta := MakeSinkObjectMeta(sink)
return MakeStatefulSet(objectMeta, sink.Spec.Replicas, sink.Spec.DownloaderImage, makeSinkContainer(sink),
makeSinkVolumes(sink, sink.Spec.Pulsar.AuthConfig), makeSinkLabels(sink), sink.Spec.Pod, *sink.Spec.Pulsar,
sink.Spec.Java, sink.Spec.Python, sink.Spec.Golang, sink.Spec.VolumeMounts, nil)
sink.Spec.Java, sink.Spec.Python, sink.Spec.Golang, sink.Spec.VolumeMounts, nil, nil)
}

func MakeSinkServiceName(sink *v1alpha1.Sink) string {
Expand Down
2 changes: 1 addition & 1 deletion controllers/spec/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func MakeSourceStatefulSet(source *v1alpha1.Source) *appsv1.StatefulSet {
objectMeta := MakeSourceObjectMeta(source)
return MakeStatefulSet(objectMeta, source.Spec.Replicas, source.Spec.DownloaderImage, makeSourceContainer(source),
makeSourceVolumes(source, source.Spec.Pulsar.AuthConfig), makeSourceLabels(source), source.Spec.Pod, *source.Spec.Pulsar,
source.Spec.Java, source.Spec.Python, source.Spec.Golang, source.Spec.VolumeMounts, nil)
source.Spec.Java, source.Spec.Python, source.Spec.Golang, source.Spec.VolumeMounts, nil, nil)
}

func MakeSourceObjectMeta(source *v1alpha1.Source) *metav1.ObjectMeta {
Expand Down
2 changes: 1 addition & 1 deletion hack/gen-helm-crd-templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function crd::convert_webhook() {
echo "clientConfig:" | sed "s/^/$(crd::nindent 1)/"
# webhook.clientConfig.caBundle
echo "{{- if eq .Values.admissionWebhook.certificate.provider \"custom\" }}" | sed "s/^/$(crd::nindent 2)/"
echo "{{- \$caSecret := (lookup \"v1\" \"Secret\" \"default\" (include \"function-mesh-operator.certificate.caSecret\" .)) -}}" | sed "s/^/$(crd::nindent 3)/"
echo "{{- \$caSecret := (lookup \"v1\" \"Secret\" .Values.admissionWebhook.secretsWebhookNamespace (include \"function-mesh-operator.certificate.caSecret\" .)) -}}" | sed "s/^/$(crd::nindent 3)/"
echo "{{- if \$caSecret }}" | sed "s/^/$(crd::nindent 3)/"
echo "{{- \$caCert := (b64dec (get \$caSecret.data \"tls.crt\")) -}}" | sed "s/^/$(crd::nindent 4)/"
echo "{{ printf (include \"function-mesh-operator.caBundle\" .) (b64enc \$caCert) | nindent 8 }}" | sed "s/^/$(crd::nindent 4)/"
Expand Down

0 comments on commit 8f16303

Please sign in to comment.