Skip to content

Commit

Permalink
Merge pull request #680 from errordeveloper/error-messages
Browse files Browse the repository at this point in the history
Improve readiness diagnotics messages
  • Loading branch information
stefanprodan authored May 2, 2024
2 parents 8c7df3e + 22c8ab0 commit 346400d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/provider/resource_bootstrap_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,10 @@ func (r *bootstrapGitResource) Read(ctx context.Context, req resource.ReadReques
if err != nil {
warnDetails = err.Error()
}
resp.Diagnostics.AddWarning("Flux controllers are not healthy and will be redeployed", warnDetails)
resp.Diagnostics.AddWarning(
fmt.Sprintf("Flux resources GitRepository and Kustomization in %s namespace are not ready and Flux will be redeployed", data.Namespace.ValueString()),
warnDetails,
)
}

mapValue, diags := types.MapValueFrom(ctx, types.StringType, repositoryFiles)
Expand Down Expand Up @@ -1168,17 +1171,18 @@ func isKubernetesReady(ctx context.Context, kubeClient client.Client) error {

// isFluxReady checks if the Flux sync objects are present and ready.
func isFluxReady(ctx context.Context, kubeClient client.Client, data bootstrapGitResourceData) (bool, error) {
ns := data.Namespace.ValueString()
syncName := apitypes.NamespacedName{
Namespace: data.Namespace.ValueString(),
Name: data.Namespace.ValueString(),
Namespace: ns,
Name: ns,
}

rootSource := &sourcev1.GitRepository{}
if err := kubeClient.Get(ctx, syncName, rootSource); err != nil {
return false, err
}
if conditions.IsFalse(rootSource, meta.ReadyCondition) {
return false, errors.New(conditions.GetMessage(rootSource, meta.ReadyCondition))
return false, fmt.Errorf("GitRepository/%s: %s", ns, conditions.GetMessage(rootSource, meta.ReadyCondition))
}

rootSync := &kustomizev1.Kustomization{}
Expand All @@ -1187,7 +1191,7 @@ func isFluxReady(ctx context.Context, kubeClient client.Client, data bootstrapGi
}
if conditions.IsFalse(rootSync, meta.ReadyCondition) {
conditions.GetMessage(rootSync, meta.ReadyCondition)
return false, errors.New(conditions.GetMessage(rootSync, meta.ReadyCondition))
return false, fmt.Errorf("Kustomization/%s: %s", ns, conditions.GetMessage(rootSync, meta.ReadyCondition))
}

return true, nil
Expand Down

0 comments on commit 346400d

Please sign in to comment.