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

Add sysprop driven XML tags to default solr.xml #636

Merged
merged 7 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 13 additions & 11 deletions controllers/util/solr_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ const (

DefaultStatefulSetPodManagementPolicy = appsv1.ParallelPodManagement

DistLibs = "/opt/solr/dist"
ContribLibs = "/opt/solr/contrib/%s/lib"
DistLibs = "/opt/solr/dist"
ContribLibs = "/opt/solr/contrib/%s/lib"
SysPropLibPlaceholder = "${solr.sharedLib:}"
)

var (
Expand Down Expand Up @@ -786,6 +787,8 @@ const DefaultSolrXML = `<?xml version="1.0" encoding="UTF-8" ?>
<int name="connTimeout">${connTimeout:60000}</int>
</shardHandlerFactory>
<int name="maxBooleanClauses">${solr.max.booleanClauses:1024}</int>
<str name="allowPaths">${solr.allowPaths:}</str>
<metrics enabled="${metricsEnabled:true}"/>
%s
</solr>
`
Expand Down Expand Up @@ -831,6 +834,9 @@ func GenerateSolrXMLString(backupSection string, solrModules []string, additiona
func GenerateAdditionalLibXMLPart(solrModules []string, additionalLibs []string) string {
libs := make(map[string]bool, 0)

// Placeholder for users to specify libs via sysprop
libs[SysPropLibPlaceholder] = true

// Add all module library locations
if len(solrModules) > 0 {
libs[DistLibs] = true
Expand All @@ -844,16 +850,12 @@ func GenerateAdditionalLibXMLPart(solrModules []string, additionalLibs []string)
libs[libPath] = true
}

libXml := ""
if len(libs) > 0 {
libList := make([]string, 0)
for lib := range libs {
libList = append(libList, lib)
}
sort.Strings(libList)
libXml = fmt.Sprintf("<str name=\"sharedLib\">%s</str>", strings.Join(libList, ","))
libList := make([]string, 0)
for lib := range libs {
libList = append(libList, lib)
}
return libXml
sort.Strings(libList)
return fmt.Sprintf("<str name=\"sharedLib\">%s</str>", strings.Join(libList, ","))
}

func getAppProtocol(solrCloud *solr.SolrCloud) *string {
Expand Down
30 changes: 17 additions & 13 deletions controllers/util/solr_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,29 @@ func TestGeneratedGcsRepositoryXmlSkipsCredentialIfUnset(t *testing.T) {
}

func TestGenerateAdditionalLibXMLPart(t *testing.T) {
// No specified libs
xmlString := GenerateAdditionalLibXMLPart([]string{}, []string{})
assert.EqualValuesf(t, xmlString, "<str name=\"sharedLib\">${solr.sharedLib:}</str>", "Wrong sharedLib xml for no specified libs")

// Just 1 repeated solr module
xmlString := GenerateAdditionalLibXMLPart([]string{"gcs-repository", "gcs-repository"}, []string{})
assert.EqualValuesf(t, xmlString, "<str name=\"sharedLib\">/opt/solr/contrib/gcs-repository/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for just 1 repeated solr module")
xmlString = GenerateAdditionalLibXMLPart([]string{"gcs-repository", "gcs-repository"}, []string{})
assert.EqualValuesf(t, xmlString, "<str name=\"sharedLib\">${solr.sharedLib:},/opt/solr/contrib/gcs-repository/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for just 1 repeated solr module")

// Just 2 different solr modules
xmlString = GenerateAdditionalLibXMLPart([]string{"gcs-repository", "analytics"}, []string{})
assert.EqualValuesf(t, xmlString, "<str name=\"sharedLib\">/opt/solr/contrib/analytics/lib,/opt/solr/contrib/gcs-repository/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for just 2 different solr modules")
assert.EqualValuesf(t, xmlString, "<str name=\"sharedLib\">${solr.sharedLib:},/opt/solr/contrib/analytics/lib,/opt/solr/contrib/gcs-repository/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for just 2 different solr modules")

// Just 2 repeated libs
xmlString = GenerateAdditionalLibXMLPart([]string{}, []string{"/ext/lib", "/ext/lib"})
assert.EqualValuesf(t, xmlString, "<str name=\"sharedLib\">/ext/lib</str>", "Wrong sharedLib xml for just 1 repeated additional lib")
assert.EqualValuesf(t, xmlString, "<str name=\"sharedLib\">${solr.sharedLib:},/ext/lib</str>", "Wrong sharedLib xml for just 1 repeated additional lib")

// Just 2 different libs
xmlString = GenerateAdditionalLibXMLPart([]string{}, []string{"/ext/lib2", "/ext/lib1"})
assert.EqualValuesf(t, xmlString, "<str name=\"sharedLib\">/ext/lib1,/ext/lib2</str>", "Wrong sharedLib xml for just 2 different additional libs")
assert.EqualValuesf(t, xmlString, "<str name=\"sharedLib\">${solr.sharedLib:},/ext/lib1,/ext/lib2</str>", "Wrong sharedLib xml for just 2 different additional libs")

// Combination of everything
xmlString = GenerateAdditionalLibXMLPart([]string{"gcs-repository", "analytics", "analytics"}, []string{"/ext/lib2", "/ext/lib2", "/ext/lib1"})
assert.EqualValuesf(t, xmlString, "<str name=\"sharedLib\">/ext/lib1,/ext/lib2,/opt/solr/contrib/analytics/lib,/opt/solr/contrib/gcs-repository/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for mix of additional libs and solr modules")
assert.EqualValuesf(t, xmlString, "<str name=\"sharedLib\">${solr.sharedLib:},/ext/lib1,/ext/lib2,/opt/solr/contrib/analytics/lib,/opt/solr/contrib/gcs-repository/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for mix of additional libs and solr modules")
}

func TestGenerateSolrXMLStringForCloud(t *testing.T) {
Expand All @@ -151,7 +155,7 @@ func TestGenerateSolrXMLStringForCloud(t *testing.T) {
SolrModules: []string{"ltr", "analytics"},
},
}
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">/ext/lib1,/ext/lib2,/opt/solr/contrib/analytics/lib,/opt/solr/contrib/gcs-repository/lib,/opt/solr/contrib/ltr/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for a cloud with a backupRepo, additionalLibs and solrModules")
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">${solr.sharedLib:},/ext/lib1,/ext/lib2,/opt/solr/contrib/analytics/lib,/opt/solr/contrib/gcs-repository/lib,/opt/solr/contrib/ltr/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for a cloud with a backupRepo, additionalLibs and solrModules")

// Just SolrModules and AdditionalLibs
solrCloud = &solr.SolrCloud{
Expand All @@ -160,7 +164,7 @@ func TestGenerateSolrXMLStringForCloud(t *testing.T) {
SolrModules: []string{"ltr", "analytics"},
},
}
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">/ext/lib1,/ext/lib2,/opt/solr/contrib/analytics/lib,/opt/solr/contrib/ltr/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for a cloud with additionalLibs and solrModules")
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">${solr.sharedLib:},/ext/lib1,/ext/lib2,/opt/solr/contrib/analytics/lib,/opt/solr/contrib/ltr/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for a cloud with additionalLibs and solrModules")

// Just SolrModules and Backups
solrCloud = &solr.SolrCloud{
Expand All @@ -174,7 +178,7 @@ func TestGenerateSolrXMLStringForCloud(t *testing.T) {
SolrModules: []string{"ltr", "analytics"},
},
}
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">/opt/solr/contrib/analytics/lib,/opt/solr/contrib/gcs-repository/lib,/opt/solr/contrib/ltr/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for a cloud with a backupRepo and solrModules")
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">${solr.sharedLib:},/opt/solr/contrib/analytics/lib,/opt/solr/contrib/gcs-repository/lib,/opt/solr/contrib/ltr/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for a cloud with a backupRepo and solrModules")

// Just AdditionalLibs and Backups
solrCloud = &solr.SolrCloud{
Expand All @@ -188,15 +192,15 @@ func TestGenerateSolrXMLStringForCloud(t *testing.T) {
AdditionalLibs: []string{"/ext/lib2", "/ext/lib1"},
},
}
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">/ext/lib1,/ext/lib2,/opt/solr/contrib/gcs-repository/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for a cloud with a backupRepo and additionalLibs")
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">${solr.sharedLib:},/ext/lib1,/ext/lib2,/opt/solr/contrib/gcs-repository/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for a cloud with a backupRepo and additionalLibs")

// Just SolrModules
solrCloud = &solr.SolrCloud{
Spec: solr.SolrCloudSpec{
SolrModules: []string{"ltr", "analytics"},
},
}
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">/opt/solr/contrib/analytics/lib,/opt/solr/contrib/ltr/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for a cloud with just solrModules")
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">${solr.sharedLib:},/opt/solr/contrib/analytics/lib,/opt/solr/contrib/ltr/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for a cloud with just solrModules")

// Just Backups
solrCloud = &solr.SolrCloud{
Expand All @@ -209,13 +213,13 @@ func TestGenerateSolrXMLStringForCloud(t *testing.T) {
},
},
}
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">/opt/solr/contrib/gcs-repository/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for a cloud with just a backupRepo")
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">${solr.sharedLib:},/opt/solr/contrib/gcs-repository/lib,/opt/solr/dist</str>", "Wrong sharedLib xml for a cloud with just a backupRepo")

// Just AdditionalLibs
solrCloud = &solr.SolrCloud{
Spec: solr.SolrCloudSpec{
AdditionalLibs: []string{"/ext/lib2", "/ext/lib1"},
},
}
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">/ext/lib1,/ext/lib2</str>", "Wrong sharedLib xml for a cloud with a just additionalLibs")
assert.Containsf(t, GenerateSolrXMLStringForCloud(solrCloud), "<str name=\"sharedLib\">${solr.sharedLib:},/ext/lib1,/ext/lib2</str>", "Wrong sharedLib xml for a cloud with a just additionalLibs")
}
7 changes: 7 additions & 0 deletions helm/solr/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ annotations:
url: https://github.com/apache/solr-operator/issues/630
- name: Github PR
url: https://github.com/apache/solr-operator/pull/631
- kind: changed
description: The default solr.xml now includes the necessary boilerplate to specify additional `sharedLib` and `allowPath` values (via the `solr.sharedLib` and `solr.allowPaths` system properties respectively). The `metricsEnabled` system property can also be used to toggle Solr's metrics processing (defaults to `true`).
links:
- name: Github Issue
url: https://github.com/apache/solr-operator/issues/635
- name: Github PR
url: https://github.com/apache/solr-operator/pull/636
artifacthub.io/containsSecurityUpdates: "false"
artifacthub.io/recommendations: |
- url: https://artifacthub.io/packages/helm/apache-solr/solr-operator
Expand Down
Loading