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

Commit

Permalink
rename to capd
Browse files Browse the repository at this point in the history
Signed-off-by: Chuck Ha <chuckh@vmware.com>
  • Loading branch information
chuckha committed Jun 19, 2019
1 parent b692739 commit 5bef5f9
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.capk → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ADD go.sum .
RUN go mod download
RUN curl -L https://dl.k8s.io/v1.14.3/kubernetes-client-linux-amd64.tar.gz | tar xvz
ADD cmd cmd
ADD capkactuators capkactuators
ADD actuators capkactuators
ADD kind kind
ADD execer execer
ADD third_party third_party
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Cluster API Provider Kind
# Cluster API Provider Docker

A temporary home for CAPK
A temporary home for CAPD

## Manager Container Image

A sample is built and hosted at `gcr.io/kubernetes1-226021/capk-manager:latest`
A sample is built and hosted at `gcr.io/kubernetes1-226021/capd-manager:latest`

### Building the binaries

Expand All @@ -19,9 +19,9 @@ Requires `gcloud` authenticated and configured.

Requires a google cloud project

`./scripts/publish-capk-manager.sh`
`./scripts/publish-capd-manager.sh`

# Testing out CAPK
# Testing out CAPD

Tested on: Linux, OS X

Expand All @@ -33,19 +33,19 @@ Install capkctl

Start a management kind cluster

`capkctl setup`
`capdctl setup`

Set up your `kubectl`

`export KUBECONFIG="$(kind get kubeconfig-path --name="kind")"`

Install the cluster-api CRDs

`capkctl crds | kubectl apply -f -`
`capdctl crds | kubectl apply -f -`

Run the capk & capi manager
Run the capd & capi manager

`capkctl capk | kubectl apply -f -`
`capdctl capd | kubectl apply -f -`

## Create a worker cluster

Expand Down
4 changes: 2 additions & 2 deletions capkactuators/actuators.go → actuators/actuators.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package capkactuators
package actuators

import (
"fmt"
"io/ioutil"

"github.com/chuckha/cluster-api-provider-kind/kind/actions"
"github.com/chuckha/cluster-api-provider-docker/kind/actions"
"github.com/pkg/errors"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
51 changes: 41 additions & 10 deletions capkactuators/machine.go → actuators/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package capkactuators
package actuators

import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/chuckha/cluster-api-provider-kind/kind/actions"
v1 "k8s.io/api/core/v1"

"github.com/chuckha/cluster-api-provider-docker/kind/actions"
"k8s.io/apimachinery/pkg/types"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
Expand Down Expand Up @@ -83,7 +85,7 @@ func (m *Machine) Create(ctx context.Context, c *clusterv1.Cluster, machine *clu
fmt.Printf("%+v", err)
return err
}
name := providerName(controlPlaneNode.Name())
name := providerID(controlPlaneNode.Name())
machine.Spec.ProviderID = &name
return m.save(old, machine)
}
Expand All @@ -104,7 +106,9 @@ func (m *Machine) Create(ctx context.Context, c *clusterv1.Cluster, machine *clu
fmt.Printf("%+v\n", err)
return err
}
name := providerName(controlPlaneNode.Name())

// set the machine's providerID
name := providerID(controlPlaneNode.Name())
machine.Spec.ProviderID = &name
if err := m.save(old, machine); err != nil {
fmt.Printf("%+v\n", err)
Expand Down Expand Up @@ -135,10 +139,11 @@ func (m *Machine) Create(ctx context.Context, c *clusterv1.Cluster, machine *clu
fmt.Printf("%+v", err)
return err
}
name := providerName(worker.Name())
name := providerID(worker.Name())
machine.Spec.ProviderID = &name
return m.save(old, machine)
}

func (m *Machine) Delete(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
return actions.DeleteNode(cluster.Name, providerNameToLookupID(*machine.Spec.ProviderID))
}
Expand Down Expand Up @@ -176,7 +181,7 @@ func (m *Machine) save(old, new *clusterv1.Machine) error {
fmt.Printf("%+v\n", err)
return err
}
fmt.Println("Patches", p)
fmt.Println("Patches for machine", p)
if len(p) != 0 {
pb, err := json.MarshalIndent(p, "", " ")
if err != nil {
Expand All @@ -187,17 +192,43 @@ func (m *Machine) save(old, new *clusterv1.Machine) error {
fmt.Printf("%+v\n", err)
return err
}
fmt.Println("updated")
fmt.Println("updated machine")
}
return nil
}

// This should be the cloud-provider for docker, but that doesn't exist.
func (m *Machine) setProviderID(node *v1.Node, kindName string) error {
old := node.DeepCopy()
node.Spec.ProviderID = providerID(kindName)
p, err := patch.NewJSONPatch(old, node)
if err != nil {
fmt.Printf("%+v\n", err)
return err
}
fmt.Println("Patches for node", p)
if len(p) != 0 {
pb, err := json.MarshalIndent(p, "", " ")
if err != nil {
fmt.Printf("%+v\n", err)
return err
}
if _, err := m.Core.Nodes().Patch(node.Name, types.JSONPatchType, pb); err != nil {
fmt.Printf("%+v\n", err)
return err
}
fmt.Println("updated node")
}
return nil

}

func providerNameToLookupID(providerName string) string {
return providerName[1:]
return providerName[len("docker://"):]
}

func providerName(name string) string {
return fmt.Sprintf("/%s", name)
func providerID(name string) string {
return fmt.Sprintf("docker://%s", name)
}

func CAPIroleToKindRole(CAPIRole string) string {
Expand Down
6 changes: 3 additions & 3 deletions cmd/capk-manager/main.go → cmd/capd-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"time"

"github.com/chuckha/cluster-api-provider-kind/capkactuators"
"github.com/chuckha/cluster-api-provider-docker/actuators"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/cluster-api/pkg/apis"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/common"
Expand Down Expand Up @@ -57,8 +57,8 @@ func main() {
panic(err)
}

clusterActuator := capkactuators.NewClusterActuator()
machineActuator := capkactuators.NewMachineActuator(cs.ClusterV1alpha1(), k8sclientset.CoreV1())
clusterActuator := actuators.NewClusterActuator()
machineActuator := actuators.NewMachineActuator(cs.ClusterV1alpha1(), k8sclientset.CoreV1())

// Register our cluster deployer (the interface is in clusterctl and we define the Deployer interface on the actuator)
common.RegisterClusterProvisioner("aws", clusterActuator)
Expand Down
52 changes: 26 additions & 26 deletions cmd/capkctl/main.go → cmd/capdctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"io/ioutil"
"os"

"github.com/chuckha/cluster-api-provider-kind/execer"
"github.com/chuckha/cluster-api-provider-docker/execer"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
)
Expand All @@ -46,9 +46,9 @@ func main() {

// crds takes no args

capk := flag.NewFlagSet("capk", flag.ExitOnError)
capkImage := capk.String("capk-image", "gcr.io/kubernetes1-226021/capk-manager:latest", "The capk manager image to run")
capiImage := capk.String("capi-image", "gcr.io/k8s-cluster-api/cluster-api-controller:0.1.1", "The capi manager image to run")
capd := flag.NewFlagSet("capd", flag.ExitOnError)
capdImage := capd.String("capd-image", "gcr.io/kubernetes1-226021/capd-manager:latest", "The capd manager image to run")
capiImage := capd.String("capi-image", "gcr.io/k8s-cluster-api/cluster-api-controller:0.1.1", "The capi manager image to run")

controlPlane := flag.NewFlagSet("control-plane", flag.ExitOnError)
controlPlaneOpts := new(machineOptions)
Expand All @@ -75,9 +75,9 @@ func main() {
makeManagementCluster(*managementClusterName)
case "crds":
printCRDs()
case "capk":
capk.Parse(os.Args[2:])
printClusterAPIPlane(*capkImage, *capiImage)
case "capd":
capd.Parse(os.Args[2:])
printClusterAPIPlane(*capdImage, *capiImage)
case "control-plane":
controlPlane.Parse(os.Args[2:])
fmt.Fprintf(os.Stdout, machineYAML(controlPlaneOpts))
Expand All @@ -96,27 +96,27 @@ func main() {
}

func usage() string {
return `capkctl gets you up and running with capk
return `capdctl gets you up and running with capd
subcommands are:
setup - Create a management cluster
example: capkctl setup --name my-management-cluster-name
example: capdctl setup --name my-management-cluster-name
crds - Write Cluster API CRDs required to run capk to stdout
example: capkctl crds | kubectl apply -f -
crds - Write Cluster API CRDs required to run capd to stdout
example: capdctl crds | kubectl apply -f -
capk - Write capk kubernetes components that run necessary managers to stdout
example: capkctl capk -capk-image gcr.io/kubernetes1-226021/capk-manager:latest -capi-image gcr.io/k8s-cluster-api/cluster-api-controller:0.1.2 | kubeclt apply -f -
capd - Write capd kubernetes components that run necessary managers to stdout
example: capdctl capd -capd-image gcr.io/kubernetes1-226021/capd-manager:latest -capi-image gcr.io/k8s-cluster-api/cluster-api-controller:0.1.2 | kubeclt apply -f -
control-plane - Write a capk control plane machine to stdout
example: capkctl control-plane -name my-control-plane -namespace my-namespace -cluster-name my-cluster -version v1.14.1 | kubectl apply -f -
control-plane - Write a capd control plane machine to stdout
example: capdctl control-plane -name my-control-plane -namespace my-namespace -cluster-name my-cluster -version v1.14.1 | kubectl apply -f -
worker - Write a capk worker machine to stdout
example: capkctl worker -name my-worker -namespace my-namespace -cluster-name my-cluster -version 1.14.2 | kubectl apply -f -
worker - Write a capd worker machine to stdout
example: capdctl worker -name my-worker -namespace my-namespace -cluster-name my-cluster -version 1.14.2 | kubectl apply -f -
cluster - Write a capk cluster object to stdout
example: capkctl cluster -cluster-name my-cluster -namespace my-namespace | kubectl apply -f -
cluster - Write a capd cluster object to stdout
example: capdctl cluster -cluster-name my-cluster -namespace my-namespace | kubectl apply -f -
`
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func machineYAML(opts *machineOptions) string {
Namespace: *opts.namespace,
Labels: map[string]string{
"cluster.k8s.io/cluster-name": *opts.clusterName,
"set": *opts.set,
"set": *opts.set,
},
},
Spec: v1alpha1.MachineSpec{
Expand Down Expand Up @@ -208,12 +208,12 @@ func printCRDs() {
fmt.Fprintln(os.Stdout, crds)
}

func printClusterAPIPlane(capkImage, capiImage string) {
fmt.Fprintln(os.Stdout, getCAPKPlane(capkImage, capiImage))
func printClusterAPIPlane(capdImage, capiImage string) {
fmt.Fprintln(os.Stdout, getCAPDPlane(capdImage, capiImage))
}

func getCAPKPlane(capkImage, capiImage string) string {
return fmt.Sprintf(capiPlane, capkImage, capiImage)
func getCAPDPlane(capdImage, capiImage string) string {
return fmt.Sprintf(capiPlane, capdImage, capiImage)
}

var capiPlane = `
Expand Down Expand Up @@ -249,10 +249,10 @@ spec:
control-plane: controller-manager
spec:
containers:
- name: capk-manager
- name: capd-manager
image: %s
command:
- capk-manager
- capd-manager
volumeMounts:
- mountPath: /var/run/docker.sock
name: dockersock
Expand Down
2 changes: 1 addition & 1 deletion cmd/kind-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"os"
"strings"

"github.com/chuckha/cluster-api-provider-kind/kind/actions"
"github.com/chuckha/cluster-api-provider-docker/kind/actions"
"sigs.k8s.io/kind/pkg/cluster/constants"
"sigs.k8s.io/kind/pkg/cluster/nodes"
)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/chuckha/cluster-api-provider-kind
module github.com/chuckha/cluster-api-provider-docker

go 1.12

Expand Down
37 changes: 34 additions & 3 deletions kind/actions/cluster_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"html/template"
"strings"

"github.com/chuckha/cluster-api-provider-kind/kind/kubeadm"
"github.com/chuckha/cluster-api-provider-kind/third_party/forked/loadbalancer"
"github.com/chuckha/cluster-api-provider-docker/kind/kubeadm"
"github.com/chuckha/cluster-api-provider-docker/third_party/forked/loadbalancer"
"github.com/pkg/errors"
"sigs.k8s.io/kind/pkg/cluster/constants"
"sigs.k8s.io/kind/pkg/cluster/nodes"
Expand Down Expand Up @@ -177,7 +177,7 @@ func KubeadmInit(clusterName string) error {
return nil
}

func InstallCNI(node *nodes.Node, clusterName string) error {
func InstallCNI(node *nodes.Node) error {
// read the manifest from the node
var raw bytes.Buffer
if err := node.Command("cat", "/kind/manifests/default-cni.yaml").SetStdout(&raw).Run(); err != nil {
Expand Down Expand Up @@ -242,3 +242,34 @@ func KubeadmJoin(clusterName string, node *nodes.Node) error {

return nil
}

func SetNodeRef(clusterName, nodeName string) error {
allNodes, err := nodes.List(fmt.Sprintf("label=%s=%s", constants.ClusterLabelKey, clusterName))
if err != nil {
return nil
}

node, err := nodes.BootstrapControlPlaneNode(allNodes)
if err != nil {
return err
}

patch := fmt.Sprintf(`{"spec": {"providerID": "docker://%s"}}`, nodeName)
fmt.Println("trying to apply:", patch)
cmd := node.Command(
"kubectl",
"--kubeconfig", "/etc/kubernetes/admin.conf",
"patch",
"node", nodeName,
"--patch", patch,
)
lines, err := exec.CombinedOutputLines(cmd)
if err != nil {
for _, line := range lines {
fmt.Println(line)
}
return errors.Wrap(err, "failed update providerID")
}

return nil
}
Loading

0 comments on commit 5bef5f9

Please sign in to comment.