-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add boilerplate for clusterctl #119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
clusterctl |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Contributing Guidelines | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# clusterctl | ||
|
||
`clusterctl` is the SIG-cluster-lifecycle sponsored tool that implements the Cluster API. | ||
|
||
Read the [experience doc here](https://docs.google.com/document/d/1-sYb3EdkRga49nULH1kSwuQFf1o6GvAw_POrsNo5d8c/edit#). | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
Follow the steps listed at [CONTRIBUTING.md](https://github.com/kubernetes-sigs/cluster-api/blob/master/cluster-api/clusterctl/CONTRIBUTING.md) to: | ||
|
||
1. Build the `clusterctl` tool | ||
|
||
``` | ||
go build | ||
``` | ||
|
||
2. Create a `machines.yaml` file configured for your cluster. See the provided template for an example. | ||
|
||
### Limitations | ||
|
||
|
||
### Creating a cluster | ||
|
||
**NOT YET SUPPORTED!** | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would cut out everything other than NOT YET SUPPORTED! in the creating a cluster section till it actually is supported. Similar reasoning to flags, it is best to keep the implementation and documentation in sync. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair. |
||
### Interacting with your cluster | ||
|
||
Once you have created a cluster, you can interact with the cluster and machine | ||
resources using kubectl: | ||
|
||
``` | ||
$ kubectl get clusters | ||
$ kubectl get machines | ||
$ kubectl get machines -o yaml | ||
``` | ||
|
||
#### Scaling your cluster | ||
|
||
**NOT YET SUPPORTED!** | ||
|
||
#### Upgrading your cluster | ||
|
||
**NOT YET SUPPORTED!** | ||
|
||
#### Node repair | ||
|
||
**NOT YET SUPPORTED!** | ||
|
||
### Deleting a cluster | ||
|
||
**NOT YET SUPPORTED!** |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
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 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would recommend the cluster subcommand files be named with the cluster prefix. That way we do not have confusion when we have other NOUNS that happen to have a similar verb eg. create. cluster_create.go or clustercreate.go instead of create.go There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that we are going with the kubectl/kops model of VERB NOUN, this comment is moot? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. Moot. |
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var createCmd = &cobra.Command{ | ||
Use: "create", | ||
Short: "Create a cluster API resource", | ||
Long: `Create a cluster API resource with one command`, | ||
} | ||
|
||
func init() { | ||
createCmd.AddCommand(NewCmdCreateCluster()) | ||
RootCmd.AddCommand(createCmd) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
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/golang/glog" | ||
"github.com/spf13/cobra" | ||
"sigs.k8s.io/cluster-api/errors" | ||
) | ||
|
||
type CreateOptions struct { | ||
Cluster string | ||
Machine string | ||
ProviderComponents string | ||
} | ||
|
||
var co = &CreateOptions{} | ||
|
||
func NewCmdCreateCluster() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "cluster", | ||
Short: "Create kubernetes cluster", | ||
Long: `Create a kubernetes cluster with one command`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if co.Cluster == "" { | ||
exitWithHelp(cmd, "Please provide yaml file for cluster definition.") | ||
} | ||
if co.Machine == "" { | ||
exitWithHelp(cmd, "Please provide yaml file for machine definition.") | ||
} | ||
if co.ProviderComponents == "" { | ||
exitWithHelp(cmd, "Please provide a yaml file for provider component definitions.") | ||
} | ||
if err := RunCreate(co); err != nil { | ||
glog.Exit(err) | ||
} | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func RunCreate(co *CreateOptions) error { | ||
return errors.NotImplementedError | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
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 deleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "Delete a cluster API resource", | ||
Long: `Delete a cluster API resource with one command`, | ||
} | ||
|
||
func init() { | ||
deleteCmd.AddCommand(NewCmdDeleteCluster()) | ||
RootCmd.AddCommand(deleteCmd) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
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/golang/glog" | ||
"github.com/spf13/cobra" | ||
"sigs.k8s.io/cluster-api/errors" | ||
) | ||
|
||
type DeleteOptions struct { | ||
ClusterName string | ||
} | ||
|
||
var do = &DeleteOptions{} | ||
|
||
func NewCmdDeleteCluster() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "delete", | ||
Short: "Delete kubernetes cluster", | ||
Long: `Delete a kubernetes cluster with one command`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if do.ClusterName == "" { | ||
exitWithHelp(cmd, "Please provide cluster name.") | ||
} | ||
if err := RunDelete(); err != nil { | ||
glog.Exit(err) | ||
} | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func RunDelete() error { | ||
return errors.NotImplementedError | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
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 ( | ||
"flag" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/ghodss/yaml" | ||
"github.com/golang/glog" | ||
"github.com/spf13/cobra" | ||
"k8s.io/apiserver/pkg/util/logs" | ||
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1" | ||
"sigs.k8s.io/cluster-api/util" | ||
) | ||
|
||
var RootCmd = &cobra.Command{ | ||
Use: "clusterctl", | ||
Short: "cluster management", | ||
Long: `Simple kubernetes cluster management`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Do Stuff Here | ||
cmd.Help() | ||
}, | ||
} | ||
|
||
func Execute() { | ||
if err := RootCmd.Execute(); err != nil { | ||
glog.Exit(err) | ||
} | ||
} | ||
|
||
func parseClusterYaml(file string) (*clusterv1.Cluster, error) { | ||
bytes, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cluster := &clusterv1.Cluster{} | ||
err = yaml.Unmarshal(bytes, cluster) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return cluster, nil | ||
} | ||
|
||
func parseMachinesYaml(file string) ([]*clusterv1.Machine, error) { | ||
bytes, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
machines := &clusterv1.MachineList{} | ||
err = yaml.Unmarshal(bytes, &machines) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return util.MachineP(machines.Items), nil | ||
} | ||
|
||
func exitWithHelp(cmd *cobra.Command, err string) { | ||
glog.Error(err) | ||
cmd.Help() | ||
os.Exit(1) | ||
} | ||
|
||
func init() { | ||
flag.CommandLine.Parse([]string{}) | ||
logs.InitLogs() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
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 main | ||
|
||
import "sigs.k8s.io/cluster-api/clusterctl/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
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 errors | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
var NotImplementedError = fmt.Errorf("not implemented") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intentional to have empty conributing guidelines for this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I'm happy to remove the file though, but I wanted to link to something from the README.