Skip to content

Commit

Permalink
fix: add more logging to blixt readiness test utils
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneutt committed Aug 30, 2023
1 parent 9b2620c commit ce689e4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions internal/test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
"github.com/kong/kubernetes-testing-framework/pkg/clusters"
"github.com/kong/kubernetes-testing-framework/pkg/environments"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
"sigs.k8s.io/kustomize/kyaml/yaml"

"github.com/kong/blixt/pkg/vars"
)
Expand Down Expand Up @@ -73,9 +75,47 @@ func NewFakeClientWithGatewayClasses(initObjects ...client.Object) (gatewayv1bet
// environment (but deploying Blixt is expected to have already been handled
// elsewhere).
func WaitForBlixtReadiness(ctx context.Context, env environments.Environment) error {
defer func() {
fmt.Println("INFO: dumping cluster details")

deployments, err := env.Cluster().Client().AppsV1().Deployments(corev1.NamespaceAll).List(ctx, corev1.ListOptions{})
if err == nil {
b, err := yaml.Marshal(deployments)
if err != nil {
fmt.Printf("Warning: failed to marshal YAML report of current deployment status on shutdown: %s\n", err)
}
fmt.Printf("Deployments:\n---\n%s\n", string(b))
} else {
fmt.Printf("Warning: failed to report current deployment status on shutdown: %s\n", err)
}

daemonsets, err := env.Cluster().Client().AppsV1().DaemonSets(corev1.NamespaceAll).List(ctx, corev1.ListOptions{})
if err == nil {
b, err := yaml.Marshal(daemonsets)
if err != nil {
fmt.Printf("Warning: failed to marshal YAML report of current daemonset status on shutdown: %s\n", err)
}
fmt.Printf("Daemonsets:\n---\n%s\n", string(b))
} else {
fmt.Printf("Warning: failed to report current daemonset status on shutdown: %s\n", err)
}

pods, err := env.Cluster().Client().CoreV1().Pods(corev1.NamespaceAll).List(ctx, corev1.ListOptions{})
if err == nil {
b, err := yaml.Marshal(pods)
if err != nil {
fmt.Printf("Warning: failed to marshal YAML report of current pod status on shutdown: %s\n", err)
}
fmt.Printf("Pods:\n---\n%s\n", string(b))
} else {
fmt.Printf("Warning: failed to report current pod status on shutdown: %s\n", err)
}
}()

for {
select {
case <-ctx.Done():

if err := ctx.Err(); err != nil {
return fmt.Errorf("context completed while waiting for components: %w", err)
}
Expand All @@ -85,6 +125,7 @@ func WaitForBlixtReadiness(ctx context.Context, env environments.Environment) er

controlplane, err := env.Cluster().Client().AppsV1().Deployments(vars.DefaultNamespace).Get(ctx, vars.DefaultControlPlaneDeploymentName, metav1.GetOptions{})
if err != nil {
fmt.Printf("Error while checking controlplane components: %s\n", err)
return err
}
if controlplane.Status.AvailableReplicas > 0 {
Expand All @@ -93,6 +134,7 @@ func WaitForBlixtReadiness(ctx context.Context, env environments.Environment) er

dataplane, err := env.Cluster().Client().AppsV1().DaemonSets(vars.DefaultNamespace).Get(ctx, vars.DefaultDataPlaneDaemonSetName, metav1.GetOptions{})
if err != nil {
fmt.Printf("Error while checking dataplane components: %s\n", err)
return err
}
if dataplane.Status.NumberAvailable > 0 {
Expand All @@ -102,6 +144,8 @@ func WaitForBlixtReadiness(ctx context.Context, env environments.Environment) er
if controlplaneReady && dataplaneReady {
return nil
}

fmt.Println("Warning: waiting for blixt components to be ready")
}
}
}
Expand Down

0 comments on commit ce689e4

Please sign in to comment.