diff --git a/pkg/splunk/common/util.go b/pkg/splunk/common/util.go index 2515b4c79..e08aa7631 100644 --- a/pkg/splunk/common/util.go +++ b/pkg/splunk/common/util.go @@ -86,6 +86,17 @@ func ParseResourceQuantity(str string, useIfEmpty string) (resource.Quantity, er return result, nil } +// GetServiceURI returns the fully qualified domain name for a Kubernetes service as URI. +func GetServiceURI(namespace string, name string) string { + var scheme string = "https" + if os.Getenv("SPLUNKD_SSL_ENABLE") == "false" { + scheme = "http" + } + return fmt.Sprintf( + "%s://%s:8089", scheme, GetServiceFQDN(namespace, name), + ) +} + // GetServiceFQDN returns the fully qualified domain name for a Kubernetes service. func GetServiceFQDN(namespace string, name string) string { clusterDomain := os.Getenv("CLUSTER_DOMAIN") diff --git a/pkg/splunk/common/util_test.go b/pkg/splunk/common/util_test.go index c92d00d86..a6927871b 100644 --- a/pkg/splunk/common/util_test.go +++ b/pkg/splunk/common/util_test.go @@ -1013,3 +1013,19 @@ func TestSortAndCompareSlices(t *testing.T) { t.Errorf("Expect 2 slices to be equal - (%v, %v)", a, b) } } + +func TestGetServiceURI(t *testing.T) { + test := func(namespace string, name string, want string) { + got := GetServiceURI(namespace, name) + if got != want { + t.Errorf("GetServiceURI() = %s; want %s", got, want) + } + } + + os.Setenv("SPLUNKD_SSL_ENABLE", "true") + test("test", "t1", "https://t1.test.svc.cluster.local:8089") + + os.Setenv("CLUSTER_DOMAIN", "cluster.local") + os.Setenv("SPLUNKD_SSL_ENABLE", "false") + test("test", "t2", "http://t2.test.svc.cluster.local:8089") +} diff --git a/pkg/splunk/enterprise/configuration.go b/pkg/splunk/enterprise/configuration.go index 7987a2ea1..354067dc7 100644 --- a/pkg/splunk/enterprise/configuration.go +++ b/pkg/splunk/enterprise/configuration.go @@ -910,6 +910,22 @@ func updateSplunkPodTemplateWithConfig(ctx context.Context, client splcommon.Con {Name: livenessProbeDriverPathEnv, Value: GetLivenessDriverFilePath()}, } + if os.Getenv("SPLUNKD_SSL_ENABLE") == "false" { + env = append(env, corev1.EnvVar{ + Name: "SPLUNK_CERT_PREFIX", + Value: "http", + }) + env = append(env, corev1.EnvVar{ + Name: "SPLUNKD_SSL_ENABLE", + Value: "false", + }) + } + if os.Getenv("SPLUNK_HEC_SSL") == "false" { + env = append(env, corev1.EnvVar{ + Name: "SPLUNK_HEC_SSL", + Value: "false", + }) + } // update variables for licensing, if configured if spec.LicenseURL != "" { env = append(env, corev1.EnvVar{