refactor(config): Nested edge connect config and added default flavor
Some checks failed
build / build (push) Successful in 43s
Go Tests / go-tests (push) Failing after 1m2s

This commit is contained in:
Patrick Sy 2025-10-23 15:14:41 +02:00
parent 5ee04cd131
commit f824429e8f
Signed by: Patrick.Sy
GPG key ID: DDDC8EC51823195E
3 changed files with 48 additions and 35 deletions

View file

@ -45,10 +45,7 @@ func NewCredentials(credFile string) (*Credentials, error) {
type Config struct {
LogFile string `toml:"log_file"`
CredentialsFile string `toml:"credentials_file"`
Organization string `toml:"organization"`
CloudletKey CloudletKey `toml:"cloudlet"`
Region string `toml:"region"`
EdgeConnectURL string `toml:"edge_connect_url"`
EdgeConnect EdgeConnect `toml:"edge_connect"`
}
type Credentials struct {
@ -61,12 +58,20 @@ type CloudletKey struct {
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 {
if c.LogFile == "" {
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")
}

View file

@ -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"
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"
organization = "TelekomOP"

View file

@ -58,7 +58,7 @@ func NewEdgeConnectProvider(configPath, controllerID string) (execution.External
}
client := edgeconnect.NewClientWithCredentials(
conf.EdgeConnectURL,
conf.EdgeConnect.URL,
creds.Username,
creds.Password,
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)
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)
deployment := appsv1.Deployment{
@ -122,29 +127,29 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
}
_, err = a.client.ShowApp(ctx, edgeconnect.AppKey{
Organization: a.cfg.Organization,
Organization: a.cfg.EdgeConnect.Organization,
Name: instancename,
Version: "1",
}, a.cfg.Region)
}, a.cfg.EdgeConnect.Region)
if err != nil && !errors.Is(err, edgeconnect.ErrResourceNotFound) {
return params.ProviderInstance{}, err
}
if errors.Is(err, edgeconnect.ErrResourceNotFound) {
err = a.client.CreateApp(ctx, &edgeconnect.NewAppInput{
Region: a.cfg.Region,
Region: a.cfg.EdgeConnect.Region,
App: edgeconnect.App{
Key: edgeconnect.AppKey{
Organization: a.cfg.Organization,
Organization: a.cfg.EdgeConnect.Organization,
Name: instancename,
Version: "1",
},
Deployment: "kubernetes",
ImageType: "Docker",
ImagePath: "edp.buildth.ing/devfw-cicd/garm-act-runner:1",
ImagePath: bootstrapParams.Image,
AllowServerless: true,
ServerlessConfig: struct{}{},
DefaultFlavor: edgeconnect.Flavor{
Name: "defualt",
Name: a.cfg.EdgeConnect.DefaultFlavor,
},
DeploymentGenerator: "kubernetes-basic",
DeploymentManifest: string(manifest),
@ -170,24 +175,24 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
}
_, err = a.client.ShowAppInstance(ctx, edgeconnect.AppInstanceKey{
Organization: a.cfg.Organization,
Organization: a.cfg.EdgeConnect.Organization,
Name: instancename,
CloudletKey: edgeconnect.CloudletKey(a.cfg.CloudletKey),
}, a.cfg.Region)
CloudletKey: edgeconnect.CloudletKey(a.cfg.EdgeConnect.CloudletKey),
}, a.cfg.EdgeConnect.Region)
if err != nil && !errors.Is(err, edgeconnect.ErrResourceNotFound) {
return params.ProviderInstance{}, err
}
if errors.Is(err, edgeconnect.ErrResourceNotFound) {
err = a.client.CreateAppInstance(ctx, &edgeconnect.NewAppInstanceInput{
Region: a.cfg.Region,
Region: a.cfg.EdgeConnect.Region,
AppInst: edgeconnect.AppInstance{
Key: edgeconnect.AppInstanceKey{
Organization: a.cfg.Organization,
Organization: a.cfg.EdgeConnect.Organization,
Name: instancename,
CloudletKey: edgeconnect.CloudletKey(a.cfg.CloudletKey),
CloudletKey: edgeconnect.CloudletKey(a.cfg.EdgeConnect.CloudletKey),
},
AppKey: edgeconnect.AppKey{
Organization: a.cfg.Organization,
Organization: a.cfg.EdgeConnect.Organization,
Name: instancename,
Version: "1",
},
@ -219,8 +224,8 @@ func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance strin
log.Printf("Executing DeleteInstance %s\n", instance)
appsinstances, err := a.client.ShowAppInstances(ctx, edgeconnect.AppInstanceKey{
Organization: a.cfg.Organization,
}, a.cfg.Region)
Organization: a.cfg.EdgeConnect.Organization,
}, a.cfg.EdgeConnect.Region)
if err != nil {
log.Printf("Error in method DeleteInstance() ShowAppInstances")
return err
@ -235,15 +240,15 @@ func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance strin
log.Printf("filtered %d appinstances", len(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 {
return err
}
}
apps, err := a.client.ShowApps(ctx, edgeconnect.AppKey{
Organization: a.cfg.Organization,
}, a.cfg.Region)
Organization: a.cfg.EdgeConnect.Organization,
}, a.cfg.EdgeConnect.Region)
if err != nil {
log.Printf("Error in method DeleteInstance() ShowApps")
return err
@ -254,7 +259,7 @@ func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance strin
})
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 {
log.Printf("Error in method DeleteInstance() DeleteApp")
return err
@ -278,8 +283,8 @@ func (a *edgeConnectProvider) GetInstance(ctx context.Context, instance string)
}
appinstances, err := a.client.ShowAppInstances(ctx, edgeconnect.AppInstanceKey{
Organization: a.cfg.Organization,
}, a.cfg.Region)
Organization: a.cfg.EdgeConnect.Organization,
}, a.cfg.EdgeConnect.Region)
if err != nil {
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)
apps, err := a.client.ShowAppInstances(ctx, edgeconnect.AppInstanceKey{
Organization: a.cfg.Organization,
}, a.cfg.Region)
Organization: a.cfg.EdgeConnect.Organization,
}, a.cfg.EdgeConnect.Region)
if err != nil {
return nil, err
}
@ -354,8 +359,8 @@ func (a *edgeConnectProvider) RemoveAllInstances(ctx context.Context) error {
log.Printf("Executing RemoveAllInstances\n")
apps, err := a.client.ShowAppInstances(ctx, edgeconnect.AppInstanceKey{
Organization: a.cfg.Organization,
}, a.cfg.Region)
Organization: a.cfg.EdgeConnect.Organization,
}, a.cfg.EdgeConnect.Region)
if err != nil {
return err
}