예제 #1
0
파일: cmds.go 프로젝트: klucar/pachyderm
func getAPIServer(
	kubernetesAddress string,
	kubernetesUsername string,
	kubernetesPassword string,
	providerName string,
	gceProject string,
	gceZone string,
) (server.APIServer, error) {
	config := &kube.Config{
		Host:     kubernetesAddress,
		Insecure: true,
		Username: kubernetesUsername,
		Password: kubernetesPassword,
	}
	kubeClient, err := kube.New(config)
	if err != nil {
		return nil, err
	}
	provider, err := getProvider(providerName, gceProject, gceZone)
	if err != nil {
		return nil, err
	}
	return server.NewAPIServer(kubeClient, provider), nil
}
예제 #2
0
func do(appEnvObj interface{}) error {
	appEnv := appEnvObj.(*appEnv)
	logrus.Register()
	config := &client.Config{
		Host: appEnv.KubernetesAddress,
	}
	client, err := client.New(config)
	if err != nil {
		return err
	}
	apiServer := server.NewAPIServer(client)

	createCluster := &cobra.Command{
		Use:   "create-cluster cluster-name nodes shards replicas",
		Short: "Create a new pachyderm cluster.",
		Long:  "Create a new pachyderm cluster.",
		Run: pkgcobra.RunFixedArgs(4, func(args []string) error {
			nodes, err := strconv.ParseUint(args[1], 10, 64)
			if err != nil {
				return err
			}
			shards, err := strconv.ParseUint(args[2], 10, 64)
			if err != nil {
				return err
			}
			replicas, err := strconv.ParseUint(args[3], 10, 64)
			if err != nil {
				return err
			}
			_, err = apiServer.CreateCluster(
				context.Background(),
				&deploy.CreateClusterRequest{
					Cluster: &deploy.Cluster{
						Name: args[0],
					},
					Nodes:    nodes,
					Shards:   shards,
					Replicas: replicas,
				})
			return err
		}),
	}

	deleteCluster := &cobra.Command{
		Use:   "delete-cluster cluster-name",
		Short: "Delete a cluster.",
		Long:  "Delete a cluster.",
		Run: pkgcobra.RunFixedArgs(1, func(args []string) error {
			_, err = apiServer.DeleteCluster(
				context.Background(),
				&deploy.DeleteClusterRequest{
					Cluster: &deploy.Cluster{
						Name: args[0],
					},
				})
			return err
		}),
	}

	rootCmd := &cobra.Command{
		Use: "deploy",
		Long: `Deploy Pachyderm clusters.

The environment variable KUBERNETES_ADDRESS controls the Kubernetes endpoint the CLI connects to, the default is https://localhost:8080.`,
	}
	rootCmd.AddCommand(createCluster)
	rootCmd.AddCommand(deleteCluster)
	return rootCmd.Execute()
}