Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set LTPA Job to match wlapp leader's config #580

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion controllers/ltpa_keys_sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,17 @@ func (r *ReconcileWebSphereLiberty) generateLTPAKeys(instance *wlv1.WebSphereLib
if err != nil {
return fmt.Errorf("Failed to create Job " + generateLTPAKeysJob.Name), ""
}
} else if err != nil {
} else if err == nil {
// If the LTPA Secret is not yet created (LTPA Job has not successfully completed)
// and the LTPA Job's configuration is outdated, retry LTPA generation with the new configuration
if lutils.IsLTPAJobConfigurationOutdated(generateLTPAKeysJob, instance) {
// Delete the Job request to restart the entire LTPA generation process (i.e. reloading the script, ltpa.xml, and Job)
err = r.DeleteResource(ltpaJobRequest)
if err != nil {
return err, ltpaSecret.Name
}
}
} else {
return fmt.Errorf("Failed to get Job " + generateLTPAKeysJob.Name), ""
}
}
Expand Down
29 changes: 29 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"context"
"fmt"
"reflect"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -661,6 +662,34 @@ func CustomizeLTPAServerXML(xmlSecret *corev1.Secret, la *wlv1.WebSphereLibertyA
xmlSecret.StringData[ltpaXMLFileName] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<server>\n <ltpa keysFileName=\"" + keysFileName + "/" + ltpaKeysFileName + "\" keysPassword=\"" + encryptedPassword + "\" />\n</server>"
}

// Returns true if the WebSphereApplication leader's state has changed, causing existing LTPA Jobs to need a configuration update, otherwise return false
func IsLTPAJobConfigurationOutdated(job *v1.Job, appLeaderInstance *wlv1.WebSphereLibertyApplication) bool {
// The Job contains the leader's pull secret
if appLeaderInstance.GetPullSecret() != nil && *appLeaderInstance.GetPullSecret() != "" {
ltpaJobHasLeaderPullSecret := false
for _, objectReference := range job.Spec.Template.Spec.ImagePullSecrets {
if objectReference.Name == *appLeaderInstance.GetPullSecret() {
ltpaJobHasLeaderPullSecret = true
}
}
if !ltpaJobHasLeaderPullSecret {
return true
}
}
if len(job.Spec.Template.Spec.Containers) != 1 {
return true
}
// The Job matches the leader's pull policy
if job.Spec.Template.Spec.Containers[0].ImagePullPolicy != *appLeaderInstance.GetPullPolicy() {
return true
}
// The Job matches the leader's security context
if !reflect.DeepEqual(*job.Spec.Template.Spec.Containers[0].SecurityContext, *rcoutils.GetSecurityContext(appLeaderInstance)) {
return true
}
return false
}

func CustomizeLTPAJob(job *v1.Job, la *wlv1.WebSphereLibertyApplication, ltpaSecretName string, serviceAccountName string, ltpaScriptName string) {
encodingType := "aes" // the password encoding type for securityUtility (one of "xor", "aes", or "hash")
job.Spec.Template.ObjectMeta.Name = "liberty"
Expand Down