Skip to content

Commit 92dc3a7

Browse files
committed
feat: add comment for public method and function
Signed-off-by: hlts2 <hiroto.funakoshi.hiroto@gmail.com>
1 parent 9c521a4 commit 92dc3a7

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

pkg/driver/hooks/hooks.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import (
1010
"k8s.io/client-go/tools/clientcmd"
1111
)
1212

13+
// Hook defines the lifecycle methods for a hook, such as PreStop, PostStart, and PostStop.
14+
// Implementations of this interface can define actions to be performed at different lifecycle stages.
1315
type Hook interface {
1416
PreStop(ctx context.Context) error
15-
// PostStop, ...
1617
}
1718

1819
type hook struct {
@@ -21,12 +22,12 @@ type hook struct {
2122
clientCfgPath string
2223
}
2324

25+
// NewHook creates a new Hook with the provided options. It returns an error if setup fails.
2426
func NewHook(opts ...Option) (Hook, error) {
2527
h := &hook{}
2628
for _, opt := range append(defaultOpts, opts...) {
2729
opt(h)
2830
}
29-
3031
if h.nodeName == "" {
3132
return nil, errors.New("node name not found")
3233
}

pkg/driver/hooks/options.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"k8s.io/client-go/kubernetes"
77
)
88

9+
// Option represents a configuration function that modifies hook object.
910
type Option func(*hook)
1011

1112
var defaultOpts = []Option{
@@ -21,6 +22,7 @@ func WithKubernetesClient(client kubernetes.Interface) Option {
2122
}
2223
}
2324

25+
// WithKubernetesClient returns Option to set Kubernetes config path.
2426
func WithKubernetesClientConfigPath(path string) Option {
2527
return func(h *hook) {
2628
if path != "" {
@@ -29,7 +31,7 @@ func WithKubernetesClientConfigPath(path string) Option {
2931
}
3032
}
3133

32-
// WithNodeName returns Option to set node node name.
34+
// WithNodeName returns Option to set node name.
3335
func WithNodeName(name string) Option {
3436
return func(h *hook) {
3537
if name != "" {

pkg/driver/hooks/prestop.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ var drainTaints = map[string]struct{}{
1919
v1.TaintNodeUnschedulable: {}, // Kubernetes common eviction taint (kubectl drain)
2020
}
2121

22+
// PreStop handles the PreStop lifecycle event. It retrieves the node information
23+
// from the Kubernetes API and checks if the node is being drained. If the node is not
24+
// being drained, it skips the VolumeAttachment cleanup check. If the node is being drained,
25+
// it waits for the cleanup of VolumeAttachments. If any errors occur during this process,
26+
// they are logged and returned.
2227
func (h *hook) PreStop(ctx context.Context) error {
2328
node, err := h.client.CoreV1().Nodes().Get(ctx, h.nodeName, metav1.GetOptions{})
2429
if err != nil {
@@ -49,7 +54,6 @@ func (h *hook) PreStop(ctx context.Context) error {
4954
log.Info().
5055
Str("node_name", h.nodeName).
5156
Msg("Finished waiting for VolumeAttachments cleanup")
52-
5357
return nil
5458
}
5559

0 commit comments

Comments
 (0)