diff --git a/docs/Manual/Deployment/Kubernetes/DeploymentResource.md b/docs/Manual/Deployment/Kubernetes/DeploymentResource.md index 7ccf56d91..bbffce03d 100644 --- a/docs/Manual/Deployment/Kubernetes/DeploymentResource.md +++ b/docs/Manual/Deployment/Kubernetes/DeploymentResource.md @@ -401,6 +401,14 @@ for each server of this group. This setting is not available for group `coordinators`, `syncmasters` & `syncworkers` because servers in these groups do not need persistent storage. +### `spec..probes.livenessProbeDisabled: bool` + +If set to true, the operator does not generate a liveness probe for new pods belonging to this group. + +### `spec..probes.readinessProbeDisabled: bool` + +If set to true, the operator does not generate a readiness probe for new pods belonging to this group. + ### `spec..tolerations: []Toleration` This setting specifies the `tolerations` for the `Pod`s created diff --git a/pkg/apis/deployment/v1alpha/server_group_spec.go b/pkg/apis/deployment/v1alpha/server_group_spec.go index 7e0c657d0..de0c1a53c 100644 --- a/pkg/apis/deployment/v1alpha/server_group_spec.go +++ b/pkg/apis/deployment/v1alpha/server_group_spec.go @@ -56,6 +56,40 @@ type ServerGroupSpec struct { ServiceAccountName *string `json:"serviceAccountName,omitempty"` // NodeSelector speficies a set of selectors for nodes NodeSelector map[string]string `json:"nodeSelector,omitempty"` + // Probes specifies additional behaviour for probes + Probes *ServerGroupProbesSpec `json:"probes,omitempty"` +} + +// ServerGroupProbesSpec contains specification for probes for pods of the server group +type ServerGroupProbesSpec struct { + // LivenessProbeDisabled if true livenessProbes are disabled + LivenessProbeDisabled *bool `json:"livenessProbeDisabled,omitempty"` + // LivenessProbeDisabled if specified the given probes is used as liveness probe + //LivenessProbeOverride *v1.Probe `json:"LivenessProbeOverride,omitempty"` + // LivenessProbeDisabled if true readinessProbes are disabled + ReadinessProbeDisabled *bool `json:"ReadinessProbeDisabled,omitempty"` + // ReadinessProbeOverride if specified the given probes is used as readiness probe + //ReadinessProbeOverride *v1.Probe `json:"ReadinessProbeOverride,omitempty"` +} + +// // HasLivenessProbeOverride returns true if a livenessprobe override is set +// func (s ServerGroupProbesSpec) HasLivenessProbeOverride() bool { +// return s.LivenessProbeOverride != nil +// } + +// // HasReadinessProbeOverride returns true if a readinessprobe override is set +// func (s ServerGroupProbesSpec) HasReadinessProbeOverride() bool { +// return s.ReadinessProbeOverride != nil +// } + +// IsLivenessProbeDisabled returns true if liveness probes are disabled +func (s ServerGroupProbesSpec) IsLivenessProbeDisabled() bool { + return util.BoolOrDefault(s.LivenessProbeDisabled) +} + +// IsReadinessProbeDisabled returns true if readiness probes are disabled +func (s ServerGroupProbesSpec) IsReadinessProbeDisabled() bool { + return util.BoolOrDefault(s.ReadinessProbeDisabled) } // GetCount returns the value of count. @@ -98,6 +132,19 @@ func (s ServerGroupSpec) GetServiceAccountName() string { return util.StringOrDefault(s.ServiceAccountName) } +// HasProbesSpec returns true if Probes is non nil +func (s ServerGroupSpec) HasProbesSpec() bool { + return s.Probes != nil +} + +// GetProbesSpec returns the Probes spec or the nil value if not set +func (s ServerGroupSpec) GetProbesSpec() ServerGroupProbesSpec { + if s.HasProbesSpec() { + return *s.Probes + } + return ServerGroupProbesSpec{} +} + // Validate the given group spec func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentMode, env Environment) error { if used { diff --git a/pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go b/pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go index cdd4d9662..3a237bd59 100644 --- a/pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go +++ b/pkg/apis/deployment/v1alpha/zz_generated.deepcopy.go @@ -627,6 +627,32 @@ func (in *SecretHashes) DeepCopy() *SecretHashes { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServerGroupProbesSpec) DeepCopyInto(out *ServerGroupProbesSpec) { + *out = *in + if in.LivenessProbeDisabled != nil { + in, out := &in.LivenessProbeDisabled, &out.LivenessProbeDisabled + *out = new(bool) + **out = **in + } + if in.ReadinessProbeDisabled != nil { + in, out := &in.ReadinessProbeDisabled, &out.ReadinessProbeDisabled + *out = new(bool) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerGroupProbesSpec. +func (in *ServerGroupProbesSpec) DeepCopy() *ServerGroupProbesSpec { + if in == nil { + return nil + } + out := new(ServerGroupProbesSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ServerGroupSpec) DeepCopyInto(out *ServerGroupSpec) { *out = *in @@ -675,6 +701,11 @@ func (in *ServerGroupSpec) DeepCopyInto(out *ServerGroupSpec) { (*out)[key] = val } } + if in.Probes != nil { + in, out := &in.Probes, &out.Probes + *out = new(ServerGroupProbesSpec) + (*in).DeepCopyInto(*out) + } return } diff --git a/pkg/deployment/resources/pod_creator.go b/pkg/deployment/resources/pod_creator.go index 1ff5d0bf5..d76964068 100644 --- a/pkg/deployment/resources/pod_creator.go +++ b/pkg/deployment/resources/pod_creator.go @@ -331,6 +331,15 @@ func createArangoSyncArgs(apiObject metav1.Object, spec api.DeploymentSpec, grou // createLivenessProbe creates configuration for a liveness probe of a server in the given group. func (r *Resources) createLivenessProbe(spec api.DeploymentSpec, group api.ServerGroup) (*k8sutil.HTTPProbeConfig, error) { + groupspec := spec.GetServerGroupSpec(group) + + if groupspec.HasProbesSpec() { + probesspec := groupspec.GetProbesSpec() + if probesspec.IsLivenessProbeDisabled() { + return nil, nil + } + } + switch group { case api.ServerGroupSingle, api.ServerGroupAgents, api.ServerGroupDBServers: authorization := "" @@ -394,9 +403,19 @@ func (r *Resources) createLivenessProbe(spec api.DeploymentSpec, group api.Serve // createReadinessProbe creates configuration for a readiness probe of a server in the given group. func (r *Resources) createReadinessProbe(spec api.DeploymentSpec, group api.ServerGroup, version driver.Version) (*k8sutil.HTTPProbeConfig, error) { + groupspec := spec.GetServerGroupSpec(group) + + if groupspec.HasProbesSpec() { + probesspec := groupspec.GetProbesSpec() + if probesspec.IsReadinessProbeDisabled() { + return nil, nil + } + } + if group != api.ServerGroupSingle && group != api.ServerGroupCoordinators { return nil, nil } + authorization := "" if spec.IsAuthenticated() { secretData, err := r.getJWTSecret(spec) diff --git a/pkg/util/k8sutil/probes.go b/pkg/util/k8sutil/probes.go index 2b51d0825..222c76162 100644 --- a/pkg/util/k8sutil/probes.go +++ b/pkg/util/k8sutil/probes.go @@ -77,10 +77,10 @@ func (config HTTPProbeConfig) Create() *v1.Probe { HTTPHeaders: headers, }, }, - InitialDelaySeconds: def(config.InitialDelaySeconds, 30), // Wait 30s before first probe - TimeoutSeconds: def(config.TimeoutSeconds, 2), // Timeout of each probe is 2s - PeriodSeconds: def(config.PeriodSeconds, 10), // Interval between probes is 10s - SuccessThreshold: def(config.SuccessThreshold, 1), // Single probe is enough to indicate success - FailureThreshold: def(config.FailureThreshold, 3), // Need 3 failed probes to consider a failed state + InitialDelaySeconds: def(config.InitialDelaySeconds, 15*60), // Wait 15min before first probe + TimeoutSeconds: def(config.TimeoutSeconds, 2), // Timeout of each probe is 2s + PeriodSeconds: def(config.PeriodSeconds, 60), // Interval between probes is 10s + SuccessThreshold: def(config.SuccessThreshold, 1), // Single probe is enough to indicate success + FailureThreshold: def(config.FailureThreshold, 10), // Need 10 failed probes to consider a failed state } } diff --git a/pkg/util/k8sutil/probes_test.go b/pkg/util/k8sutil/probes_test.go index a993354a6..26883206c 100644 --- a/pkg/util/k8sutil/probes_test.go +++ b/pkg/util/k8sutil/probes_test.go @@ -37,11 +37,11 @@ func TestCreate(t *testing.T) { config := HTTPProbeConfig{path, false, secret, 0, 0, 0, 0, 0, 0} probe := config.Create() - assert.Equal(t, probe.InitialDelaySeconds, int32(30)) + assert.Equal(t, probe.InitialDelaySeconds, int32(15*60)) assert.Equal(t, probe.TimeoutSeconds, int32(2)) - assert.Equal(t, probe.PeriodSeconds, int32(10)) + assert.Equal(t, probe.PeriodSeconds, int32(60)) assert.Equal(t, probe.SuccessThreshold, int32(1)) - assert.Equal(t, probe.FailureThreshold, int32(3)) + assert.Equal(t, probe.FailureThreshold, int32(10)) assert.Equal(t, probe.Handler.HTTPGet.Path, path) assert.Equal(t, probe.Handler.HTTPGet.HTTPHeaders[0].Name, "Authorization")