Skip to content

Commit

Permalink
fix: message handling
Browse files Browse the repository at this point in the history
Signed-off-by: chansuke <[email protected]>
  • Loading branch information
chansuke committed Dec 30, 2024
1 parent 33e99fd commit 6680ca0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions controller/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func setApplicationHealth(resources []managedResource, statuses []appv1.Resource
if condTypeExists && condStatusExists && condType == "NonStructuralSchema" && condStatus == "True" {
healthStatus = &health.HealthStatus{
Status: health.HealthStatusDegraded,
Message: "CRD has non-structural schema issues",
Message: condMessage,
}
log.Infof("Health status set to Degraded with message: %s", condMessage)
log.Infof("Health status set to Degraded with message: %s", healthStatus.Message)
break
}
} else {
Expand Down Expand Up @@ -100,6 +100,7 @@ func setApplicationHealth(resources []managedResource, statuses []appv1.Resource

if persistResourceHealth {
resHealth := appv1.HealthStatus{Status: healthStatus.Status, Message: healthStatus.Message}
log.Infof("Persisting health status: %+v", resHealth)
statuses[i].Health = &resHealth
} else {
statuses[i].Health = nil
Expand Down Expand Up @@ -137,5 +138,7 @@ func setApplicationHealth(resources []managedResource, statuses []appv1.Resource
savedErr = fmt.Errorf("see application-controller logs for %d other errors; most recent error was: %w", errCount-1, savedErr)
}

log.Infof("Application %s health: %s", app.Name, appHealth)

return &appHealth, savedErr
}
10 changes: 8 additions & 2 deletions controller/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/argoproj/gitops-engine/pkg/health"
synccommon "github.com/argoproj/gitops-engine/pkg/sync/common"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -281,7 +282,12 @@ func TestSetApplicationHealth_CRDHealthCheck(t *testing.T) {
// Test the health check for CRDs
healthStatus, err := setApplicationHealth(resources, resourceStatuses, lua.ResourceHealthOverrides{}, app, true)
require.NoError(t, err)
assert.Equal(t, health.HealthStatusDegraded, healthStatus.Status)
assert.Equal(t, "CRD has non-structural schema issues", healthStatus.Message)

// Debug log to inspect resource statuses
log.Infof("Overall health status: %+v", healthStatus)
log.Infof("Resource statuses after health check: %+v", resourceStatuses)

require.NotNil(t, resourceStatuses[0].Health, "Health should not be nil")
assert.Equal(t, health.HealthStatusDegraded, resourceStatuses[0].Health.Status)
assert.Equal(t, "CRD has non-structural schema issues", resourceStatuses[0].Health.Message)
}

0 comments on commit 6680ca0

Please sign in to comment.