Skip to content

Commit

Permalink
Merge pull request #830 from maskarb/pod-lifecycle-hooks
Browse files Browse the repository at this point in the history
[RHCLOUD-27862] add Pod Lifecyle hooks
  • Loading branch information
adamrdrew authored Nov 3, 2023
2 parents 885c588 + 24f77f7 commit 702169f
Show file tree
Hide file tree
Showing 11 changed files with 1,399 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apis/cloud.redhat.com/v1alpha1/clowdapp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ type PodSpec struct {
// A pass-through of a list of VolumesMounts in standa k8s format.
VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"`

// A pass-through of Lifecycle specification in standard k8s format
Lifecycle *v1.Lifecycle `json:"lifecycle,omitempty"`

// A pass-through of TerminationGracePeriodSeconds specification in standard k8s format
// default is 30 seconds
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`

// Lists the expected side cars, will be validated in the validating webhook
Sidecars []Sidecar `json:"sidecars,omitempty"`

Expand Down
10 changes: 10 additions & 0 deletions apis/cloud.redhat.com/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

402 changes: 402 additions & 0 deletions config/crd/bases/cloud.redhat.com_clowdapps.yaml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions controllers/cloud.redhat.com/providers/deployment/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func initDeployment(app *crd.ClowdApp, env *crd.ClowdEnvironment, d *apps.Deploy
TerminationMessagePath: TerminationLogPath,
TerminationMessagePolicy: core.TerminationMessageReadFile,
ImagePullPolicy: core.PullIfNotPresent,
Lifecycle: pod.Lifecycle,
}

setLivenessProbe(&pod, deployment, env, &c)
Expand Down Expand Up @@ -270,6 +271,8 @@ func initDeployment(app *crd.ClowdApp, env *crd.ClowdEnvironment, d *apps.Deploy

d.Spec.Template.Spec.InitContainers = ics

d.Spec.Template.Spec.TerminationGracePeriodSeconds = pod.TerminationGracePeriodSeconds

d.Spec.Template.Spec.Volumes = pod.Volumes
d.Spec.Template.Spec.Volumes = append(d.Spec.Template.Spec.Volumes, core.Volume{
Name: "config-secret",
Expand Down
416 changes: 416 additions & 0 deletions deploy-mutate.yml

Large diffs are not rendered by default.

416 changes: 416 additions & 0 deletions deploy.yml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/antora/modules/ROOT/pages/api_reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,8 @@ PodSpec defines a container running inside a ClowdApp.
| *`readinessProbe`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#probe-v1-core[$$Probe$$]__ | A pass-through of a Readiness Probe specification in standard k8s format. If omitted, a standard probe will be setup point to the webPort defined in the ClowdEnvironment and a path of /healthz. Ignored if Web is set to false.
| *`volumes`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#volume-v1-core[$$Volume$$] array__ | A pass-through of a list of Volumes in standa k8s format.
| *`volumeMounts`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#volumemount-v1-core[$$VolumeMount$$] array__ | A pass-through of a list of VolumesMounts in standa k8s format.
| *`lifecycle`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#lifecycle-v1-core[$$Lifecycle$$]__ | A pass-through of Lifecycle specification in standard k8s format
| *`terminationGracePeriodSeconds`* __integer__ | A pass-through of TerminationGracePeriodSeconds specification in standard k8s format default is 30 seconds
| *`sidecars`* __xref:{anchor_prefix}-github-com-redhatinsights-clowder-apis-cloud-redhat-com-v1alpha1-sidecar[$$Sidecar$$] array__ | Lists the expected side cars, will be validated in the validating webhook
| *`machinePool`* __string__ | MachinePool allows the pod to be scheduled to a particular machine pool.
|===
Expand Down
7 changes: 7 additions & 0 deletions tests/kuttl/test-lifecycle-hook/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Namespace
metadata:
name: test-lifecycle-hook
spec:
finalizers:
- kubernetes
59 changes: 59 additions & 0 deletions tests/kuttl/test-lifecycle-hook/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: lifecycle-processor
namespace: test-lifecycle-hook
spec:
template:
spec:
serviceAccountName: lifecycle-processor
containers:
- name: lifecycle-processor
image: quay.io/psav/clowder-hello
lifecycle:
postStart:
exec:
command:
- ./clowder-hello
- boo
preStop:
httpGet:
path: /healthz
port: 8000
scheme: HTTP
terminationGracePeriodSeconds: 500
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: lifecycle-processor-no-termination-period
namespace: test-lifecycle-hook
spec:
template:
spec:
serviceAccountName: lifecycle-processor-no-termination-period
containers:
- name: lifecycle-processor-no-termination-period
image: quay.io/psav/clowder-hello
lifecycle:
preStop:
httpGet:
path: /healthz
port: 8000
scheme: HTTP
terminationGracePeriodSeconds: 30
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: lifecycle-processor-only-termination-period
namespace: test-lifecycle-hook
spec:
template:
spec:
serviceAccountName: lifecycle-processor-only-termination-period
containers:
- name: lifecycle-processor-only-termination-period
image: quay.io/psav/clowder-hello
terminationGracePeriodSeconds: 29
67 changes: 67 additions & 0 deletions tests/kuttl/test-lifecycle-hook/01-pods.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdEnvironment
metadata:
name: test-lifecycle-hook
spec:
targetNamespace: test-lifecycle-hook
providers:
web:
port: 8000
mode: operator
metrics:
port: 9000
mode: operator
path: "/metrics"
kafka:
mode: none
db:
mode: none
logging:
mode: none
objectStore:
mode: none
inMemoryDb:
mode: none
resourceDefaults:
limits:
cpu: 400m
memory: 1024Mi
requests:
cpu: 30m
memory: 512Mi
---
apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdApp
metadata:
name: lifecycle
namespace: test-lifecycle-hook
spec:
envName: test-lifecycle-hook
deployments:
- name: processor
podSpec:
image: quay.io/psav/clowder-hello
lifecycle:
postStart:
exec:
command:
- ./clowder-hello
- boo
preStop:
httpGet:
port: 8000
path: /healthz
terminationGracePeriodSeconds: 500
- name: processor-no-termination-period
podSpec:
image: quay.io/psav/clowder-hello
lifecycle:
preStop:
httpGet:
port: 8000
path: /healthz
- name: processor-only-termination-period
podSpec:
image: quay.io/psav/clowder-hello
terminationGracePeriodSeconds: 29
10 changes: 10 additions & 0 deletions tests/kuttl/test-lifecycle-hook/02-delete.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestStep
delete:
- apiVersion: v1
kind: Namespace
name: test-lifecycle-hook
- apiVersion: cloud.redhat.com/v1alpha1
kind: ClowdEnvironment
name: test-lifecycle-hook

0 comments on commit 702169f

Please sign in to comment.