feat(client): implemented RemoveAllInstances
Some checks failed
Go Tests / go-tests (push) Failing after 1m31s

This commit is contained in:
Christopher Hase 2025-09-04 13:47:35 +02:00
parent 2145cec970
commit bbfbba74cc
2 changed files with 31 additions and 7 deletions

View file

@ -5,7 +5,6 @@ import (
"fmt"
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/provider"
"github.com/cloudbase/garm-provider-common/params"
)
var testManifest = `
@ -147,17 +146,23 @@ func main() {
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{
Name: "bootstrapparams-2",
/*_, err := edgeprovider.CreateInstance(ctx, params.BootstrapInstance{
Name: "bootstrapparams-1",
PoolID: "123456",
})
lists, err := edgeprovider.ListInstances(ctx, "123456")
_, err = edgeprovider.CreateInstance(ctx, params.BootstrapInstance{
Name: "bootstrapparams-2",
PoolID: "123456",
})*/
err := edgeprovider.RemoveAllInstances(ctx)
//lists, err := edgeprovider.ListInstances(ctx, "123456")
/*result, _ := e.ShowApps(ctx, client.AppKey{
Organization: "edp-developer-framework",
}, "EU")*/
fmt.Printf("Lists: %v", lists)
//fmt.Printf("Lists: %v", lists)
fmt.Printf("Error: %v", err)
//ShowApps

View file

@ -66,7 +66,7 @@ type edgeConnectProvider struct {
// CreateInstance creates a new compute instance in the provider.
func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParams params.BootstrapInstance) (params.ProviderInstance, error) {
instancename := fmt.Sprintf("garm-%v-%v", bootstrapParams.PoolID, bootstrapParams.Name)
instancename := fmt.Sprintf("garm-%v-%v-%v", a.controllerID, bootstrapParams.PoolID, bootstrapParams.Name)
podv1 := corev1.Pod{
TypeMeta: metav1.TypeMeta{
@ -263,7 +263,7 @@ func (a *edgeConnectProvider) ListInstances(ctx context.Context, poolID string)
}
myappintances := filter(apps, func(app client.AppInstance) bool {
return strings.HasPrefix(app.Key.Name, fmt.Sprintf("garm-%v", poolID))
return strings.HasPrefix(app.Key.Name, fmt.Sprintf("garm-%v-%v", a.controllerID, poolID))
})
providerinstances := []params.ProviderInstance{}
@ -301,6 +301,25 @@ func filter[T any](s []T, predicate func(T) bool) []T {
// RemoveAllInstances will remove all instances created by this provider.
func (a *edgeConnectProvider) RemoveAllInstances(ctx context.Context) error {
apps, err := a.client.ShowAppInstances(ctx, client.AppInstanceKey{
Organization: a.cfg.Organization,
}, a.cfg.Region)
if err != nil {
return err
}
myappintances := filter(apps, func(app client.AppInstance) bool {
return strings.HasPrefix(app.Key.Name, fmt.Sprintf("garm-%v", a.controllerID))
})
for _, v := range myappintances {
err = a.DeleteInstance(ctx, v.Key.Name)
if err != nil {
return err
}
}
return nil
}