-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clusterctl] start adding phase support
- add a separate `clusterctl alpha phases create-bootstrap-cluster` command - move bootstrap cluster creation steps out of clusterdeployer
- Loading branch information
Showing
11 changed files
with
240 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,6 @@ bazel-cluster-api | |
bazel-genfiles | ||
bazel-out | ||
bazel-testlogs | ||
|
||
# kubeconfigs | ||
minikube.kubeconfig |
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,24 @@ | ||
/* | ||
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 bootstrap | ||
|
||
// Can provision a kubernetes cluster | ||
type ClusterProvisioner interface { | ||
Create() error | ||
Delete() error | ||
GetKubeconfig() (string, error) | ||
} |
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,31 @@ | ||
/* | ||
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 cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var alphaCmd = &cobra.Command{ | ||
Use: "alpha", | ||
Short: "Alpha/Experimental features", | ||
Long: `Alpha/Experimental features`, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(alphaCmd) | ||
} |
72 changes: 72 additions & 0 deletions
72
cmd/clusterctl/cmd/alpha_phase_create_bootstrap_cluster.go
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 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 cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"sigs.k8s.io/cluster-api/cmd/clusterctl/phases" | ||
|
||
"github.com/golang/glog" | ||
"github.com/spf13/cobra" | ||
"sigs.k8s.io/cluster-api/cmd/clusterctl/clusterdeployer/bootstrap/minikube" | ||
"sigs.k8s.io/cluster-api/cmd/clusterctl/clusterdeployer/clusterclient" | ||
) | ||
|
||
type AlphaPhaseCreateBootstrapClusterOptions struct { | ||
MiniKube []string | ||
VmDriver string | ||
KubeconfigOutput string | ||
} | ||
|
||
var pcbco = &AlphaPhaseCreateBootstrapClusterOptions{} | ||
|
||
var alphaPhaseCreateBootstrapClusterCmd = &cobra.Command{ | ||
Use: "create-bootstrap-cluster", | ||
Short: "Create a bootstrap cluster", | ||
Long: `Create a bootstrap cluster`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := RunAlphaPhaseCreateBootstrapCluster(pcbco); err != nil { | ||
glog.Exit(err) | ||
} | ||
}, | ||
} | ||
|
||
func RunAlphaPhaseCreateBootstrapCluster(pcbco *AlphaPhaseCreateBootstrapClusterOptions) error { | ||
if pcbco.VmDriver != "" { | ||
pcbco.MiniKube = append(pcbco.MiniKube, fmt.Sprintf("vm-driver=%s", pcbco.VmDriver)) | ||
} | ||
|
||
bootstrapProvider := minikube.WithOptionsAndKubeConfigPath(pcbco.MiniKube, pcbco.KubeconfigOutput) | ||
|
||
_, _, err := phases.CreateBootstrapCluster(bootstrapProvider, false, clusterclient.NewFactory()) | ||
if err != nil { | ||
return fmt.Errorf("failed to create bootstrap cluster: %v", err) | ||
} | ||
|
||
glog.Infof("Created bootstrap cluster, path to kubeconfig: %q", pcbco.KubeconfigOutput) | ||
return nil | ||
} | ||
|
||
func init() { | ||
// Optional flags | ||
alphaPhaseCreateBootstrapClusterCmd.Flags().StringSliceVarP(&pcbco.MiniKube, "minikube", "", []string{}, "Minikube options") | ||
alphaPhaseCreateBootstrapClusterCmd.Flags().StringVarP(&pcbco.VmDriver, "vm-driver", "", "", "Which vm driver to use for minikube") | ||
alphaPhaseCreateBootstrapClusterCmd.Flags().StringVarP(&pcbco.KubeconfigOutput, "kubeconfig-out", "", "minikube.kubeconfig", "Where to output the kubeconfig for the bootstrap cluster") | ||
|
||
alphaPhasesCmd.AddCommand(alphaPhaseCreateBootstrapClusterCmd) | ||
} |
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,31 @@ | ||
/* | ||
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 cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var alphaPhasesCmd = &cobra.Command{ | ||
Use: "phases", | ||
Short: "Run an individual phase", | ||
Long: `Run an individual phase`, | ||
} | ||
|
||
func init() { | ||
alphaCmd.AddCommand(alphaPhasesCmd) | ||
} |
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,53 @@ | ||
/* | ||
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 phases | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/golang/glog" | ||
|
||
"sigs.k8s.io/cluster-api/cmd/clusterctl/clusterdeployer/bootstrap" | ||
"sigs.k8s.io/cluster-api/cmd/clusterctl/clusterdeployer/clusterclient" | ||
) | ||
|
||
func CreateBootstrapCluster(provisioner bootstrap.ClusterProvisioner, cleanupBootstrapCluster bool, clientFactory clusterclient.Factory) (clusterclient.Client, func(), error) { | ||
glog.Info("Creating bootstrap cluster") | ||
|
||
cleanupFn := func() {} | ||
if err := provisioner.Create(); err != nil { | ||
return nil, cleanupFn, fmt.Errorf("could not create bootstrap control plane: %v", err) | ||
} | ||
|
||
if cleanupBootstrapCluster { | ||
cleanupFn = func() { | ||
glog.Info("Cleaning up bootstrap cluster.") | ||
provisioner.Delete() | ||
} | ||
} | ||
|
||
bootstrapKubeconfig, err := provisioner.GetKubeconfig() | ||
if err != nil { | ||
return nil, cleanupFn, fmt.Errorf("unable to get bootstrap cluster kubeconfig: %v", err) | ||
} | ||
bootstrapClient, err := clientFactory.NewClientFromKubeconfig(bootstrapKubeconfig) | ||
if err != nil { | ||
return nil, cleanupFn, fmt.Errorf("unable to create bootstrap client: %v", err) | ||
} | ||
|
||
return bootstrapClient, cleanupFn, 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