Skip to content
Open
Changes from all 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
10 changes: 10 additions & 0 deletions pkg/ddc/alluxio/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ func (e *AlluxioEngine) getMasterPod(name string, namespace string) (pod *v1.Pod
return pod, err
}

// getMasterStatefulset retrieves the Alluxio Master StatefulSet with the specified name
// and namespace from the Kubernetes cluster using the embedded client.
//
// Parameters:
// - name: the name of the StatefulSet resource.
// - namespace: the Kubernetes namespace where the StatefulSet resides.
//
// Returns:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding GoDoc here — the description of the parameters and behavior is clear. One small accuracy nit on the return value: the comment says master: a pointer to the appsv1.StatefulSet object if found; nil on error., but the implementation always allocates master = &appsv1.StatefulSet{} before calling e.Client.Get, so the returned pointer is never nil. On error it just points to a zero-value StatefulSet.

Consider rewording to match the actual behavior, for example:

//   - master: a non-nil pointer to an appsv1.StatefulSet; populated when err is nil,
//             otherwise points to a zero-value StatefulSet and should not be relied upon.

Keeping the doc precise here helps callers reason about nil checks vs. error checks.

// - master: a pointer to the appsv1.StatefulSet object if found; nil on error.
// - err: non-nil if the retrieval fails (e.g., resource not found, network issue).
Comment on lines +85 to +87

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The comment states that master is nil on error. However, looking at the implementation of getMasterStatefulset, master is initialized as &appsv1.StatefulSet{} and then returned along with the error. Therefore, on error, master will be a pointer to an empty StatefulSet struct rather than nil. The comment should be updated to accurately reflect this behavior to prevent callers from incorrectly assuming they can perform a simple nil check on the returned master pointer.

Suggested change
// Returns:
// - master: a pointer to the appsv1.StatefulSet object if found; nil on error.
// - err: non-nil if the retrieval fails (e.g., resource not found, network issue).
// Returns:
// - master: a pointer to the appsv1.StatefulSet object (note: on error, this is a pointer to an empty StatefulSet, not nil).
// - err: non-nil if the retrieval fails (e.g., resource not found, network issue).

func (e *AlluxioEngine) getMasterStatefulset(name string, namespace string) (master *appsv1.StatefulSet, err error) {
master = &appsv1.StatefulSet{}
err = e.Client.Get(context.TODO(), types.NamespacedName{
Expand Down
Loading