Skip to content

Commit

Permalink
bugfix: loadconfig (onsi#17)
Browse files Browse the repository at this point in the history
feature: add tenant to request
  • Loading branch information
LiuqingLiao committed Dec 31, 2020
1 parent 996ce59 commit 81ecd3d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
10 changes: 6 additions & 4 deletions framework/client/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

// User is used to login.
type User struct {
Tenant string
Username string
Password string
}
Expand All @@ -22,7 +23,7 @@ func (u *User) App() (appclient.Interface, error) {
return appclient.NewClient(&rest.Config{
Scheme: config.Context.Scheme,
Host: config.Context.BaseUrl + "/hodor",
Executor: baseclient.NewRequestExecutorWithAuth(u.Username, u.Password),
Executor: baseclient.NewRequestExecutorWithAuth(u.Tenant, u.Username, u.Password),
})
}

Expand All @@ -31,7 +32,7 @@ func (u *User) Pipeline() (pipelineclient.Interface, error) {
return pipelineclient.NewClient(&rest.Config{
Scheme: config.Context.Scheme,
Host: config.Context.BaseUrl + "/hodor/apis/pipeline.caicloud.io",
Executor: baseclient.NewRequestExecutorWithAuth(u.Username, u.Password),
Executor: baseclient.NewRequestExecutorWithAuth(u.Tenant, u.Username, u.Password),
})
}

Expand All @@ -40,7 +41,7 @@ func (u *User) Cargo() (cargoclient.Interface, error) {
return cargoclient.NewClient(&rest.Config{
Scheme: config.Context.Scheme,
Host: config.Context.BaseUrl,
Executor: baseclient.NewRequestExecutorWithAuth(u.Username, u.Password),
Executor: baseclient.NewRequestExecutorWithAuth(u.Tenant, u.Username, u.Password),
})
}

Expand All @@ -50,8 +51,9 @@ func (u *User) Auth() (*http.Client, error) {
}

// NewAPIClient return a rest client with specified user
func NewAPIClient(username, password string) User {
func NewAPIClient(tenant, username, password string) User {
return User{
Tenant: tenant,
Username: username,
Password: password,
}
Expand Down
30 changes: 16 additions & 14 deletions framework/client/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

var BaseClient *BaseClientType
var ControlClient *BaseClientType
var UserClients []BaseClientType
var UserClients []*BaseClientType
var err error

type BaseClientType struct {
Expand All @@ -25,29 +25,31 @@ type BaseClientType struct {
// LoadClientFromConfig returns basic baseclient and crd clients for the kubernetes cluster.
func LoadClientsetFromConfig(kubeConfig, controlConfig, userConfigs string) error {
if kubeConfig == "" {
logger.Infof("kubeconfig file is not set")
return fmt.Errorf("kubeConfig file is not set")
}
if BaseClient, err = loadClient(kubeConfig); err != nil {
return err
return fmt.Errorf("load config file %q failed, %v", kubeConfig, err)
}

if controlConfig == "" {
logger.Infof("controlConfig file is not set")
}
if ControlClient, err = loadClient(controlConfig); err != nil {
return err
} else {
if ControlClient, err = loadClient(controlConfig); err != nil {
return fmt.Errorf("load config file %q failed, %v", controlConfig, err)
}
}

if userConfigs == "" {
logger.Infof("userConfigs file is not set")
}
// load multi userClusterClient, config files are separated by comma.
configs := strings.Split(userConfigs, ", ")
for _, c := range configs {
if client, err := loadClient(c); err != nil {
return err
} else {
UserClients = append(UserClients, *client)
} else {
// load multi userClusterClient, config files are separated by comma.
configs := strings.Split(userConfigs, ", ")
for _, c := range configs {
if client, err := loadClient(c); err != nil {
return fmt.Errorf("load userconfigs %q failed, %v", c, err)
} else {
UserClients = append(UserClients, client)
}
}
}
return nil
Expand Down
12 changes: 6 additions & 6 deletions framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ type Framework struct {
UniqueName string

// Set the Clientset for kubernetes
skipK8sClientsetCreation bool // Whether to skip creationg a k8s clientset
ClientSet *client.BaseClientType // return backend clientset
ControlClusterClientSet *client.BaseClientType // control cluster clientset
UserClusterClientSet []client.BaseClientType // user cluster clientset
skipK8sClientsetCreation bool // Whether to skip creationg a k8s clientset
ClientSet *client.BaseClientType // return backend clientset
ControlClusterClientSet *client.BaseClientType // control cluster clientset
UserClusterClientSet []*client.BaseClientType // user cluster clientset

// cluster info
APIClient client.User
Expand Down Expand Up @@ -66,8 +66,8 @@ func NewFramework(baseName string, skipK8sClientsetCreation, skipNamespaceCreati
func (f *Framework) BeforeEach() {
f.ClusterID = e2econfig.Context.ClusterID
f.PresetResource = e2econfig.Context.PresetCompassResource
f.APIClient = client.NewAPIClient(f.PresetResource.Auth.User, f.PresetResource.Auth.Password)
f.AdminAPIClient = client.NewAPIClient(f.PresetResource.Auth.AdminUser, f.PresetResource.Auth.Password)
f.APIClient = client.NewAPIClient(f.PresetResource.Auth.TenantID, f.PresetResource.Auth.User, f.PresetResource.Auth.Password)
f.AdminAPIClient = client.NewAPIClient(f.PresetResource.Auth.AdminTenantID, f.PresetResource.Auth.AdminUser, f.PresetResource.Auth.Password)
f.ClientSet = client.BaseClient
f.ControlClusterClientSet = client.ControlClient
f.UserClusterClientSet = client.UserClients
Expand Down

0 comments on commit 81ecd3d

Please sign in to comment.