refactor(config): Nested edge connect config and added default flavor
This commit is contained in:
parent
5ee04cd131
commit
f824429e8f
3 changed files with 48 additions and 35 deletions
|
|
@ -45,10 +45,7 @@ func NewCredentials(credFile string) (*Credentials, error) {
|
||||||
type Config struct {
|
type Config struct {
|
||||||
LogFile string `toml:"log_file"`
|
LogFile string `toml:"log_file"`
|
||||||
CredentialsFile string `toml:"credentials_file"`
|
CredentialsFile string `toml:"credentials_file"`
|
||||||
Organization string `toml:"organization"`
|
EdgeConnect EdgeConnect `toml:"edge_connect"`
|
||||||
CloudletKey CloudletKey `toml:"cloudlet"`
|
|
||||||
Region string `toml:"region"`
|
|
||||||
EdgeConnectURL string `toml:"edge_connect_url"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Credentials struct {
|
type Credentials struct {
|
||||||
|
|
@ -61,12 +58,20 @@ type CloudletKey struct {
|
||||||
Name string `toml:"name"`
|
Name string `toml:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type EdgeConnect struct {
|
||||||
|
URL string `toml:"url"`
|
||||||
|
Organization string `toml:"organization"`
|
||||||
|
Region string `toml:"region"`
|
||||||
|
DefaultFlavor string `toml:"default_flavor"`
|
||||||
|
CloudletKey CloudletKey `toml:"cloudlet"`
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Config) Validate() error {
|
func (c *Config) Validate() error {
|
||||||
if c.LogFile == "" {
|
if c.LogFile == "" {
|
||||||
return fmt.Errorf("log_file is not defined in provider config")
|
return fmt.Errorf("log_file is not defined in provider config")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.EdgeConnectURL == "" {
|
if c.EdgeConnect.URL == "" {
|
||||||
return fmt.Errorf("edge_connect_url is not defined in provider config")
|
return fmt.Errorf("edge_connect_url is not defined in provider config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
edge_connect_url = "https://hub.apps.orca.platform.mg3.mdb.osc.live"
|
|
||||||
organization = "edp-developer-framework"
|
|
||||||
region = "EU"
|
|
||||||
log_file = "./lala.log"
|
log_file = "./lala.log"
|
||||||
credentials_file = "/home/chris/ipcei/projects/garm-provider-edge-connect/config/creds.toml"
|
credentials_file = "/home/chris/ipcei/projects/garm-provider-edge-connect/config/creds.toml"
|
||||||
|
|
||||||
[cloudlet]
|
[edge_connect]
|
||||||
|
url = "https://hub.apps.orca.platform.mg3.mdb.osc.live"
|
||||||
|
organization = "edp-developer-framework"
|
||||||
|
region = "EU"
|
||||||
|
default_flavor = "defualt"
|
||||||
|
|
||||||
|
[edge_connect.cloudlet]
|
||||||
name = "Munich"
|
name = "Munich"
|
||||||
organization = "TelekomOP"
|
organization = "TelekomOP"
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ func NewEdgeConnectProvider(configPath, controllerID string) (execution.External
|
||||||
}
|
}
|
||||||
|
|
||||||
client := edgeconnect.NewClientWithCredentials(
|
client := edgeconnect.NewClientWithCredentials(
|
||||||
conf.EdgeConnectURL,
|
conf.EdgeConnect.URL,
|
||||||
creds.Username,
|
creds.Username,
|
||||||
creds.Password,
|
creds.Password,
|
||||||
edgeconnect.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
|
edgeconnect.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
|
||||||
|
|
@ -91,6 +91,11 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
||||||
|
|
||||||
podSpec := spec.GetPodSpec(gitHubScopeDetails, bootstrapParams)
|
podSpec := spec.GetPodSpec(gitHubScopeDetails, bootstrapParams)
|
||||||
|
|
||||||
|
if podSpec.Containers[0].Image != bootstrapParams.Image {
|
||||||
|
log.Printf("Overriding PodSpec image %s with bootstrap image %s\n", podSpec.Containers[0].Image, bootstrapParams.Image)
|
||||||
|
podSpec.Containers[0].Image = bootstrapParams.Image
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("Executing CreateInstance with PodSpec %v\n", &podSpec)
|
log.Printf("Executing CreateInstance with PodSpec %v\n", &podSpec)
|
||||||
|
|
||||||
deployment := appsv1.Deployment{
|
deployment := appsv1.Deployment{
|
||||||
|
|
@ -122,29 +127,29 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = a.client.ShowApp(ctx, edgeconnect.AppKey{
|
_, err = a.client.ShowApp(ctx, edgeconnect.AppKey{
|
||||||
Organization: a.cfg.Organization,
|
Organization: a.cfg.EdgeConnect.Organization,
|
||||||
Name: instancename,
|
Name: instancename,
|
||||||
Version: "1",
|
Version: "1",
|
||||||
}, a.cfg.Region)
|
}, a.cfg.EdgeConnect.Region)
|
||||||
if err != nil && !errors.Is(err, edgeconnect.ErrResourceNotFound) {
|
if err != nil && !errors.Is(err, edgeconnect.ErrResourceNotFound) {
|
||||||
return params.ProviderInstance{}, err
|
return params.ProviderInstance{}, err
|
||||||
}
|
}
|
||||||
if errors.Is(err, edgeconnect.ErrResourceNotFound) {
|
if errors.Is(err, edgeconnect.ErrResourceNotFound) {
|
||||||
err = a.client.CreateApp(ctx, &edgeconnect.NewAppInput{
|
err = a.client.CreateApp(ctx, &edgeconnect.NewAppInput{
|
||||||
Region: a.cfg.Region,
|
Region: a.cfg.EdgeConnect.Region,
|
||||||
App: edgeconnect.App{
|
App: edgeconnect.App{
|
||||||
Key: edgeconnect.AppKey{
|
Key: edgeconnect.AppKey{
|
||||||
Organization: a.cfg.Organization,
|
Organization: a.cfg.EdgeConnect.Organization,
|
||||||
Name: instancename,
|
Name: instancename,
|
||||||
Version: "1",
|
Version: "1",
|
||||||
},
|
},
|
||||||
Deployment: "kubernetes",
|
Deployment: "kubernetes",
|
||||||
ImageType: "Docker",
|
ImageType: "Docker",
|
||||||
ImagePath: "edp.buildth.ing/devfw-cicd/garm-act-runner:1",
|
ImagePath: bootstrapParams.Image,
|
||||||
AllowServerless: true,
|
AllowServerless: true,
|
||||||
ServerlessConfig: struct{}{},
|
ServerlessConfig: struct{}{},
|
||||||
DefaultFlavor: edgeconnect.Flavor{
|
DefaultFlavor: edgeconnect.Flavor{
|
||||||
Name: "defualt",
|
Name: a.cfg.EdgeConnect.DefaultFlavor,
|
||||||
},
|
},
|
||||||
DeploymentGenerator: "kubernetes-basic",
|
DeploymentGenerator: "kubernetes-basic",
|
||||||
DeploymentManifest: string(manifest),
|
DeploymentManifest: string(manifest),
|
||||||
|
|
@ -170,24 +175,24 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = a.client.ShowAppInstance(ctx, edgeconnect.AppInstanceKey{
|
_, err = a.client.ShowAppInstance(ctx, edgeconnect.AppInstanceKey{
|
||||||
Organization: a.cfg.Organization,
|
Organization: a.cfg.EdgeConnect.Organization,
|
||||||
Name: instancename,
|
Name: instancename,
|
||||||
CloudletKey: edgeconnect.CloudletKey(a.cfg.CloudletKey),
|
CloudletKey: edgeconnect.CloudletKey(a.cfg.EdgeConnect.CloudletKey),
|
||||||
}, a.cfg.Region)
|
}, a.cfg.EdgeConnect.Region)
|
||||||
if err != nil && !errors.Is(err, edgeconnect.ErrResourceNotFound) {
|
if err != nil && !errors.Is(err, edgeconnect.ErrResourceNotFound) {
|
||||||
return params.ProviderInstance{}, err
|
return params.ProviderInstance{}, err
|
||||||
}
|
}
|
||||||
if errors.Is(err, edgeconnect.ErrResourceNotFound) {
|
if errors.Is(err, edgeconnect.ErrResourceNotFound) {
|
||||||
err = a.client.CreateAppInstance(ctx, &edgeconnect.NewAppInstanceInput{
|
err = a.client.CreateAppInstance(ctx, &edgeconnect.NewAppInstanceInput{
|
||||||
Region: a.cfg.Region,
|
Region: a.cfg.EdgeConnect.Region,
|
||||||
AppInst: edgeconnect.AppInstance{
|
AppInst: edgeconnect.AppInstance{
|
||||||
Key: edgeconnect.AppInstanceKey{
|
Key: edgeconnect.AppInstanceKey{
|
||||||
Organization: a.cfg.Organization,
|
Organization: a.cfg.EdgeConnect.Organization,
|
||||||
Name: instancename,
|
Name: instancename,
|
||||||
CloudletKey: edgeconnect.CloudletKey(a.cfg.CloudletKey),
|
CloudletKey: edgeconnect.CloudletKey(a.cfg.EdgeConnect.CloudletKey),
|
||||||
},
|
},
|
||||||
AppKey: edgeconnect.AppKey{
|
AppKey: edgeconnect.AppKey{
|
||||||
Organization: a.cfg.Organization,
|
Organization: a.cfg.EdgeConnect.Organization,
|
||||||
Name: instancename,
|
Name: instancename,
|
||||||
Version: "1",
|
Version: "1",
|
||||||
},
|
},
|
||||||
|
|
@ -219,8 +224,8 @@ func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance strin
|
||||||
log.Printf("Executing DeleteInstance %s\n", instance)
|
log.Printf("Executing DeleteInstance %s\n", instance)
|
||||||
|
|
||||||
appsinstances, err := a.client.ShowAppInstances(ctx, edgeconnect.AppInstanceKey{
|
appsinstances, err := a.client.ShowAppInstances(ctx, edgeconnect.AppInstanceKey{
|
||||||
Organization: a.cfg.Organization,
|
Organization: a.cfg.EdgeConnect.Organization,
|
||||||
}, a.cfg.Region)
|
}, a.cfg.EdgeConnect.Region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error in method DeleteInstance() ShowAppInstances")
|
log.Printf("Error in method DeleteInstance() ShowAppInstances")
|
||||||
return err
|
return err
|
||||||
|
|
@ -235,15 +240,15 @@ func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance strin
|
||||||
log.Printf("filtered %d appinstances", len(myappintances))
|
log.Printf("filtered %d appinstances", len(myappintances))
|
||||||
|
|
||||||
for _, v := range myappintances {
|
for _, v := range myappintances {
|
||||||
err = a.client.DeleteAppInstance(ctx, v.Key, a.cfg.Region)
|
err = a.client.DeleteAppInstance(ctx, v.Key, a.cfg.EdgeConnect.Region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apps, err := a.client.ShowApps(ctx, edgeconnect.AppKey{
|
apps, err := a.client.ShowApps(ctx, edgeconnect.AppKey{
|
||||||
Organization: a.cfg.Organization,
|
Organization: a.cfg.EdgeConnect.Organization,
|
||||||
}, a.cfg.Region)
|
}, a.cfg.EdgeConnect.Region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error in method DeleteInstance() ShowApps")
|
log.Printf("Error in method DeleteInstance() ShowApps")
|
||||||
return err
|
return err
|
||||||
|
|
@ -254,7 +259,7 @@ func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance strin
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, v := range myapps {
|
for _, v := range myapps {
|
||||||
err = a.client.DeleteApp(ctx, v.Key, a.cfg.Region)
|
err = a.client.DeleteApp(ctx, v.Key, a.cfg.EdgeConnect.Region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error in method DeleteInstance() DeleteApp")
|
log.Printf("Error in method DeleteInstance() DeleteApp")
|
||||||
return err
|
return err
|
||||||
|
|
@ -278,8 +283,8 @@ func (a *edgeConnectProvider) GetInstance(ctx context.Context, instance string)
|
||||||
}
|
}
|
||||||
|
|
||||||
appinstances, err := a.client.ShowAppInstances(ctx, edgeconnect.AppInstanceKey{
|
appinstances, err := a.client.ShowAppInstances(ctx, edgeconnect.AppInstanceKey{
|
||||||
Organization: a.cfg.Organization,
|
Organization: a.cfg.EdgeConnect.Organization,
|
||||||
}, a.cfg.Region)
|
}, a.cfg.EdgeConnect.Region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return params.ProviderInstance{}, err
|
return params.ProviderInstance{}, err
|
||||||
}
|
}
|
||||||
|
|
@ -306,8 +311,8 @@ func (a *edgeConnectProvider) ListInstances(ctx context.Context, poolID string)
|
||||||
log.Printf("Executing ListInstances for PoolID %s\n", poolID)
|
log.Printf("Executing ListInstances for PoolID %s\n", poolID)
|
||||||
|
|
||||||
apps, err := a.client.ShowAppInstances(ctx, edgeconnect.AppInstanceKey{
|
apps, err := a.client.ShowAppInstances(ctx, edgeconnect.AppInstanceKey{
|
||||||
Organization: a.cfg.Organization,
|
Organization: a.cfg.EdgeConnect.Organization,
|
||||||
}, a.cfg.Region)
|
}, a.cfg.EdgeConnect.Region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -354,8 +359,8 @@ func (a *edgeConnectProvider) RemoveAllInstances(ctx context.Context) error {
|
||||||
log.Printf("Executing RemoveAllInstances\n")
|
log.Printf("Executing RemoveAllInstances\n")
|
||||||
|
|
||||||
apps, err := a.client.ShowAppInstances(ctx, edgeconnect.AppInstanceKey{
|
apps, err := a.client.ShowAppInstances(ctx, edgeconnect.AppInstanceKey{
|
||||||
Organization: a.cfg.Organization,
|
Organization: a.cfg.EdgeConnect.Organization,
|
||||||
}, a.cfg.Region)
|
}, a.cfg.EdgeConnect.Region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue