Skip to content

Commit

Permalink
kfctl uses kfconfig (#4250)
Browse files Browse the repository at this point in the history
* gcp use kfconfig

* fix write config

* fix

* fix test

* put back spec wip

* fix test

* fix test

* fix

* fix test

* remove backfill app

* kustomize changes

* coordinator use kfconfig wip

* coordinator can compile now

* fix minikube

* fix aws

* fix test

* fix existing

* fix appdir

* fix test

* address comments

* fix delete

* fix test

* fix?

* populate err msg

* remove app.yaml check

* logs

* hardcode UseIstio to true

* set missing specs

* remove dir check

* unit test

* fix unit test

* fix converter for secret

* rebase done. port changes from original pr

* fix

* fix delete
  • Loading branch information
lluunn authored and k8s-ci-robot committed Oct 16, 2019
1 parent 3b259dd commit 3c813ef
Show file tree
Hide file tree
Showing 15 changed files with 297 additions and 283 deletions.
2 changes: 1 addition & 1 deletion bootstrap/cmd/bootstrap/app/kfctlServer.go
Expand Up @@ -103,7 +103,7 @@ func (s *kfctlServer) handleDeployment(r kfdefsv3.KfDef) (*kfdefsv3.KfDef, error
cfgFile := path.Join(r.Spec.AppDir, kftypes.KfConfigFile)
if _, err := os.Stat(cfgFile); os.IsNotExist(err) {
log.Infof("Creating cfgFile; %v", cfgFile)
newCfgFile, err := coordinator.CreateKfAppCfgFile(&r)
newCfgFile, err := coordinator.CreateKfAppCfgFileWithKfDef(&r)

if newCfgFile != cfgFile {
log.Errorf("Actual config file %v; doesn't match expected %v", newCfgFile, cfgFile)
Expand Down
12 changes: 6 additions & 6 deletions bootstrap/cmd/kfctl/cmd/delete.go
Expand Up @@ -15,7 +15,6 @@
package cmd

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -48,11 +47,12 @@ var deleteCmd = &cobra.Command{
if err != nil || kfApp == nil {
return fmt.Errorf("error loading kfapp: %v", err)
}
kfGetter, ok := kfApp.(coordinator.KfDefGetter)
if !ok {
return errors.New("internal error: coordinator does not implement KfDefGetter")
}
kfGetter.GetKfDef().Spec.DeleteStorage = deleteCfg.GetBool(string(kftypes.DELETE_STORAGE))
// TODO(lunkai): do we need set delete storage here?
// kfGetter, ok := kfApp.(coordinator.KfDefGetter)
// if !ok {
// return errors.New("internal error: coordinator does not implement KfDefGetter")
// }
// kfGetter.GetKfDef().Spec.DeleteStorage = deleteCfg.GetBool(string(kftypes.DELETE_STORAGE))
deleteErr := kfApp.Delete(kftypes.ALL)
if deleteErr != nil {
return fmt.Errorf("couldn't delete KfApp: %v", deleteErr)
Expand Down
1 change: 1 addition & 0 deletions bootstrap/go.mod
Expand Up @@ -15,6 +15,7 @@ require (
github.com/gogo/protobuf v1.2.1
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/protobuf v1.3.1
github.com/google/go-cmp v0.3.0
github.com/hashicorp/go-getter v1.0.2
github.com/imdario/mergo v0.3.7
github.com/kubeflow/kfctl/v3 v3.0.0-20190917231916-6ebaf60b014a
Expand Down
9 changes: 9 additions & 0 deletions bootstrap/pkg/apis/apps/configconverters/converters.go
Expand Up @@ -136,6 +136,15 @@ func LoadConfigFromURI(configFile string) (*kfconfig.KfConfig, error) {
return converter.ToKfConfig(cwd, configFileBytes)
}

func isCwdEmpty() string {
cwd, _ := os.Getwd()
files, _ := ioutil.ReadDir(cwd)
if len(files) > 1 {
return ""
}
return cwd
}

func WriteConfigToFile(config kfconfig.KfConfig, filename string) error {
converters := map[string]Converter{
"v1alpha1": V1alpha1{},
Expand Down
5 changes: 5 additions & 0 deletions bootstrap/pkg/apis/kferrors.go
Expand Up @@ -42,6 +42,11 @@ func (e *KfError) Error() string {
e.Code, e.Message)
}

func IsNotFound(e error) bool {
kfError, ok := e.(*KfError)
return ok && kfError.Code == int(NOT_FOUND)
}

// NewKfErrorWithMessage will propogate the error with the given message.
//
// TODO(jlewi): Not sure this is the best way to propogate the error messages and turn them
Expand Down
37 changes: 20 additions & 17 deletions bootstrap/pkg/kfapp/aws/aws.go
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/ghodss/yaml"
kfapis "github.com/kubeflow/kubeflow/bootstrap/v3/pkg/apis"
kftypes "github.com/kubeflow/kubeflow/bootstrap/v3/pkg/apis/apps"
"github.com/kubeflow/kubeflow/bootstrap/v3/pkg/apis/apps/kfconfig"
kfdefs "github.com/kubeflow/kubeflow/bootstrap/v3/pkg/apis/apps/kfdef/v1alpha1"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -69,7 +70,7 @@ const (
// Aws implements KfApp Interface
// It includes the KsApp along with additional Aws types
type Aws struct {
kfDef *kfdefs.KfDef
kfDef *kfconfig.KfConfig
iamClient *iam.IAM
eksClient *eks.EKS
sess *session.Session
Expand All @@ -79,7 +80,7 @@ type Aws struct {
}

// GetKfApp returns the aws kfapp. It's called by coordinator.GetKfApp
func GetPlatform(kfdef *kfdefs.KfDef) (kftypes.Platform, error) {
func GetPlatform(kfdef *kfconfig.KfConfig) (kftypes.Platform, error) {
session := session.Must(session.NewSession())

_aws := &Aws{
Expand Down Expand Up @@ -303,7 +304,7 @@ func (aws *Aws) updateClusterConfig(clusterConfigFile string) error {
// ${KUBEFLOW_SRC}/${KFAPP}/aws_config -> destDir (dest)
func (aws *Aws) generateInfraConfigs() error {
// 1. Copy and Paste all files from `sourceDir` to `destDir`
repo, ok := aws.kfDef.Status.ReposCache[kftypes.ManifestsRepoName]
repo, ok := aws.kfDef.GetRepoCache(kftypes.ManifestsRepoName)
if !ok {
err := fmt.Errorf("Repo %v not found in KfDef.Status.ReposCache", kftypes.ManifestsRepoName)
log.Errorf("%v", err)
Expand Down Expand Up @@ -476,13 +477,14 @@ func (aws *Aws) Init(resources kftypes.ResourceEnum) error {
}
}

createConfigErr := aws.kfDef.WriteToConfigFile()
if createConfigErr != nil {
return &kfapis.KfError{
Code: int(kfapis.INVALID_ARGUMENT),
Message: fmt.Sprintf("Cannot create config file app.yaml in %v", aws.kfDef.Spec.AppDir),
}
}
// Should not need to write config here?
// createConfigErr := aws.kfDef.WriteToConfigFile()
// if createConfigErr != nil {
// return &kfapis.KfError{
// Code: int(kfapis.INVALID_ARGUMENT),
// Message: fmt.Sprintf("Cannot create config file app.yaml in %v", aws.kfDef.Spec.AppDir),
// }
// }

return nil
}
Expand Down Expand Up @@ -623,13 +625,14 @@ func (aws *Aws) Generate(resources kftypes.ResourceEnum) error {
}
}

if createConfigErr := aws.kfDef.WriteToConfigFile(); createConfigErr != nil {
return &kfapis.KfError{
Code: createConfigErr.(*kfapis.KfError).Code,
Message: fmt.Sprintf("Cannot create config file app.yaml in %v: %v", aws.kfDef.Spec.AppDir,
createConfigErr.(*kfapis.KfError).Message),
}
}
// Should not need to write config here.
// if createConfigErr := aws.kfDef.WriteToConfigFile(); createConfigErr != nil {
// return &kfapis.KfError{
// Code: createConfigErr.(*kfapis.KfError).Code,
// Message: fmt.Sprintf("Cannot create config file app.yaml in %v: %v", aws.kfDef.Spec.AppDir,
// createConfigErr.(*kfapis.KfError).Message),
// }
// }
return nil
}

Expand Down

0 comments on commit 3c813ef

Please sign in to comment.