Skip to content

Commit

Permalink
Refactor runtime Implementation (fluid-cloudnative#273)
Browse files Browse the repository at this point in the history
* Rename pkg name, To #30961382

* Refactor helm chart, To #30961382

* Refactor helm chart, To #30961382

* Lint the source code, To #30961382

* Lint the source code, To #30961382

* Lint the source code, To #30961382

* Lint the source code, To #30961382

* Lint the source code, To #30961382

* Lint the source code, To #30961382

* Lint the source code, To #30961382

* Lint the source code, To #30961382

* Lint the source code, To #30961382
  • Loading branch information
cheyang authored Oct 27, 2020
1 parent f731526 commit 81ea9b0
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 108 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
command: |
test -z "$(go fmt ./... 2>/dev/null | tee /dev/stderr)" || (echo "please format Go code with 'gofmt'")
go vet ./...
- run: docker build . -t fluid:${CIRCLE_BUILD_NUM}
- run: docker build . -f Dockerfile.dataset dataset-controller:${CIRCLE_BUILD_NUM}
- run: docker build . -f Dockerfile.alluxioruntime alluxioruntime-controller:${CIRCLE_BUILD_NUM}
- run: docker build . -f Dockerfile.csi -t fluid-csi:${CIRCLE_BUILD_NUM}

# maybe later we need to upload output to helm repository
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ matrix:
- sudo mv /tmp/kubebuilder_2.3.1_linux_${arch} /usr/local/kubebuilder
- export PATH=$PATH:/usr/local/kubebuilder/bin
script:
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -o bin/dataset-controller cmd/dataset_controller/main.go
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -o bin/alluxioruntime-controller cmd/alluxioruntime_controller/main.go
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -o bin/dataset-controller cmd/dataset/main.go
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -o bin/alluxioruntime-controller cmd/alluxio/main.go
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -o bin/csi cmd/csi/main.go
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go vet ./...
- golangci-lint run --timeout=10m ./...
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.alluxioruntime
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ FROM golang:1.14.2 as builder
WORKDIR /go/src/github.com/fluid-cloudnative/fluid
COPY . .

RUN make alluxioruntime-controller-build
RUN make alluxioruntime-controller-build && \
cp bin/alluxioruntime-controller /go/bin/alluxioruntime-controller

FROM alpine:3.10
RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.csi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ COPY . .
# Build
# RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o csi main.go
#RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -a -o /go/bin/fluid-csi cmd/csi/*.go
RUN make csi-build
RUN make csi-build && \
cp bin/fluid-csi /go/bin/fluid-csi

# RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -gcflags="-N -l" -a -o /go/bin/fluid-csi cmd/csi/*.go

Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.dataset
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ FROM golang:1.14.2 as builder
WORKDIR /go/src/github.com/fluid-cloudnative/fluid
COPY . .

RUN make dataset-controller-build
RUN make dataset-controller-build && \
cp bin/dataset-controller /go/bin/dataset-controller

FROM alpine:3.10
RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \
Expand Down
24 changes: 9 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ override LDFLAGS += \
-X ${PACKAGE}.gitTreeState=${GIT_TREE_STATE} \
-extldflags "-static"

all: manager
all: build

# Run tests
test: generate fmt vet
Expand All @@ -47,23 +47,17 @@ test: generate fmt vet
unit-test: generate fmt vet
GO111MODULE=off go list ./... | grep -v controller | xargs go test ${CI_TEST_FLAGS} ${LOCAL_FLAGS}

# Build manager binary
manager: generate fmt vet
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -o bin/manager cmd/controller/main.go
# Build binary
build: dataset-controller-build alluxioruntime-controller-build csi-build

# Build CSI binary
csi: generate fmt vet
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -o bin/csi -ldflags '${LDFLAGS}' cmd/csi/main.go
csi-build: generate fmt vet
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -o bin/fluid-csi -ldflags '${LDFLAGS}' cmd/csi/main.go

# Build binary in docker images, will be called in Dockerfile
csi-build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -o /go/bin/fluid-csi -ldflags '${LDFLAGS}' cmd/csi/main.go
dataset-controller-build: generate fmt vet
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -gcflags="-N -l" -a -o bin/dataset-controller -ldflags '${LDFLAGS}' cmd/dataset/main.go

dataset-controller-build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -gcflags="-N -l" -a -o /go/bin/dataset-controller -ldflags '${LDFLAGS}' cmd/dataset_controller/main.go

alluxioruntime-controller-build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -gcflags="-N -l" -a -o /go/bin/alluxioruntime-controller -ldflags '${LDFLAGS}' cmd/alluxioruntime_controller/main.go
alluxioruntime-controller-build: generate fmt vet
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=off go build -gcflags="-N -l" -a -o bin/alluxioruntime-controller -ldflags '${LDFLAGS}' cmd/alluxio/main.go

# Debug against the configured Kubernetes cluster in ~/.kube/config, add debug
debug: generate fmt vet manifests
Expand Down
1 change: 1 addition & 0 deletions charts/fluid/fluid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
* Add debug info for csi
* Make mount root configurable
* Update HCFS URL
* Split the controller into alluxio runtime and dataset
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: alluxioruntime-controller-manager
name: alluxioruntime-controller
namespace: fluid-system
labels:
control-plane: alluxioruntime-controller-manager
control-plane: alluxioruntime-controller
spec:
selector:
matchLabels:
control-plane: alluxioruntime-controller-manager
control-plane: alluxioruntime-controller
replicas: 1
template:
metadata:
labels:
control-plane: alluxioruntime-controller-manager
control-plane: alluxioruntime-controller
spec:
serviceAccountName: alluxioruntime-controller
tolerations:
- operator: Exists
hostNetwork: true
containers:
- image: "{{ .Values.runtime.alluxio.image }}"
- image: "{{ .Values.runtime.alluxio.controller.image }}"
name: manager
command: ["alluxioruntime-controller", "start"]
args:
- --development=false
env:
{{- if .Values.runtime.alluxio.initImage }}
{{- if .Values.runtime.alluxio.init.image }}
- name: ALLUXIO_INIT_IMAGE_ENV
value: {{ .Values.runtime.alluxio.initImage | quote }}
value: {{ .Values.runtime.alluxio.init.image | quote }}
{{- end }}
{{- if .Values.runtime.mountRoot }}
- name: MOUNT_ROOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
# kind: Namespace
# metadata:
# labels:
# control-plane: controller-manager
# control-plane: controller
# name: fluid-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: dataset-controller-manager
name: dataset-controller
namespace: fluid-system
labels:
control-plane: dataset-controller-manager
control-plane: dataset-controller
spec:
selector:
matchLabels:
control-plane: dataset-controller-manager
control-plane: dataset-controller
replicas: 1
template:
metadata:
labels:
control-plane: dataset-controller-manager
control-plane: dataset-controller
spec:
serviceAccountName: dataset-controller
tolerations:
Expand All @@ -33,9 +33,9 @@ spec:
args:
- --development=false
env:
{{- if .Values.runtime.alluxio.initImage }}
{{- if .Values.runtime.alluxio.init.image }}
- name: ALLUXIO_INIT_IMAGE_ENV
value: {{ .Values.runtime.alluxio.initImage | quote }}
value: {{ .Values.runtime.alluxio.init.image | quote }}
{{- end }}
ports:
- containerPort: 8080
Expand Down
27 changes: 0 additions & 27 deletions charts/fluid/fluid/templates/role/ClusterRoleBindind.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions charts/fluid/fluid/templates/role/ServiceAccount

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: dataset-manager
rules:
- apiGroups:
- data.fluid.io
resources:
- datasets
- datasets/status
verbs:
- '*'
- apiGroups:
- ""
resources:
- events
verbs:
- '*'
---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: alluxioruntime-manager
name: alluxioruntime-controller
rules:
- apiGroups:
- ""
Expand Down Expand Up @@ -58,4 +39,23 @@ rules:
- daemonsets/status
- statefulsets/status
verbs:
- '*'
- '*'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: alluxioruntime-clusterrolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: alluxioruntime-controller
subjects:
- kind: ServiceAccount
name: alluxioruntime-controller
namespace: fluid-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: alluxioruntime-controller
namespace: fluid-system
38 changes: 38 additions & 0 deletions charts/fluid/fluid/templates/role/dataset/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: dataset-controller
rules:
- apiGroups:
- data.fluid.io
resources:
- datasets
- datasets/status
verbs:
- '*'
- apiGroups:
- ""
resources:
- events
verbs:
- '*'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: dataset-clusterrolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: dataset-controller
subjects:
- kind: ServiceAccount
name: dataset-controller
namespace: fluid-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: dataset-controller
namespace: fluid-system
10 changes: 6 additions & 4 deletions charts/fluid/fluid/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

dataset:
controller:
image: registry.cn-hangzhou.aliyuncs.com/qiulingwei/dataset-controller:v0.4.0-f2c3a3f
image: registry.cn-hangzhou.aliyuncs.com/fluid/dataset-controller:v0.4.0-7aec4d3

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-a8ba7c9
image: registry.cn-hangzhou.aliyuncs.com/fluid/fluid-csi:v0.4.0-7aec4d3

runtime:
mountRoot: /alluxio-mnt
alluxio:
initImage: registry.cn-hangzhou.aliyuncs.com/fluid/init-users:v0.4.0-a8ba7c9
image: registry.cn-hangzhou.aliyuncs.com/qiulingwei/alluxioruntime-controller:v0.4.0-f2c3a3f
init:
image: registry.cn-hangzhou.aliyuncs.com/fluid/init-users:v0.4.0-a8ba7c9
controller:
image: registry.cn-hangzhou.aliyuncs.com/fluid/alluxioruntime-controller:v0.4.0-7aec4d3
6 changes: 2 additions & 4 deletions cmd/alluxioruntime_controller/main.go → cmd/alluxio/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ var (
// Use compiler to check if the struct implements all the interface
_ base.Implement = (*alluxio.AlluxioEngine)(nil)

short bool
short bool
metricsAddr string
enableLeaderElection bool
development bool
)


var cmd = &cobra.Command{
Use: "alluxioruntime-controller",
Short: "Controller for alluxioruntime",
Expand Down Expand Up @@ -112,7 +111,7 @@ func handle() {
MetricsBindAddress: metricsAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "7857424864.data.fluid.io",
Port: 9443,
Port: 9443,
})
if err != nil {
setupLog.Error(err, "unable to start alluxioruntime manager")
Expand Down Expand Up @@ -142,4 +141,3 @@ func handle() {
os.Exit(1)
}
}

5 changes: 2 additions & 3 deletions cmd/dataset_controller/main.go → cmd/dataset/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ var (
// Use compiler to check if the struct implements all the interface
_ base.Implement = (*alluxio.AlluxioEngine)(nil)

short bool
short bool
metricsAddr string
enableLeaderElection bool
development bool
)


var cmd = &cobra.Command{
Use: "dataset-controller",
Short: "controller for dataset",
Expand Down Expand Up @@ -111,7 +110,7 @@ func handle() {
MetricsBindAddress: metricsAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "89759796.data.fluid.io",
Port: 9443,
Port: 9443,
})
if err != nil {
setupLog.Error(err, "unable to start dataset manager")
Expand Down
Loading

0 comments on commit 81ea9b0

Please sign in to comment.