From c1581ea26bc03c93078cf1fdcdc9b7e15db81e04 Mon Sep 17 00:00:00 2001
From: Ming Wang <miwan@redhat.com>
Date: Tue, 30 Jul 2024 15:04:44 -0400
Subject: [PATCH] tmp

---
 ...yostat-operator.clusterserviceversion.yaml |  2 +-
 .../resource_definitions.go                   | 15 +++---------
 internal/controllers/reconciler_test.go       | 23 ++----------------
 internal/test/resources.go                    | 24 ++++---------------
 4 files changed, 10 insertions(+), 54 deletions(-)

diff --git a/bundle/manifests/cryostat-operator.clusterserviceversion.yaml b/bundle/manifests/cryostat-operator.clusterserviceversion.yaml
index b0dbe3fa1..8dd09edc0 100644
--- a/bundle/manifests/cryostat-operator.clusterserviceversion.yaml
+++ b/bundle/manifests/cryostat-operator.clusterserviceversion.yaml
@@ -35,7 +35,7 @@ metadata:
     capabilities: Seamless Upgrades
     categories: Monitoring, Developer Tools
     containerImage: quay.io/cryostat/cryostat-operator:4.0.0-dev
-    createdAt: "2024-07-29T20:48:29Z"
+    createdAt: "2024-07-30T14:31:04Z"
     description: JVM monitoring and profiling tool
     operatorframework.io/initialization-resource: |-
       {
diff --git a/internal/controllers/common/resource_definitions/resource_definitions.go b/internal/controllers/common/resource_definitions/resource_definitions.go
index 37fdd770d..67f61e72f 100644
--- a/internal/controllers/common/resource_definitions/resource_definitions.go
+++ b/internal/controllers/common/resource_definitions/resource_definitions.go
@@ -929,7 +929,7 @@ func NewOpenShiftAuthProxyContainer(cr *model.CryostatInstance, specs *ServiceSp
 		"--pass-basic-auth=false",
 		fmt.Sprintf("--upstream=http://localhost:%d/", constants.CryostatHTTPContainerPort),
 		fmt.Sprintf("--upstream=http://localhost:%d/grafana/", constants.GrafanaContainerPort),
-		fmt.Sprintf("--upstream=http://localhost:%d/storage/", constants.StorageContainerPort),
+		// fmt.Sprintf("--upstream=http://localhost:%d/storage/", constants.StorageContainerPort),
 		fmt.Sprintf("--openshift-service-account=%s", cr.Name),
 		"--proxy-websockets=true",
 		"--proxy-prefix=/oauth2",
@@ -1215,7 +1215,7 @@ func NewCoreContainer(cr *model.CryostatInstance, specs *ServiceSpecs, imageTag
 		},
 		{
 			Name:  "QUARKUS_DATASOURCE_JDBC_URL",
-			Value: fmt.Sprintf("jdbc:postgresql://%s-database:5432/cryostat", cr.Name),
+			Value: fmt.Sprintf("jdbc:postgresql://%s-database.%s.svc.cluster.local:5432/cryostat", cr.Name, cr.InstallNamespace),
 		},
 		{
 			Name:  "STORAGE_BUCKETS_ARCHIVE_NAME",
@@ -1223,7 +1223,7 @@ func NewCoreContainer(cr *model.CryostatInstance, specs *ServiceSpecs, imageTag
 		},
 		{
 			Name:  "QUARKUS_S3_ENDPOINT_OVERRIDE",
-			Value: fmt.Sprintf("http://%s-storage:8333", cr.Name),
+			Value: fmt.Sprintf("http://%s-storage.%s.svc.cluster.local:8333", cr.Name, cr.InstallNamespace),
 		},
 		{
 			Name:  "QUARKUS_S3_PATH_STYLE_ACCESS",
@@ -1328,15 +1328,6 @@ func NewCoreContainer(cr *model.CryostatInstance, specs *ServiceSpecs, imageTag
 		envs = append(envs, reportsEnvs...)
 	}
 
-	envs = append(envs, corev1.EnvVar{
-		Name:  "CRYOSTAT_SERVICES_DATABASE_URL",
-		Value: specs.DatabaseURL.String(),
-	})
-	envs = append(envs, corev1.EnvVar{
-		Name:  "CRYOSTAT_SERVICES_STORAGE_URL",
-		Value: specs.StorageURL.String(),
-	})
-
 	// Define INSIGHTS_PROXY URL if Insights integration is enabled
 	if specs.InsightsURL != nil {
 		insightsEnvs := []corev1.EnvVar{
diff --git a/internal/controllers/reconciler_test.go b/internal/controllers/reconciler_test.go
index f819aa0b8..81b7e6bf9 100644
--- a/internal/controllers/reconciler_test.go
+++ b/internal/controllers/reconciler_test.go
@@ -2680,22 +2680,12 @@ func (t *cryostatTestInput) checkMainPodTemplate(deployment *appsv1.Deployment,
 	// Check that the networking environment variables are set correctly
 	coreContainer := template.Spec.Containers[0]
 	reportPort := int32(10000)
-	databasePort := int32(5432)
-	storagePort := int32(8333)
 	if cr.Spec.ServiceOptions != nil {
 		if cr.Spec.ServiceOptions.ReportsConfig != nil && cr.Spec.ServiceOptions.ReportsConfig.HTTPPort != nil {
 			reportPort = *cr.Spec.ServiceOptions.ReportsConfig.HTTPPort
 		}
-		if cr.Spec.ServiceOptions.DatabaseConfig != nil && cr.Spec.ServiceOptions.DatabaseConfig.HTTPPort != nil {
-			databasePort = *cr.Spec.ServiceOptions.DatabaseConfig.HTTPPort
-		}
-		if cr.Spec.ServiceOptions.StorageConfig != nil && cr.Spec.ServiceOptions.StorageConfig.HTTPPort != nil {
-			storagePort = *cr.Spec.ServiceOptions.StorageConfig.HTTPPort
-		}
 	}
 	var reportsUrl string
-	var databaseUrl string
-	var storageUrl string
 	if t.ReportReplicas == 0 {
 		reportsUrl = ""
 	} else if t.TLS {
@@ -2703,13 +2693,6 @@ func (t *cryostatTestInput) checkMainPodTemplate(deployment *appsv1.Deployment,
 	} else {
 		reportsUrl = fmt.Sprintf("http://%s-reports:%d", t.Name, reportPort)
 	}
-	if t.TLS {
-		databaseUrl = fmt.Sprintf("https://%s-database:%d", t.Name, databasePort)
-		storageUrl = fmt.Sprintf("https://%s-storage:%d", t.Name, storagePort)
-	} else {
-		databaseUrl = fmt.Sprintf("http://%s-database:%d", t.Name, databasePort)
-		storageUrl = fmt.Sprintf("http://%s-storage:%d", t.Name, storagePort)
-	}
 	ingress := !t.OpenShift &&
 		cr.Spec.NetworkOptions != nil && cr.Spec.NetworkOptions.CoreConfig != nil && cr.Spec.NetworkOptions.CoreConfig.IngressSpec != nil
 	emptyDir := cr.Spec.StorageOptions != nil && cr.Spec.StorageOptions.EmptyDir != nil && cr.Spec.StorageOptions.EmptyDir.Enabled
@@ -2722,7 +2705,7 @@ func (t *cryostatTestInput) checkMainPodTemplate(deployment *appsv1.Deployment,
 		cr.Spec.TargetDiscoveryOptions.DisableBuiltInPortNumbers
 	dbSecretProvided := cr.Spec.DatabaseOptions != nil && cr.Spec.DatabaseOptions.SecretName != nil
 
-	t.checkCoreContainer(&coreContainer, ingress, reportsUrl, databaseUrl, storageUrl,
+	t.checkCoreContainer(&coreContainer, ingress, reportsUrl,
 		emptyDir,
 		hasPortConfig,
 		builtInDiscoveryDisabled,
@@ -2978,8 +2961,6 @@ func (t *cryostatTestInput) checkDeploymentHasTemplates() {
 
 func (t *cryostatTestInput) checkCoreContainer(container *corev1.Container, ingress bool,
 	reportsUrl string,
-	databaseUrl string,
-	storageUrl string,
 	emptyDir bool,
 	hasPortConfig bool, builtInDiscoveryDisabled bool, builtInPortConfigDisabled bool,
 	dbSecretProvided bool,
@@ -2992,7 +2973,7 @@ func (t *cryostatTestInput) checkCoreContainer(container *corev1.Container, ingr
 		Expect(container.Image).To(Equal(*t.EnvCoreImageTag))
 	}
 	Expect(container.Ports).To(ConsistOf(t.NewCorePorts()))
-	Expect(container.Env).To(ConsistOf(t.NewCoreEnvironmentVariables(reportsUrl, databaseUrl, storageUrl, ingress, emptyDir, hasPortConfig, builtInDiscoveryDisabled, builtInPortConfigDisabled, dbSecretProvided)))
+	Expect(container.Env).To(ConsistOf(t.NewCoreEnvironmentVariables(reportsUrl, ingress, emptyDir, hasPortConfig, builtInDiscoveryDisabled, builtInPortConfigDisabled, dbSecretProvided)))
 	Expect(container.EnvFrom).To(ConsistOf(t.NewCoreEnvFromSource()))
 	Expect(container.VolumeMounts).To(ConsistOf(t.NewCoreVolumeMounts()))
 	Expect(container.LivenessProbe).To(Equal(t.NewCoreLivenessProbe()))
diff --git a/internal/test/resources.go b/internal/test/resources.go
index d3a37e97f..f051364c5 100644
--- a/internal/test/resources.go
+++ b/internal/test/resources.go
@@ -1352,7 +1352,7 @@ func (r *TestResources) NewAuthProxyPorts() []corev1.ContainerPort {
 	}
 }
 
-func (r *TestResources) NewCoreEnvironmentVariables(reportsUrl string, databaseUrl string, storageUrl string, ingress bool,
+func (r *TestResources) NewCoreEnvironmentVariables(reportsUrl string, ingress bool,
 	emptyDir bool, hasPortConfig bool, builtInDiscoveryDisabled bool, builtInPortConfigDisabled bool, dbSecretProvided bool) []corev1.EnvVar {
 	envs := []corev1.EnvVar{
 		{
@@ -1389,7 +1389,7 @@ func (r *TestResources) NewCoreEnvironmentVariables(reportsUrl string, databaseU
 		},
 		{
 			Name:  "QUARKUS_DATASOURCE_JDBC_URL",
-			Value: fmt.Sprintf("jdbc:postgresql://%s-database:5432/cryostat", r.Name),
+			Value: fmt.Sprintf("jdbc:postgresql://%s-database.%s.svc.cluster.local:5432/cryostat", r.Name, r.Namespace),
 		},
 		{
 			Name:  "STORAGE_BUCKETS_ARCHIVE_NAME",
@@ -1397,7 +1397,7 @@ func (r *TestResources) NewCoreEnvironmentVariables(reportsUrl string, databaseU
 		},
 		{
 			Name:  "QUARKUS_S3_ENDPOINT_OVERRIDE",
-			Value: fmt.Sprintf("http://%s-storage:8333", r.Name),
+			Value: fmt.Sprintf("http://%s-storage.%s.svc.cluster.local:8333", r.Name, r.Namespace),
 		},
 		{
 			Name:  "QUARKUS_S3_PATH_STYLE_ACCESS",
@@ -1501,22 +1501,6 @@ func (r *TestResources) NewCoreEnvironmentVariables(reportsUrl string, databaseU
 			})
 	}
 
-	if databaseUrl != "" {
-		envs = append(envs,
-			corev1.EnvVar{
-				Name:  "CRYOSTAT_SERVICES_DATABASE_URL",
-				Value: databaseUrl,
-			})
-	}
-
-	if storageUrl != "" {
-		envs = append(envs,
-			corev1.EnvVar{
-				Name:  "CRYOSTAT_SERVICES_STORAGE_URL",
-				Value: storageUrl,
-			})
-	}
-
 	if len(r.InsightsURL) > 0 {
 		envs = append(envs,
 			corev1.EnvVar{
@@ -1904,7 +1888,7 @@ func (r *TestResources) NewAuthProxyArguments(authOptions *operatorv1beta2.Autho
 		"--pass-basic-auth=false",
 		"--upstream=http://localhost:8181/",
 		"--upstream=http://localhost:3000/grafana/",
-		"--upstream=http://localhost:8333/storage/",
+		// "--upstream=http://localhost:8333/storage/",
 		fmt.Sprintf("--openshift-service-account=%s", r.Name),
 		"--proxy-websockets=true",
 		"--proxy-prefix=/oauth2",