Skip to content

Commit

Permalink
migrate dataset-manager from hwameistor/hwameistor to this repo
Browse files Browse the repository at this point in the history
migrated directories:
- cmd/dataset-manager
- pkg/dataset-manager
- build/dataset-manager
- Makefile.variables
  • Loading branch information
SSmallMonster committed Jun 11, 2024
1 parent 9be0d9b commit 2439eb2
Show file tree
Hide file tree
Showing 184 changed files with 44,990 additions and 13 deletions.
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,41 @@ release_dataload_init:
# push to a public registry
${MUILT_ARCH_PUSH_CMD} -i ${DATALOAD_INIT_IMAGE_NAME}:${RELEASE_TAG}

#### for Dataset Manager controller ##########
DS_ACCL_CONTROLLER_MODULE_NAME = dataset-manager
DS_ACCL_CONTROLLER_BUILD_INPUT = ${CMDS_DIR}/${DS_ACCL_CONTROLLER_MODULE_NAME}/dataset-manager.go

.PHONY: compile_ds_accl
compile_ds_accl:
GOARCH=amd64 ${BUILD_ENVS} ${BUILD_CMD} ${BUILD_OPTIONS} -o ${DS_ACCL_CONTROLLER_BUILD_OUTPUT} ${DS_ACCL_CONTROLLER_BUILD_INPUT}

.PHONY: compile_ds_accl_arm64
compile_ds_accl_arm64:
GOARCH=arm64 ${BUILD_ENVS} ${BUILD_CMD} ${BUILD_OPTIONS} -o ${DS_ACCL_CONTROLLER_BUILD_OUTPUT} ${DS_ACCL_CONTROLLER_BUILD_INPUT}

.PHONY: build_ds_accl_image
build_ds_accl_image:
@echo "Build dataset-manager-controller image ${DS_ACCL_CONTROLLER_IMAGE_NAME}:${IMAGE_TAG}"
${DOCKER_MAKE_CMD} make compile_ds_accl
docker build -t ${DS_ACCL_CONTROLLER_IMAGE_NAME}:${IMAGE_TAG} -f ${DS_ACCL_CONTROLLER_IMAGE_DOCKERFILE} ${PROJECT_SOURCE_CODE_DIR}

.PHONY: build_ds_accl_image_arm64
build_ds_accl_image_arm64:
@echo "Build dataset-manager-controller image ${DS_ACCL_CONTROLLER_IMAGE_NAME}:${IMAGE_TAG}"
${DOCKER_MAKE_CMD} make compile_ds_accl_arm64
${DOCKER_BUILDX_CMD_ARM64} -t ${DS_ACCL_CONTROLLER_IMAGE_NAME}:${IMAGE_TAG} -f ${DS_ACCL_CONTROLLER_IMAGE_DOCKERFILE} ${PROJECT_SOURCE_CODE_DIR}

.PHONY: release_ds_accl
release_ds_accl:
# build for amd64 version
${DOCKER_MAKE_CMD} make compile_ds_accl
${DOCKER_BUILDX_CMD_AMD64} -t ${DS_ACCL_CONTROLLER_IMAGE_NAME}:${RELEASE_TAG}-amd64 -f ${DS_ACCL_CONTROLLER_IMAGE_DOCKERFILE} ${PROJECT_SOURCE_CODE_DIR}
# build for arm64 version
${DOCKER_MAKE_CMD} make compile_ds_accl_arm64
${DOCKER_BUILDX_CMD_ARM64} -t ${DS_ACCL_CONTROLLER_IMAGE_NAME}:${RELEASE_TAG}-arm64 -f ${DS_ACCL_CONTROLLER_IMAGE_DOCKERFILE} ${PROJECT_SOURCE_CODE_DIR}
# push to a public registry
${MUILT_ARCH_PUSH_CMD} -i ${DS_ACCL_CONTROLLER_IMAGE_NAME}:${RELEASE_TAG}

.PHONY: apis
apis:
${DOCKER_MAKE_CMD} make _gen-apis
Expand Down
5 changes: 5 additions & 0 deletions Makefile.variables
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ DATALOAD_INIT_IMAGE_NAME = ${IMAGE_REGISTRY}/${DATALOAD_INIT_MODULE_NAME}
DATALOAD_INIT_IMAGE_DOCKERFILE = ${PROJECT_SOURCE_CODE_DIR}/build/${DATALOAD_INIT_MODULE_NAME}/Dockerfile
DATALOAD_INIT_BUILD_OUTPUT = ${BINS_DIR}/${DATALOAD_INIT_MODULE_NAME}

# [ IMAGE/DS-ACCL ]
DS_ACCL_CONTROLLER_IMAGE_NAME = ${IMAGE_REGISTRY}/${DS_ACCL_CONTROLLER_MODULE_NAME}
DS_ACCL_CONTROLLER_IMAGE_DOCKERFILE = ${PROJECT_SOURCE_CODE_DIR}/build/${DS_ACCL_CONTROLLER_MODULE_NAME}/Dockerfile
DS_ACCL_CONTROLLER_BUILD_OUTPUT = ${BINS_DIR}/${DS_ACCL_CONTROLLER_MODULE_NAME}

# [ BUILD ]
#----------------
# Common build tools and build flags
Expand Down
7 changes: 7 additions & 0 deletions build/dataset-manager/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM centos:7

RUN yum upgrade nss -y

COPY ./_build/dataset-manager /

ENTRYPOINT [ "/dataset-manager" ]
107 changes: 107 additions & 0 deletions cmd/dataset-manager/dataset-manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package main

import (
"context"
"flag"
"fmt"
datasetManager "github.com/hwameistor/datastore/pkg/dataset-manager"
"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
"k8s.io/client-go/informers"
"strings"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
"os"
"time"

dsclientset "github.com/hwameistor/datastore/pkg/apis/client/clientset/versioned"
dsinformers "github.com/hwameistor/datastore/pkg/apis/client/informers/externalversions"
hmclientset "github.com/hwameistor/hwameistor/pkg/apis/client/clientset/versioned"
)

var (
showVersion = flag.Bool("version", false, "Show version.")
enableLeaderElection = flag.Bool("leader-election", false, "Enable leader election.")
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
rsync = flag.Duration("rsync", 10*time.Minute, "Rsync interval of the controller.")
version = "unknown"
)

func main() {
klog.InitFlags(nil)
flag.Set("logtostderr", "true")
flag.Parse()
klog.Infof("args: %s", strings.Join(os.Args, " "))

if *showVersion {
fmt.Println(os.Args[0], version)
return
}
klog.Infof("Version: %s", version)

// Create the client config. Use kubeconfig if given, otherwise assume in-cluster.
config, err := buildConfig(*kubeconfig)
if err != nil {
klog.Error(err.Error())
os.Exit(1)
}

// Create the kubeClientset for in-cluster resources
kubeClientset, err := kubernetes.NewForConfig(config)
if err != nil {
klog.Error(err.Error())
os.Exit(1)
}

// Create the kubeClientset for datastore resources
dsClient, err := dsclientset.NewForConfig(config)
if err != nil {
klog.Error(err.Error())
os.Exit(1)
}

// Create the kubeClientset for hwameistor resources
hmClient, err := hmclientset.NewForConfig(config)
if err != nil {
klog.Error(err.Error())
os.Exit(1)
}

// Create the kubeClientset for datastore resources
coreFactory := informers.NewSharedInformerFactory(kubeClientset, *rsync)
pvInformer := coreFactory.Core().V1().PersistentVolumes()
dsFactory := dsinformers.NewSharedInformerFactory(dsClient, *rsync)
datasetInformer := dsFactory.Datastore().V1alpha1().DataSets()

ctr := datasetManager.New(kubeClientset, dsClient, hmClient, datasetInformer, pvInformer)
run := func(ctx context.Context) {
stopCh := ctx.Done()
dsFactory.Start(stopCh)
coreFactory.Start(stopCh)
ctr.Run(stopCh)
}

leClientset, err := kubernetes.NewForConfig(config)
if err != nil {
klog.Fatalf("Failed to create leaderelection client: %v", err)
}

if *enableLeaderElection {
lockName := "hwameistor-dataset-manager-master"
le := leaderelection.NewLeaderElection(leClientset, lockName, run)
if err = le.Run(); err != nil {
klog.Fatalf("Failed to initialize leader election: %v", err)
}
} else {
run(context.TODO())
}
}

func buildConfig(kubeconfig string) (*rest.Config, error) {
if kubeconfig != "" {
return clientcmd.BuildConfigFromFlags("", kubeconfig)
}
return rest.InClusterConfig()
}
5 changes: 0 additions & 5 deletions cmd/manager/main.go

This file was deleted.

6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
)

require (
github.com/hwameistor/hwameistor v0.14.4
github.com/jlaffaye/ftp v0.2.0
github.com/minio/minio-go/v7 v7.0.66
github.com/pytool/ssh v0.0.0-20190312091242-5aaea5918db7
Expand All @@ -35,6 +36,7 @@ require (
)

require (
github.com/container-storage-interface/spec v1.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
Expand All @@ -47,12 +49,12 @@ require (
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/gomega v1.19.0 // indirect
github.com/pkg/sftp v1.10.1 // indirect
github.com/prometheus/client_golang v1.13.1 // indirect
github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93 // indirect
github.com/rs/xid v1.5.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
google.golang.org/grpc v1.40.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
)
Expand Down
7 changes: 5 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/container-storage-interface/spec v1.5.0 h1:lvKxe3uLgqQeVQcrnL2CPQKISoKjTJxojEs9cBk+HXo=
github.com/container-storage-interface/spec v1.5.0/go.mod h1:8K96oQNkJ7pFcC2R9Z1ynGGBB1I93kcS6PGg3SsOk8s=
github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko=
github.com/containerd/cgroups v1.0.1/go.mod h1:0SJrPIenamHDcZhEcJMNBB85rHcUsw4f25ZfBiPYRkU=
Expand Down Expand Up @@ -595,6 +596,8 @@ github.com/heketi/heketi v10.3.0+incompatible/go.mod h1:bB9ly3RchcQqsQ9CpyaQwvva
github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6/go.mod h1:xGMAM8JLi7UkZt1i4FQeQy0R2T8GLUwQhOP5M1gBhy4=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/hwameistor/hwameistor v0.14.4 h1:MKblPQraGLp0NUWuS7+jTv0yIGhR411sagYppbjeziY=
github.com/hwameistor/hwameistor v0.14.4/go.mod h1:d+J2bzNIU2UFIKaihRK3rh2gN45NJcOA6D4Qv2fiEi4=
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down Expand Up @@ -810,7 +813,6 @@ github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoT
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
Expand Down Expand Up @@ -882,7 +884,6 @@ github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
github.com/prometheus/client_golang v1.13.1 h1:3gMjIY2+/hzmqhtUC/aQNYldJA6DtH3CgQvwS+02K1c=
github.com/prometheus/client_golang v1.13.1/go.mod h1:vTeo+zgvILHsnnj/39Ou/1fPN5nJFOEMgftOUOmlvYQ=
github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
Expand Down Expand Up @@ -1620,7 +1621,9 @@ google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaE
google.golang.org/genproto v0.0.0-20210429181445-86c259c2b4ab/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A=
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY=
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 h1:Et6SkiuvnBn+SgrSYXs/BrUpGB4mbdwt4R3vaPIlicA=
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0=
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
Expand Down
Loading

0 comments on commit 2439eb2

Please sign in to comment.