Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Commit

Permalink
confige machine deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Amy Chen committed Jun 27, 2019
1 parent e9226bc commit 064fb05
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions cmd/capdctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ func (mo *machineOptions) initFlags(fs *flag.FlagSet) {
mo.version = fs.String("version", "v1.14.2", "The Kubernetes version to run")
}

type machineDeyploymentOptions struct {
name, namespace, clusterName, controlPlaneVersion, kubeletVersion *string
replicas *int32
}

func (mo *machineDeyploymentOptions) initFlags(fs *flag.FlagSet) {
mo.name = fs.String("name", "my-machine", "The name of the machine")
mo.namespace = fs.String("namespace", "my-namespace", "The namespece of the machine")
mo.clusterName = fs.String("cluster-name", "my-cluster", "The name of the cluster the machine belongs to")
mo.controlPlaneVersion = fs.String("control-plane-version", "v1.14.2", "The Kubernetes control plane version to run")
mo.kubeletVersion = fs.String("kubelet-version", "v1.14.2", "The Kubernetes kubelet version to run")
replicas := int32(*fs.Int("replicas", 1, "The number of replicas"))
mo.replicas = &replicas
}

func main() {
setup := flag.NewFlagSet("setup", flag.ExitOnError)
managementClusterName := setup.String("cluster-name", "kind", "The name of the management cluster")
Expand Down Expand Up @@ -143,6 +158,41 @@ spec:
providerSpec: {}`, name, namespace)
}

func machineDeploymentYAML(opts *machineDeyploymentOptions) string {
deployment := v1alpha1.MachineDeployment{
TypeMeta: metav1.TypeMeta{
Kind: "MachineDeployment",
APIVersion: "cluster.k8s.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: *opts.name,
Namespace: *opts.namespace,
Labels: map[string]string{
"cluster.k8s.io/cluster-name": *opts.clusterName,
"set": "node",
},
},
Spec: v1alpha1.MachineDeploymentSpec{
Replicas: opts.replicas,
Template: v1alpha1.MachineTemplateSpec{
Spec: v1alpha1.MachineSpec{
Versions: v1alpha1.MachineVersionInfo{
ControlPlane: *opts.controlPlaneVersion,
Kubelet: *opts.kubeletVersion,
},
},
},
},
}

b, err := json.Marshal(deployment)
// TODO don't panic on the error
if err != nil {
panic(err)
}
return string(b)
}

func machineYAML(opts *machineOptions) string {
machine := v1alpha1.Machine{
TypeMeta: metav1.TypeMeta{
Expand Down

0 comments on commit 064fb05

Please sign in to comment.