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()
|
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)
|
token, err := client.RetrieveToken(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Responses[T]{}, err
|
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)
|
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
|
return responses, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,20 @@ package client
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
type Responses[T any] struct {
|
type Responses[T Message] struct {
|
||||||
Responses []Response[T]
|
Responses []Response[T]
|
||||||
StatusCode int
|
StatusCode int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Message interface {
|
||||||
|
GetMessage() string
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Responses[T]) GetData() []T {
|
func (r *Responses[T]) GetData() []T {
|
||||||
var data []T
|
var data []T
|
||||||
for _, v := range r.Responses {
|
for _, v := range r.Responses {
|
||||||
if v.HasData() {
|
if v.HasData() {
|
||||||
data = append(data, *v.Data)
|
data = append(data, v.Data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
@ -20,8 +24,8 @@ func (r *Responses[T]) GetData() []T {
|
||||||
func (r *Responses[T]) GetMessages() []string {
|
func (r *Responses[T]) GetMessages() []string {
|
||||||
var messages []string
|
var messages []string
|
||||||
for _, v := range r.Responses {
|
for _, v := range r.Responses {
|
||||||
if v.HasData() {
|
if v.IsMessage() {
|
||||||
messages = append(messages, v.Message)
|
messages = append(messages, v.Data.GetMessage())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return messages
|
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())
|
return fmt.Errorf("error with status code %v and messages %v", r.StatusCode, r.GetMessages())
|
||||||
}
|
}
|
||||||
|
|
||||||
type Response[T any] struct {
|
type Response[T Message] struct {
|
||||||
Data *T `json:"data"`
|
Data T `json:"data"`
|
||||||
Message string `json:"message"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (res *Response[T]) HasData() bool {
|
func (res *Response[T]) HasData() bool {
|
||||||
return res.Data != nil
|
return !res.IsMessage()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (res *Response[T]) IsMessage() bool {
|
func (res *Response[T]) IsMessage() bool {
|
||||||
return res.Message != ""
|
return res.Data.GetMessage() != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
type NewAppInstanceInput struct {
|
type NewAppInstanceInput struct {
|
||||||
|
|
@ -57,7 +60,16 @@ type NewAppInstanceInput struct {
|
||||||
AppInst AppInstance `json:"appinst"`
|
AppInst AppInstance `json:"appinst"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type msg struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg msg) GetMessage() string {
|
||||||
|
return msg.Message
|
||||||
|
}
|
||||||
|
|
||||||
type AppInstance struct {
|
type AppInstance struct {
|
||||||
|
msg `json:",inline"`
|
||||||
Key AppInstanceKey `json:"key"`
|
Key AppInstanceKey `json:"key"`
|
||||||
AppKey AppKey `json:"app_key,omitzero"`
|
AppKey AppKey `json:"app_key,omitzero"`
|
||||||
Flavor Flavor `json:"flavor,omitzero"`
|
Flavor Flavor `json:"flavor,omitzero"`
|
||||||
|
|
@ -92,6 +104,7 @@ type NewAppInput struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
|
msg `json:",inline"`
|
||||||
Key AppKey `json:"key"`
|
Key AppKey `json:"key"`
|
||||||
Deployment string `json:"deployment,omitempty"`
|
Deployment string `json:"deployment,omitempty"`
|
||||||
ImageType string `json:"image_type,omitempty"`
|
ImageType string `json:"image_type,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ import (
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/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"
|
execution "github.com/cloudbase/garm-provider-common/execution/v0.1.0"
|
||||||
"github.com/cloudbase/garm-provider-common/params"
|
"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)
|
podjson, err := json.Marshal(podv1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return params.ProviderInstance{}, err
|
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{
|
_, err = a.client.ShowApp(ctx, client.AppKey{
|
||||||
Organization: a.cfg.Organization,
|
Organization: a.cfg.Organization,
|
||||||
Name: instancename,
|
Name: instancename,
|
||||||
|
|
@ -180,14 +150,14 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
||||||
},
|
},
|
||||||
Deployment: "kubernetes",
|
Deployment: "kubernetes",
|
||||||
ImageType: "Docker",
|
ImageType: "Docker",
|
||||||
ImagePath: "edp.buildth.ing/devfw-cicd/nginx",
|
ImagePath: "edp.buildth.ing/devfw-cicd/garm-act-runner:1",
|
||||||
AllowServerless: true,
|
AllowServerless: true,
|
||||||
ServerlessConfig: struct{}{},
|
ServerlessConfig: struct{}{},
|
||||||
DefaultFlavor: client.Flavor{
|
DefaultFlavor: client.Flavor{
|
||||||
Name: "EU.small",
|
Name: "EU.small",
|
||||||
},
|
},
|
||||||
DeploymentGenerator: "kubernetes-basic",
|
DeploymentGenerator: "kubernetes-basic",
|
||||||
DeploymentManifest: manifest,
|
DeploymentManifest: string(podjson),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -228,7 +198,7 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
||||||
}
|
}
|
||||||
|
|
||||||
instance := params.ProviderInstance{
|
instance := params.ProviderInstance{
|
||||||
ProviderID: a.controllerID,
|
ProviderID: instancename,
|
||||||
Name: instancename,
|
Name: instancename,
|
||||||
OSType: params.Linux,
|
OSType: params.Linux,
|
||||||
OSArch: params.Amd64,
|
OSArch: params.Amd64,
|
||||||
|
|
@ -355,10 +325,14 @@ func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance strin
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("got %d appinstances", len(appsinstances))
|
||||||
|
|
||||||
myappintances := filter(appsinstances, func(app client.AppInstance) bool {
|
myappintances := filter(appsinstances, func(app client.AppInstance) bool {
|
||||||
return strings.HasSuffix(app.Key.Name, strings.ToLower(instance))
|
return strings.HasSuffix(app.Key.Name, strings.ToLower(instance))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
log.Printf("filtered %d appinstances", len(myappintances))
|
||||||
|
|
||||||
for _, v := range myappintances {
|
for _, v := range myappintances {
|
||||||
err = a.client.DeleteAppInstance(ctx, v.Key, a.cfg.Region)
|
err = a.client.DeleteAppInstance(ctx, v.Key, a.cfg.Region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue