@@ -112,12 +112,13 @@ type WorkflowDagExecutor interface {
112112	UpdateWorkflowRunnerStatusForDeployment (appIdentifier  * helmBean.AppIdentifier , wfr  * pipelineConfig.CdWorkflowRunner , skipReleaseNotFound  bool ) bool 
113113
114114	BuildCiArtifactRequestForWebhook (event  pipeline.ExternalCiWebhookDto ) (* bean2.CiArtifactWebhookRequest , error )
115- 	UpdateWorkflowRunnerStatusForFluxDeployment (appIdentifier  * bean8.FluxAppIdentifier , wfr  * pipelineConfig.CdWorkflowRunner , hash   string ) bool 
115+ 	UpdateWorkflowRunnerStatusForFluxDeployment (appIdentifier  * bean8.FluxAppIdentifier , wfr  * pipelineConfig.CdWorkflowRunner , pipelineOverride   * chartConfig. PipelineOverride ) bool 
116116}
117117
118118type  WorkflowDagExecutorImpl  struct  {
119119	logger                         * zap.SugaredLogger 
120120	pipelineRepository             pipelineConfig.PipelineRepository 
121+ 	pipelineOverrideRepository     chartConfig.PipelineOverrideRepository 
121122	cdWorkflowRepository           pipelineConfig.CdWorkflowRepository 
122123	ciArtifactRepository           repository.CiArtifactRepository 
123124	enforcerUtil                   rbac.EnforcerUtil 
@@ -159,6 +160,7 @@ type WorkflowDagExecutorImpl struct {
159160}
160161
161162func  NewWorkflowDagExecutorImpl (Logger  * zap.SugaredLogger , pipelineRepository  pipelineConfig.PipelineRepository ,
163+ 	pipelineOverrideRepository  chartConfig.PipelineOverrideRepository ,
162164	cdWorkflowRepository  pipelineConfig.CdWorkflowRepository ,
163165	ciArtifactRepository  repository.CiArtifactRepository ,
164166	enforcerUtil  rbac.EnforcerUtil ,
@@ -193,6 +195,7 @@ func NewWorkflowDagExecutorImpl(Logger *zap.SugaredLogger, pipelineRepository pi
193195) * WorkflowDagExecutorImpl  {
194196	wde  :=  & WorkflowDagExecutorImpl {logger : Logger ,
195197		pipelineRepository :            pipelineRepository ,
198+ 		pipelineOverrideRepository :    pipelineOverrideRepository ,
196199		cdWorkflowRepository :          cdWorkflowRepository ,
197200		ciArtifactRepository :          ciArtifactRepository ,
198201		enforcerUtil :                  enforcerUtil ,
@@ -1299,7 +1302,8 @@ func (impl *WorkflowDagExecutorImpl) BuildCiArtifactRequestForWebhook(event pipe
12991302	return  request , nil 
13001303}
13011304
1302- func  (impl  * WorkflowDagExecutorImpl ) UpdateWorkflowRunnerStatusForFluxDeployment (appIdentifier  * bean8.FluxAppIdentifier , wfr  * pipelineConfig.CdWorkflowRunner , hash  string ) bool  {
1305+ func  (impl  * WorkflowDagExecutorImpl ) UpdateWorkflowRunnerStatusForFluxDeployment (appIdentifier  * bean8.FluxAppIdentifier , wfr  * pipelineConfig.CdWorkflowRunner ,
1306+ 	pipelineOverride  * chartConfig.PipelineOverride ) bool  {
13031307	fluxAppDetail , err  :=  impl .fluxApplicationService .GetFluxAppDetail (context .Background (), appIdentifier )
13041308	if  err  !=  nil  {
13051309		impl .logger .Errorw ("error in getting helm app release status" , "appIdentifier" , appIdentifier , "err" , err )
@@ -1310,7 +1314,7 @@ func (impl *WorkflowDagExecutorImpl) UpdateWorkflowRunnerStatusForFluxDeployment
13101314		wfr .FinishedOn  =  time .Now ()
13111315		return  true 
13121316	}
1313- 	if  ! matchShortHash (fluxAppDetail .LastObservedVersion , hash ) {
1317+ 	if  ! impl . checkIfFluxPipelineEventIsValid (fluxAppDetail .LastObservedVersion , pipelineOverride ) {
13141318		return  false 
13151319	}
13161320	wfr .FinishedOn  =  time .Now ()
@@ -1331,24 +1335,39 @@ func (impl *WorkflowDagExecutorImpl) UpdateWorkflowRunnerStatusForFluxDeployment
13311335	return  true 
13321336}
13331337
1334- // matchShortHash compares the short Git hash embedded in the version string 
1338+ func  (impl  * WorkflowDagExecutorImpl ) checkIfFluxPipelineEventIsValid (lastObservedVersion  string , pipelineOverride  * chartConfig.PipelineOverride ) bool  {
1339+ 	gitHash  :=  getShortHash (lastObservedVersion )
1340+ 	if  ! strings .HasPrefix (pipelineOverride .GitHash , gitHash ) {
1341+ 		pipelineOverrideByHash , err  :=  impl .pipelineOverrideRepository .FindByPipelineLikeTriggerGitHash (gitHash )
1342+ 		if  err  !=  nil  {
1343+ 			impl .logger .Errorw ("error on update application status" , "gitHash" , gitHash , "err" , err )
1344+ 			return  false 
1345+ 		}
1346+ 		if  pipelineOverrideByHash  ==  nil  ||  pipelineOverrideByHash .CommitTime .Before (pipelineOverride .CommitTime ) {
1347+ 			// we have received trigger hash which is committed before this apps actual gitHash stored by us 
1348+ 			// this means that the hash stored by us will be synced later, so we will drop this event 
1349+ 			return  false 
1350+ 		}
1351+ 	}
1352+ 	return  true 
1353+ }
1354+ 
1355+ // getShortHash gets the short Git hash embedded in the version string 
13351356// with the beginning of the full Git commit hash. 
13361357// 
13371358// version: expected format like "4.22.1+<shortHash>.<buildNumber>" 
13381359// fullHash: expected to be a full 40-character Git commit SHA 
1339- // 
1340- // Returns true if the short hash is a prefix of the full hash. 
1341- func  matchShortHash (version , fullHash  string ) bool  {
1360+ func  getShortHash (version  string ) string  {
13421361	// Split version string at '+' to extract metadata 
13431362	parts  :=  strings .Split (version , "+" )
13441363	if  len (parts ) <  2  {
1345- 		return  false  // No metadata found 
1364+ 		return  ""  // No metadata found 
13461365	}
13471366
13481367	// Metadata might look like "2b6c6b2.2" → short hash + build number 
13491368	metaParts  :=  strings .Split (parts [1 ], "." )
13501369	shortHash  :=  metaParts [0 ] // Take only the short hash before the dot 
13511370
13521371	// Compare short hash with prefix of full hash 
1353- 	return  strings . HasPrefix ( fullHash ,  shortHash ) 
1372+ 	return  shortHash 
13541373}
0 commit comments