Skip to content

Commit

Permalink
Add or modify comments for multiple methods (fluid-cloudnative#247)
Browse files Browse the repository at this point in the history
* Add some comments for utils

* Add some comments for ddc/alluxio
  • Loading branch information
TrafalgarZZZ authored Oct 21, 2020
1 parent bf0a7d0 commit b31f60a
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/ddc/alluxio/operations/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (a AlluxioFileUtils) IsMounted(alluxioPath string) (mounted bool, err error
return mounted, err
}

// Check if it's ready
// Check if the Alluxio is ready by running `alluxio fsadmin report` command
func (a AlluxioFileUtils) Ready() (ready bool) {
var (
command = []string{"alluxio", "fsadmin", "report"}
Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/alluxio/operations/cached.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (a AlluxioFileUtils) CachedState() (cached int64, err error) {
return
}

// clean cache with a preset timeout of 60s
func (a AlluxioFileUtils) CleanCache(path string) (err error) {
var (
command = []string{"timeout", "-t", "60", "alluxio", "fs", "free", "-f", path}
Expand Down
5 changes: 5 additions & 0 deletions pkg/ddc/alluxio/operations/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import (
"time"
)

/*
* Sync local path by running command `du -sh <path>`.
* Under the circumstance where some NAS(e.g. NFS) is mounted on the `<path>`, the function will sync metadata of all files in the NAS.
* This is necessary for Alluxio to get consistent file metadata with UFS(i.e. NAS in this case).
*/
func (a AlluxioFileUtils) SyncLocalDir(path string) (err error) {
var (
// command = []string{"alluxio", "fs", "-Dalluxio.user.file.metadata.sync.interval=0", "ls", "-R", alluxioPath}
Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/alluxio/shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// shut down the Alluxio engine
func (e *AlluxioEngine) Shutdown() (err error) {
if e.retryShutdown < e.gracefulShutdownLimits {
err = e.cleanupCache()
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddc/alluxio/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"k8s.io/client-go/util/retry"
)

// init the status of the engine when it's ready
// Check the related runtime status and update it
func (e *AlluxioEngine) CheckAndUpdateRuntimeStatus() (ready bool, err error) {

var (
Expand Down
6 changes: 6 additions & 0 deletions pkg/ddc/alluxio/ufs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@ import (
"github.com/fluid-cloudnative/fluid/pkg/ddc/alluxio/operations"
)

// return used storage size of Alluxio in bytes
func (e *AlluxioEngine) UsedStorageBytes() (value int64, err error) {
// return e.usedStorageBytesInternal()
return e.usedStorageBytesInternal()
}

// return free storage size of Alluxio in bytes
func (e *AlluxioEngine) FreeStorageBytes() (value int64, err error) {
// return e.freeStorageBytesInternal()
return e.freeStorageBytesInternal()
}

// return total storage size of Alluxio in bytes
func (e *AlluxioEngine) TotalStorageBytes() (value int64, err error) {
// return e.totalStorageBytesInternal()
return e.totalStorageBytesInternal()
}

// return the total num of files in Alluxio
func (e *AlluxioEngine) TotalFileNums() (value int64, err error) {
// return e.totalFileNumsInternal()
return e.totalFileNumsInternal()
Expand Down
2 changes: 2 additions & 0 deletions pkg/utils/byte_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func BytesSize(size float64) string {
return units.CustomSize("%.2f%s", size, 1024.0, binaryAbbrs)
}

// FromHumanSize returns an integer from a human-readable specification of a
// size with 1024 as multiplier (eg. "44kB" = "(44 * 1024)B").
func FromHumanSize(size string) (int64, error) {
return parseSize(size, binaryMap)
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/utils/crtl_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ func IgnoreNotFound(err error) error {
return err
}

// No requeue
// NoRequeue returns the result of a reconciler invocation and won't requeue.
func NoRequeue() (ctrl.Result, error) {
return RequeueIfError(nil)
}

// RequeueAfterInterval returns the result of a reconciler invocation with a given requeue interval.
func RequeueAfterInterval(interval time.Duration) (ctrl.Result, error) {
return ctrl.Result{RequeueAfter: interval}, nil
}

// RequeueImmediately returns the result of a reconciler invocation and requeue immediately.
func RequeueImmediately() (ctrl.Result, error) {
return ctrl.Result{Requeue: true}, nil
}

// RequeueIfError returns the result of a reconciler invocation and requeue immediately if err is not nil.
func RequeueIfError(err error) (ctrl.Result, error) {
return ctrl.Result{}, err
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/utils/dataset_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func UpdateDatasetCondition(conditions []datav1alpha1.DatasetCondition, conditio
return conditions
}

// get dataset condition given a dataset condition type.
// If found, return index of the founded condition in the condition array and the founded condition itself, otherwise return -1 and nil.
func GetDatasetCondition(conditions []datav1alpha1.DatasetCondition,
condType datav1alpha1.DatasetConditionType) (index int, condition *datav1alpha1.DatasetCondition) {

Expand Down Expand Up @@ -84,6 +86,7 @@ func GetDatasetCondition(conditions []datav1alpha1.DatasetCondition,
// return newConditions
// }

// Check if the given dataset condition exists in the given dataset condition array.
func IsDatasetConditionExist(conditions []datav1alpha1.DatasetCondition,
cond datav1alpha1.DatasetCondition) (found bool) {

Expand Down
1 change: 1 addition & 0 deletions pkg/utils/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func GetChartVersion(chart string) (version string, err error) {
return version, nil
}

// GetChartName extracts the last element of the chart's path as the chart's name
func GetChartName(chart string) string {
return filepath.Base(chart)
}
2 changes: 2 additions & 0 deletions pkg/utils/kubeclient/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// Check if the configMap exists given its name and namespace
func IsConfigMapExist(client client.Client, name, namespace string) (found bool, err error) {
key := types.NamespacedName{
Name: name,
Expand All @@ -44,6 +45,7 @@ func IsConfigMapExist(client client.Client, name, namespace string) (found bool,
return found, err
}

// Delete the configmap given its name and namespace if the configmap exists
func DeleteConfigMap(client client.Client, name, namespace string) (err error) {
key := types.NamespacedName{
Name: name,
Expand Down
3 changes: 3 additions & 0 deletions pkg/utils/kubeclient/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,17 @@ func ExecCommandInContainerWithFullOutput(podName string, containerName string,
})
}

// Execute shell command or script in the specified container and return stdout, stderr and error
func ExecShellInContainer(podName string, containerName string, namespace string, cmd string) (stdout string, stderr string, err error) {
return ExecCommandInContainer(podName, containerName, namespace, []string{"/bin/sh", "-c", cmd})
}

// A wrapper function of ExecCommandInContainerWithFullOutput
func ExecCommandInContainer(podName string, containerName string, namespace string, cmd []string) (stdout string, stderr string, err error) {
return ExecCommandInContainerWithFullOutput(podName, containerName, namespace, cmd)
}

// Find the first container in the given pod, executes command in that container, and return stdout, stderr and error.
func ExecCommandInPod(podName string, namespace string, cmd []string) (stdout string, stderr string, err error) {
pod, err := clientset.CoreV1().Pods(namespace).Get(context.TODO(), podName, metav1.GetOptions{})
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions pkg/utils/kubeclient/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ func EnsureNamespace(client client.Client, namespace string) (err error) {
if err = client.Get(context.TODO(), key, &ns); err != nil {
if apierrs.IsNotFound(err) {
return createNamespace(client, namespace)
} else {
return err
}
}
return err
Expand Down
2 changes: 2 additions & 0 deletions pkg/utils/kubeclient/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func IsFailedPod(pod *corev1.Pod) bool {
return pod != nil && pod.Status.Phase == corev1.PodFailed
}

// get pod given name and namespace of the pod.
func GetPodByName(client client.Client, name, namespace string) (pod *corev1.Pod, err error) {
key := types.NamespacedName{
Name: name,
Expand All @@ -64,6 +65,7 @@ func GetPodByName(client client.Client, name, namespace string) (pod *corev1.Pod
return
}

// delete the given pod if it exists
func DeletePod(client client.Client, pod *corev1.Pod) error {
err := client.Delete(context.TODO(), pod)
if apierrs.IsNotFound(err) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/kubeclient/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
persistentVolumeClaimProtectionFinalizerName = "kubernetes.io/pvc-protection"
)

// IsPersistentVolumeExist
// IsPersistentVolumeExist checks if the persistent volume exists given name and annotations of the PV.
func IsPersistentVolumeExist(client client.Client, name string, annotations map[string]string) (found bool, err error) {
key := types.NamespacedName{
Name: name,
Expand Down Expand Up @@ -66,7 +66,7 @@ func IsPersistentVolumeExist(client client.Client, name string, annotations map[
return found, err
}

// IsPersistentVolumeClaimExist
// IsPersistentVolumeClaimExist checks if the persistent volume claim exists given name, namespace and annotations of the PVC.
func IsPersistentVolumeClaimExist(client client.Client, name, namespace string, annotations map[string]string) (found bool, err error) {
key := types.NamespacedName{
Name: name,
Expand Down
1 change: 1 addition & 0 deletions pkg/utils/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import "os"

const MountRoot string = "MOUNT_ROOT"

//GetMountRoot gets the value of the env variable named MOUNT_ROOT
func GetMountRoot() string {
return os.Getenv(MountRoot)
}
4 changes: 3 additions & 1 deletion pkg/utils/runtime_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewRuntimeCondition(conditionType data.RuntimeConditionType, reason, messag
}
}

// SetDatasetCondition updates the dataset to include the provided condition.
// UpdateRuntimeCondition updates the runtime to include the provided condition.
// If the condition that we are about to add already exists
// and has the same status and reason then we are not going to update.
func UpdateRuntimeCondition(conditions []data.RuntimeCondition, condition data.RuntimeCondition) []data.RuntimeCondition {
Expand All @@ -56,6 +56,8 @@ func UpdateRuntimeCondition(conditions []data.RuntimeCondition, condition data.R
return conditions
}

// get runtime condition given a runtime condition type.
// If found, return index of the founded condition in the condition array and the founded condition itself, otherwise return -1 and nil.
func GetRuntimeCondition(conditions []data.RuntimeCondition,
condType data.RuntimeConditionType) (index int, condition *data.RuntimeCondition) {
if conditions == nil {
Expand Down

0 comments on commit b31f60a

Please sign in to comment.