@@ -271,25 +271,28 @@ func (r *ReconcileWebSphereLiberty) Reconcile(ctx context.Context, request ctrl.
271271 }
272272 if ! skipLibertyVersionChecks {
273273 libertyVersion := libertyimage .ParseLibertyVersionFromContainerImageMetadata (& isTag .Image .DockerImageMetadata )
274+ warningMessage := "Could not parse Liberty version field from ImageStream metadata; version was not found in any of the labels: " + strings .Join (libertyimage .ValidLibertyVersionLabels , ", " )
274275 if libertyVersion == "" {
275- warningMessage := "Could not parse Liberty version field from ImageStream metadata; version was not found in any of the labels: " + strings .Join (libertyimage .ValidLibertyVersionLabels , ", " )
276276 reqLogger .Info (warningMessage )
277277 instance .Status .SetReference (lutils .StatusReferenceLibertyVersion , libertyimage .NilLibertyVersion )
278278 instance .Status .SetReference (lutils .StatusReferenceLibertyVersionLastPull , fmt .Sprint (time .Now ().UTC ().Unix ()))
279279 // add a warning that displays to the user when the Liberty version couldn't be parsed
280- r .SetStatusWarnings ( append ( r . GetStatusWarnings (), oputils.StatusWarning {
280+ r .AddStatusWarning ( oputils.StatusWarning {
281281 GetCondition : func (ba common.BaseComponent ) bool {
282282 libVersion := ba .GetStatus ().GetReferences ()[lutils .StatusReferenceLibertyVersion ]
283283 return libVersion == libertyimage .NilLibertyVersion
284284 },
285285 Message : warningMessage ,
286- }))
286+ })
287287 } else if instance .Status .GetReferences ()[lutils .StatusReferenceLibertyVersion ] != libertyVersion {
288288 instance .Status .SetReference (lutils .StatusReferenceLibertyVersion , libertyVersion )
289289 if instance .Status .PulledImageReference != instance .Status .ImageReference {
290290 instance .Status .PulledImageReference = instance .Status .ImageReference
291291 instance .Status .SetReference (lutils .StatusReferenceLibertyVersionLastPull , fmt .Sprint (time .Now ().UTC ().Unix ()))
292292 }
293+ r .DeleteStatusWarning (warningMessage )
294+ } else {
295+ r .DeleteStatusWarning (warningMessage )
293296 }
294297 }
295298 versionTakenFromImageStream = true
@@ -353,29 +356,30 @@ func (r *ReconcileWebSphereLiberty) Reconcile(ctx context.Context, request ctrl.
353356 }
354357
355358 // Get liberty version if the reference is not set or if secondsSinceLastPull >= 60*imageVersionChecksRefreshIntervalMinutes
359+ failedToPullContainerMessage := "Failed to pull container image metadata; unauthorized or the image does not exist"
356360 if libertyVersion == "" || int (float64 (secondsSinceLastPull )/ 60 ) >= imageVersionChecksRefreshIntervalMinutes {
357361 pulledManifestDigest , pulledLibertyVersion , err := r .pullLibertyVersionFromManifest (reqLogger , instance , instance .Spec .ApplicationImage , image , isTagNamespace )
358362 if err != nil {
359- reqLogger .Error (err , "Failed to pull container image metadata; unauthorized or the image does not exist" )
363+ reqLogger .Error (err , failedToPullContainerMessage )
360364 instance .Status .SetReference (lutils .StatusReferenceLibertyVersion , libertyimage .NilLibertyVersion )
365+ // add a warning that displays to the user when the Liberty version couldn't be parsed
366+ r .AddStatusWarning (oputils.StatusWarning {
367+ GetCondition : func (ba common.BaseComponent ) bool {
368+ libVersion := ba .GetStatus ().GetReferences ()[lutils .StatusReferenceLibertyVersion ]
369+ return libVersion == libertyimage .NilLibertyVersion
370+ },
371+ Message : failedToPullContainerMessage ,
372+ })
361373 } else {
362374 libertyVersion = pulledLibertyVersion
363375 if pulledManifestDigest != "" {
364376 instance .Status .PulledImageReference = pulledManifestDigest
365377 }
366378 instance .Status .SetReference (lutils .StatusReferenceLibertyVersion , libertyVersion )
367379 instance .Status .SetReference (lutils .StatusReferenceLibertyVersionLastPull , fmt .Sprint (time .Now ().UTC ().Unix ()))
380+ r .DeleteStatusWarning (failedToPullContainerMessage )
368381 }
369382 }
370-
371- // add a warning that displays to the user when the Liberty version couldn't be parsed
372- r .SetStatusWarnings (append (r .GetStatusWarnings (), oputils.StatusWarning {
373- GetCondition : func (ba common.BaseComponent ) bool {
374- libVersion := ba .GetStatus ().GetReferences ()[lutils .StatusReferenceLibertyVersion ]
375- return libVersion == libertyimage .NilLibertyVersion || libVersion == ""
376- },
377- Message : "Failed to pull container image metadata; unauthorized or the image does not exist" ,
378- }))
379383 }
380384
381385 if ! skipLibertyVersionChecks {
@@ -424,13 +428,13 @@ func (r *ReconcileWebSphereLiberty) Reconcile(ctx context.Context, request ctrl.
424428 _ , passwordFound , _ := r .hasUserEncryptionKeySecret (instance , passwordEncryptionMetadata )
425429 _ , aesFound , _ := r .hasUserAESEncryptionKeySecret (instance , passwordEncryptionMetadata )
426430 if passwordFound && aesFound {
427- r .SetStatusWarnings ( append ( r . GetStatusWarnings (), oputils.StatusWarning {
431+ r .AddStatusWarning ( oputils.StatusWarning {
428432 GetCondition : func (ba common.BaseComponent ) bool {
429433 // manually delete the warning in the else blocks to avoid checking the secret every time
430434 return true
431435 },
432436 Message : cannotUseBothKeysMessage ,
433- }))
437+ })
434438 } else {
435439 r .DeleteStatusWarning (cannotUseBothKeysMessage )
436440 }
0 commit comments