fixed bug when parsing messages from edge connect
Some checks failed
Go Tests / go-tests (push) Failing after 1m9s
Some checks failed
Go Tests / go-tests (push) Failing after 1m9s
This commit is contained in:
parent
0b01584122
commit
b544bd1538
3 changed files with 34 additions and 44 deletions
|
|
@ -255,7 +255,7 @@ func (e *EdgeConnect) DeleteAppInstance(ctx context.Context, appinstancekey AppI
|
|||
return responses.Error()
|
||||
}
|
||||
|
||||
func call[T any](ctx context.Context, client *EdgeConnect, path string, body []byte) (Responses[T], error) {
|
||||
func call[T Message](ctx context.Context, client *EdgeConnect, path string, body []byte) (Responses[T], error) {
|
||||
token, err := client.RetrieveToken(ctx)
|
||||
if err != nil {
|
||||
return Responses[T]{}, err
|
||||
|
|
@ -294,7 +294,10 @@ func call[T any](ctx context.Context, client *EdgeConnect, path string, body []b
|
|||
responses.Responses = append(responses.Responses, d)
|
||||
}
|
||||
|
||||
log.Printf("call(): %s resulting in http status %v and %v messages\n", path, resp.StatusCode, len(responses.Responses))
|
||||
log.Printf("call(): %s resulting in http status %v and %v responses\n", path, resp.StatusCode, len(responses.GetMessages()))
|
||||
for i, v := range responses.GetMessages() {
|
||||
log.Printf("call(): response[%v]: %s\n", i, v)
|
||||
}
|
||||
|
||||
return responses, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,16 +2,20 @@ package client
|
|||
|
||||
import "fmt"
|
||||
|
||||
type Responses[T any] struct {
|
||||
type Responses[T Message] struct {
|
||||
Responses []Response[T]
|
||||
StatusCode int
|
||||
}
|
||||
|
||||
type Message interface {
|
||||
GetMessage() string
|
||||
}
|
||||
|
||||
func (r *Responses[T]) GetData() []T {
|
||||
var data []T
|
||||
for _, v := range r.Responses {
|
||||
if v.HasData() {
|
||||
data = append(data, *v.Data)
|
||||
data = append(data, v.Data)
|
||||
}
|
||||
}
|
||||
return data
|
||||
|
|
@ -20,8 +24,8 @@ func (r *Responses[T]) GetData() []T {
|
|||
func (r *Responses[T]) GetMessages() []string {
|
||||
var messages []string
|
||||
for _, v := range r.Responses {
|
||||
if v.HasData() {
|
||||
messages = append(messages, v.Message)
|
||||
if v.IsMessage() {
|
||||
messages = append(messages, v.Data.GetMessage())
|
||||
}
|
||||
}
|
||||
return messages
|
||||
|
|
@ -39,17 +43,16 @@ func (r *Responses[T]) Error() error {
|
|||
return fmt.Errorf("error with status code %v and messages %v", r.StatusCode, r.GetMessages())
|
||||
}
|
||||
|
||||
type Response[T any] struct {
|
||||
Data *T `json:"data"`
|
||||
Message string `json:"message"`
|
||||
type Response[T Message] struct {
|
||||
Data T `json:"data"`
|
||||
}
|
||||
|
||||
func (res *Response[T]) HasData() bool {
|
||||
return res.Data != nil
|
||||
return !res.IsMessage()
|
||||
}
|
||||
|
||||
func (res *Response[T]) IsMessage() bool {
|
||||
return res.Message != ""
|
||||
return res.Data.GetMessage() != ""
|
||||
}
|
||||
|
||||
type NewAppInstanceInput struct {
|
||||
|
|
@ -57,7 +60,16 @@ type NewAppInstanceInput struct {
|
|||
AppInst AppInstance `json:"appinst"`
|
||||
}
|
||||
|
||||
type msg struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (msg msg) GetMessage() string {
|
||||
return msg.Message
|
||||
}
|
||||
|
||||
type AppInstance struct {
|
||||
msg `json:",inline"`
|
||||
Key AppInstanceKey `json:"key"`
|
||||
AppKey AppKey `json:"app_key,omitzero"`
|
||||
Flavor Flavor `json:"flavor,omitzero"`
|
||||
|
|
@ -92,6 +104,7 @@ type NewAppInput struct {
|
|||
}
|
||||
|
||||
type App struct {
|
||||
msg `json:",inline"`
|
||||
Key AppKey `json:"key"`
|
||||
Deployment string `json:"deployment,omitempty"`
|
||||
ImageType string `json:"image_type,omitempty"`
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import (
|
|||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
||||
execution "github.com/cloudbase/garm-provider-common/execution/v0.1.0"
|
||||
"github.com/cloudbase/garm-provider-common/params"
|
||||
|
|
@ -127,40 +126,11 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
|||
},
|
||||
}
|
||||
|
||||
service := corev1.Service{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Service",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: instancename,
|
||||
},
|
||||
Spec: corev1.ServiceSpec{
|
||||
Type: corev1.ServiceTypeLoadBalancer,
|
||||
Ports: []corev1.ServicePort{
|
||||
corev1.ServicePort{
|
||||
Name: "tcp80",
|
||||
Protocol: "TCP",
|
||||
Port: 80,
|
||||
TargetPort: intstr.FromInt(80),
|
||||
},
|
||||
},
|
||||
Selector: map[string]string{"run": instancename},
|
||||
},
|
||||
}
|
||||
|
||||
podjson, err := json.Marshal(podv1)
|
||||
if err != nil {
|
||||
return params.ProviderInstance{}, err
|
||||
}
|
||||
|
||||
servicejson, err := json.Marshal(service)
|
||||
if err != nil {
|
||||
return params.ProviderInstance{}, err
|
||||
}
|
||||
|
||||
manifest := fmt.Sprintf("%s\n---\n%s", string(podjson), string(servicejson))
|
||||
|
||||
_, err = a.client.ShowApp(ctx, client.AppKey{
|
||||
Organization: a.cfg.Organization,
|
||||
Name: instancename,
|
||||
|
|
@ -180,14 +150,14 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
|||
},
|
||||
Deployment: "kubernetes",
|
||||
ImageType: "Docker",
|
||||
ImagePath: "edp.buildth.ing/devfw-cicd/nginx",
|
||||
ImagePath: "edp.buildth.ing/devfw-cicd/garm-act-runner:1",
|
||||
AllowServerless: true,
|
||||
ServerlessConfig: struct{}{},
|
||||
DefaultFlavor: client.Flavor{
|
||||
Name: "EU.small",
|
||||
},
|
||||
DeploymentGenerator: "kubernetes-basic",
|
||||
DeploymentManifest: manifest,
|
||||
DeploymentManifest: string(podjson),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
|
@ -228,7 +198,7 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
|||
}
|
||||
|
||||
instance := params.ProviderInstance{
|
||||
ProviderID: a.controllerID,
|
||||
ProviderID: instancename,
|
||||
Name: instancename,
|
||||
OSType: params.Linux,
|
||||
OSArch: params.Amd64,
|
||||
|
|
@ -355,10 +325,14 @@ func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance strin
|
|||
return err
|
||||
}
|
||||
|
||||
log.Printf("got %d appinstances", len(appsinstances))
|
||||
|
||||
myappintances := filter(appsinstances, func(app client.AppInstance) bool {
|
||||
return strings.HasSuffix(app.Key.Name, strings.ToLower(instance))
|
||||
})
|
||||
|
||||
log.Printf("filtered %d appinstances", len(myappintances))
|
||||
|
||||
for _, v := range myappintances {
|
||||
err = a.client.DeleteAppInstance(ctx, v.Key, a.cfg.Region)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue