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

Commit

Permalink
Merge pull request #56 from chuckha/remove-kind
Browse files Browse the repository at this point in the history
remove `kind` the binary as a dependnecy
k8s-ci-robot authored Jul 3, 2019
2 parents 1064568 + 11c4cf9 commit 8999df7
Showing 11 changed files with 87 additions and 220 deletions.
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.12.5
FROM golang:1.12.6
WORKDIR /cluster-api-provider-docker
ADD go.mod .
ADD go.sum .
@@ -21,17 +21,14 @@ RUN curl -L https://dl.k8s.io/v1.14.3/kubernetes-client-linux-amd64.tar.gz | ta
ADD cmd cmd
ADD actuators actuators
ADD kind kind
ADD execer execer
ADD third_party third_party
ADD logger logger

RUN go install -v ./cmd/capd-manager
RUN GO111MODULE="on" go get sigs.k8s.io/kind@v0.3.0
RUN curl https://get.docker.com | sh

FROM golang:1.12.5
COPY --from=0 /cluster-api-provider-docker/kubernetes/client/bin/kubectl /usr/local/bin
COPY --from=0 /go/bin/capd-manager /usr/local/bin
COPY --from=0 /go/bin/kind /usr/local/bin
COPY --from=0 /usr/bin/docker /usr/local/bin
ENTRYPOINT ["capd-manager"]
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ A sample is built and hosted at `gcr.io/kubernetes1-226021/capd-manager:latest`
### External Dependencies

- `go, 1.12+`
- `kind, >= 0.3.0`
- `kubectl`
- `docker`

@@ -42,7 +41,7 @@ Alternatively, run: `REGISTRY=<MY_REGISTRY> ./scripts/publish-manager.sh`

Tested on: Linux, works ok on OS X sometimes

Make sure you have `kind` > 0.3.0 and `kubectl`.
Make sure you have `kubectl`.

1. Install capdctl:

@@ -54,7 +53,7 @@ Make sure you have `kind` > 0.3.0 and `kubectl`.

1. Set up your `kubectl`

`export KUBECONFIG="$(kind get kubeconfig-path --name="kind")"`
`export KUBECONFIG="${HOME}/.kube/kind-config-management"`

1. Install the cluster-api CRDs

4 changes: 2 additions & 2 deletions actuators/machine.go
Original file line number Diff line number Diff line change
@@ -97,12 +97,12 @@ func (m *Machine) Create(ctx context.Context, c *clusterv1.Cluster, machine *clu
m.Log.Error(err, "Error getting external load balancer node")
return err
}
lbip, err := elb.IP()
lbipv4, _, err := elb.IP()
if err != nil {
m.Log.Error(err, "Error getting node IP address")
return err
}
controlPlaneNode, err := actions.CreateControlPlane(c.Name, machine.GetName(), lbip, machine.Spec.Versions.ControlPlane)
controlPlaneNode, err := actions.CreateControlPlane(c.Name, machine.GetName(), lbipv4, machine.Spec.Versions.ControlPlane, nil)
if err != nil {
m.Log.Error(err, "Error creating control plane")
return err
73 changes: 48 additions & 25 deletions cmd/capdctl/main.go
Original file line number Diff line number Diff line change
@@ -18,13 +18,18 @@ package main

import (
"encoding/json"
"errors"
"flag"
"fmt"
"io/ioutil"
"os"
"sigs.k8s.io/cluster-api-provider-docker/kind/actions"
"sigs.k8s.io/kind/pkg/cluster/nodes"
"sigs.k8s.io/kind/pkg/container/cri"
"sigs.k8s.io/kind/pkg/exec"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/cluster-api-provider-docker/execer"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
)

@@ -62,7 +67,7 @@ func (mo *machineDeyploymentOptions) initFlags(fs *flag.FlagSet) {

func main() {
setup := flag.NewFlagSet("setup", flag.ExitOnError)
managementClusterName := setup.String("cluster-name", "kind", "The name of the management cluster")
managementClusterName := setup.String("cluster-name", "management", "The name of the management cluster")

// crds takes no args

@@ -91,6 +96,7 @@ func main() {
if len(os.Args) < 2 {
fmt.Println("At least one subcommand is requied.")
fmt.Println(usage())
os.Exit(1)
}

switch os.Args[1] {
@@ -242,37 +248,43 @@ func machineYAML(opts *machineOptions) string {
}

func makeManagementCluster(clusterName string) {
kind := execer.NewClient("kind")
// start kind with docker mount
kindConfig, err := kindConfigFile()
fmt.Println("Creating a brand new cluster")
elb, err := actions.SetUpLoadBalancer(clusterName)
if err != nil {
panic(err)
}
if err := kind.RunCommand("create", "cluster", "--name", clusterName, "--config", kindConfig); err != nil {
lbipv4, _, err := elb.IP()
if err != nil {
panic(err)
}
}

// TODO if possible, use the kind library instead of the command line tool
func kindConfigFile() (string, error) {
kfg := `kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
nodes:
- role: control-plane
extraMounts:
- containerPath: /var/run/docker.sock
hostPath: /var/run/docker.sock
`

f, err := ioutil.TempFile("", "*-kind-config.yaml")
cpMounts := []cri.Mount{
{
ContainerPath: "/var/run/docker.sock",
HostPath: "/var/run/docker.sock",
},
}
cp, err := actions.CreateControlPlane(clusterName, "management-control-plane", lbipv4, "v1.14.2", cpMounts)
if err != nil {
return "", err
panic(err)
}
if !nodes.WaitForReady(cp, time.Now().Add(5*time.Minute)) {
panic(errors.New("control plane was not ready in 5 minutes"))
}
defer f.Close()
if _, err := f.WriteString(kfg); err != nil {
return "", err
f, err := ioutil.TempFile("", "crds")
if err != nil {
panic(err)
}
defer os.Remove(f.Name())
fmt.Fprintln(f, crds)
fmt.Fprintln(f, "---")
fmt.Fprintln(f, getCAPDPlane("gcr.io/kubernetes1-226021/capd-manager:latest", "gcr.io/k8s-cluster-api/cluster-api-controller:0.1.3"))
cmd := exec.Command("kubectl", "apply", "-f", f.Name())
cmd.SetEnv(fmt.Sprintf("KUBECONFIG=%s/.kube/kind-config-%s", os.Getenv("HOME"), clusterName))
cmd.SetStdout(os.Stdout)
cmd.SetStderr(os.Stderr)
if err := cmd.Run(); err != nil {
panic(err)
}
return f.Name(), nil
}

func printCRDs() {
@@ -376,6 +388,17 @@ spec:
- /manager
image: %s
name: manager
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
- key: CriticalAddonsOnly
operator: Exists
- effect: NoExecute
key: node.alpha.kubernetes.io/notReady
operator: Exists
- effect: NoExecute
key: node.alpha.kubernetes.io/unreachable
operator: Exists
`

// TODO generate the CRDs
4 changes: 2 additions & 2 deletions cmd/kind-test/main.go
Original file line number Diff line number Diff line change
@@ -44,11 +44,11 @@ func main() {
if err != nil {
panic(fmt.Sprintf("%+v", err))
}
ip, err := lb.IP()
lbipv4, _, err := lb.IP()
if err != nil {
panic(fmt.Sprintf("%+v", err))
}
if _, err := actions.CreateControlPlane(clusterName, inputs[1], ip, version); err != nil {
if _, err := actions.CreateControlPlane(clusterName, inputs[1], lbipv4, version, nil); err != nil {
panic(fmt.Sprintf("%+v", err))
}
case "add-worker":
165 changes: 0 additions & 165 deletions execer/client.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ require (
k8s.io/kubernetes v1.13.1
sigs.k8s.io/cluster-api v0.0.0-20190607141803-aacb0c613ffb
sigs.k8s.io/controller-runtime v0.1.10
sigs.k8s.io/kind v0.3.0
sigs.k8s.io/kind v0.4.0
sigs.k8s.io/testing_frameworks v0.1.1 // indirect
)

4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -195,8 +195,8 @@ sigs.k8s.io/cluster-api v0.0.0-20190607141803-aacb0c613ffb h1:sL9u/pvPx+6/9pIssy
sigs.k8s.io/cluster-api v0.0.0-20190607141803-aacb0c613ffb/go.mod h1:aEXstFx3krpj6/AOcV/rOP2VLKdrtSNUMDR2Kmt6YSs=
sigs.k8s.io/controller-runtime v0.1.10 h1:amLOmcekVdnsD1uIpmgRqfTbQWJ2qxvQkcdeFhcotn4=
sigs.k8s.io/controller-runtime v0.1.10/go.mod h1:HFAYoOh6XMV+jKF1UjFwrknPbowfyHEHHRdJMf2jMX8=
sigs.k8s.io/kind v0.3.0 h1:TUIRsJZy123ejyWECuYOU2XzSsIsauoqaeoUGsfdj6k=
sigs.k8s.io/kind v0.3.0/go.mod h1:bgGo2cWxKGQ7esVxtGp9H17Ttlexju92CTMjCg08HNQ=
sigs.k8s.io/kind v0.4.0 h1:C/QMxmF5Sp3yyKkTJ5+VJPcclZyu/JV8wLyihZbsHaI=
sigs.k8s.io/kind v0.4.0/go.mod h1:bgGo2cWxKGQ7esVxtGp9H17Ttlexju92CTMjCg08HNQ=
sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0=
sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
sigs.k8s.io/structured-merge-diff v0.0.0-20190426204423-ea680f03cc65/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
1 change: 1 addition & 0 deletions hack/verify-gofmt.sh
Original file line number Diff line number Diff line change
@@ -28,4 +28,5 @@ if [[ -n "${diff}" ]]; then
echo "${diff}"
echo
echo "Check failed. Please run hack/update-gofmt.sh"
exit 1
fi
Loading

0 comments on commit 8999df7

Please sign in to comment.