-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate dataset-manager from hwameistor/hwameistor to this repo
migrated directories: - cmd/dataset-manager - pkg/dataset-manager - build/dataset-manager - Makefile.variables
- Loading branch information
1 parent
9be0d9b
commit 2439eb2
Showing
184 changed files
with
44,990 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.