Skip to content

Commit

Permalink
rename field and pre-commit-local
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Kieweg <mail@manuelkieweg.de>
  • Loading branch information
mkieweg committed Jun 14, 2024
1 parent 70c2591 commit 11944ca
Show file tree
Hide file tree
Showing 15 changed files with 788 additions and 784 deletions.
6 changes: 3 additions & 3 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7325,16 +7325,16 @@
"type": "object",
"title": "HealthStatus contains information about the currently observed health state of an application or resource",
"properties": {
"lastTransitionTime": {
"$ref": "#/definitions/v1Time"
},
"message": {
"type": "string",
"title": "Message is a human-readable informational message describing the health status"
},
"status": {
"type": "string",
"title": "Status holds the status code of the application or resource"
},
"timestamp": {
"$ref": "#/definitions/v1Time"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions controller/appcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ func createFakeApp(testApp string) *v1alpha1.Application {
func createFakeAppWithHealthAndTime(testApp string, status health.HealthStatusCode, timestamp metav1.Time) *v1alpha1.Application {
app := createFakeApp(testApp)
app.Status.Health = v1alpha1.HealthStatus{
Status: status,
Timestamp: timestamp,
Status: status,
LastTransitionTime: timestamp,
}
return app
}
Expand Down
11 changes: 5 additions & 6 deletions controller/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func getOldTimestamp(statuses []appv1.ResourceStatus, i int) metav1.Time {
return metav1.Now()
}

oldTimestamp := statuses[i].Health.Timestamp
oldTimestamp := statuses[i].Health.LastTransitionTime

if oldTimestamp.IsZero() {
oldTimestamp = metav1.Now()
Expand Down Expand Up @@ -73,13 +73,12 @@ func setApplicationHealth(resources []managedResource, statuses []appv1.Resource
}

if persistResourceHealth {

// If the status didn't change, we don't want to update the timestamp
if healthStatus.Status == statuses[i].Health.Status {
timestamp = getOldTimestamp(statuses, i)
}

resHealth := appv1.HealthStatus{Status: healthStatus.Status, Message: healthStatus.Message, Timestamp: timestamp}
resHealth := appv1.HealthStatus{Status: healthStatus.Status, Message: healthStatus.Message, LastTransitionTime: timestamp}
statuses[i].Health = &resHealth
} else {
statuses[i].Health = nil
Expand All @@ -98,12 +97,12 @@ func setApplicationHealth(resources []managedResource, statuses []appv1.Resource
if health.IsWorse(appHealth.Status, healthStatus.Status) {
appHealth.Status = healthStatus.Status
if persistResourceHealth {
appHealth.Timestamp = statuses[i].Health.Timestamp
appHealth.LastTransitionTime = statuses[i].Health.LastTransitionTime
} else {
appHealth.Timestamp = timestamp
appHealth.LastTransitionTime = timestamp
}
} else if healthStatus.Status == health.HealthStatusHealthy {
appHealth.Timestamp = oldTimestamp
appHealth.LastTransitionTime = oldTimestamp
}
}
if persistResourceHealth {
Expand Down
23 changes: 12 additions & 11 deletions controller/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func initStatuses(resources []managedResource) []appv1.ResourceStatus {
Group: resources[i].Group,
Kind: resources[i].Kind,
Version: resources[i].Version,
Health: &appv1.HealthStatus{Timestamp: testTimestamp},
Health: &appv1.HealthStatus{LastTransitionTime: testTimestamp},
}
}
return statuses
Expand Down Expand Up @@ -65,15 +65,15 @@ func TestSetApplicationHealth(t *testing.T) {
resourceStatuses[0].Health.Status = health.HealthStatusHealthy

healthStatus, err := setApplicationHealth(resources, resourceStatuses, lua.ResourceHealthOverrides{}, app, true)
firstHealthStatusTimestamp := healthStatus.Timestamp
firstHealthStatusTimestamp := healthStatus.LastTransitionTime
assert.NoError(t, err)
assert.Equal(t, health.HealthStatusDegraded, healthStatus.Status)
assert.NotEqual(t, testTimestamp, firstHealthStatusTimestamp)

assert.Equal(t, health.HealthStatusHealthy, resourceStatuses[0].Health.Status)
assert.Equal(t, testTimestamp, resourceStatuses[0].Health.Timestamp)
assert.Equal(t, testTimestamp, resourceStatuses[0].Health.LastTransitionTime)
assert.Equal(t, health.HealthStatusDegraded, resourceStatuses[1].Health.Status)
assert.Equal(t, firstHealthStatusTimestamp, resourceStatuses[1].Health.Timestamp)
assert.Equal(t, firstHealthStatusTimestamp, resourceStatuses[1].Health.LastTransitionTime)

// Mark both health statuses as degraded, as app is degraded.
resourceStatuses[0].Health.Status = health.HealthStatusDegraded
Expand All @@ -84,7 +84,7 @@ func TestSetApplicationHealth(t *testing.T) {
healthStatus, err = setApplicationHealth(resources, resourceStatuses, nil, app, true)
assert.NoError(t, err)
assert.Equal(t, health.HealthStatusHealthy, healthStatus.Status)
assert.Equal(t, testTimestamp, healthStatus.Timestamp)
assert.Equal(t, testTimestamp, healthStatus.LastTransitionTime)
}

func TestSetApplicationHealth_ResourceHealthNotPersisted(t *testing.T) {
Expand All @@ -100,7 +100,7 @@ func TestSetApplicationHealth_ResourceHealthNotPersisted(t *testing.T) {
assert.Equal(t, health.HealthStatusDegraded, healthStatus.Status)

assert.Nil(t, resourceStatuses[0].Health)
assert.False(t, healthStatus.Timestamp.IsZero())
assert.False(t, healthStatus.LastTransitionTime.IsZero())
}

func TestSetApplicationHealth_MissingResource(t *testing.T) {
Expand All @@ -114,7 +114,7 @@ func TestSetApplicationHealth_MissingResource(t *testing.T) {
healthStatus, err := setApplicationHealth(resources, resourceStatuses, lua.ResourceHealthOverrides{}, app, true)
assert.NoError(t, err)
assert.Equal(t, health.HealthStatusMissing, healthStatus.Status)
assert.False(t, healthStatus.Timestamp.IsZero())
assert.False(t, healthStatus.LastTransitionTime.IsZero())
}

func TestSetApplicationHealth_HealthImproves(t *testing.T) {
Expand All @@ -131,15 +131,16 @@ return hs`,
degradedApp := newAppLiveObj(health.HealthStatusDegraded)
timestamp := metav1.Now()
resources := []managedResource{{
Group: application.Group, Version: "v1alpha1", Kind: application.ApplicationKind, Live: degradedApp}, {}}
Group: application.Group, Version: "v1alpha1", Kind: application.ApplicationKind, Live: degradedApp,
}, {}}
resourceStatuses := initStatuses(resources)
resourceStatuses[0].Health.Status = health.HealthStatusDegraded
resourceStatuses[0].Health.Timestamp = timestamp
resourceStatuses[0].Health.LastTransitionTime = timestamp

healthStatus, err := setApplicationHealth(resources, resourceStatuses, overrides, app, true)
assert.NoError(t, err)
assert.Equal(t, health.HealthStatusProgressing, healthStatus.Status)
assert.NotEqual(t, healthStatus.Timestamp, timestamp)
assert.NotEqual(t, healthStatus.LastTransitionTime, timestamp)
}

func TestSetApplicationHealth_MissingResourceNoBuiltHealthCheck(t *testing.T) {
Expand All @@ -165,7 +166,7 @@ func TestSetApplicationHealth_MissingResourceNoBuiltHealthCheck(t *testing.T) {
}, app, true)
assert.NoError(t, err)
assert.Equal(t, health.HealthStatusMissing, healthStatus.Status)
assert.False(t, healthStatus.Timestamp.IsZero())
assert.False(t, healthStatus.LastTransitionTime.IsZero())
})
}

Expand Down
4 changes: 2 additions & 2 deletions controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *v1
Status: v1alpha1.SyncStatusCodeUnknown,
Revisions: revisions,
},
healthStatus: &v1alpha1.HealthStatus{Status: health.HealthStatusUnknown, Timestamp: metav1.Now()},
healthStatus: &v1alpha1.HealthStatus{Status: health.HealthStatusUnknown, LastTransitionTime: metav1.Now()},
}, nil
} else {
return &comparisonResult{
Expand All @@ -415,7 +415,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *v1
Status: v1alpha1.SyncStatusCodeUnknown,
Revision: revisions[0],
},
healthStatus: &v1alpha1.HealthStatus{Status: health.HealthStatusUnknown, Timestamp: metav1.Now()},
healthStatus: &v1alpha1.HealthStatus{Status: health.HealthStatusUnknown, LastTransitionTime: metav1.Now()},
}, nil
}
}
Expand Down
10 changes: 5 additions & 5 deletions controller/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ func TestSetHealth(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, health.HealthStatusHealthy, compRes.healthStatus.Status)
assert.False(t, compRes.healthStatus.Timestamp.IsZero())
assert.False(t, compRes.healthStatus.LastTransitionTime.IsZero())
}

func TestPreserveStatusTimestamp(t *testing.T) {
Expand Down Expand Up @@ -749,10 +749,10 @@ func TestPreserveStatusTimestamp(t *testing.T) {
revisions := make([]string, 0)
revisions = append(revisions, "")
compRes, err := ctrl.appStateManager.CompareAppState(app, &defaultProj, revisions, sources, false, false, nil, false, false)
assert.Nil(t, err)
assert.NoError(t, err)

assert.Equal(t, health.HealthStatusHealthy, compRes.healthStatus.Status)
assert.Equal(t, timestamp, compRes.healthStatus.Timestamp)
assert.Equal(t, timestamp, compRes.healthStatus.LastTransitionTime)
}

func TestSetHealthSelfReferencedApp(t *testing.T) {
Expand Down Expand Up @@ -790,7 +790,7 @@ func TestSetHealthSelfReferencedApp(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, health.HealthStatusHealthy, compRes.healthStatus.Status)
assert.False(t, compRes.healthStatus.Timestamp.IsZero())
assert.False(t, compRes.healthStatus.LastTransitionTime.IsZero())
}

func TestSetManagedResourcesWithOrphanedResources(t *testing.T) {
Expand Down Expand Up @@ -866,7 +866,7 @@ func TestReturnUnknownComparisonStateOnSettingLoadError(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, health.HealthStatusUnknown, compRes.healthStatus.Status)
assert.False(t, compRes.healthStatus.Timestamp.IsZero())
assert.False(t, compRes.healthStatus.LastTransitionTime.IsZero())
assert.Equal(t, argoappv1.SyncStatusCodeUnknown, compRes.syncStatus.Status)
}

Expand Down
25 changes: 13 additions & 12 deletions manifests/core-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,11 @@ spec:
description: Health contains information about the application's current
health status
properties:
lastTransitionTime:
description: LastTransitionTime is the time the HealthStatus was
set
format: date-time
type: string
message:
description: Message is a human-readable informational message
describing the health status
Expand All @@ -1726,10 +1731,6 @@ spec:
description: Status holds the status code of the application or
resource
type: string
timestamp:
description: Timestamp is the time the HealthStatus was set
format: date-time
type: string
type: object
history:
description: History contains information about the application's
Expand Down Expand Up @@ -4158,6 +4159,11 @@ spec:
description: HealthStatus contains information about the currently
observed health state of an application or resource
properties:
lastTransitionTime:
description: LastTransitionTime is the time the HealthStatus
was set
format: date-time
type: string
message:
description: Message is a human-readable informational message
describing the health status
Expand All @@ -4166,11 +4172,6 @@ spec:
description: Status holds the status code of the application
or resource
type: string
timestamp:
description: Timestamp is the time the HealthStatus was
set
format: date-time
type: string
type: object
hook:
type: boolean
Expand Down Expand Up @@ -20354,13 +20355,13 @@ spec:
type: string
health:
properties:
lastTransitionTime:
format: date-time
type: string
message:
type: string
status:
type: string
timestamp:
format: date-time
type: string
type: object
hook:
type: boolean
Expand Down
19 changes: 10 additions & 9 deletions manifests/crds/application-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,11 @@ spec:
description: Health contains information about the application's current
health status
properties:
lastTransitionTime:
description: LastTransitionTime is the time the HealthStatus was
set
format: date-time
type: string
message:
description: Message is a human-readable informational message
describing the health status
Expand All @@ -1725,10 +1730,6 @@ spec:
description: Status holds the status code of the application or
resource
type: string
timestamp:
description: Timestamp is the time the HealthStatus was set
format: date-time
type: string
type: object
history:
description: History contains information about the application's
Expand Down Expand Up @@ -4157,6 +4158,11 @@ spec:
description: HealthStatus contains information about the currently
observed health state of an application or resource
properties:
lastTransitionTime:
description: LastTransitionTime is the time the HealthStatus
was set
format: date-time
type: string
message:
description: Message is a human-readable informational message
describing the health status
Expand All @@ -4165,11 +4171,6 @@ spec:
description: Status holds the status code of the application
or resource
type: string
timestamp:
description: Timestamp is the time the HealthStatus was
set
format: date-time
type: string
type: object
hook:
type: boolean
Expand Down
6 changes: 3 additions & 3 deletions manifests/crds/applicationset-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15344,13 +15344,13 @@ spec:
type: string
health:
properties:
lastTransitionTime:
format: date-time
type: string
message:
type: string
status:
type: string
timestamp:
format: date-time
type: string
type: object
hook:
type: boolean
Expand Down
Loading

0 comments on commit 11944ca

Please sign in to comment.