Skip to content

Commit

Permalink
Add the ability to create CloudEndpoint resources using kfctl.
Browse files Browse the repository at this point in the history
* This is GCP specific code that allows CloudEndpoints to be created using
  the CloudEndpoint controller. A Cloud endpoint is a KRM style resource
  so we can kust have `kfctl apply -f {path}` invoke the appropriate
  logic.

* For GCP this addresses GoogleCloudPlatform/kubeflow-distribution#36; specifically when
  deploying private GKE the CloudEndpoints controller won't be able
  to contact the servicemanagement API. This provides a work around
  by running it locally.

* This pattern seems extensible; i.e. other platforms could link in
  code to handle CR's specific to their platforms. This could basically
  be an alternative to plugins.

* I added a context flag to control the kubecontext that apply applies to.
  Unfortunately, it doesn't look like there is an easy way to use
  that in the context of applying KFDef. It looks like the current logic
  assumes the cluster will be added to the KFDef metadata and then
  look up that cluster in .kubeconfig.

  * Modifying that logic to support the context flag seemed riskier
    then simply adding a comment to the flag.

* Added some warnings that KFUpgrade is deprecated since per kubeflow#304
  we want to follow the off shelf workflow.
  • Loading branch information
Jeremy Lewi committed Jun 5, 2020
1 parent 4c1060b commit 389f40c
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 10 deletions.
8 changes: 8 additions & 0 deletions cmd/kfctl/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd
import (
"fmt"

ep "github.com/jlewi/cloud-endpoints-controller/pkg"
kftypes "github.com/kubeflow/kfctl/v3/pkg/apis/apps"
"github.com/kubeflow/kfctl/v3/pkg/kfapp/coordinator"
"github.com/kubeflow/kfctl/v3/pkg/kfupgrade"
Expand All @@ -30,6 +31,8 @@ var applyCfg = viper.New()
var kfApp kftypes.KfApp
var err error

var kubeContext = ""

// KFDef example configs to be printed out from apply --help
const (
awsConfig = "https://raw.githubusercontent.com/kubeflow/manifests/v1.0-branch/kfdef/kfctl_aws.v1.0.0.yaml"
Expand Down Expand Up @@ -72,6 +75,7 @@ var applyCmd = &cobra.Command{
log.Info("Applied the configuration Successfully!")
return nil
case string(kftypes.KFUPGRADE):
log.Warnf("Support for kind %s is deprecated and will be removed in subsequent versions", kftypes.KFUPGRADE)
kfUpgrade, err := kfupgrade.NewKfUpgrade(configFilePath)
if err != nil {
return fmt.Errorf("couldn't load KfUpgrade: %v", err)
Expand All @@ -82,6 +86,8 @@ var applyCmd = &cobra.Command{
return fmt.Errorf("couldn't apply KfUpgrade: %v", err)
}
return nil
case ep.Kind:
return ep.Process(configFilePath, kubeContext)
default:
return fmt.Errorf("Unsupported object kind: %v", kind)
}
Expand All @@ -108,6 +114,8 @@ func init() {
// verbose output
applyCmd.Flags().BoolP(string(kftypes.VERBOSE), "V", false,
string(kftypes.VERBOSE)+" output default is false")

applyCmd.Flags().StringVar(&kubeContext, "context", "", "Optional kubernetes context to use when applying resources. Currently not used by KFDef resources.")
bindErr := applyCfg.BindPFlag(string(kftypes.VERBOSE), applyCmd.Flags().Lookup(string(kftypes.VERBOSE)))
if bindErr != nil {
log.Errorf("Couldn't set flag --%v: %v", string(kftypes.VERBOSE), bindErr)
Expand Down
1 change: 1 addition & 0 deletions cmd/kfctl/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var buildCmd = &cobra.Command{
return fmt.Errorf("failed to build kfApp from URI %s: %v", configFilePath, err)
}
case string(kftypes.KFUPGRADE):
log.Warnf("Support for kind %s is deprecated and will be removed in subsequent versions", kftypes.KFUPGRADE)
kfApp, err := kfupgrade.NewKfUpgrade(configFilePath)
if err != nil {
return fmt.Errorf("couldn't load KfUpgrade: %v", err)
Expand Down
20 changes: 10 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/kubeflow/kfctl/v3

require (
cloud.google.com/go v0.47.0
cloud.google.com/go v0.57.0
github.com/Azure/go-autorest v13.3.3+incompatible // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/Sirupsen/logrus v0.0.0-00010101000000-000000000000 // indirect
Expand All @@ -18,30 +18,31 @@ require (
github.com/go-yaml/yaml v2.1.0+incompatible
github.com/gogo/protobuf v1.3.1
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e
github.com/google/go-cmp v0.3.1
github.com/google/go-cmp v0.4.0
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/go-getter v1.0.2
github.com/hashicorp/go-version v1.2.0
github.com/imdario/mergo v0.3.8
github.com/jlewi/cloud-endpoints-controller v0.0.0-20200604211613-aff0aaad5602
github.com/kubernetes-sigs/application v0.8.0
github.com/onrik/logrus v0.2.1
github.com/onrik/logrus v0.5.1
github.com/operator-framework/operator-sdk v0.13.0
github.com/otiai10/copy v1.0.2
github.com/pkg/errors v0.8.1
github.com/prometheus/common v0.7.0
github.com/sirupsen/logrus v1.4.2
github.com/sirupsen/logrus v1.6.0
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.4.0
github.com/tektoncd/pipeline v0.10.1
github.com/tidwall/gjson v1.4.0
github.com/tidwall/gjson v1.6.0
github.com/tidwall/pretty v1.0.1 // indirect
go.uber.org/zap v1.12.0 // indirect
golang.org/x/crypto v0.0.0
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
google.golang.org/api v0.10.0
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
google.golang.org/api v0.25.0
google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
gopkg.in/yaml.v2 v2.2.8
Expand All @@ -52,7 +53,6 @@ require (
k8s.io/client-go v12.0.0+incompatible
k8s.io/code-generator v0.18.1 // indirect
k8s.io/kubernetes v1.16.2
k8s.io/utils v0.0.0-20191030222137-2b95a09bc58d // indirect
sigs.k8s.io/controller-runtime v0.4.0
sigs.k8s.io/kustomize/v3 v3.2.0
sigs.k8s.io/yaml v1.1.0
Expand Down
Loading

0 comments on commit 389f40c

Please sign in to comment.