Skip to content

Commit

Permalink
fixes 'add docker-for-desktop platform to kfctl (golang)' (kubeflow#2433
Browse files Browse the repository at this point in the history
)

* revert to prior version

* fixes kfctl (golang) rename 'ks' directory and app to ksonnet and ksonnet.go respectively

* fixes 'kfctl - Fetch registry automatically'

* fixes 'refactor gcp, minikube, docker-for-desktop, ack to be kfctl plugins'

* change DefaultDevRepo to point to just the repo not repo/kubeflow

* fixes 'refactor gcp, minikube, docker-for-desktop, ack to be kfctl plugins'

* plugins for all existing KfApp instances {ksonnet, minikube, foo}.

* update golang version

* fixes 'docker-for-desktop'

* delete meta-controller-cluster-role-binding

* update README.md

* remove unused var DEBUG

* remove bootstrap/cmd/plugins/foo.go

* merge changes from upstream master

* remove old files, update README.md

* removing foo, making dockerfordesktop a plugin

* remove foo, make dockerfordesktop the plugin
  • Loading branch information
kkasravi authored and k8s-ci-robot committed Feb 14, 2019
1 parent f48ec9c commit 36e3289
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 163 deletions.
18 changes: 9 additions & 9 deletions bootstrap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ build-bootstrap: generate fmt vet
build-kfctl: generate fmt vet
$(GO) build -i -gcflags 'all=-N -l' -o bin/kfctl cmd/kfctl/main.go

build-foo-plugin: generate fmt vet
$(GO) build -i -gcflags 'all=-N -l' -o bin/foo.so -buildmode=plugin cmd/plugins/foo/foo.go
build-dockerfordesktop-plugin: generate fmt vet
$(GO) build -i -gcflags 'all=-N -l' -o bin/dockerfordesktop.so -buildmode=plugin cmd/plugins/dockerfordesktop/dockerfordesktop.go

build-local: build-bootstrap build-kfctl

Expand Down Expand Up @@ -85,18 +85,18 @@ run-local-docker:
--mount type=bind,source=${HOME}/kf_app,target=/home/kubeflow \
--entrypoint /bin/bash $(IMG):$(TAG)

test-known-platforms-init: install build-foo-plugin
@rm -rf $(HOME)/foo && \
PLUGINS_ENVIRONMENT=$(PLUGINS_ENVIRONMENT) kfctl init $(HOME)/foo -V --platform foo --version master && \
test-known-platforms-init: install build-dockerfordesktop-plugin
@rm -rf $(HOME)/dockerfordesktop && \
PLUGINS_ENVIRONMENT=$(PLUGINS_ENVIRONMENT) kfctl init $(HOME)/dockerfordesktop -V --platform docker-for-desktop --version master && \
rm -rf $(HOME)/ksonnet && \
kfctl init $(HOME)/ksonnet -V --platform ksonnet --version master && \
rm -rf $(HOME)/minikube && \
kfctl init $(HOME)/minikube -V --platform minikube --version master && \
echo SUCCESS

test-known-platforms-generate: test-known-platforms-init
@cd ~/foo && \
PLUGINS_ENVIRONMENT=$(GOPATH)/src/github.com/kubeflow/kubeflow/bootstrap/bin kfctl generate all -V && \
@cd ~/dockerfordesktop && \
PLUGINS_ENVIRONMENT=$(PLUGINS_ENVIRONMENT) kfctl generate all -V && \
cd ~/ksonnet && \
kfctl generate all -V && \
cd ~/minikube && \
Expand All @@ -105,8 +105,8 @@ test-known-platforms-generate: test-known-platforms-init


# static and plugins toogle whether we try and load a platform as a .so.
# There is an example plugin 'foo' that can be loaded as a .so.
# By default we disable loading plugins and link foo into the kfctl binary (static)
# There is an example plugin 'dockerfordesktop' that can be loaded as a .so.
# By default we disable loading plugins and link dockerfordesktop into the kfctl binary (static)
static:
@ex pkg/apis/apps/group.go <hack/static
@ex cmd/kfctl/cmd/root.go <hack/static || echo Plugin functionality disabled
Expand Down
28 changes: 13 additions & 15 deletions bootstrap/cmd/kfctl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ New directories (`cmd/kfctl, pkg`):
```sh
bootstrap/cmd/kfctl
bootstrap/cmd/kfctl/cmd
bootstrap/pkg
bootstrap/pkg/apis
bootstrap/cmd/plugins/dockerfordesktop
bootstrap/pkg/apis/apps
bootstrap/pkg/apis/apps/ksonnet/v1alpha1
bootstrap/pkg/utils
bootstrap/pkg/client
bootstrap/pkg/client/dockerfordesktop
bootstrap/pkg/client/ksonnet
bootstrap/pkg/client/minikube
bootstrap/plugins
```

### KfApp Interface
Expand All @@ -49,6 +47,7 @@ const (
K8S ResourceEnum = "k8s"
PLATFORM ResourceEnum = "platform"
)

//
// KfApp is used by commands under bootstrap/cmd/{bootstrap,kfctl}. KfApp provides a common
// API for different implementations like Ksonnet, GcpApp, MinikubeApp, etc.
Expand All @@ -67,10 +66,8 @@ kfctl includes platforms that implement the KfApp interface. (gcp will be added
- bootstrap/pkg/client/ksonnet/ksonnet.go
- platform: **minikube**
- bootstrap/pkg/client/minikube/minikube.go
- platform: **docker-for-desktop** (in progress)
- platform: **docker-for-desktop**
- bootstrap/pkg/client/dockerfordesktop/dockerfordesktop.go
- platform: **ack** (in progress)
- bootstrap/pkg/client/ack/ack.go

## Usage

Expand Down Expand Up @@ -116,11 +113,12 @@ Usage:
kfctl init <[path/]name> [flags]
Flags:
--debug debug debug default is false
-h, --help help for init
-n, --namespace string namespace where kubeflow will be deployed (default "kubeflow")
-p, --platform string one of 'gcp|minikube|docker-for-desktop|ack' (default "none")
--project string name of the gcp project if --platform gcp
-r, --repo string local github kubeflow repo (default "$GOPATH/src/github.com/kubeflow/kubeflow/kubeflow")
-r, --repo string local github kubeflow repo
-V, --verbose verbose output default is false
-v, --version string desired version Kubeflow or latest tag if not provided by user (default "v0.4.1")
```
Expand Down Expand Up @@ -178,7 +176,7 @@ Flags:
## Extending kfctl

`kfctl` can be extended to work with new platforms without requiring recompilation.
An example is under bootstrap/cmd/plugins/fooapp.go. A particular platform
An example is under bootstrap/cmd/plugins/dockerfordesktop/dockerfordesktop.go. A particular platform
provides a shared library (.so) under the env var `PLUGINS_ENVIRONMENT`
that kfctl would load and execute. The shared library needs to define

Expand All @@ -191,27 +189,27 @@ where the return type implements the [KfApp Interface](#kfapp-interface).
In this sample, running

```
kfctl init ~/foo-app --platform foo
kfctl init ~/dockerfordesktop --platform dockerfordesktop
```

will result in kfctl loading $PLUGINS_ENVIRONMENT/fooapp.so and calling its methods that
will result in kfctl loading $PLUGINS_ENVIRONMENT/dockerfordesktop.so and calling its methods that
implement the KfApp Interface.

### Building the sample plugin

```
make build-foo-plugin
make build-dockerfordesktop-plugin
```

## Testing

### Testing init for all platforms including the `foo` platform plugin
### Testing init for all platforms including the `dockerfordesktop` platform plugin

```
make test-known-platforms-init
```

### Testing generate for all platforms including the `foo` platform plugin
### Testing generate for all platforms including the `dockerfordesktop` platform plugin

```
make test-known-platforms-generate
Expand All @@ -222,7 +220,7 @@ make test-known-platforms-generate
In order to debug in goland, the plugin code must be disabled.
See https://github.com/golang/go/issues/23733.
This is expected to be resolved with golang 1.12.X
To disable the plugin code (which will cause foo.go to be linked statically in kfctl)
To disable the plugin code (which will cause dockerfordesktop.go to be linked statically in kfctl)
and allow debugging in goland run:

```
Expand Down
1 change: 0 additions & 1 deletion bootstrap/cmd/kfctl/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ directory is name is a path.`,
repo := initCfg.GetString(string(kftypes.REPO))
debug := initCfg.GetBool(string(kftypes.DEBUG))
project := initCfg.GetString(string(kftypes.PROJECT))

options := map[string]interface{}{
string(kftypes.PLATFORM): platform,
string(kftypes.NAMESPACE): namespace,
Expand Down
6 changes: 3 additions & 3 deletions bootstrap/cmd/kfctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
kftypes "github.com/kubeflow/kubeflow/bootstrap/pkg/apis/apps"
kstypes "github.com/kubeflow/kubeflow/bootstrap/pkg/apis/apps/ksonnet/v1alpha1"
// STATIC
"github.com/kubeflow/kubeflow/bootstrap/pkg/client/foo"
"github.com/kubeflow/kubeflow/bootstrap/pkg/client/dockerfordesktop"
// -STATIC //
"github.com/kubeflow/kubeflow/bootstrap/pkg/client/ksonnet"
"github.com/kubeflow/kubeflow/bootstrap/pkg/client/minikube"
Expand All @@ -45,8 +45,8 @@ func GetPlatform(options map[string]interface{}) (kftypes.KfApp, error) {
case "minikube":
return minikube.GetKfApp(options), nil
// STATIC
case "foo":
return foo.GetKfApp(options), nil
case "docker-for-desktop":
return dockerfordesktop.GetKfApp(options), nil
// -STATIC //
default:
log.Infof("** loading %v.so for platform %v **", platform, platform)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package main

import (
kftypes "github.com/kubeflow/kubeflow/bootstrap/pkg/apis/apps"
"github.com/kubeflow/kubeflow/bootstrap/pkg/client/foo"
"github.com/kubeflow/kubeflow/bootstrap/pkg/client/dockerfordesktop"
)

func GetKfApp(options map[string]interface{}) kftypes.KfApp {
return foo.GetKfApp(options)
return dockerfordesktop.GetKfApp(options)
}
58 changes: 0 additions & 58 deletions bootstrap/cmd/plugins/foo.go

This file was deleted.

1 change: 1 addition & 0 deletions bootstrap/pkg/apis/apps/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type KfApp interface {
func LoadPlatform(options map[string]interface{}) (KfApp, error) {
/* PLUGINS
platform := options[string(PLATFORM)].(string)
platform = strings.Replace(platform, "-", "", -1)
plugindir := os.Getenv("PLUGINS_ENVIRONMENT")
pluginpath := filepath.Join(plugindir, platform+".so")
p, err := plugin.Open(pluginpath)
Expand Down
Loading

0 comments on commit 36e3289

Please sign in to comment.