Skip to content

Commit

Permalink
feat : add Lifecycle to AppSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
ekgns33 committed May 15, 2024
1 parent 425aa39 commit 2e8628d
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/application_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type AppSpec struct {
AppType string `json:"appType,omitempty"` // back, front-spa, front-srr
Annotations map[string]string `json:"annotations,omitempty"`
ContainerName string `json:"containerName"`
LifeCycle *v1.Lifecycle `json:"lifeCycle"`
}

type PodDisruptionBudgetSpec struct {
Expand Down Expand Up @@ -95,7 +96,6 @@ type ApplicationSpec struct {
// Important: Run "make" to regenerate code after modifying this file
App AppSpec `json:"app"`
Scheduler SchedulerSpec `json:"scheduler,omitempty"`
//TODO: need lifecycle spec
Probe ProbeSpec `json:"probe,omitempty"`
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
Service ServiceSpec `json:"service,omitempty"`
Expand Down
194 changes: 193 additions & 1 deletion config/crd/bases/app.cloudclub.com_applications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,206 @@ spec:
type: integer
image:
type: string
lifeCycle:
description: Lifecycle describes actions that the management system
should take in response to container lifecycle events. For the
PostStart and PreStop lifecycle handlers, management of the
container blocks until the action is complete, unless the container
process fails, in which case the handler is aborted.
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: 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: Deprecated. TCPSocket is NOT supported as
a LifecycleHandler and kept for the backward compatibility.
There are no validation of this field and lifecycle
hooks will fail in runtime when tcp handler is specified.
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 Pod''s termination grace period countdown
begins before the PreStop hook is executed. Regardless of
the outcome of the handler, the container will eventually
terminate within the Pod''s termination grace period (unless
delayed by finalizers). 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: 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: Deprecated. TCPSocket is NOT supported as
a LifecycleHandler and kept for the backward compatibility.
There are no validation of this field and lifecycle
hooks will fail in runtime when tcp handler is specified.
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
replicas:
format: int32
type: integer
required:
- containerName
- containerPort
- image
- lifeCycle
type: object
ingress:
properties:
Expand Down Expand Up @@ -93,7 +286,6 @@ spec:
- rules
type: object
probe:
description: 'TODO: need lifecycle spec'
properties:
liveness:
description: Probe describes a health check to be performed against
Expand Down
7 changes: 7 additions & 0 deletions config/samples/app_v1alpha1_application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ spec:
containerName: nginx
image: nginx:latest
containerPort: 80
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"]
preStop:
exec:
command: ["/bin/sh","-c","nginx -s quit; while killall -0 nginx; do sleep 1; done"]
1 change: 1 addition & 0 deletions internal/driver/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (a *ApplicationClient) UpsertDeployment(ctx context.Context, req ctrl.Reque
{
Name: req.Name,
Image: app.Spec.App.Image,
Lifecycle: app.Spec.App.LifeCycle,
},
},
},
Expand Down

0 comments on commit 2e8628d

Please sign in to comment.