Skip to content

Commit

Permalink
Support HCFS (fluid-cloudnative#256)
Browse files Browse the repository at this point in the history
* Support HCFS, Fix #30651485

* Support HCFS, Fix #30651485

* Update spec, to #29833753

* Support HCFS, Fix #30651485

* Support HCFS, Fix #30651485

* Update spec, to #29833753

* Support HCFS, Fix #30651485

* Support HCFS, Fix #30651485

* Support HCFS, Fix #30651485

* Support HCFS, Fix #30651485

* Support HCFS, Fix #30651485

* Support HCFS, Fix #30651485

* Support HCFS, To #30960673

* Support HCFS, To #30960673

* Support HCFS, To #30960673
  • Loading branch information
cheyang authored Oct 24, 2020
1 parent 2c92afd commit fcca6d5
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

### Features

- Show the HCFS Access Endpoint


### Bugs

Expand Down
9 changes: 9 additions & 0 deletions api/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@ type InitUsersSpec struct {
// +optional
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
}

// HCFS Endpoint info
type HCFSStatus struct {
// Endpoint for accessing
Endpoint string `json:"endpoint,omitempty"`

// Underlayer HCFS Compatible Version
UnderlayerFileSystemVersion string `json:"underlayerFileSystemVersion,omitempty"`
}
4 changes: 4 additions & 0 deletions api/v1alpha1/dataset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ type DatasetStatus struct {

// CacheStatus represents the total resources of the dataset.
CacheStates common.CacheStateList `json:"cacheStates,omitempty"`

// HCFSStatus represents hcfs info
HCFSStatus *HCFSStatus `json:"hcfs,omitempty"`
}

// DatasetConditionType defines all kinds of types of cacheStatus.<br>
Expand Down Expand Up @@ -170,6 +173,7 @@ type DatasetCondition struct {
// +kubebuilder:printcolumn:name="Cache Capacity",type="string",JSONPath=`.status.cacheStates.cacheCapacity`
// +kubebuilder:printcolumn:name="Cached Percentage",type="string",JSONPath=`.status.cacheStates.cachedPercentage`
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=`.status.phase`
// +kubebuilder:printcolumn:name="HCFS URL",type="string",JSONPath=`.status.hcfs.endpoint`,priority=10
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=`.metadata.creationTimestamp`
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
Expand Down
20 changes: 20 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions charts/fluid/fluid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@

* Add debug info for csi
* Make mount root configurable
* Update HCFS URL
14 changes: 14 additions & 0 deletions charts/fluid/fluid/crds/data.fluid.io_datasets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ spec:
- JSONPath: .status.phase
name: Phase
type: string
- JSONPath: .status.hcfs.endpoint
name: HCFS URL
priority: 10
type: string
- JSONPath: .metadata.creationTimestamp
name: Age
type: date
Expand Down Expand Up @@ -264,6 +268,16 @@ spec:
- type
type: object
type: array
hcfs:
description: HCFSStatus represents hcfs info
properties:
endpoint:
description: Endpoint for accessing
type: string
underlayerFileSystemVersion:
description: Underlayer HCFS Compatible Version
type: string
type: object
phase:
description: 'Dataset Phase. One of the four phases: `Pending`, `Bound`,
`NotBound` and `Failed`'
Expand Down
6 changes: 3 additions & 3 deletions charts/fluid/fluid/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# Declare variables to be passed into your templates.

controller:
image: registry.cn-hangzhou.aliyuncs.com/fluid/runtime-controller:v0.4.0-8d707f1
image: registry.cn-hangzhou.aliyuncs.com/fluid/runtime-controller:v0.4.0-6648572


csi:
registrar:
image: registry.cn-hangzhou.aliyuncs.com/acs/csi-node-driver-registrar:v1.2.0
plugins:
image: registry.cn-hangzhou.aliyuncs.com/fluid/fluid-csi:v0.4.0-8d707f1
image: registry.cn-hangzhou.aliyuncs.com/fluid/fluid-csi:v0.4.0-6648572

runtime:
mountRoot: /alluxio-mnt
alluxio:
initImage: registry.cn-hangzhou.aliyuncs.com/fluid/init-users:v0.4.0-8d707f1
initImage: registry.cn-hangzhou.aliyuncs.com/fluid/init-users:v0.4.0-6648572
14 changes: 14 additions & 0 deletions config/crd/bases/data.fluid.io_datasets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ spec:
- JSONPath: .status.phase
name: Phase
type: string
- JSONPath: .status.hcfs.endpoint
name: HCFS URL
priority: 10
type: string
- JSONPath: .metadata.creationTimestamp
name: Age
type: date
Expand Down Expand Up @@ -264,6 +268,16 @@ spec:
- type
type: object
type: array
hcfs:
description: HCFSStatus represents hcfs info
properties:
endpoint:
description: Endpoint for accessing
type: string
underlayerFileSystemVersion:
description: Underlayer HCFS Compatible Version
type: string
type: object
phase:
description: 'Dataset Phase. One of the four phases: `Pending`, `Bound`,
`NotBound` and `Failed`'
Expand Down
30 changes: 6 additions & 24 deletions docs/zh/samples/accelerate_data_accessing_by_hdfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,6 @@ NAME UFS TOTAL SIZE CACHED CACHE CAPACITY CACHED PERCENTAGE PHASE
hadoop 390.2MiB 0B 4GiB 0% Bound 55m
```
**查看与远程文件关联的PersistentVolume以及PersistentVolumeClaim**
```shell
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
hadoop 100Gi RWX Retain Bound default/hadoop 3m49s
```
```shell
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
hadoop Bound hadoop 100Gi RWX 3m57s
```
Dataset资源对象准备完成后(即与Alluxio实例绑定后),与该资源对象关联的PV, PVC已经由Fluid生成,应用可以通过该PVC完成远程文件在Pod中的挂载,并通过挂载目录实现远程文件访问
Expand Down Expand Up @@ -182,28 +169,23 @@ Dataset资源对象准备完成后(即与Alluxio实例绑定后),与该资
在通过HDFS Client访问文件时,需要指定HDFS Server地址
```java
final String HDFS_URL = "alluxio://hadoop-master-0.default.svc.cluster.local:19998/hadoop"
final String HDFS_URL = "alluxio://hadoop-master-0.default:19998/hadoop"
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(HDFS_URL), conf);
```
注意这里的HDFS_URL域名规则为:
```shell
alluxio://{RUNTIME_HOST}:{RUNTIME_PORT}/{DATASET_NAME}
alluxio://{HCFS URL}/{DATASET_NAME}
```
其中DATASET_NAME为前面创建的Dataset名称,本例中为hadoop。RUNTIME_HOST为{DATASET_NAME}-master-0.{NAMESPACE}.svc.cluster.local,即hadoop-master-0 service对应的dns地址。
其中DATASET_NAME为前面创建的Dataset名称,本例中为hadoop。而Endpoint的获得完全可以通过如下命令获得HCFS(Hadoop Compatible FileSystem) URL
```shell
$ kubectl get svc
hadoop-master-0 ClusterIP None <none> 19998/TCP,19999/TCP,20001/TCP,20002/TCP,19200/TCP,20003/TCP 18m
kubernetes ClusterIP 172.22.0.1 <none> 443/TCP 24h
```
端口RUNTIME_PORT为hadoop-master-0的rpc端口,可通过以下命令得到
```shell
$ kubectl get service hadoop-master-0 -o jsonpath='{.spec.ports[?(@.name=="rpc")].port}'
19998
kubectl get datasets.data.fluid.io -owide
NAME UFS TOTAL SIZE CACHED CACHE CAPACITY CACHED PERCENTAGE PHASE HCFS URL AGE
hbase 443.49MiB 0.00B 4.00GiB 0.0% Bound alluxio://hbase-master-0.default:19998 97s
```
完整的测试代码可参考[samples/hdfs](../../../samples/hdfs)。我们把测试代码制作成镜像,方便接下来的测试,镜像地址为 registry.cn-beijing.aliyuncs.com/yukong/fluid-hdfs-demo:1.0.0。
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/runtime_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func (r *RuntimeReconciler) ReconcileRuntimeDeletion(engine base.Engine, ctx cru
// dataset.Status.RuntimeNamespace = ""
// if len(dataset.Status.Runtimes) == 0 {
dataset.Status.Runtimes = []datav1alpha1.Runtime{}
dataset.Status.HCFSStatus = nil
// }

if err := r.Status().Update(ctx, dataset); err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/ddc/alluxio/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ func (e *AlluxioEngine) UpdateDatasetStatus(phase datav1alpha1.DatasetPhase) (er
datasetToUpdate.Status.CacheStates = runtime.Status.CacheStates
// datasetToUpdate.Status.CacheStates =

if datasetToUpdate.Status.HCFSStatus == nil {
datasetToUpdate.Status.HCFSStatus, err = e.GetHCFSStatus()
if err != nil {
return err
}
} else {
e.Log.Info("No need to update HCFS status")
}

e.Log.Info("the dataset status", "status", datasetToUpdate.Status)

if !reflect.DeepEqual(dataset.Status, datasetToUpdate.Status) {
Expand Down
87 changes: 87 additions & 0 deletions pkg/ddc/alluxio/hcfs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package alluxio

import (
"fmt"

datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
"github.com/fluid-cloudnative/fluid/pkg/ddc/alluxio/operations"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
)

// Query the hcfs status
func (e *AlluxioEngine) GetHCFSStatus() (status *datav1alpha1.HCFSStatus, err error) {
endpoint, err := e.queryHCFSEndpoint()
if err != nil {
e.Log.Error(err, "Failed to get HCFS Endpoint")
return status, err
}

version, err := e.queryCompatibleUFSVersion()
if err != nil {
e.Log.Error(err, "Failed to get Compatiable Endpoint")
return status, err
}

status = &datav1alpha1.HCFSStatus{
Endpoint: endpoint,
UnderlayerFileSystemVersion: version,
}
return
}

// query the hcfs endpoint
func (e *AlluxioEngine) queryHCFSEndpoint() (endpoint string, err error) {

var (
serviceName = fmt.Sprintf("%s-master-0", e.name)
host = fmt.Sprintf("%s.%s", serviceName, e.namespace)
)

svc, err := kubeclient.GetServiceByName(e.Client, serviceName, e.namespace)
if err != nil {
e.Log.Error(err, "Failed to get Endpoint")
return endpoint, err
}

if svc == nil {
e.Log.Error(fmt.Errorf("Failed to find the svc %s in %s", e.name, e.namespace), "Failed to find the svc, it's nil")
return
}

for _, port := range svc.Spec.Ports {
if port.Name == "rpc" {
endpoint = fmt.Sprintf("alluxio://%s:%d", host, port.Port)
return
}
}

return
}

// query the compatible version of UFS
func (e *AlluxioEngine) queryCompatibleUFSVersion() (version string, err error) {
podName, containerName := e.getMasterPodInfo()
fileUtils := operations.NewAlluxioFileUtils(podName, containerName, e.namespace, e.Log)

version, err = fileUtils.GetConf("alluxio.underfs.version")
if err != nil {
e.Log.Error(err, "Failed to getConf")
return
}
return
}
34 changes: 34 additions & 0 deletions pkg/ddc/alluxio/operations/conf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package operations

import "fmt"

// Get Conf info of the Alluxio Engine
func (a AlluxioFileUtils) GetConf(key string) (value string, err error) {
var (
command = []string{"alluxio", "getConf", key}
stdout string
stderr string
)

stdout, stderr, err = a.exec(command, false)
if err != nil {
err = fmt.Errorf("execute command %v with expectedErr: %v stdout %s and stderr %s", command, err, stdout, stderr)
return stdout, err
}
return stdout, err
}
Loading

0 comments on commit fcca6d5

Please sign in to comment.