From 56fcf406d9379554b658faa777b7215e0c4fdeb7 Mon Sep 17 00:00:00 2001 From: Nick Vladiceanu Date: Fri, 17 Sep 2021 13:20:18 +0200 Subject: [PATCH 01/10] Adding lifecycle to the main container --- api/v1beta1/common_types.go | 4 + api/v1beta1/zz_generated.deepcopy.go | 5 + .../crd/bases/solr.apache.org_solrclouds.yaml | 134 +++++++++ ...lr.apache.org_solrprometheusexporters.yaml | 134 +++++++++ .../solrprometheusexporter_controller_test.go | 7 +- controllers/util/common.go | 13 +- controllers/util/prometheus_exporter_util.go | 5 +- controllers/util/solr_util.go | 22 +- helm/solr-operator/crds/crds.yaml | 268 ++++++++++++++++++ 9 files changed, 573 insertions(+), 19 deletions(-) diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index 838b9f5e..13984f4d 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -110,6 +110,10 @@ type PodOptions struct { // +optional PriorityClassName string `json:"priorityClassName,omitempty"` + // Lifecycle for the main container + // +optional + Lifecycle *corev1.Lifecycle `json:"lifecycle,omitempty"` + // Sidecar containers to run in the pod. These are in addition to the Solr Container // +optional SidecarContainers []corev1.Container `json:"sidecarContainers,omitempty"` diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 6560597e..9fb0fd96 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -465,6 +465,11 @@ func (in *PodOptions) DeepCopyInto(out *PodOptions) { *out = new(v1.Probe) (*in).DeepCopyInto(*out) } + if in.Lifecycle != nil { + in, out := &in.Lifecycle, &out.Lifecycle + *out = new(v1.Lifecycle) + (*in).DeepCopyInto(*out) + } if in.SidecarContainers != nil { in, out := &in.SidecarContainers, &out.SidecarContainers *out = make([]v1.Container, len(*in)) diff --git a/config/crd/bases/solr.apache.org_solrclouds.yaml b/config/crd/bases/solr.apache.org_solrclouds.yaml index 8632db70..bdd7eab8 100644 --- a/config/crd/bases/solr.apache.org_solrclouds.yaml +++ b/config/crd/bases/solr.apache.org_solrclouds.yaml @@ -1335,6 +1335,140 @@ spec: type: string description: Labels to be added for pods. type: object + lifecycle: + description: Lifecycle for the main container + properties: + postStart: + description: 'PostStart is called immediately after a container is created. If the handler fails, the container is terminated and restarted according to its restart policy. Other management of the container blocks until the hook completes. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: One and only one of the following should be specified. Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. The command is simply exec'd, it is not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use a shell, you need to explicitly call out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: 'TCPSocket specifies an action involving a TCP port. TCP hooks not yet supported TODO: implement a realistic TCP lifecycle hook' + properties: + host: + description: 'Optional: Host name to connect to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + preStop: + description: 'PreStop is called immediately before a container is terminated due to an API request or management event such as liveness/startup probe failure, preemption, resource contention, etc. The handler is not called if the container crashes or exits. The reason for termination is passed to the handler. The Pod''s termination grace period countdown begins before the PreStop hooked is executed. Regardless of the outcome of the handler, the container will eventually terminate within the Pod''s termination grace period. Other management of the container blocks until the hook completes or until the termination grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: One and only one of the following should be specified. Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. The command is simply exec'd, it is not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use a shell, you need to explicitly call out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: 'TCPSocket specifies an action involving a TCP port. TCP hooks not yet supported TODO: implement a realistic TCP lifecycle hook' + properties: + host: + description: 'Optional: Host name to connect to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + type: object livenessProbe: description: Liveness probe parameters properties: diff --git a/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml b/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml index e8d9f9bf..eb1a9e4d 100644 --- a/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml +++ b/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml @@ -1277,6 +1277,140 @@ spec: type: string description: Labels to be added for pods. type: object + lifecycle: + description: Lifecycle for the main container + properties: + postStart: + description: 'PostStart is called immediately after a container is created. If the handler fails, the container is terminated and restarted according to its restart policy. Other management of the container blocks until the hook completes. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: One and only one of the following should be specified. Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. The command is simply exec'd, it is not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use a shell, you need to explicitly call out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: 'TCPSocket specifies an action involving a TCP port. TCP hooks not yet supported TODO: implement a realistic TCP lifecycle hook' + properties: + host: + description: 'Optional: Host name to connect to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + preStop: + description: 'PreStop is called immediately before a container is terminated due to an API request or management event such as liveness/startup probe failure, preemption, resource contention, etc. The handler is not called if the container crashes or exits. The reason for termination is passed to the handler. The Pod''s termination grace period countdown begins before the PreStop hooked is executed. Regardless of the outcome of the handler, the container will eventually terminate within the Pod''s termination grace period. Other management of the container blocks until the hook completes or until the termination grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: One and only one of the following should be specified. Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. The command is simply exec'd, it is not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use a shell, you need to explicitly call out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: 'TCPSocket specifies an action involving a TCP port. TCP hooks not yet supported TODO: implement a realistic TCP lifecycle hook' + properties: + host: + description: 'Optional: Host name to connect to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + type: object livenessProbe: description: Liveness probe parameters properties: diff --git a/controllers/solrprometheusexporter_controller_test.go b/controllers/solrprometheusexporter_controller_test.go index d4b3a8d2..b25e84d8 100644 --- a/controllers/solrprometheusexporter_controller_test.go +++ b/controllers/solrprometheusexporter_controller_test.go @@ -20,6 +20,10 @@ package controllers import ( "crypto/md5" "fmt" + "strings" + "testing" + "time" + solr "github.com/apache/solr-operator/api/v1beta1" "github.com/apache/solr-operator/controllers/util" "github.com/onsi/gomega" @@ -34,9 +38,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" - "strings" - "testing" - "time" ) var _ reconcile.Reconciler = &SolrPrometheusExporterReconciler{} diff --git a/controllers/util/common.go b/controllers/util/common.go index 45074d44..1ef1ea67 100644 --- a/controllers/util/common.go +++ b/controllers/util/common.go @@ -18,6 +18,10 @@ package util import ( + "reflect" + "strconv" + "strings" + "github.com/go-logr/logr" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -25,10 +29,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/utils/pointer" - "reflect" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "strconv" - "strings" ) // CopyLabelsAndAnnotations copies the labels and annotations from one object to another. @@ -559,6 +560,12 @@ func CopyPodContainers(fromPtr, toPtr *[]corev1.Container, basePath string, logg to[i].StartupProbe = from[i].StartupProbe } + if !DeepEqualWithNils(to[i].Lifecycle, from[i].Lifecycle) { + requireUpdate = true + logger.Info("Update required because field changed", "field", containerBasePath+"Lifecycle", "from", to[i].Lifecycle, "to", from[i].Lifecycle) + to[i].Lifecycle = from[i].Lifecycle + } + if from[i].TerminationMessagePath != "" && !DeepEqualWithNils(to[i].TerminationMessagePath, from[i].TerminationMessagePath) { requireUpdate = true logger.Info("Update required because field changed", "field", containerBasePath+"TerminationMessagePath", "from", to[i].TerminationMessagePath, "to", from[i].TerminationMessagePath) diff --git a/controllers/util/prometheus_exporter_util.go b/controllers/util/prometheus_exporter_util.go index 99ee1d0f..3b6535c1 100644 --- a/controllers/util/prometheus_exporter_util.go +++ b/controllers/util/prometheus_exporter_util.go @@ -18,14 +18,15 @@ package util import ( + "strconv" + "strings" + solr "github.com/apache/solr-operator/api/v1beta1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" netv1 "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "strconv" - "strings" ) const ( diff --git a/controllers/util/solr_util.go b/controllers/util/solr_util.go index d686e0b8..0db550af 100644 --- a/controllers/util/solr_util.go +++ b/controllers/util/solr_util.go @@ -22,18 +22,19 @@ import ( b64 "encoding/base64" "encoding/json" "fmt" - solr "github.com/apache/solr-operator/api/v1beta1" - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - netv1 "k8s.io/api/networking/v1beta1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/intstr" "math/rand" "regexp" "sort" "strconv" "strings" "time" + + solr "github.com/apache/solr-operator/api/v1beta1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + netv1 "k8s.io/api/networking/v1beta1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" ) const ( @@ -422,11 +423,6 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl Env: envVars, Lifecycle: &corev1.Lifecycle{ PostStart: postStart, - PreStop: &corev1.Handler{ - Exec: &corev1.ExecAction{ - Command: []string{"solr", "stop", "-p", strconv.Itoa(solrPodPort)}, - }, - }, }, }, } @@ -522,6 +518,10 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl stateful.Spec.Template.Spec.SecurityContext = customPodOptions.PodSecurityContext } + if customPodOptions.Lifecycle != nil { + solrContainer.Lifecycle = customPodOptions.Lifecycle + } + if customPodOptions.Tolerations != nil { stateful.Spec.Template.Spec.Tolerations = customPodOptions.Tolerations } diff --git a/helm/solr-operator/crds/crds.yaml b/helm/solr-operator/crds/crds.yaml index 0d53866b..508bd40b 100644 --- a/helm/solr-operator/crds/crds.yaml +++ b/helm/solr-operator/crds/crds.yaml @@ -2462,6 +2462,140 @@ spec: type: string description: Labels to be added for pods. type: object + lifecycle: + description: Lifecycle for the main container + properties: + postStart: + description: 'PostStart is called immediately after a container is created. If the handler fails, the container is terminated and restarted according to its restart policy. Other management of the container blocks until the hook completes. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: One and only one of the following should be specified. Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. The command is simply exec'd, it is not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use a shell, you need to explicitly call out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: 'TCPSocket specifies an action involving a TCP port. TCP hooks not yet supported TODO: implement a realistic TCP lifecycle hook' + properties: + host: + description: 'Optional: Host name to connect to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + preStop: + description: 'PreStop is called immediately before a container is terminated due to an API request or management event such as liveness/startup probe failure, preemption, resource contention, etc. The handler is not called if the container crashes or exits. The reason for termination is passed to the handler. The Pod''s termination grace period countdown begins before the PreStop hooked is executed. Regardless of the outcome of the handler, the container will eventually terminate within the Pod''s termination grace period. Other management of the container blocks until the hook completes or until the termination grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: One and only one of the following should be specified. Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. The command is simply exec'd, it is not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use a shell, you need to explicitly call out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: 'TCPSocket specifies an action involving a TCP port. TCP hooks not yet supported TODO: implement a realistic TCP lifecycle hook' + properties: + host: + description: 'Optional: Host name to connect to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + type: object livenessProbe: description: Liveness probe parameters properties: @@ -8093,6 +8227,140 @@ spec: type: string description: Labels to be added for pods. type: object + lifecycle: + description: Lifecycle for the main container + properties: + postStart: + description: 'PostStart is called immediately after a container is created. If the handler fails, the container is terminated and restarted according to its restart policy. Other management of the container blocks until the hook completes. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: One and only one of the following should be specified. Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. The command is simply exec'd, it is not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use a shell, you need to explicitly call out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: 'TCPSocket specifies an action involving a TCP port. TCP hooks not yet supported TODO: implement a realistic TCP lifecycle hook' + properties: + host: + description: 'Optional: Host name to connect to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + preStop: + description: 'PreStop is called immediately before a container is terminated due to an API request or management event such as liveness/startup probe failure, preemption, resource contention, etc. The handler is not called if the container crashes or exits. The reason for termination is passed to the handler. The Pod''s termination grace period countdown begins before the PreStop hooked is executed. Regardless of the outcome of the handler, the container will eventually terminate within the Pod''s termination grace period. Other management of the container blocks until the hook completes or until the termination grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks' + properties: + exec: + description: One and only one of the following should be specified. Exec specifies the action to take. + properties: + command: + description: Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. The command is simply exec'd, it is not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use a shell, you need to explicitly call out to that shell. Exit status of 0 is treated as live/healthy and non-zero is unhealthy. + items: + type: string + type: array + type: object + httpGet: + description: HTTPGet specifies the http request to perform. + properties: + host: + description: Host name to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead. + type: string + httpHeaders: + description: Custom headers to set in the request. HTTP allows repeated headers. + items: + description: HTTPHeader describes a custom header to be used in HTTP probes + properties: + name: + description: The header field name + type: string + value: + description: The header field value + type: string + required: + - name + - value + type: object + type: array + path: + description: Path to access on the HTTP server. + type: string + port: + anyOf: + - type: integer + - type: string + description: Name or number of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + scheme: + description: Scheme to use for connecting to the host. Defaults to HTTP. + type: string + required: + - port + type: object + tcpSocket: + description: 'TCPSocket specifies an action involving a TCP port. TCP hooks not yet supported TODO: implement a realistic TCP lifecycle hook' + properties: + host: + description: 'Optional: Host name to connect to, defaults to the pod IP.' + type: string + port: + anyOf: + - type: integer + - type: string + description: Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. + x-kubernetes-int-or-string: true + required: + - port + type: object + type: object + type: object livenessProbe: description: Liveness probe parameters properties: From 645849cb80fc718d5f4bb43269ff2b94d0c37c5a Mon Sep 17 00:00:00 2001 From: Nick Vladiceanu Date: Fri, 17 Sep 2021 17:23:37 +0200 Subject: [PATCH 02/10] adding default value for preStop hook --- dependency_licenses.csv | 56 ----------------------------------------- 1 file changed, 56 deletions(-) diff --git a/dependency_licenses.csv b/dependency_licenses.csv index d9c423f5..e69de29b 100644 --- a/dependency_licenses.csv +++ b/dependency_licenses.csv @@ -1,56 +0,0 @@ -cloud.google.com/go/compute/metadata,Unknown,Apache-2.0 -github.com/beorn7/perks/quantile,https://github.com/beorn7/perks/blob/master/quantile/LICENSE,MIT -github.com/cespare/xxhash/v2,https://github.com/cespare/xxhash/blob/master/v2/LICENSE.txt,MIT -github.com/davecgh/go-spew/spew,https://github.com/davecgh/go-spew/blob/master/spew/LICENSE,ISC -github.com/docker/spdystream,https://github.com/docker/spdystream/blob/master/LICENSE,Apache-2.0 -github.com/evanphx/json-patch,https://github.com/evanphx/json-patch/blob/master/LICENSE,BSD-3-Clause -github.com/fsnotify/fsnotify,https://github.com/fsnotify/fsnotify/blob/master/LICENSE,BSD-3-Clause -github.com/go-logr/logr,https://github.com/go-logr/logr/blob/master/LICENSE,Apache-2.0 -github.com/go-logr/zapr,https://github.com/go-logr/zapr/blob/master/LICENSE,Apache-2.0 -github.com/gogo/protobuf,https://github.com/gogo/protobuf/blob/master/LICENSE,BSD-3-Clause -github.com/golang/groupcache/lru,https://github.com/golang/groupcache/blob/master/lru/LICENSE,Apache-2.0 -github.com/golang/protobuf,https://github.com/golang/protobuf/blob/master/LICENSE,BSD-3-Clause -github.com/google/go-cmp/cmp,https://github.com/google/go-cmp/blob/master/cmp/LICENSE,BSD-3-Clause -github.com/google/gofuzz,https://github.com/google/gofuzz/blob/master/LICENSE,Apache-2.0 -github.com/google/uuid,https://github.com/google/uuid/blob/master/LICENSE,BSD-3-Clause -github.com/googleapis/gnostic,https://github.com/googleapis/gnostic/blob/master/LICENSE,Apache-2.0 -github.com/hashicorp/golang-lru,https://github.com/hashicorp/golang-lru/blob/master/LICENSE,MPL-2.0 -github.com/imdario/mergo,https://github.com/imdario/mergo/blob/master/LICENSE,BSD-3-Clause -github.com/json-iterator/go,https://github.com/json-iterator/go/blob/master/LICENSE,MIT -github.com/matttproud/golang_protobuf_extensions/pbutil,https://github.com/matttproud/golang_protobuf_extensions/blob/master/pbutil/LICENSE,Apache-2.0 -github.com/modern-go/concurrent,https://github.com/modern-go/concurrent/blob/master/LICENSE,Apache-2.0 -github.com/modern-go/reflect2,https://github.com/modern-go/reflect2/blob/master/LICENSE,Apache-2.0 -github.com/pkg/errors,https://github.com/pkg/errors/blob/master/LICENSE,BSD-2-Clause -github.com/pravega/zookeeper-operator/pkg/apis,https://github.com/pravega/zookeeper-operator/blob/master/pkg/apis/LICENSE,Apache-2.0 -github.com/prometheus/client_golang/prometheus,https://github.com/prometheus/client_golang/blob/master/prometheus/LICENSE,Apache-2.0 -github.com/prometheus/client_model/go,https://github.com/prometheus/client_model/blob/master/go/LICENSE,Apache-2.0 -github.com/prometheus/common,https://github.com/prometheus/common/blob/master/LICENSE,Apache-2.0 -github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg,https://github.com/prometheus/common/blob/master/internal/bitbucket.org/ww/goautoneg/README.txt,BSD-3-Clause -github.com/prometheus/procfs,https://github.com/prometheus/procfs/blob/master/LICENSE,Apache-2.0 -github.com/robfig/cron/v3,https://github.com/robfig/cron/blob/master/v3/LICENSE,MIT -github.com/spf13/pflag,https://github.com/spf13/pflag/blob/master/LICENSE,BSD-3-Clause -go.uber.org/atomic,Unknown,MIT -go.uber.org/multierr,Unknown,MIT -go.uber.org/zap,Unknown,MIT -golang.org/x/crypto/ssh/terminal,Unknown,BSD-3-Clause -golang.org/x/net,Unknown,BSD-3-Clause -golang.org/x/oauth2,Unknown,BSD-3-Clause -golang.org/x/sys,Unknown,BSD-3-Clause -golang.org/x/term,Unknown,BSD-3-Clause -golang.org/x/text,Unknown,BSD-3-Clause -golang.org/x/time/rate,Unknown,BSD-3-Clause -gomodules.xyz/jsonpatch/v2,Unknown,Apache-2.0 -google.golang.org/protobuf,Unknown,BSD-3-Clause -gopkg.in/inf.v0,Unknown,BSD-3-Clause -gopkg.in/yaml.v2,Unknown,Apache-2.0 -gopkg.in/yaml.v3,Unknown,MIT -k8s.io/api,Unknown,Apache-2.0 -k8s.io/apiextensions-apiserver/pkg/apis/apiextensions,Unknown,Apache-2.0 -k8s.io/apimachinery,Unknown,Apache-2.0 -k8s.io/client-go,Unknown,Apache-2.0 -k8s.io/klog/v2,Unknown,Apache-2.0 -k8s.io/kube-openapi/pkg/util/proto,Unknown,Apache-2.0 -k8s.io/utils,Unknown,Apache-2.0 -sigs.k8s.io/controller-runtime,Unknown,Apache-2.0 -sigs.k8s.io/structured-merge-diff/v4/value,Unknown,Apache-2.0 -sigs.k8s.io/yaml,Unknown,MIT From accd0a885257be54fbebb05c54a0a46290b02f02 Mon Sep 17 00:00:00 2001 From: Nick Vladiceanu Date: Fri, 17 Sep 2021 17:27:15 +0200 Subject: [PATCH 03/10] Add default value for preStop Hook --- controllers/util/solr_util.go | 8 +++++ dependency_licenses.csv | 56 +++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/controllers/util/solr_util.go b/controllers/util/solr_util.go index 0db550af..53621232 100644 --- a/controllers/util/solr_util.go +++ b/controllers/util/solr_util.go @@ -328,6 +328,13 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl } } + // Default preStop hook + preStop := &corev1.Handler{ + Exec: &corev1.ExecAction{ + Command: []string{"solr", "stop", "-p", strconv.Itoa(solrPodPort)}, + }, + } + // Add Custom EnvironmentVariables to the solr container if nil != customPodOptions { envVars = append(envVars, customPodOptions.EnvVariables...) @@ -423,6 +430,7 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl Env: envVars, Lifecycle: &corev1.Lifecycle{ PostStart: postStart, + PreStop: preStop, }, }, } diff --git a/dependency_licenses.csv b/dependency_licenses.csv index e69de29b..d9c423f5 100644 --- a/dependency_licenses.csv +++ b/dependency_licenses.csv @@ -0,0 +1,56 @@ +cloud.google.com/go/compute/metadata,Unknown,Apache-2.0 +github.com/beorn7/perks/quantile,https://github.com/beorn7/perks/blob/master/quantile/LICENSE,MIT +github.com/cespare/xxhash/v2,https://github.com/cespare/xxhash/blob/master/v2/LICENSE.txt,MIT +github.com/davecgh/go-spew/spew,https://github.com/davecgh/go-spew/blob/master/spew/LICENSE,ISC +github.com/docker/spdystream,https://github.com/docker/spdystream/blob/master/LICENSE,Apache-2.0 +github.com/evanphx/json-patch,https://github.com/evanphx/json-patch/blob/master/LICENSE,BSD-3-Clause +github.com/fsnotify/fsnotify,https://github.com/fsnotify/fsnotify/blob/master/LICENSE,BSD-3-Clause +github.com/go-logr/logr,https://github.com/go-logr/logr/blob/master/LICENSE,Apache-2.0 +github.com/go-logr/zapr,https://github.com/go-logr/zapr/blob/master/LICENSE,Apache-2.0 +github.com/gogo/protobuf,https://github.com/gogo/protobuf/blob/master/LICENSE,BSD-3-Clause +github.com/golang/groupcache/lru,https://github.com/golang/groupcache/blob/master/lru/LICENSE,Apache-2.0 +github.com/golang/protobuf,https://github.com/golang/protobuf/blob/master/LICENSE,BSD-3-Clause +github.com/google/go-cmp/cmp,https://github.com/google/go-cmp/blob/master/cmp/LICENSE,BSD-3-Clause +github.com/google/gofuzz,https://github.com/google/gofuzz/blob/master/LICENSE,Apache-2.0 +github.com/google/uuid,https://github.com/google/uuid/blob/master/LICENSE,BSD-3-Clause +github.com/googleapis/gnostic,https://github.com/googleapis/gnostic/blob/master/LICENSE,Apache-2.0 +github.com/hashicorp/golang-lru,https://github.com/hashicorp/golang-lru/blob/master/LICENSE,MPL-2.0 +github.com/imdario/mergo,https://github.com/imdario/mergo/blob/master/LICENSE,BSD-3-Clause +github.com/json-iterator/go,https://github.com/json-iterator/go/blob/master/LICENSE,MIT +github.com/matttproud/golang_protobuf_extensions/pbutil,https://github.com/matttproud/golang_protobuf_extensions/blob/master/pbutil/LICENSE,Apache-2.0 +github.com/modern-go/concurrent,https://github.com/modern-go/concurrent/blob/master/LICENSE,Apache-2.0 +github.com/modern-go/reflect2,https://github.com/modern-go/reflect2/blob/master/LICENSE,Apache-2.0 +github.com/pkg/errors,https://github.com/pkg/errors/blob/master/LICENSE,BSD-2-Clause +github.com/pravega/zookeeper-operator/pkg/apis,https://github.com/pravega/zookeeper-operator/blob/master/pkg/apis/LICENSE,Apache-2.0 +github.com/prometheus/client_golang/prometheus,https://github.com/prometheus/client_golang/blob/master/prometheus/LICENSE,Apache-2.0 +github.com/prometheus/client_model/go,https://github.com/prometheus/client_model/blob/master/go/LICENSE,Apache-2.0 +github.com/prometheus/common,https://github.com/prometheus/common/blob/master/LICENSE,Apache-2.0 +github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg,https://github.com/prometheus/common/blob/master/internal/bitbucket.org/ww/goautoneg/README.txt,BSD-3-Clause +github.com/prometheus/procfs,https://github.com/prometheus/procfs/blob/master/LICENSE,Apache-2.0 +github.com/robfig/cron/v3,https://github.com/robfig/cron/blob/master/v3/LICENSE,MIT +github.com/spf13/pflag,https://github.com/spf13/pflag/blob/master/LICENSE,BSD-3-Clause +go.uber.org/atomic,Unknown,MIT +go.uber.org/multierr,Unknown,MIT +go.uber.org/zap,Unknown,MIT +golang.org/x/crypto/ssh/terminal,Unknown,BSD-3-Clause +golang.org/x/net,Unknown,BSD-3-Clause +golang.org/x/oauth2,Unknown,BSD-3-Clause +golang.org/x/sys,Unknown,BSD-3-Clause +golang.org/x/term,Unknown,BSD-3-Clause +golang.org/x/text,Unknown,BSD-3-Clause +golang.org/x/time/rate,Unknown,BSD-3-Clause +gomodules.xyz/jsonpatch/v2,Unknown,Apache-2.0 +google.golang.org/protobuf,Unknown,BSD-3-Clause +gopkg.in/inf.v0,Unknown,BSD-3-Clause +gopkg.in/yaml.v2,Unknown,Apache-2.0 +gopkg.in/yaml.v3,Unknown,MIT +k8s.io/api,Unknown,Apache-2.0 +k8s.io/apiextensions-apiserver/pkg/apis/apiextensions,Unknown,Apache-2.0 +k8s.io/apimachinery,Unknown,Apache-2.0 +k8s.io/client-go,Unknown,Apache-2.0 +k8s.io/klog/v2,Unknown,Apache-2.0 +k8s.io/kube-openapi/pkg/util/proto,Unknown,Apache-2.0 +k8s.io/utils,Unknown,Apache-2.0 +sigs.k8s.io/controller-runtime,Unknown,Apache-2.0 +sigs.k8s.io/structured-merge-diff/v4/value,Unknown,Apache-2.0 +sigs.k8s.io/yaml,Unknown,MIT From 62486df1dff71c8afff5eb282e540605d0fd303a Mon Sep 17 00:00:00 2001 From: Nick Vladiceanu Date: Sat, 18 Sep 2021 18:14:58 +0200 Subject: [PATCH 04/10] Default values for postStart and preStop independently --- controllers/util/solr_util.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/controllers/util/solr_util.go b/controllers/util/solr_util.go index 53621232..ba27f585 100644 --- a/controllers/util/solr_util.go +++ b/controllers/util/solr_util.go @@ -428,10 +428,6 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl }, VolumeMounts: volumeMounts, Env: envVars, - Lifecycle: &corev1.Lifecycle{ - PostStart: postStart, - PreStop: preStop, - }, }, } @@ -510,6 +506,9 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl if nil != customPodOptions { solrContainer := &stateful.Spec.Template.Spec.Containers[0] + solrContainer.Lifecycle.PostStart = postStart + solrContainer.Lifecycle.PreStop = preStop + if customPodOptions.ServiceAccountName != "" { stateful.Spec.Template.Spec.ServiceAccountName = customPodOptions.ServiceAccountName } @@ -526,8 +525,12 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl stateful.Spec.Template.Spec.SecurityContext = customPodOptions.PodSecurityContext } - if customPodOptions.Lifecycle != nil { - solrContainer.Lifecycle = customPodOptions.Lifecycle + if customPodOptions.Lifecycle.PostStart != nil { + solrContainer.Lifecycle.PostStart = customPodOptions.Lifecycle.PostStart + } + + if customPodOptions.Lifecycle.PreStop != nil { + solrContainer.Lifecycle.PreStop = customPodOptions.Lifecycle.PreStop } if customPodOptions.Tolerations != nil { From ff34e34fd76a4bb5c64bcf808de2a147b6647897 Mon Sep 17 00:00:00 2001 From: Nick Vladiceanu Date: Mon, 20 Sep 2021 10:41:04 +0200 Subject: [PATCH 05/10] Update Helm chart --- helm/solr/README.md | 1 + helm/solr/templates/_custom_option_helpers.tpl | 4 ++++ helm/solr/values.yaml | 3 +++ 3 files changed, 8 insertions(+) diff --git a/helm/solr/README.md b/helm/solr/README.md index 4ca49ea0..10b15cca 100644 --- a/helm/solr/README.md +++ b/helm/solr/README.md @@ -255,6 +255,7 @@ Configure Solr to use a separate TLS certificate for client auth. | podOptions.livenessProbe | object | | Custom liveness probe for the Solr container | | podOptions.readinessProbe | object | | Custom readiness probe for the Solr container | | podOptions.startupProbe | object | | Custom startup probe for the Solr container | +| podOptions.lifecycle | object | | Custom lifecycle for the Solr container | | podOptions.imagePullSecrets | []object | | List of image pull secrets to inject into the Solr pod, in addition to `global.imagePullSecrets` | | podOptions.volumes | []object | | List of additional volumes to attach to the Solr pod, and optionally how to mount them to the Solr container | | statefulSetOptions.annotations | map[string]string | | Custom annotations to add to the Solr statefulSet | diff --git a/helm/solr/templates/_custom_option_helpers.tpl b/helm/solr/templates/_custom_option_helpers.tpl index b4d21ceb..0e02556a 100644 --- a/helm/solr/templates/_custom_option_helpers.tpl +++ b/helm/solr/templates/_custom_option_helpers.tpl @@ -82,6 +82,10 @@ readinessProbe: startupProbe: {{- toYaml .Values.podOptions.startupProbe | nindent 2 }} {{ end }} +{{- if .Values.podOptions.lifecycle -}} +lifecycle: + {{- toYaml .Values.podOptions.lifecycle | nindent 2 }} +{{ end }} {{- if .Values.podOptions.sidecarContainers -}} sidecarContainers: {{- toYaml .Values.podOptions.sidecarContainers | nindent 2 }} diff --git a/helm/solr/values.yaml b/helm/solr/values.yaml index 0473421a..0ef711b0 100644 --- a/helm/solr/values.yaml +++ b/helm/solr/values.yaml @@ -255,6 +255,9 @@ podOptions: livenessProbe: {} readinessProbe: {} startupProbe: {} + + # Lifecycle for the Solr container + lifecycle: {} imagePullSecrets: [] From 43c46014e065dbc130ddf82f21e4ac18e27a63eb Mon Sep 17 00:00:00 2001 From: Nick Vladiceanu Date: Wed, 22 Sep 2021 14:11:06 +0200 Subject: [PATCH 06/10] fix tests --- controllers/util/solr_util.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/controllers/util/solr_util.go b/controllers/util/solr_util.go index ba27f585..53621232 100644 --- a/controllers/util/solr_util.go +++ b/controllers/util/solr_util.go @@ -428,6 +428,10 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl }, VolumeMounts: volumeMounts, Env: envVars, + Lifecycle: &corev1.Lifecycle{ + PostStart: postStart, + PreStop: preStop, + }, }, } @@ -506,9 +510,6 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl if nil != customPodOptions { solrContainer := &stateful.Spec.Template.Spec.Containers[0] - solrContainer.Lifecycle.PostStart = postStart - solrContainer.Lifecycle.PreStop = preStop - if customPodOptions.ServiceAccountName != "" { stateful.Spec.Template.Spec.ServiceAccountName = customPodOptions.ServiceAccountName } @@ -525,12 +526,8 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl stateful.Spec.Template.Spec.SecurityContext = customPodOptions.PodSecurityContext } - if customPodOptions.Lifecycle.PostStart != nil { - solrContainer.Lifecycle.PostStart = customPodOptions.Lifecycle.PostStart - } - - if customPodOptions.Lifecycle.PreStop != nil { - solrContainer.Lifecycle.PreStop = customPodOptions.Lifecycle.PreStop + if customPodOptions.Lifecycle != nil { + solrContainer.Lifecycle = customPodOptions.Lifecycle } if customPodOptions.Tolerations != nil { From fe2ba0b7d713eb217bd847f04773f6d8b0f01564 Mon Sep 17 00:00:00 2001 From: Nick Vladiceanu Date: Thu, 23 Sep 2021 20:48:48 +0200 Subject: [PATCH 07/10] Cleaning up and adding Lifecycle tests for Solr and PromExporter main containers --- controllers/controller_utils_test.go | 19 ++++++++++++++++++- .../solrcloud_controller_externaldns_test.go | 9 ++------- .../solrcloud_controller_ingress_test.go | 11 +++-------- controllers/solrcloud_controller_test.go | 8 +++++--- controllers/solrcloud_controller_zk_test.go | 5 ++--- .../solrprometheusexporter_controller_test.go | 4 ++++ controllers/util/prometheus_exporter_util.go | 4 ++++ 7 files changed, 38 insertions(+), 22 deletions(-) diff --git a/controllers/controller_utils_test.go b/controllers/controller_utils_test.go index a7279d6b..db69faea 100644 --- a/controllers/controller_utils_test.go +++ b/controllers/controller_utils_test.go @@ -19,10 +19,11 @@ package controllers import ( "fmt" + "testing" + "github.com/apache/solr-operator/controllers/util" zkv1beta1 "github.com/pravega/zookeeper-operator/pkg/apis/zookeeper/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "testing" solr "github.com/apache/solr-operator/api/v1beta1" "github.com/onsi/gomega" @@ -276,6 +277,10 @@ func testPodProbe(t *testing.T, expectedProbe *corev1.Probe, foundProbe *corev1. assert.EqualValuesf(t, expectedProbe, foundProbe, "Incorrect default container %s probe", probeType) } +func testPodLifecycle(t *testing.T, expectedLifecycle *corev1.Lifecycle, foundLifecycle *corev1.Lifecycle) { + assert.EqualValuesf(t, expectedLifecycle, foundLifecycle, "Expected Lifecycle and found Lifecyle don't match") +} + func testMapsEqual(t *testing.T, mapName string, expected map[string]string, found map[string]string) { assert.Equal(t, expected, found, "Expected and found %s are not the same", mapName) } @@ -520,6 +525,18 @@ var ( }, }, } + testLifecycle = &corev1.Lifecycle{ + PostStart: &corev1.Handler{ + Exec: &corev1.ExecAction{ + Command: []string{"/bin/sh", "-c", "echo Hello from the postStart handler"}, + }, + }, + PreStop: &corev1.Handler{ + Exec: &corev1.ExecAction{ + Command: []string{"/bin/sh", "-c", "echo Hello from the preStop handler"}, + }, + }, + } testTolerations = []corev1.Toleration{ { Effect: "NoSchedule", diff --git a/controllers/solrcloud_controller_externaldns_test.go b/controllers/solrcloud_controller_externaldns_test.go index 3a68cd44..a6ca3b3d 100644 --- a/controllers/solrcloud_controller_externaldns_test.go +++ b/controllers/solrcloud_controller_externaldns_test.go @@ -18,9 +18,10 @@ package controllers import ( - "k8s.io/apimachinery/pkg/types" "testing" + "k8s.io/apimachinery/pkg/types" + "github.com/apache/solr-operator/controllers/util" "github.com/stretchr/testify/assert" @@ -114,7 +115,6 @@ func TestEDSCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) - assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -233,7 +233,6 @@ func TestEDSNoNodesCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) - assert.Equal(t, []string{"solr", "stop", "-p", "2000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -349,7 +348,6 @@ func TestEDSNoCommonCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) - assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -464,7 +462,6 @@ func TestEDSUseInternalAddressCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) - assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -583,7 +580,6 @@ func TestEDSExtraDomainsCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) - assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") hostnameAnnotation := instance.Namespace + "." + testDomain for _, domain := range testAdditionalDomains { @@ -709,7 +705,6 @@ func TestEDSKubeDomainCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) - assert.Equal(t, []string{"solr", "stop", "-p", "2000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) diff --git a/controllers/solrcloud_controller_ingress_test.go b/controllers/solrcloud_controller_ingress_test.go index a86a5c1c..04455590 100644 --- a/controllers/solrcloud_controller_ingress_test.go +++ b/controllers/solrcloud_controller_ingress_test.go @@ -18,11 +18,12 @@ package controllers import ( - extv1 "k8s.io/api/extensions/v1beta1" - "k8s.io/apimachinery/pkg/types" "strconv" "testing" + extv1 "k8s.io/api/extensions/v1beta1" + "k8s.io/apimachinery/pkg/types" + "github.com/apache/solr-operator/controllers/util" "github.com/stretchr/testify/assert" @@ -131,7 +132,6 @@ func TestIngressCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) - assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -261,7 +261,6 @@ func TestIngressNoNodesCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) - assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -393,7 +392,6 @@ func TestIngressNoCommonCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) - assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -520,7 +518,6 @@ func TestIngressUseInternalAddressCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) - assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -655,7 +652,6 @@ func TestIngressExtraDomainsCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) - assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -779,7 +775,6 @@ func TestIngressKubeDomainCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) - assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) diff --git a/controllers/solrcloud_controller_test.go b/controllers/solrcloud_controller_test.go index 5a9ecdbf..353876dc 100644 --- a/controllers/solrcloud_controller_test.go +++ b/controllers/solrcloud_controller_test.go @@ -23,6 +23,9 @@ import ( "strconv" "time" + "strings" + "testing" + solr "github.com/apache/solr-operator/api/v1beta1" "github.com/apache/solr-operator/controllers/util" "github.com/onsi/gomega" @@ -36,8 +39,6 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/reconcile" - "strings" - "testing" ) var _ reconcile.Reconciler = &SolrCloudReconciler{} @@ -206,6 +207,7 @@ func TestCustomKubeOptionsCloudReconcile(t *testing.T) { LivenessProbe: testProbeLivenessNonDefaults, ReadinessProbe: testProbeReadinessNonDefaults, StartupProbe: testProbeStartup, + Lifecycle: testLifecycle, PriorityClassName: testPriorityClass, ImagePullSecrets: testAdditionalImagePullSecrets, TerminationGracePeriodSeconds: &testTerminationGracePeriodSeconds, @@ -297,7 +299,7 @@ func TestCustomKubeOptionsCloudReconcile(t *testing.T) { testPodProbe(t, testProbeLivenessNonDefaults, statefulSet.Spec.Template.Spec.Containers[0].LivenessProbe, "liveness") testPodProbe(t, testProbeReadinessNonDefaults, statefulSet.Spec.Template.Spec.Containers[0].ReadinessProbe, "readiness") testPodProbe(t, testProbeStartup, statefulSet.Spec.Template.Spec.Containers[0].StartupProbe, "startup") - assert.Equal(t, []string{"solr", "stop", "-p", "8983"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") + testPodLifecycle(t, testLifecycle, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle) testPodTolerations(t, testTolerations, statefulSet.Spec.Template.Spec.Tolerations) assert.EqualValues(t, testPriorityClass, statefulSet.Spec.Template.Spec.PriorityClassName, "Incorrect Priority class name for Pod Spec") assert.ElementsMatch(t, append(testAdditionalImagePullSecrets, corev1.LocalObjectReference{Name: testImagePullSecretName}), statefulSet.Spec.Template.Spec.ImagePullSecrets, "Incorrect imagePullSecrets") diff --git a/controllers/solrcloud_controller_zk_test.go b/controllers/solrcloud_controller_zk_test.go index 03aab7e1..9df4b717 100644 --- a/controllers/solrcloud_controller_zk_test.go +++ b/controllers/solrcloud_controller_zk_test.go @@ -19,13 +19,14 @@ package controllers import ( "fmt" + "testing" + "github.com/apache/solr-operator/controllers/util" zkv1beta1 "github.com/pravega/zookeeper-operator/pkg/apis/zookeeper/v1beta1" "github.com/pravega/zookeeper-operator/pkg/controller/zookeepercluster" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" - "testing" "github.com/stretchr/testify/assert" @@ -400,7 +401,6 @@ func TestZKACLsCloudReconcile(t *testing.T) { // Note that this check changes the variable foundEnv, so the values are no longer valid afterwards. // TODO: Make this not invalidate foundEnv testPodEnvVariables(t, expectedEnvVars, append(foundEnv[:len(foundEnv)-6], foundEnv[len(foundEnv)-1])) - assert.Equal(t, []string{"solr", "stop", "-p", "8983"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -545,7 +545,6 @@ func testZkACLsReconcile(t *testing.T, useZkCRD bool, instance *solr.SolrCloud, // Note that this check changes the variable foundEnv, so the values are no longer valid afterwards. // TODO: Make this not invalidate foundEnv testPodEnvVariables(t, expectedEnvVars, append(foundEnv[:len(foundEnv)-8], foundEnv[len(foundEnv)-1])) - assert.Equal(t, []string{"solr", "stop", "-p", "8983"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) diff --git a/controllers/solrprometheusexporter_controller_test.go b/controllers/solrprometheusexporter_controller_test.go index b25e84d8..5432133b 100644 --- a/controllers/solrprometheusexporter_controller_test.go +++ b/controllers/solrprometheusexporter_controller_test.go @@ -69,6 +69,7 @@ func TestMetricsReconcileWithoutExporterConfig(t *testing.T) { TerminationGracePeriodSeconds: &testTerminationGracePeriodSeconds, LivenessProbe: testProbeLivenessNonDefaults, ReadinessProbe: testProbeReadinessNonDefaults, + Lifecycle: testLifecycle, }, }, ExporterEntrypoint: "/test/entry-point", @@ -138,6 +139,7 @@ func TestMetricsReconcileWithoutExporterConfig(t *testing.T) { testPodProbe(t, testProbeLivenessNonDefaults, deployment.Spec.Template.Spec.Containers[0].LivenessProbe, "liveness") testPodProbe(t, testProbeReadinessNonDefaults, deployment.Spec.Template.Spec.Containers[0].ReadinessProbe, "readiness") + testPodLifecycle(t, testLifecycle, deployment.Spec.Template.Spec.Containers[0].Lifecycle) assert.Nilf(t, deployment.Spec.Template.Spec.Containers[0].StartupProbe, "%s probe should be nil since it was not specified", "startup") // Check the Service @@ -161,6 +163,7 @@ func TestMetricsReconcileWithExporterConfig(t *testing.T) { NodeSelector: testNodeSelectors, PriorityClassName: testPriorityClass, StartupProbe: testProbeStartup, + Lifecycle: testLifecycle, }, DeploymentOptions: &solr.DeploymentOptions{ Annotations: testDeploymentAnnotations, @@ -253,6 +256,7 @@ func TestMetricsReconcileWithExporterConfig(t *testing.T) { FailureThreshold: 3, }, deployment.Spec.Template.Spec.Containers[0].LivenessProbe, "liveness") testPodProbe(t, testProbeStartup, deployment.Spec.Template.Spec.Containers[0].StartupProbe, "startup") + testPodLifecycle(t, testLifecycle, deployment.Spec.Template.Spec.Containers[0].Lifecycle) assert.Nilf(t, deployment.Spec.Template.Spec.Containers[0].ReadinessProbe, "%s probe should be nil since it was not specified", "readiness") // Check the Service diff --git a/controllers/util/prometheus_exporter_util.go b/controllers/util/prometheus_exporter_util.go index 3b6535c1..f5a122a7 100644 --- a/controllers/util/prometheus_exporter_util.go +++ b/controllers/util/prometheus_exporter_util.go @@ -323,6 +323,10 @@ func GenerateSolrPrometheusExporterDeployment(solrPrometheusExporter *solr.SolrP if customPodOptions.LivenessProbe != nil { metricsContainer.LivenessProbe = customizeProbe(metricsContainer.LivenessProbe, *customPodOptions.LivenessProbe) } + + if customPodOptions.Lifecycle != nil { + metricsContainer.Lifecycle = customPodOptions.Lifecycle + } } // Enrich the deployment definition to allow the exporter to make requests to TLS enabled Solr pods From 14555cec2f0e8439b9253bc2b4088e5f9f295cab Mon Sep 17 00:00:00 2001 From: Nick Vladiceanu Date: Thu, 23 Sep 2021 21:25:49 +0200 Subject: [PATCH 08/10] Adding preStop tests back to make sure the right port is used --- controllers/solrcloud_controller_externaldns_test.go | 7 ++++++- controllers/solrcloud_controller_ingress_test.go | 6 ++++++ controllers/solrcloud_controller_zk_test.go | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/controllers/solrcloud_controller_externaldns_test.go b/controllers/solrcloud_controller_externaldns_test.go index a6ca3b3d..d362e35e 100644 --- a/controllers/solrcloud_controller_externaldns_test.go +++ b/controllers/solrcloud_controller_externaldns_test.go @@ -115,6 +115,7 @@ func TestEDSCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) + assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -233,6 +234,7 @@ func TestEDSNoNodesCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) + assert.Equal(t, []string{"solr", "stop", "-p", "2000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -348,6 +350,7 @@ func TestEDSNoCommonCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) + assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -462,7 +465,7 @@ func TestEDSUseInternalAddressCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) - + assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) expectedCommonServiceAnnotations := util.MergeLabelsOrAnnotations(testCommonServiceAnnotations, map[string]string{ @@ -580,6 +583,7 @@ func TestEDSExtraDomainsCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) + assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") hostnameAnnotation := instance.Namespace + "." + testDomain for _, domain := range testAdditionalDomains { @@ -705,6 +709,7 @@ func TestEDSKubeDomainCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) + assert.Equal(t, []string{"solr", "stop", "-p", "2000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) diff --git a/controllers/solrcloud_controller_ingress_test.go b/controllers/solrcloud_controller_ingress_test.go index 04455590..fc6e6eb2 100644 --- a/controllers/solrcloud_controller_ingress_test.go +++ b/controllers/solrcloud_controller_ingress_test.go @@ -132,6 +132,7 @@ func TestIngressCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) + assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -261,6 +262,7 @@ func TestIngressNoNodesCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) + assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -392,6 +394,7 @@ func TestIngressNoCommonCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) + assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -518,6 +521,7 @@ func TestIngressUseInternalAddressCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) + assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -652,6 +656,7 @@ func TestIngressExtraDomainsCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) + assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -775,6 +780,7 @@ func TestIngressKubeDomainCloudReconcile(t *testing.T) { "SOLR_OPTS": "-DhostPort=$(SOLR_NODE_PORT)", } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) + assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) diff --git a/controllers/solrcloud_controller_zk_test.go b/controllers/solrcloud_controller_zk_test.go index 9df4b717..ff75e245 100644 --- a/controllers/solrcloud_controller_zk_test.go +++ b/controllers/solrcloud_controller_zk_test.go @@ -401,6 +401,7 @@ func TestZKACLsCloudReconcile(t *testing.T) { // Note that this check changes the variable foundEnv, so the values are no longer valid afterwards. // TODO: Make this not invalidate foundEnv testPodEnvVariables(t, expectedEnvVars, append(foundEnv[:len(foundEnv)-6], foundEnv[len(foundEnv)-1])) + assert.Equal(t, []string{"solr", "stop", "-p", "8983"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) @@ -545,6 +546,7 @@ func testZkACLsReconcile(t *testing.T, useZkCRD bool, instance *solr.SolrCloud, // Note that this check changes the variable foundEnv, so the values are no longer valid afterwards. // TODO: Make this not invalidate foundEnv testPodEnvVariables(t, expectedEnvVars, append(foundEnv[:len(foundEnv)-8], foundEnv[len(foundEnv)-1])) + assert.Equal(t, []string{"solr", "stop", "-p", "8983"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) From 793395b46162ae0a60a903b47f2d1693af0c2449 Mon Sep 17 00:00:00 2001 From: Nick Vladiceanu Date: Thu, 23 Sep 2021 21:29:52 +0200 Subject: [PATCH 09/10] (tiny syntax fix) --- controllers/solrcloud_controller_externaldns_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/controllers/solrcloud_controller_externaldns_test.go b/controllers/solrcloud_controller_externaldns_test.go index d362e35e..696c769a 100644 --- a/controllers/solrcloud_controller_externaldns_test.go +++ b/controllers/solrcloud_controller_externaldns_test.go @@ -466,6 +466,7 @@ func TestEDSUseInternalAddressCloudReconcile(t *testing.T) { } testPodEnvVariables(t, expectedEnvVars, statefulSet.Spec.Template.Spec.Containers[0].Env) assert.Equal(t, []string{"solr", "stop", "-p", "3000"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command") + // Check the client Service service := expectService(t, g, requests, expectedCloudRequest, cloudCsKey, statefulSet.Spec.Template.Labels) expectedCommonServiceAnnotations := util.MergeLabelsOrAnnotations(testCommonServiceAnnotations, map[string]string{ From 53847b44f2bec20016dd89d009ae5d3a7396a9a5 Mon Sep 17 00:00:00 2001 From: Houston Putman Date: Thu, 23 Sep 2021 15:59:17 -0400 Subject: [PATCH 10/10] Add changelog entry --- helm/solr-operator/Chart.yaml | 115 +--------------------------------- 1 file changed, 3 insertions(+), 112 deletions(-) diff --git a/helm/solr-operator/Chart.yaml b/helm/solr-operator/Chart.yaml index 2c3f0122..bf2b25b5 100644 --- a/helm/solr-operator/Chart.yaml +++ b/helm/solr-operator/Chart.yaml @@ -55,121 +55,12 @@ annotations: # Allowed syntax is described at: https://artifacthub.io/docs/topics/annotations/helm/#example artifacthub.io/changes: | - kind: changed - description: Zookeeper Operator supported version changed to v0.2.12 + description: Customize the Lifecycle for Solr and PrometheusExporter containers links: - name: Github Issue - url: https://github.com/apache/solr-operator/issues/271 + url: https://github.com/apache/solr-operator/issues/322 - name: Github PR - url: https://github.com/apache/solr-operator/pull/304 - - name: Zookeeper Operator Release Notes - url: https://github.com/pravega/zookeeper-operator/releases/tag/v0.2.12 - - kind: added - description: Ability to schedule automatic restarts for SolrClouds - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/281 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/279 - - kind: removed - description: "Removed deprecated Solr Operator Helm chart option `useZkOperator`, use `zookeeper-operator.use` instead" - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/286 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/288 - - name: Deprecating Github PR - url: https://github.com/apache/solr-operator/pull/231 - - kind: changed - description: Default Solr Version upgraded to 8.9, does not affect existing clouds - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/285 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/287 - - kind: added - description: Customize serviceAccountName for SolrCloud and SolrPrometheusExporter - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/264 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/283 - - kind: added - description: Introduced ephemeral option for Zookeeper storage - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/259 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/284 - - kind: security - description: Changed Solr Operator base Docker image to reduce vulnerabilities. - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/294 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/295 - - kind: added - description: Ability to customize probes for PrometheusExporter - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/282 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/297 - - kind: security - description: Remove users role from the all permission in the initial security.json - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/274 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/299 - - kind: fixed - description: Grant access to the /admin/zookeeper/status path to the k8s role in the initial security.json - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/289 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/299 - - kind: security - description: Add a mountedServerTLSDir config option to support a unique certificate per pod mounted dynamically by an external agent or CSI driver - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/291 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/292 - - kind: added - description: Ability to terminate TLS at Ingress for SolrCloud. - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/268 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/293 - - kind: added - description: Ability to schedule automatic restarts for SolrPrometheusExporters - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/310 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/313 - - kind: added - description: Ability to specify ZK Config properties for provided Zookeeper Clusters. - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/290 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/311 - - kind: added - description: Option to watch for updates to the mTLS client certificate used by the operator to call Solr pods. - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/317 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/318 - - kind: added - description: Configuration options to support an additional client TLS cert in addition to the server certificate - links: - - name: Github Issue - url: https://github.com/apache/solr-operator/issues/300 - - name: Github PR - url: https://github.com/apache/solr-operator/pull/312 + url: https://github.com/apache/solr-operator/pull/324 artifacthub.io/images: | - name: solr-operator image: apache/solr-operator:v0.5.0-prerelease