feat(Client): implemented idempotent DeleteApp, Error Handling
Some checks failed
Go Tests / go-tests (push) Failing after 1m1s

This commit is contained in:
Christopher Hase 2025-09-08 10:41:31 +02:00
parent ec1abae2d6
commit a98c76ba84
3 changed files with 75 additions and 52 deletions

View file

@ -10,6 +10,8 @@ import (
"net/http"
)
var ErrNotFound = fmt.Errorf("Not found!")
type EdgeConnect struct {
BaseURL string
HttpClient *http.Client
@ -87,6 +89,10 @@ func (e *EdgeConnect) ShowApp(ctx context.Context, appkey AppKey, region string)
return App{}, err
}
if responses.StatusCode == http.StatusNotFound {
return App{}, fmt.Errorf("Error retrieving App: %w", ErrNotFound)
}
if !responses.IsSuccessful() {
return App{}, responses.Error()
}
@ -185,6 +191,10 @@ func (e *EdgeConnect) ShowAppInstance(ctx context.Context, appinstkey AppInstanc
return AppInstance{}, err
}
if responses.StatusCode == http.StatusNotFound {
return AppInstance{}, fmt.Errorf("Error retrieving AppInstance: %w", ErrNotFound)
}
if !responses.IsSuccessful() {
return AppInstance{}, responses.Error()
}

View file

@ -143,7 +143,7 @@ func main() {
fmt.Printf("appinst: %v\n", appinst)
fmt.Printf("Error: %v\n", err)*/
edgeprovider, _ := provider.NewEdgeConnectProvider("/home/chris/ipcei/projects/garm-provider-edge-connect/config/config.toml", "lalacontroller")
edgeprovider, _, _ := provider.NewEdgeConnectProvider("/home/chris/ipcei/projects/garm-provider-edge-connect/config/config.toml", "lalacontroller")
//providerinst, err := edgeprovider.GetInstance(ctx, appinst.Key.Name)
/*_, err := edgeprovider.CreateInstance(ctx, params.BootstrapInstance{

View file

@ -17,6 +17,7 @@ package provider
import (
"context"
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
@ -135,6 +136,15 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
manifest := fmt.Sprintf("%s\n---\n%s", string(podjson), string(servicejson))
_, err = a.client.ShowApp(ctx, client.AppKey{
Organization: a.cfg.Organization,
Name: instancename,
Version: "0.0.1",
}, a.cfg.Region)
if err != nil && !errors.As(err, client.ErrNotFound) {
return params.ProviderInstance{}, err
}
if errors.As(err, client.ErrNotFound) {
err = a.client.CreateApp(ctx, client.NewAppInput{
Region: a.cfg.Region,
App: client.App{
@ -158,7 +168,17 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
if err != nil {
return params.ProviderInstance{}, err
}
}
_, err = a.client.ShowAppInstance(ctx, client.AppInstanceKey{
Organization: a.cfg.Organization,
Name: instancename,
CloudletKey: client.CloudletKey(a.cfg.CloudletKey),
}, a.cfg.Region)
if err != nil && !errors.As(err, client.ErrNotFound) {
return params.ProviderInstance{}, err
}
if errors.As(err, client.ErrNotFound) {
err = a.client.CreateAppInstance(ctx, client.NewAppInstanceInput{
Region: a.cfg.Region,
AppInst: client.AppInstance{
@ -180,6 +200,7 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
if err != nil {
return params.ProviderInstance{}, err
}
}
instance := params.ProviderInstance{
ProviderID: a.controllerID,
@ -202,6 +223,7 @@ func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance strin
Organization: a.cfg.Organization,
}, a.cfg.Region)
if err != nil {
log.Printf("Error in method DeleteInstance() ShowAppInstances")
return err
}
@ -220,6 +242,7 @@ func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance strin
Organization: a.cfg.Organization,
}, a.cfg.Region)
if err != nil {
log.Printf("Error in method DeleteInstance() ShowApps")
return err
}
@ -230,21 +253,11 @@ func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance strin
for _, v := range myapps {
err = a.client.DeleteApp(ctx, v.Key, a.cfg.Region)
if err != nil {
log.Printf("Error in method DeleteInstance() DeleteApp")
return err
}
}
appkey := client.AppKey{
Organization: a.cfg.Organization,
Name: instance,
Version: "0.0.1",
}
err = a.client.DeleteApp(ctx, appkey, a.cfg.Region)
if err != nil {
return err
}
return nil
}