Skip to content

Commit f6ba0e5

Browse files
authored
Use AddStatusWarning to better track existing status warnings (#839)
* Use AddStatusWarning to better track existing status warnings * Pull OLO/RCO@warning-status changes * Add better warning message during encode failure * Remove errors.Wrapf call * Remove libVersion == nil check * Pull RCO/OLO@main changes
1 parent aed4a44 commit f6ba0e5

4 files changed

Lines changed: 32 additions & 23 deletions

File tree

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module github.com/WASdev/websphere-liberty-operator
33
go 1.26
44

55
require (
6-
github.com/OpenLiberty/open-liberty-operator v0.8.1-0.20260304151221-cb668161f163
7-
github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20260304144046-b4479b8e8f57
6+
github.com/OpenLiberty/open-liberty-operator v0.8.1-0.20260304214311-b03bfd05e3e0
7+
github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20260304200410-a271abcdf23b
88
github.com/cert-manager/cert-manager v1.16.5
99
github.com/go-logr/logr v1.4.3
1010
github.com/openshift/api v0.0.0-20250710004639-926605d3338b

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25
22
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
33
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
44
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
5-
github.com/OpenLiberty/open-liberty-operator v0.8.1-0.20260304151221-cb668161f163 h1:Puh+5nAgi8HdBkN0Ewy6+5d01RXXB8t4L9H7+WwRbQw=
6-
github.com/OpenLiberty/open-liberty-operator v0.8.1-0.20260304151221-cb668161f163/go.mod h1:sWNyqatxrix8R8h7E2FkTdKyVL8RsKRHPtb2MfT1taM=
5+
github.com/OpenLiberty/open-liberty-operator v0.8.1-0.20260304214311-b03bfd05e3e0 h1:P7rD3mtUI4ApT4hfhfm7DDJlWrkB/gQsWvHhkWmYW8M=
6+
github.com/OpenLiberty/open-liberty-operator v0.8.1-0.20260304214311-b03bfd05e3e0/go.mod h1:7lcV0zAepekmdyDxA1tUcn8Ynnmbwsmgrwe9yJS9TS4=
77
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
88
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
9-
github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20260304144046-b4479b8e8f57 h1:pbNmWv3eJfL7pNVA9yspXjhRa4xVAPFxCuh2M4K/S1I=
10-
github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20260304144046-b4479b8e8f57/go.mod h1:+Ye7LS0VUDoQZvyEJfMSBkhftEAGfk8RUlMTp8RAaIY=
9+
github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20260304200410-a271abcdf23b h1:WRs38CYvXWM/CfMMu71iOcopuDJVPEyAE5XToJTscLg=
10+
github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20260304200410-a271abcdf23b/go.mod h1:+Ye7LS0VUDoQZvyEJfMSBkhftEAGfk8RUlMTp8RAaIY=
1111
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
1212
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
1313
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=

internal/controller/ltpa_keys_sharing.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
wlv1 "github.com/WASdev/websphere-liberty-operator/api/v1"
3030
lutils "github.com/WASdev/websphere-liberty-operator/utils"
3131
"github.com/application-stacks/runtime-component-operator/common"
32-
"github.com/pkg/errors"
3332
corev1 "k8s.io/api/core/v1"
3433
kerrors "k8s.io/apimachinery/pkg/api/errors"
3534
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -469,7 +468,13 @@ func (r *ReconcileWebSphereLiberty) generateLTPAConfig(instance *wlv1.WebSphereL
469468

470469
encodedPassword, err := encode(password, currentPasswordEncryptionKey, currentAESEncryptionKey, common.LoadFromConfig(common.Config, lutils.OpConfigPasswordEncodingType))
471470
if err != nil {
472-
return "", errors.Wrapf(err, "failed to encode the password encryption key")
471+
var encodeErrorMessage string
472+
if usingAES {
473+
encodeErrorMessage = "failed to encode using the aes encryption key, verify the provided key in Secret 'wlp-aes-encryption-key' is a valid base64 encoded AES-256 key"
474+
} else {
475+
encodeErrorMessage = "failed to encode using the password encryption key"
476+
}
477+
return "", fmt.Errorf("%s: %+v", encodeErrorMessage, err)
473478
}
474479

475480
ltpaConfigSecret.Labels[lutils.ResourcePathIndexLabel] = ltpaConfigMetadata.PathIndex

internal/controller/webspherelibertyapplication_controller.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)