feat(Client): implemented idempotent DeleteApp, Error Handling
Some checks failed
Go Tests / go-tests (push) Failing after 1m1s
Some checks failed
Go Tests / go-tests (push) Failing after 1m1s
This commit is contained in:
parent
ec1abae2d6
commit
a98c76ba84
3 changed files with 75 additions and 52 deletions
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ package provider
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
|
@ -135,51 +136,71 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
|||
|
||||
manifest := fmt.Sprintf("%s\n---\n%s", string(podjson), string(servicejson))
|
||||
|
||||
err = a.client.CreateApp(ctx, client.NewAppInput{
|
||||
Region: a.cfg.Region,
|
||||
App: client.App{
|
||||
Key: client.AppKey{
|
||||
Organization: a.cfg.Organization,
|
||||
Name: instancename,
|
||||
Version: "0.0.1",
|
||||
},
|
||||
Deployment: "kubernetes",
|
||||
ImageType: "Docker",
|
||||
ImagePath: "edp.buildth.ing/devfw-cicd/nginx",
|
||||
AllowServerless: true,
|
||||
ServerlessConfig: struct{}{},
|
||||
DefaultFlavor: client.Flavor{
|
||||
Name: "EU.small",
|
||||
},
|
||||
DeploymentGenerator: "kubernetes-basic",
|
||||
DeploymentManifest: manifest,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
_, 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{
|
||||
Key: client.AppKey{
|
||||
Organization: a.cfg.Organization,
|
||||
Name: instancename,
|
||||
Version: "0.0.1",
|
||||
},
|
||||
Deployment: "kubernetes",
|
||||
ImageType: "Docker",
|
||||
ImagePath: "edp.buildth.ing/devfw-cicd/nginx",
|
||||
AllowServerless: true,
|
||||
ServerlessConfig: struct{}{},
|
||||
DefaultFlavor: client.Flavor{
|
||||
Name: "EU.small",
|
||||
},
|
||||
DeploymentGenerator: "kubernetes-basic",
|
||||
DeploymentManifest: manifest,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return params.ProviderInstance{}, err
|
||||
}
|
||||
}
|
||||
|
||||
err = a.client.CreateAppInstance(ctx, client.NewAppInstanceInput{
|
||||
Region: a.cfg.Region,
|
||||
AppInst: client.AppInstance{
|
||||
Key: client.AppInstanceKey{
|
||||
Organization: a.cfg.Organization,
|
||||
Name: instancename,
|
||||
CloudletKey: client.CloudletKey(a.cfg.CloudletKey),
|
||||
},
|
||||
AppKey: client.AppKey{
|
||||
Organization: a.cfg.Organization,
|
||||
Name: instancename,
|
||||
Version: "0.0.1",
|
||||
},
|
||||
Flavor: client.Flavor{
|
||||
Name: "EU.small",
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
_, 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{
|
||||
Key: client.AppInstanceKey{
|
||||
Organization: a.cfg.Organization,
|
||||
Name: instancename,
|
||||
CloudletKey: client.CloudletKey(a.cfg.CloudletKey),
|
||||
},
|
||||
AppKey: client.AppKey{
|
||||
Organization: a.cfg.Organization,
|
||||
Name: instancename,
|
||||
Version: "0.0.1",
|
||||
},
|
||||
Flavor: client.Flavor{
|
||||
Name: "EU.small",
|
||||
},
|
||||
},
|
||||
})
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue