Skip to content

Commit

Permalink
get correct count of items from api
Browse files Browse the repository at this point in the history
  • Loading branch information
isaaguilar committed Sep 25, 2023
1 parent 34fffdc commit 20ca908
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions internal/tfhandler/qworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tfhandler
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"log"
"os"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/galleybytes/monitor/projects/terraform-operator-remote-controller/pkg/util"
tfv1beta1 "github.com/galleybytes/terraform-operator/pkg/apis/tf/v1beta1"
"github.com/isaaguilar/kedge"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/rest"
)

Expand Down Expand Up @@ -92,20 +94,32 @@ MainLoop:
}

isApplyReceivedResourcesFailed := false
totalResourcesReceivedFromAPI := 0
applyErr := ""
for _, item := range list {
b, _ := base64.StdEncoding.DecodeString(item.(string))
err = applyRawManifest(ctx, kedge.KubernetesConfig(os.Getenv("KUBECONFIG")), b, namespace)

var items corev1.List
err = json.Unmarshal(b, &items)
if err != nil {
isApplyReceivedResourcesFailed = true
applyErr += err.Error()
continue
}
totalResourcesReceivedFromAPI += len(items.Items)

err = applyRawManifest(ctx, kedge.KubernetesConfig(os.Getenv("KUBECONFIG")), b, namespace)
if err != nil {
isApplyReceivedResourcesFailed = true
applyErr += err.Error()
continue
}
}
if isApplyReceivedResourcesFailed {
i.requeueAfter(tf, failureRequeueRate, fmt.Sprintf("ERROR applying resources received: %s", applyErr))
continue
}
log.Printf("Done handling workflow and received %d resources back from api \t(%s/%s)", len(list), namespace, name)
log.Printf("Done handling workflow and received %d resources back from api \t(%s/%s)", totalResourcesReceivedFromAPI, namespace, name)
}
}

Expand Down

0 comments on commit 20ca908

Please sign in to comment.