Skip to content

Commit

Permalink
chore: operator debug
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
  • Loading branch information
AlexsJones committed Aug 1, 2023
1 parent df6407c commit 5a931fb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
7 changes: 4 additions & 3 deletions controllers/k8sgpt_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ func (r *K8sGPTReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
k8sgptReconcileErrorCount.Inc()
return r.finishReconcile(err, false)
}
// Log address
fmt.Printf("K8sGPT address: %s\n", address)

k8sgptClient, err := kclient.NewClient(address)
if err != nil {
Expand Down Expand Up @@ -216,7 +218,6 @@ func (r *K8sGPTReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
return r.finishReconcile(err, false)

}

// Update metrics
if operation == resources.CreatedResult {
k8sgptNumberOfResultsByType.With(prometheus.Labels{
Expand Down Expand Up @@ -291,13 +292,13 @@ func (r *K8sGPTReconciler) finishReconcile(err error, requeueImmediate bool) (ct
if requeueImmediate {
interval = 0
}
fmt.Printf("Finished Reconciling K8sGPT with error: %s\n", err.Error())
fmt.Printf("Finished Reconciling k8sGPT with error: %s\n", err.Error())
return ctrl.Result{Requeue: true, RequeueAfter: interval}, err
}
interval := ReconcileSuccessInterval
if requeueImmediate {
interval = 0
}
fmt.Println("Finished Reconciling K8sGPT")
fmt.Println("Finished Reconciling k8sGPT")
return ctrl.Result{Requeue: true, RequeueAfter: interval}, nil
}
13 changes: 13 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (
"context"
"encoding/json"
"fmt"
"net"
"os"
"time"

rpc "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go/schema/v1/schemav1grpc"
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1"
Expand Down Expand Up @@ -64,6 +66,17 @@ func GenerateAddress(ctx context.Context, cli client.Client, k8sgptConfig *v1alp
}
address = fmt.Sprintf("%s:%d", svc.Spec.ClusterIP, svc.Spec.Ports[0].Port)
}

fmt.Printf("Creating new client for %s\n", address)
// Test if the port is open
conn, err := net.DialTimeout("tcp", address, 1*time.Second)
if err != nil {
return "", err
}

fmt.Printf("Connection established between %s and localhost with time out of %d seconds.\n", address, int64(1))
fmt.Printf("Remote Address : %s \n", conn.RemoteAddr().String())

return address, nil
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/resources/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"
"fmt"
"reflect"
"strings"

Expand Down Expand Up @@ -62,6 +63,7 @@ func CreateOrUpdateResult(ctx context.Context, c client.Client, res v1alpha1.Res
if err := c.Create(ctx, &res); err != nil {
return NoOpResult, err
}
fmt.Printf("Created result %s\n", res.Name)
return CreatedResult, nil
}
if len(existing.Spec.Error) == len(res.Spec.Error) && reflect.DeepEqual(res.Labels, existing.Labels) {
Expand All @@ -79,6 +81,6 @@ func CreateOrUpdateResult(ctx context.Context, c client.Client, res v1alpha1.Res
if err := c.Status().Update(ctx, &existing); err != nil {
return NoOpResult, err
}

fmt.Printf("Updated result %s\n", res.Name)
return UpdatedResult, nil
}

0 comments on commit 5a931fb

Please sign in to comment.