-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: helen <haitao.zhang@daocloud.io>
- Loading branch information
helen
committed
Dec 20, 2023
1 parent
8f6cb8f
commit 5d68b55
Showing
8 changed files
with
211 additions
and
0 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
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,44 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
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 start | ||
|
||
import ( | ||
"sigs.k8s.io/kind/pkg/errors" | ||
"sigs.k8s.io/kind/pkg/log" | ||
|
||
"sigs.k8s.io/kind/pkg/cluster/internal/providers" | ||
) | ||
|
||
// Cluster starts the cluster identified by ctx | ||
// explicitKubeconfigPath is --kubeconfig, following the rules from | ||
// https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands | ||
func Cluster(logger log.Logger, p providers.Provider, name string) error { | ||
n, err := p.ListNodes(name) | ||
if err != nil { | ||
return errors.Wrap(err, "error listing nodes") | ||
} | ||
|
||
if len(n) > 0 { | ||
err = p.StartNodes(n) | ||
if err != nil { | ||
return err | ||
} | ||
logger.V(0).Infof("Started nodes: %q", n) | ||
} | ||
|
||
return nil | ||
} |
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,72 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
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 cluster implements the `start` command | ||
package cluster | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"sigs.k8s.io/kind/pkg/cluster" | ||
"sigs.k8s.io/kind/pkg/cmd" | ||
"sigs.k8s.io/kind/pkg/errors" | ||
"sigs.k8s.io/kind/pkg/log" | ||
|
||
"sigs.k8s.io/kind/pkg/internal/cli" | ||
"sigs.k8s.io/kind/pkg/internal/runtime" | ||
) | ||
|
||
type flagpole struct { | ||
Name string | ||
} | ||
|
||
// NewCommand returns a new cobra.Command for cluster startion | ||
func NewCommand(logger log.Logger, streams cmd.IOStreams) *cobra.Command { | ||
flags := &flagpole{} | ||
cmd := &cobra.Command{ | ||
Args: cobra.NoArgs, | ||
// TODO(bentheelder): more detailed usage | ||
Use: "cluster", | ||
Short: "Starts a cluster", | ||
Long: "Starts a resource", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cli.OverrideDefaultName(cmd.Flags()) | ||
return startCluster(logger, flags) | ||
}, | ||
} | ||
cmd.Flags().StringVarP( | ||
&flags.Name, | ||
"name", | ||
"n", | ||
cluster.DefaultName, | ||
"the cluster name", | ||
) | ||
return cmd | ||
} | ||
|
||
func startCluster(logger log.Logger, flags *flagpole) error { | ||
provider := cluster.NewProvider( | ||
cluster.ProviderWithLogger(logger), | ||
runtime.GetDefault(logger), | ||
) | ||
// Start individual cluster | ||
logger.V(0).Infof("Start cluster %q ...", flags.Name) | ||
if err := provider.Start(flags.Name); err != nil { | ||
return errors.Wrapf(err, "failed to start cluster %q", flags.Name) | ||
} | ||
|
||
return nil | ||
} |
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,47 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
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 create implements the `create` command | ||
package start | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"sigs.k8s.io/kind/pkg/cmd" | ||
startcluster "sigs.k8s.io/kind/pkg/cmd/kind/start/cluster" | ||
"sigs.k8s.io/kind/pkg/log" | ||
) | ||
|
||
// NewCommand returns a new cobra.Command for cluster start | ||
func NewCommand(logger log.Logger, streams cmd.IOStreams) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Args: cobra.NoArgs, | ||
Use: "start", | ||
Short: "Start one of [cluster]", | ||
Long: "Start one of local Kubernetes cluster (cluster)", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := cmd.Help() | ||
if err != nil { | ||
return err | ||
} | ||
return errors.New("Subcommand is required") | ||
}, | ||
} | ||
cmd.AddCommand(startcluster.NewCommand(logger, streams)) | ||
return cmd | ||
} |