Skip to content

Commit

Permalink
Add extra logs and increase verbosity of upgrade command for e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
panktishah26 committed Oct 3, 2023
1 parent 5428b97 commit ad99b20
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
10 changes: 7 additions & 3 deletions pkg/cluster/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/cluster-api/util/conditions"

Expand All @@ -16,8 +17,8 @@ import (
// WaitForCondition blocks until either the cluster has this condition as True
// or the retrier timeouts. If observedGeneration is not equal to generation,
// the condition is considered false regardless of the status value.
func WaitForCondition(ctx context.Context, client kubernetes.Reader, cluster *anywherev1.Cluster, retrier *retrier.Retrier, conditionType anywherev1.ConditionType) error {
return WaitFor(ctx, client, cluster, retrier, func(c *anywherev1.Cluster) error {
func WaitForCondition(ctx context.Context, log logr.Logger, client kubernetes.Reader, cluster *anywherev1.Cluster, retrier *retrier.Retrier, conditionType anywherev1.ConditionType) error {
return WaitFor(ctx, log, client, cluster, retrier, func(c *anywherev1.Cluster) error {
condition := conditions.Get(c, conditionType)
if condition == nil {
return fmt.Errorf("cluster doesn't yet have condition %s", conditionType)
Expand All @@ -36,7 +37,7 @@ type Matcher func(*anywherev1.Cluster) error
// WaitFor gets the cluster object from the client
// checks for generation and observedGeneration condition
// matches condition and returns error if the condition is not met.
func WaitFor(ctx context.Context, client kubernetes.Reader, cluster *anywherev1.Cluster, retrier *retrier.Retrier, matcher Matcher) error {
func WaitFor(ctx context.Context, log logr.Logger, client kubernetes.Reader, cluster *anywherev1.Cluster, retrier *retrier.Retrier, matcher Matcher) error {
return retrier.Retry(func() error {
c := &anywherev1.Cluster{}

Expand All @@ -51,6 +52,9 @@ func WaitFor(ctx context.Context, client kubernetes.Reader, cluster *anywherev1.

observedGeneration := c.Status.ObservedGeneration
generation := c.Generation

log.V(9).Info("Cluster generation and observedGeneration", "Generation", generation, "ObservedGeneration", observedGeneration)

if observedGeneration != generation {
return fmt.Errorf("cluster generation (%d) and observedGeneration (%d) differ", generation, observedGeneration)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestWaitForCondition(t *testing.T) {
g := NewWithT(t)
client := test.NewFakeKubeClient(tt.currentCluster)

gotErr := cluster.WaitForCondition(ctx, client, tt.clusterInput, tt.retrier, tt.condition)
gotErr := cluster.WaitForCondition(ctx, test.NewNullLogger(), client, tt.clusterInput, tt.retrier, tt.condition)
if tt.wantErr != "" {
g.Expect(gotErr).To(MatchError(tt.wantErr))
} else {
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestWaitFor(t *testing.T) {
g := NewWithT(t)
client := test.NewFakeKubeClient(tt.currentCluster)

gotErr := cluster.WaitFor(ctx, client, tt.clusterInput, tt.retrier, tt.matcher)
gotErr := cluster.WaitFor(ctx, test.NewNullLogger(), client, tt.clusterInput, tt.retrier, tt.matcher)
if tt.wantErr != "" {
g.Expect(gotErr).To(MatchError(tt.wantErr))
} else {
Expand Down
12 changes: 6 additions & 6 deletions pkg/clustermanager/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func WithApplierRetryBackOff(backOff time.Duration) ApplierOpt {
// until the changes are fully reconciled.
func (a Applier) Run(ctx context.Context, spec *cluster.Spec, managementCluster types.Cluster) error {
var client kubernetes.Client

a.log.V(9).Info("Cluster generation before applying specs", "generation", spec.Cluster.Generation)
a.log.V(3).Info("Applying cluster spec")
err := retrier.New(
a.applyClusterTimeout,
Expand Down Expand Up @@ -133,7 +133,7 @@ func (a Applier) Run(ctx context.Context, spec *cluster.Spec, managementCluster
waitStartTime := time.Now()
retry := a.retrierForWait(waitStartTime)

if err := cluster.WaitFor(ctx, client, spec.Cluster, a.retrierForFailureMessage(), func(c *anywherev1.Cluster) error {
if err := cluster.WaitFor(ctx, a.log, client, spec.Cluster, a.retrierForFailureMessage(), func(c *anywherev1.Cluster) error {
if c.Status.FailureMessage != nil && *c.Status.FailureMessage != "" {
return fmt.Errorf("cluster has an error: %s", *c.Status.FailureMessage)
}
Expand All @@ -143,27 +143,27 @@ func (a Applier) Run(ctx context.Context, spec *cluster.Spec, managementCluster
}

a.log.V(3).Info("Waiting for control plane to be ready")
if err := cluster.WaitForCondition(ctx, client, spec.Cluster, retry, anywherev1.ControlPlaneReadyCondition); err != nil {
if err := cluster.WaitForCondition(ctx, a.log, client, spec.Cluster, retry, anywherev1.ControlPlaneReadyCondition); err != nil {
return errors.Wrapf(err, "waiting for cluster's control plane to be ready")
}

if spec.Cluster.Spec.ClusterNetwork.CNIConfig.IsManaged() {
a.log.V(3).Info("Waiting for default CNI to be updated")
retry = a.retrierForWait(waitStartTime)
if err := cluster.WaitForCondition(ctx, client, spec.Cluster, retry, anywherev1.DefaultCNIConfiguredCondition); err != nil {
if err := cluster.WaitForCondition(ctx, a.log, client, spec.Cluster, retry, anywherev1.DefaultCNIConfiguredCondition); err != nil {
return errors.Wrapf(err, "waiting for cluster's CNI to be configured")
}
}

a.log.V(3).Info("Waiting for worker nodes to be ready after upgrade")
retry = a.retrierForWait(waitStartTime)
if err := cluster.WaitForCondition(ctx, client, spec.Cluster, retry, anywherev1.WorkersReadyCondition); err != nil {
if err := cluster.WaitForCondition(ctx, a.log, client, spec.Cluster, retry, anywherev1.WorkersReadyCondition); err != nil {
return errors.Wrapf(err, "waiting for cluster's workers to be ready")
}

a.log.V(3).Info("Waiting for cluster upgrade to be completed")
retry = a.retrierForWait(waitStartTime)
if err := cluster.WaitForCondition(ctx, client, spec.Cluster, retry, anywherev1.ReadyCondition); err != nil {
if err := cluster.WaitForCondition(ctx, a.log, client, spec.Cluster, retry, anywherev1.ReadyCondition); err != nil {
return errors.Wrapf(err, "waiting for cluster to be ready")
}

Expand Down
2 changes: 1 addition & 1 deletion test/framework/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ func (e *ClusterE2ETest) upgradeCluster(clusterOpts []ClusterE2ETestOpt, command

// UpgradeCluster runs the CLI upgrade command.
func (e *ClusterE2ETest) UpgradeCluster(commandOpts ...CommandOpt) {
upgradeClusterArgs := []string{"upgrade", "cluster", "-f", e.ClusterConfigLocation, "-v", "4"}
upgradeClusterArgs := []string{"upgrade", "cluster", "-f", e.ClusterConfigLocation, "-v", "9"}
if getBundlesOverride() == "true" {
upgradeClusterArgs = append(upgradeClusterArgs, "--bundles-override", defaultBundleReleaseManifestFile)
}
Expand Down

0 comments on commit ad99b20

Please sign in to comment.