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

feat : add Lifecycle to AppSpec #11

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LifeCycle *v1.Lifecycle `json:"lifeCycle"`
// +optional
LifeCycle *v1.Lifecycle `json:"lifeCycle,omitempty"`

}

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"]
Comment on lines +17 to +23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lifecycle 추가 안하고 돌렸을때는 문제 없이 돌아가나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppSpec에 추가된 상태에서 위 lifecycle에 명시된 내용이 없는 경우를 말씀하시는 걸까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make install의 경우 지우고 실행해도 이전 yaml로 돌아가는 것 같아보이네요 😢
그런데 kubectl apply -f config/samples/app_v1alpha1_application.yaml로 실행하면 명시된 필드가 비어있다고 실행되지 않습니다.

1 change: 1 addition & 0 deletions internal/driver/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@
{
Name: req.Name,
Image: app.Spec.App.Image,
Lifecycle: app.Spec.App.LifeCycle,
},
},
},
},
},
}
ctrl.SetControllerReference(app, newDeployment, a.Schema)

Check failure on line 93 in internal/driver/application.go

View workflow job for this annotation

GitHub Actions / Golang linter

Error return value is not checked (errcheck)
return a.Kubernetes.Create(ctx, newDeployment)
}
return err
Expand Down
Loading