Skip to content

Commit

Permalink
fixes 'kfctl needs to support passing swagger spec to ks init from fi…
Browse files Browse the repository at this point in the history
…le' (kubeflow#2719)

* fixes 'kfctl needs to support passing swagger spec to ks init from file'

    pick f2a218c fixes 'kfctl needs to support passing swagger spec to ks init from file'

* fix in ksonnet for passing config if not gcp

* update kfctl short, long usage

* update with suggestions from Gabriel's review
  • Loading branch information
kkasravi authored and k8s-ci-robot committed Mar 21, 2019
1 parent 4080fdf commit 036165a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 30 deletions.
5 changes: 3 additions & 2 deletions bootstrap/cmd/kfctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ func processResourceArg(args []string) (kftypes.ResourceEnum, error) {
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "kfctl",
Short: "A kfdef tool to create kubeflow applications",
Long: `kubeflow kfdef tool`,
Short: "A client CLI to create kubeflow applications",
Long: `A client CLI to create kubeflow applications for specific platforms or 'on-prem'
to an existing k8 cluster.`,
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
3 changes: 1 addition & 2 deletions bootstrap/pkg/apis/apps/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
DefaultAppLabel = "app.kubernetes.io/name"
KUBEFLOW_USERNAME = "KUBEFLOW_USERNAME"
KUBEFLOW_PASSWORD = "KUBEFLOW_PASSWORD"
DefaultSwaggerFile = "releasing/releaser/lib/v1.9.7/swagger.json"
)

type ResourceEnum string
Expand All @@ -75,13 +76,11 @@ const (
REPO CliOption = "repo"
PROJECT CliOption = "project"
APPNAME CliOption = "appname"
APPDIR CliOption = "appDir"
DATA CliOption = "Data"
ZONE CliOption = "zone"
USE_BASIC_AUTH CliOption = "use_basic_auth"
OAUTH_ID CliOption = "oauth_id"
OAUTH_SECRET CliOption = "oauth_secret"
CONFIG CliOption = "config"
)

//
Expand Down
3 changes: 1 addition & 2 deletions bootstrap/pkg/apis/apps/kfdef/v1alpha1/application_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ type KfDefSpec struct {
IpName string `json:"ipName,omitempty"`
Hostname string `json:"hostname,omitempty"`
Zone string `json:"zone,omitempty"`
BasicAuthUsername string `json:"basicAuthUsername,omitempty"`
BasicAuthPassword string `json:"basicAuthPassword,omitempty"`
UseBasicAuth bool `json:"useBasicAuth"`
SkipInitProject bool `json:"skipInitProject,omitempty"`
ServerVersion string `json:"serverVersion,omitempty"`
}

var DefaultRegistry = &RegistryConfig{
Expand Down
28 changes: 13 additions & 15 deletions bootstrap/pkg/apis/apps/kfdef/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions bootstrap/pkg/kfapp/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import (
"github.com/mitchellh/go-homedir"
log "github.com/sirupsen/logrus"
"io/ioutil"
valid "k8s.io/apimachinery/pkg/api/validation"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
"path"
"path/filepath"
"regexp"
"strings"
)

Expand Down Expand Up @@ -111,7 +111,7 @@ func downloadToCache(platform string, appDir string, version string, useBasicAut
}
//TODO see #2629
configPath := filepath.Join(newPath, kftypes.DefaultConfigDir)
if platform == "gcp" {
if platform == kftypes.GCP {
if useBasicAuth {
configPath = filepath.Join(configPath, kftypes.GcpBasicAuth)
} else {
Expand Down Expand Up @@ -210,11 +210,9 @@ func NewKfApp(options map[string]interface{}) (kftypes.KfApp, error) {
appDir = path.Join(appDir, appName)
}
}
re := regexp.MustCompile(`[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`)
validName := re.FindString(appName)
if strings.Compare(validName, appName) != 0 {
return nil, fmt.Errorf(`invalid name %v must consist of lower case alphanumeric characters, '-' or '.',
and must start and end with an alphanumeric character`, appName)
errs := valid.NameIsDNSLabel(appName, false)
if errs != nil && len(errs) > 0 {
return nil, fmt.Errorf(`invalid name due to %v`, strings.Join(errs, ", "))
}
platform := options[string(kftypes.PLATFORM)].(string)
version := options[string(kftypes.VERSION)].(string)
Expand Down
2 changes: 2 additions & 0 deletions bootstrap/pkg/kfapp/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,8 @@ func (gcp *Gcp) gcpInitProject() error {
func (gcp *Gcp) Init(resources kftypes.ResourceEnum) error {
cacheDir := path.Join(gcp.Spec.AppDir, kftypes.DefaultCacheDir)
newPath := filepath.Join(cacheDir, gcp.Spec.Version)
swaggerFile := filepath.Join(newPath, kftypes.DefaultSwaggerFile)
gcp.Spec.ServerVersion = "file:" + swaggerFile
gcp.Spec.Repo = path.Join(newPath, "kubeflow")
createConfigErr := gcp.writeConfigFile()
if createConfigErr != nil {
Expand Down
6 changes: 4 additions & 2 deletions bootstrap/pkg/kfapp/ksonnet/ksonnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,10 @@ func (ksApp *ksApp) initKs() error {
os.RemoveAll(newRoot)
}
ksApp.KsEnvName = KsEnvName
// We hard code the K8s spec because we won't have a cluster to talk to when calling init.
k8sSpec := "version:v1.11.7"
k8sSpec := ksApp.Spec.ServerVersion
if k8sSpec == "" {
k8sSpec = kftypes.GetServerVersion(kftypes.GetClientset(kftypes.GetConfig()))
}
options := map[string]interface{}{
actions.OptionFs: afero.NewOsFs(),
actions.OptionName: ksApp.KsName,
Expand Down

0 comments on commit 036165a

Please sign in to comment.