Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module github.com/fluid-cloudnative/fluid

go 1.22.10
toolchain go1.23.7
go 1.23.7

replace k8s.io/api => k8s.io/api v0.29.5

Expand Down Expand Up @@ -69,7 +68,7 @@ require (
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.36.2
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.21.0
github.com/prometheus/client_golang v1.20.5
github.com/smartystreets/goconvey v1.8.1
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,8 @@ github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrb
github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc=
github.com/prometheus/client_golang v1.21.0 h1:DIsaGmiaBkSangBgMtWdNfxbMNdku5IK6iNhrEqWvdA=
github.com/prometheus/client_golang v1.21.0/go.mod h1:U9NM32ykUErtVBxdvD3zfi+EuFkkaBvMb09mIfe0Zgg=
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddc/alluxio/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ func (e *AlluxioEngine) queryCacheStatus() (states cacheStates, err error) {
// - When the Dataset's UfsTotal field is empty
// - When the Dataset's UfsTotal field contains the metadata sync pending message
// The cached percentage is calculated as (cached bytes / UfsTotal bytes) * 100.
//
//
// Parameters:
// - dataset (v1alpha1.Dataset): Pointer to the Dataset object containing UFS metadata.
// The Status.UfsTotal field must be a valid human-readable size string (e.g. "10GiB")
// - states (cacheStates): Pointer to the cache state structure that will be modified in-place.
// The cached field must be a valid human-readable size string (e.g. "5GiB")
//
//
// Returns:
// - None: Modifies the states.cachedPercentage field directly with formatted percentage string.
// The percentage is stored as a string using cachedPercentageFormat (e.g. "45.60%")
Expand Down
3 changes: 2 additions & 1 deletion pkg/ddc/alluxio/load_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ func (e *AlluxioEngine) genDataLoadValue(image string, targetDataset *datav1alph
// It obtains master pod details, creates file utilities, and checks readiness.
//
// Returns:
// ready bool - Runtime readiness status (true = ready, false = not ready).
//
// ready bool - Runtime readiness status (true = ready, false = not ready).
func (e *AlluxioEngine) CheckRuntimeReady() (ready bool) {
podName, containerName := e.getMasterPodInfo()
fileUtils := operations.NewAlluxioFileUtils(podName, containerName, e.namespace, e.Log)
Expand Down
3 changes: 2 additions & 1 deletion pkg/ddc/alluxio/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ func TestCheckMasterReady(t *testing.T) {

// TestShouldSetupMaster tests the ShouldSetupMaster function of AlluxioEngine.
// Functionality: Verifies if the Alluxio master should be set up based on runtime status.
// Parameters:
// Parameters:
// - t *testing.T: Standard testing object for test reporting and logging.
//
// Return: None (testing function).
// Notes:
// - Uses fake client to simulate interactions with Kubernetes API.
Expand Down
8 changes: 4 additions & 4 deletions pkg/ddc/alluxio/transform_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ func (e *AlluxioEngine) transformResourcesForMaster(runtime *datav1alpha1.Alluxi
}

// transformResourcesForWorker is responsible for transforming and setting resource limits for the Alluxio Worker component.
// This function updates the resource requirements for the Worker and JobWorker based on the runtime configuration
// This function updates the resource requirements for the Worker and JobWorker based on the runtime configuration
// and ensures that memory requests meet the required constraints.
//
// Parameters:
// - runtime: *datav1alpha1.AlluxioRuntime, the runtime configuration of Alluxio, including resource definitions
// for Worker and JobWorker.
// - runtime: *datav1alpha1.AlluxioRuntime, the runtime configuration of Alluxio, including resource definitions
// for Worker and JobWorker.
// - value: *Alluxio, the Alluxio runtime instance used to store the transformed resource information.
//
//
// Return value:
// - error: Returns an error if any issue occurs during resource transformation; otherwise, returns nil.
func (e *AlluxioEngine) transformResourcesForWorker(runtime *datav1alpha1.AlluxioRuntime, value *Alluxio) error {
Expand Down
22 changes: 11 additions & 11 deletions pkg/ddc/alluxio/transform_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ func TestTransformResourcesForWorkerWithTieredStore(t *testing.T) {

// Test cases structured to validate different tiered storage configurations
var tests = []struct {
runtime *datav1alpha1.AlluxioRuntime // Input Alluxio runtime configuration
alluxioValue *Alluxio // Expected output configuration
runtime *datav1alpha1.AlluxioRuntime // Input Alluxio runtime configuration
alluxioValue *Alluxio // Expected output configuration
}{
{&datav1alpha1.AlluxioRuntime{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -229,20 +229,20 @@ func TestTransformResourcesForWorkerWithTieredStore(t *testing.T) {
Spec: datav1alpha1.AlluxioRuntimeSpec{
TieredStore: datav1alpha1.TieredStore{
Levels: []datav1alpha1.Level{{
MediumType: common.Memory, // Memory-based tiered storage configuration
MediumType: common.Memory, // Memory-based tiered storage configuration
Quota: &result, // 20Gi quota allocation
}},
},
},
}, &Alluxio{
Properties: map[string]string{}, // Expected empty properties map
Properties: map[string]string{}, // Expected empty properties map
}},
}
// Iterate through test cases to validate transformation logic
for _, test := range tests {
// Initialize test environment with mocked dependencies
engine := &AlluxioEngine{
Log: fake.NullLogger(), // Discard logging output
Log: fake.NullLogger(), // Discard logging output
name: "test",
namespace: "test",
}
Expand Down Expand Up @@ -472,12 +472,12 @@ func TestTransformResourcesForWorkerWithOnlyRequest(t *testing.T) {
// resource requests are handled as expected.
//
// The function performs the following steps:
// 1. Defines resource requirements with limits for memory (20Gi) and CPU (500m).
// 2. Sets up test cases to validate the transformation logic, including scenarios with and without
// tiered store configurations.
// 3. Initializes an AlluxioEngine instance with a fake client and runtime objects for testing.
// 4. Transforms the resource requirements for the worker using the AlluxioEngine.
// 5. Validates the transformed resource limits and requests against the expected results.
// 1. Defines resource requirements with limits for memory (20Gi) and CPU (500m).
// 2. Sets up test cases to validate the transformation logic, including scenarios with and without
// tiered store configurations.
// 3. Initializes an AlluxioEngine instance with a fake client and runtime objects for testing.
// 4. Transforms the resource requirements for the worker using the AlluxioEngine.
// 5. Validates the transformed resource limits and requests against the expected results.
//
// Test cases include:
// - A scenario where tiered store configuration is provided, ensuring memory limits and requests are set correctly.
Expand Down
24 changes: 13 additions & 11 deletions pkg/ddc/alluxio/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ func TestTransformMaster(t *testing.T) {
}
}

// TestTransformWorkers verifies that the transformWorkers function correctly transforms
// the worker configuration of AlluxioRuntime into the expected Alluxio structure.
// It tests different network modes, node selectors, and image pull secrets to ensure
// TestTransformWorkers verifies that the transformWorkers function correctly transforms
// the worker configuration of AlluxioRuntime into the expected Alluxio structure.
// It tests different network modes, node selectors, and image pull secrets to ensure
// correct transformation behavior.
func TestTransformWorkers(t *testing.T) {
testCases := map[string]struct {
Expand Down Expand Up @@ -588,19 +588,21 @@ func TestGetMediumTypeFromVolumeSource(t *testing.T) {
}
}

// TestAlluxioEngine_allocateSinglePort is a unit test function that tests
// TestAlluxioEngine_allocateSinglePort is a unit test function that tests
// the `allocateSinglePort` method of the `AlluxioEngine` struct.
// The function verifies the behavior of port allocation for Alluxio master
// The function verifies the behavior of port allocation for Alluxio master
// and worker components under different scenarios,
// including when properties are set, unset, or when runtime specifications
// including when properties are set, unset, or when runtime specifications
// are provided.
//
//
// Parameters:
// - t: A testing.T object provided by the Go testing framework, used to
// - t: A testing.T object provided by the Go testing framework, used to
//
// manage test state and support formatted test logs.
//
// Returns:
// - None. The function is a test function and does not return any value.
// - None. The function is a test function and does not return any value.
//
// It reports test failures using the `t.Errorf` method.
func TestAlluxioEngine_allocateSinglePort(t *testing.T) {
// Define the fields required for the AlluxioEngine struct.
Expand Down Expand Up @@ -902,10 +904,10 @@ func TestAlluxioEngine_allocatePorts(t *testing.T) {
//
// Test Cases:
// 1. "master properties is not null":
// - Ensures that when master-specific properties exist, they override the global properties.
// - Ensures that when master-specific properties exist, they override the global properties.
//
// 2. "properties is not null for master":
// - Ensures that both master-specific and additional global properties are correctly handled.
// - Ensures that both master-specific and additional global properties are correctly handled.
//
// The function iterates over multiple test cases and checks if the transformed properties
// match the expected values. If the transformation does not produce the expected result, the test fails.
Expand Down
8 changes: 4 additions & 4 deletions pkg/ddc/alluxio/transform_ufs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
v1 "k8s.io/api/core/v1"
)

// TestTransformDatasetToVolume is a unit test function that verifies the transformation of a Dataset into a UFSPath
// in the Alluxio runtime. It ensures that the Dataset's mount points are correctly converted into corresponding
// TestTransformDatasetToVolume is a unit test function that verifies the transformation of a Dataset into a UFSPath
// in the Alluxio runtime. It ensures that the Dataset's mount points are correctly converted into corresponding
// container and host paths.
//
// Parameters:
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestTransformDatasetToVolume(t *testing.T) {
}},
},
}, &Alluxio{}, ufsPath},

// Test case 2: Mount with a path specified
{&datav1alpha1.AlluxioRuntime{}, &datav1alpha1.Dataset{
Spec: datav1alpha1.DatasetSpec{
Expand All @@ -72,7 +72,7 @@ func TestTransformDatasetToVolume(t *testing.T) {
},
}, &Alluxio{}, ufsPath1},
}

// Iterate through all test cases and run the test.
for _, test := range tests {
// Create an instance of AlluxioEngine to call the function under test.
Expand Down
28 changes: 14 additions & 14 deletions pkg/ddc/alluxio/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,17 @@ func Test_lookUpUsedCapacity(t *testing.T) {
node corev1.Node
usedCapacityMap map[string]int64
}

internalIP := "192.168.1.147"
var usageForInternalIP int64 = 1024

internalHost := "slave001"
var usageForInternalHost int64 = 4096

usedCapacityMap := map[string]int64{}
usedCapacityMap[internalIP] = usageForInternalIP
usedCapacityMap[internalHost] = usageForInternalHost

tests := []struct {
name string
args args
Expand Down Expand Up @@ -485,16 +485,16 @@ func TestGetMasterPod(t *testing.T) {
}
}

// TestGetMasterStatefulset tests the getMasterStatefulset method of the AlluxioEngine struct.
// It verifies that the method correctly retrieves the expected StatefulSet based on the provided
// AlluxioRuntime, name, and namespace. The test includes a sample runtime and expected
// StatefulSet, checking for both successful retrieval and error scenarios.
//
// Parameters:
// - t: The test framework's context, which provides methods for logging and error reporting.
//
// Returns:
// - The test does not return any value, but it reports errors using the t.Error and
// TestGetMasterStatefulset tests the getMasterStatefulset method of the AlluxioEngine struct.
// It verifies that the method correctly retrieves the expected StatefulSet based on the provided
// AlluxioRuntime, name, and namespace. The test includes a sample runtime and expected
// StatefulSet, checking for both successful retrieval and error scenarios.
//
// Parameters:
// - t: The test framework's context, which provides methods for logging and error reporting.
//
// Returns:
// - The test does not return any value, but it reports errors using the t.Error and
// t.Errorf methods to indicate whether the test passed or failed.
func TestGetMasterStatefulset(t *testing.T) {
type fields struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddc/jindo/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ func TestUpdateDatasetStatus(t *testing.T) {
}
}

// TestBindToDataset tests the BindToDataset method of JindoEngine to verify whether it can correctly bind the dataset to the runtime
// and update the dataset's cache state and HCFS status. The test creates mock Dataset and JindoRuntime objects,
// TestBindToDataset tests the BindToDataset method of JindoEngine to verify whether it can correctly bind the dataset to the runtime
// and update the dataset's cache state and HCFS status. The test creates mock Dataset and JindoRuntime objects,
// uses a fake client to simulate operations, and finally checks if the dataset's Phase, CacheStates, and HCFSStatus match the expected results.
func TestBindToDataset(t *testing.T) {
testDatasetInputs := []*datav1alpha1.Dataset{
Expand Down
26 changes: 13 additions & 13 deletions pkg/ddc/jindo/delete_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ func doTestCases(testCases []TestCase, t *testing.T) {
//
// Test Strategy:
// 1. Setup test environment with mocked Kubernetes resources:
// - PVs with 'CreatedBy=fluid' annotation to simulate Fluid-managed persistent volumes
// - PVCs with different configurations (normal vs error cases)
// 2. Create 3 test scenarios using parameterized test pattern:
// Case 1: Normal deletion (JindoEngineCommon)
// - Input: Valid PV/PVC without conflicting annotations
// - Expected: Successful deletion (isDeleted=true, isErr=false)
// Case 2: Protected PVC deletion (JindoEngineErr)
// - Input: PVC with 'CreatedBy=fluid' annotation (protected resource)
// - Expected: Failed deletion (isErr=true)
// Case 3: Missing runtime scenario (JindoEngineNoRunTime)
// - Input: Engine with runtime=false configuration
// - Expected: Failed deletion (isErr=true)
// 3. Verification: Uses doTestCases() helper to validate deletion outcomes against expectations
// - PVs with 'CreatedBy=fluid' annotation to simulate Fluid-managed persistent volumes
// - PVCs with different configurations (normal vs error cases)
// 2. Create 3 test scenarios using parameterized test pattern:
// Case 1: Normal deletion (JindoEngineCommon)
// - Input: Valid PV/PVC without conflicting annotations
// - Expected: Successful deletion (isDeleted=true, isErr=false)
// Case 2: Protected PVC deletion (JindoEngineErr)
// - Input: PVC with 'CreatedBy=fluid' annotation (protected resource)
// - Expected: Failed deletion (isErr=true)
// Case 3: Missing runtime scenario (JindoEngineNoRunTime)
// - Input: Engine with runtime=false configuration
// - Expected: Failed deletion (isErr=true)
// 3. Verification: Uses doTestCases() helper to validate deletion outcomes against expectations
//
// Test Resources:
// - fake.NewFakeClientWithScheme: Simulates Kubernetes API server with predefined resources
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddc/juicefs/data_process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
// It verifies the behavior of the function under different scenarios, including invalid input and missing datasets.
//
// Parameters:
// - t: The testing context used for reporting test failures and logging.
// - t: The testing context used for reporting test failures and logging.
func TestJuiceFSEngine_generateDataProcessValueFile(t *testing.T) {
// 1. Define a sample dataset and dataProcess object for testing.
dataset := &datav1alpha1.Dataset{
Expand Down
20 changes: 10 additions & 10 deletions pkg/ddc/juicefs/datasetinfo_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ func GetFSInfoFromConfigMap(client client.Client, name string, namespace string)
return parseFSInfoFromConfigMap(configMap)
}

// parseFSInfoFromConfigMap extracts file system configuration information
// from the provided ConfigMap. It parses the data field of the ConfigMap
// into a JuiceFS structure and populates the returned map with relevant
// configuration details. If the parsing fails or the data field is missing,
// parseFSInfoFromConfigMap extracts file system configuration information
// from the provided ConfigMap. It parses the data field of the ConfigMap
// into a JuiceFS structure and populates the returned map with relevant
// configuration details. If the parsing fails or the data field is missing,
// an error is returned.
//
// Parameters:
// - configMap: A pointer to a v1.ConfigMap object that contains the
// configuration data.
// - configMap: A pointer to a v1.ConfigMap object that contains the
// configuration data.
//
// Returns:
// - info: A map containing parsed configuration details such as MetaUrlSecret,
// TokenSecret, AccessKeySecret, SecretKeySecret, FormatCmd, Name, and Edition.
// - err: An error if the data parsing process fails or if the required data
// field is missing.
// - info: A map containing parsed configuration details such as MetaUrlSecret,
// TokenSecret, AccessKeySecret, SecretKeySecret, FormatCmd, Name, and Edition.
// - err: An error if the data parsing process fails or if the required data
// field is missing.
func parseFSInfoFromConfigMap(configMap *v1.ConfigMap) (info map[string]string, err error) {
var value JuiceFS
info = map[string]string{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddc/juicefs/datasetinfo_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestGetFSInfoFromConfigMap(t *testing.T) {
}

// Test_parseFSInfoFromConfigMap is a unit test function for the parseFSInfoFromConfigMap method.
// It validates whether the function correctly extracts and parses dataset information
// It validates whether the function correctly extracts and parses dataset information
// from a given Kubernetes ConfigMap.
//
// Steps:
Expand Down
Loading
Loading