-
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 1 commit
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,61 @@ | ||
# 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/kube-deploy/blob/master/cluster-api/clusterctl/CONTRIBUTING.md) to: | ||
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. Wrong repo? 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. Indeed |
||
|
||
1. Build the `clusterctl` tool | ||
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. probably will want an example of how to build. 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. Added one |
||
3. Create a `machines.yaml` file configured for your cluster. See the provided template for an example. | ||
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. How come it jumped from 1 to 3? 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. MD renders ordered lists just fine even if the numbers are wrong here. I'll fix them nevertheless. |
||
|
||
### Limitation | ||
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. (nit) 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. Fixed |
||
|
||
|
||
### 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. |
||
In order to create a cluster with the Cluster API, the user will supply these: | ||
|
||
* Cluster which defines the spec common across the entire cluster. | ||
* Machine which defines the spec of a machine. Further abstractions of | ||
MachineSets and MachineClass and MachineDeployments are supported as well. | ||
* Extras (optional) spec extras.yaml file with specs of all controllers | ||
(ConfigMaps) that the cluster needs. This would include the Machine controller, | ||
MachineSet controller, Machine Setup ConfigMap etc. Note that this is not a new API | ||
object. There will be defaults running. This will make the tool easily pluggage | ||
(change the controller spec) instead of changing the tool or mucking with flags. | ||
|
||
1. Create a cluster: `./clusterctl create cluster -c cluster.yaml -m machines.yaml -e extras.yaml` | ||
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 leave the create cluster details out. They can be filled in as the implementation is checked in. That way the docs and reality keep 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. Sure |
||
|
||
### 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,71 @@ | ||
/* | ||
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 ( | ||
"os" | ||
|
||
//"fmt" | ||
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. Is it intentional to have a commented out import? 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. Removed it. Typo |
||
"github.com/golang/glog" | ||
"github.com/spf13/cobra" | ||
"sigs.k8s.io/cluster-api/errors" | ||
) | ||
|
||
type CreateOptions struct { | ||
Cluster string | ||
Machine string | ||
Extras string | ||
} | ||
|
||
var co = &CreateOptions{} | ||
|
||
var createCmd = &cobra.Command{ | ||
Use: "create", | ||
Short: "Create kubernetes cluster", | ||
Long: `Create a kubernetes cluster with one command`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if co.Cluster == "" { | ||
glog.Error("Please provide yaml file for cluster definition.") | ||
cmd.Help() | ||
os.Exit(1) | ||
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. We are doing the following:
in 4 locations in the Create command and there are similar sections in Delete and Register commands. Theoretically this number will grow as the scope of this application increases. Is there a simplification we can make so that it is only called in a single place for the various error scenarios? 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. Good point. DOne |
||
} | ||
if co.Machine == "" { | ||
glog.Error("Please provide yaml file for machine definition.") | ||
cmd.Help() | ||
os.Exit(1) | ||
} | ||
if co.Extras == "" { | ||
glog.Error("Please provide a yaml file for extra definitions (controllers, Addons etc).") | ||
cmd.Help() | ||
os.Exit(1) | ||
} | ||
if err := RunCreate(co); err != nil { | ||
glog.Exit(err) | ||
} | ||
}, | ||
} | ||
|
||
func RunCreate(co *CreateOptions) error { | ||
return errors.NotImplementedError | ||
} | ||
func init() { | ||
createCmd.Flags().StringVarP(&co.Cluster, "cluster", "c", "", "cluster yaml file") | ||
createCmd.Flags().StringVarP(&co.Machine, "machines", "m", "", "machine yaml file") | ||
createCmd.Flags().StringVarP(&co.Extras, "extras", "e", "", "extras yaml file") | ||
|
||
RootCmd.AddCommand(createCmd) | ||
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 thought the goal was something like: ./clusterctl create cluster ..... This seems to produce: ./clusterctl create .... Or did I miss something? 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. Based on community feedback, we decided to align ourselves with the rest of the tooling -- This is also reflected in https://docs.google.com/document/d/1-sYb3EdkRga49nULH1kSwuQFf1o6GvAw_POrsNo5d8c/edit#. 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 believe we are doing VERB NOUN right now. This makes me expect 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. Good catch! Added the subcommands |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
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" | ||
"os" | ||
"sigs.k8s.io/cluster-api/errors" | ||
) | ||
|
||
type DeleteOptions struct { | ||
ClusterName string | ||
} | ||
|
||
var do = &DeleteOptions{} | ||
|
||
var deleteCmd = &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 == "" { | ||
glog.Error("Please provide cluster name.") | ||
cmd.Help() | ||
os.Exit(1) | ||
} | ||
if err := RunDelete(); err != nil { | ||
glog.Exit(err) | ||
} | ||
}, | ||
} | ||
|
||
func RunDelete() error { | ||
return errors.NotImplementedError | ||
} | ||
|
||
func init() { | ||
deleteCmd.Flags().StringVarP(&do.ClusterName, "cluster-name", "n", "", "cluster name") | ||
|
||
RootCmd.AddCommand(deleteCmd) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
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 ( | ||
"os" | ||
|
||
"github.com/golang/glog" | ||
"github.com/spf13/cobra" | ||
"sigs.k8s.io/cluster-api/errors" | ||
) | ||
|
||
type RegisterOptions struct { | ||
RegistryEndpoint string | ||
} | ||
|
||
var ro = &RegisterOptions{} | ||
|
||
var registerCmd = &cobra.Command{ | ||
Use: "register", | ||
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. Should register also follow VERB NOUN? ie. "register cluster" instead of just "register"? 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. Whenever register is implemented, it can be branched out. For now, I'm leaving it as is. 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 do not think this is the right approach. Either we structure it as it is supposed to be structured ie. VERB NOUN or we leave it out entirely and when it is implemented, it is added with the right structure. 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 have decided to remove it and leave it up to implementer to add this cmd as well. |
||
Short: "Register a kubernetes cluster with a Cluster Registry", | ||
Long: `Register a kubernetes cluster with a Cluster Registry`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if ro.RegistryEndpoint == "" { | ||
glog.Error("Please provide yaml file for cluster definition.") | ||
cmd.Help() | ||
os.Exit(1) | ||
} | ||
if err := RunRegister(ro); err != nil { | ||
glog.Exit(err) | ||
} | ||
}, | ||
} | ||
|
||
func RunRegister(co *RegisterOptions) error { | ||
return errors.NotImplementedError | ||
} | ||
|
||
func init() { | ||
registerCmd.Flags().StringVarP(&ro.RegistryEndpoint, "registry-endpoint", "r", "", "registry endpoint") | ||
|
||
RootCmd.AddCommand(registerCmd) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
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" | ||
|
||
"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() | ||
}, | ||
} | ||
|
||
var ( | ||
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. On my previous comment on flags, I do mean all flags on all commands should not be implemented yet. They can be implemented when there is actually functionality to back it. This way the usage and description is accurate to how it is actually used. 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. The flags have been removed, I guess I missed the var. 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. The var seems to still be here. There also still seem to be flags on some of the commands that are not backed by implementation. 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. Weird my linter didn't complain. |
||
kubeConfig string | ||
) | ||
|
||
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 init() { | ||
RootCmd.PersistentFlags().StringVarP(&kubeConfig, "kubeconfig", "k", "", "location for the kubernetes config file. If not provided, $HOME/.kube/config is used") | ||
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. Please leave all flags out of the skeleton. They can be filled in as code uses them. This ensures the the flags actually do something when they appear and also ensure they are defined in a way that works and is accurate to the behavior of the code. For example, I already know this definition of kubeconfig will not be accurate for bootstrapping. 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. Sure. |
||
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.