forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
event-reporter: changes after pr review
- Loading branch information
1 parent
9f4fa6b
commit 4b88afa
Showing
6 changed files
with
316 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package utils | ||
|
||
import appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" | ||
|
||
type AppRevisionsFieldNames string | ||
|
||
var AppRevisionFieldName AppRevisionsFieldNames = "Revision" | ||
var AppRevisionsFieldName AppRevisionsFieldNames = "Revisions" | ||
|
||
type AppUtils struct { | ||
App *appv1.Application | ||
} | ||
|
||
func (au *AppUtils) operationStateSyncExists(fieldToCheck *AppRevisionsFieldNames) bool { | ||
result := au.App != nil && au.App.Status.OperationState != nil && au.App.Status.OperationState.Operation.Sync != nil | ||
if !result { | ||
return false | ||
} | ||
|
||
return revisionsToCheck(RevisionsData{ | ||
Revision: au.App.Status.OperationState.Operation.Sync.Revision, | ||
Revisions: au.App.Status.OperationState.Operation.Sync.Revisions, | ||
}, fieldToCheck) | ||
} | ||
|
||
func (au *AppUtils) operationSyncExists(fieldToCheck *AppRevisionsFieldNames) bool { | ||
result := au.App != nil && au.App.Operation != nil && au.App.Operation.Sync != nil | ||
if !result { | ||
return false | ||
} | ||
|
||
return revisionsToCheck(RevisionsData{ | ||
Revision: au.App.Operation.Sync.Revision, | ||
Revisions: au.App.Operation.Sync.Revisions, | ||
}, fieldToCheck) | ||
} | ||
|
||
func (au *AppUtils) operationSyncResultExists(fieldToCheck *AppRevisionsFieldNames) bool { | ||
result := au.App != nil && au.App.Status.OperationState != nil && au.App.Status.OperationState.SyncResult != nil | ||
if !result { | ||
return false | ||
} | ||
|
||
return revisionsToCheck(RevisionsData{ | ||
Revision: au.App.Status.OperationState.SyncResult.Revision, | ||
Revisions: au.App.Status.OperationState.SyncResult.Revisions, | ||
}, fieldToCheck) | ||
} | ||
|
||
// expected to return true if fieldToCheck == nil | ||
func revisionsToCheck(obj RevisionsData, fieldToCheck *AppRevisionsFieldNames) bool { | ||
if fieldToCheck == nil { | ||
return true | ||
} | ||
if *fieldToCheck == AppRevisionFieldName { | ||
return obj.Revision != "" | ||
} | ||
|
||
if *fieldToCheck == AppRevisionsFieldName { | ||
return obj.Revisions != nil && len(obj.Revisions) > 0 | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.