Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RHCLOUD-27862] add Pod Lifecyle hooks #830

Merged
merged 7 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
adamrdrew marked this conversation as resolved.
Show resolved Hide resolved
adamrdrew marked this conversation as resolved.
Show resolved Hide resolved

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Untitled string in AppConfig Schema
adamrdrew marked this conversation as resolved.
Show resolved Hide resolved

```txt
https://cloud.redhat.com/schemas/clowder-appconfig#/definitions/DependencyEndpoint/properties/apiPaths/items
```




| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
| :------------------ | ---------- | -------------- | ----------------------- | :---------------- | --------------------- | ------------------- | ------------------------------------------------------------- |
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [schema.json\*](../../out/schema.json "open original schema") |

## items Type

`string`
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Untitled array in AppConfig Schema
adamrdrew marked this conversation as resolved.
Show resolved Hide resolved

```txt
https://cloud.redhat.com/schemas/clowder-appconfig#/definitions/DependencyEndpoint/properties/apiPaths
```

The list of API paths (each matching format: '/api/some-path/') that this app will serve requests from


| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
| :------------------ | ---------- | -------------- | ----------------------- | :---------------- | --------------------- | ------------------- | ------------------------------------------------------------- |
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [schema.json\*](../../out/schema.json "open original schema") |

## apiPaths Type

`string[]`
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
25 changes: 25 additions & 0 deletions tests/kuttl/test-lifecycle-hook/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
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
55 changes: 55 additions & 0 deletions tests/kuttl/test-lifecycle-hook/01-pods.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
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
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
Loading