From a55202198f41debba71c521817c56162ebc1fce5 Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Mon, 12 Feb 2024 11:38:37 -0800 Subject: [PATCH] feat(discovery): options to configure discovery port names and numbers (#715) Signed-off-by: Thuan Vo --- api/v1beta1/cryostat_types.go | 18 +++++- api/v1beta1/zz_generated.deepcopy.go | 12 +++- ...yostat-operator.clusterserviceversion.yaml | 54 +++++++++++++++- ...operator.cryostat.io_clustercryostats.yaml | 23 ++++++- .../operator.cryostat.io_cryostats.yaml | 23 ++++++- ...operator.cryostat.io_clustercryostats.yaml | 23 ++++++- .../bases/operator.cryostat.io_cryostats.yaml | 23 ++++++- ...yostat-operator.clusterserviceversion.yaml | 52 ++++++++++++++- .../resource_definitions.go | 43 +++++++++++-- internal/controllers/reconciler_test.go | 53 +++++++++++++--- internal/test/resources.go | 63 ++++++++++++++++--- 11 files changed, 353 insertions(+), 34 deletions(-) diff --git a/api/v1beta1/cryostat_types.go b/api/v1beta1/cryostat_types.go index f4f1f368..1270866a 100644 --- a/api/v1beta1/cryostat_types.go +++ b/api/v1beta1/cryostat_types.go @@ -520,10 +520,26 @@ type ReportsSecurityOptions struct { // TargetDiscoveryOptions provides configuration options to the Cryostat application's target discovery mechanisms. type TargetDiscoveryOptions struct { - // When true, the Cryostat application will disable the built-in discovery mechanisms. Defaults to false + // When true, the Cryostat application will disable the built-in discovery mechanisms. Defaults to false. // +optional // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Disable Built-in Discovery",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"} BuiltInDiscoveryDisabled bool `json:"builtInDiscoveryDisabled,omitempty"` + // When true, the Cryostat application will use the default port name jfr-jmx to look for JMX connectable targets. + // +optional + // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Disable Built-in Port Names",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"} + DisableBuiltInPortNames bool `json:"disableBuiltInPortNames,omitempty"` + // List of port names that the Cryostat application should look for in order to consider a target as JMX connectable. + // +optional + // +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:fieldDependency:targetDiscoveryOptions.disableBuiltInPortNames:true"} + DiscoveryPortNames []string `json:"discoveryPortNames,omitempty"` + // When true, the Cryostat application will use the default port number 9091 to look for JMX connectable targets. + // +optional + // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Disable Built-in Port Numbers",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"} + DisableBuiltInPortNumbers bool `json:"disableBuiltInPortNumbers,omitempty"` + // List of port numbers that the Cryostat application should look for in order to consider a target as JMX connectable. + // +optional + // +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:fieldDependency:targetDiscoveryOptions.disableBuiltInPortNumbers:true"} + DiscoveryPortNumbers []int32 `json:"discoveryPortNumbers,omitempty"` } // JmxCredentialsDatabaseOptions provides configuration options to the Cryostat application's credentials database. diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 910b11dd..b4ca832b 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -345,7 +345,7 @@ func (in *CryostatSpec) DeepCopyInto(out *CryostatSpec) { if in.TargetDiscoveryOptions != nil { in, out := &in.TargetDiscoveryOptions, &out.TargetDiscoveryOptions *out = new(TargetDiscoveryOptions) - **out = **in + (*in).DeepCopyInto(*out) } if in.JmxCredentialsDatabaseOptions != nil { in, out := &in.JmxCredentialsDatabaseOptions, &out.JmxCredentialsDatabaseOptions @@ -865,6 +865,16 @@ func (in *StorageConfiguration) DeepCopy() *StorageConfiguration { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TargetDiscoveryOptions) DeepCopyInto(out *TargetDiscoveryOptions) { *out = *in + if in.DiscoveryPortNames != nil { + in, out := &in.DiscoveryPortNames, &out.DiscoveryPortNames + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.DiscoveryPortNumbers != nil { + in, out := &in.DiscoveryPortNumbers, &out.DiscoveryPortNumbers + *out = make([]int32, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetDiscoveryOptions. diff --git a/bundle/manifests/cryostat-operator.clusterserviceversion.yaml b/bundle/manifests/cryostat-operator.clusterserviceversion.yaml index 0ac26eaf..e29650ba 100644 --- a/bundle/manifests/cryostat-operator.clusterserviceversion.yaml +++ b/bundle/manifests/cryostat-operator.clusterserviceversion.yaml @@ -54,7 +54,7 @@ metadata: capabilities: Seamless Upgrades categories: Monitoring, Developer Tools containerImage: quay.io/cryostat/cryostat-operator:2.5.0-dev - createdAt: "2023-11-13T21:47:45Z" + createdAt: "2024-02-04T06:09:16Z" description: JVM monitoring and profiling tool operatorframework.io/initialization-resource: |- { @@ -444,11 +444,35 @@ spec: displayName: Target Discovery Options path: targetDiscoveryOptions - description: When true, the Cryostat application will disable the built-in - discovery mechanisms. Defaults to false + discovery mechanisms. Defaults to false. displayName: Disable Built-in Discovery path: targetDiscoveryOptions.builtInDiscoveryDisabled x-descriptors: - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: When true, the Cryostat application will use the default port + name jfr-jmx to look for JMX connectable targets. + displayName: Disable Built-in Port Names + path: targetDiscoveryOptions.disableBuiltInPortNames + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: When true, the Cryostat application will use the default port + number 9091 to look for JMX connectable targets. + displayName: Disable Built-in Port Numbers + path: targetDiscoveryOptions.disableBuiltInPortNumbers + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: List of port names that the Cryostat application should look + for in order to consider a target as JMX connectable. + displayName: Discovery Port Names + path: targetDiscoveryOptions.discoveryPortNames + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:fieldDependency:targetDiscoveryOptions.disableBuiltInPortNames:true + - description: List of port numbers that the Cryostat application should look + for in order to consider a target as JMX connectable. + displayName: Discovery Port Numbers + path: targetDiscoveryOptions.discoveryPortNumbers + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:fieldDependency:targetDiscoveryOptions.disableBuiltInPortNumbers:true - description: List of TLS certificates to trust when connecting to targets. displayName: Trusted TLS Certificates path: trustedCertSecrets @@ -836,11 +860,35 @@ spec: displayName: Target Discovery Options path: targetDiscoveryOptions - description: When true, the Cryostat application will disable the built-in - discovery mechanisms. Defaults to false + discovery mechanisms. Defaults to false. displayName: Disable Built-in Discovery path: targetDiscoveryOptions.builtInDiscoveryDisabled x-descriptors: - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: When true, the Cryostat application will use the default port + name jfr-jmx to look for JMX connectable targets. + displayName: Disable Built-in Port Names + path: targetDiscoveryOptions.disableBuiltInPortNames + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: When true, the Cryostat application will use the default port + number 9091 to look for JMX connectable targets. + displayName: Disable Built-in Port Numbers + path: targetDiscoveryOptions.disableBuiltInPortNumbers + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: List of port names that the Cryostat application should look + for in order to consider a target as JMX connectable. + displayName: Discovery Port Names + path: targetDiscoveryOptions.discoveryPortNames + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:fieldDependency:targetDiscoveryOptions.disableBuiltInPortNames:true + - description: List of port numbers that the Cryostat application should look + for in order to consider a target as JMX connectable. + displayName: Discovery Port Numbers + path: targetDiscoveryOptions.discoveryPortNumbers + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:fieldDependency:targetDiscoveryOptions.disableBuiltInPortNumbers:true - description: List of TLS certificates to trust when connecting to targets. displayName: Trusted TLS Certificates path: trustedCertSecrets diff --git a/bundle/manifests/operator.cryostat.io_clustercryostats.yaml b/bundle/manifests/operator.cryostat.io_clustercryostats.yaml index 9d32a187..383979ab 100644 --- a/bundle/manifests/operator.cryostat.io_clustercryostats.yaml +++ b/bundle/manifests/operator.cryostat.io_clustercryostats.yaml @@ -4606,8 +4606,29 @@ spec: properties: builtInDiscoveryDisabled: description: When true, the Cryostat application will disable - the built-in discovery mechanisms. Defaults to false + the built-in discovery mechanisms. Defaults to false. type: boolean + disableBuiltInPortNames: + description: When true, the Cryostat application will use the + default port name jfr-jmx to look for JMX connectable targets. + type: boolean + disableBuiltInPortNumbers: + description: When true, the Cryostat application will use the + default port number 9091 to look for JMX connectable targets. + type: boolean + discoveryPortNames: + description: List of port names that the Cryostat application + should look for in order to consider a target as JMX connectable. + items: + type: string + type: array + discoveryPortNumbers: + description: List of port numbers that the Cryostat application + should look for in order to consider a target as JMX connectable. + items: + format: int32 + type: integer + type: array type: object targetNamespaces: description: 'List of namespaces whose workloads Cryostat should be diff --git a/bundle/manifests/operator.cryostat.io_cryostats.yaml b/bundle/manifests/operator.cryostat.io_cryostats.yaml index d0af1017..b465c845 100644 --- a/bundle/manifests/operator.cryostat.io_cryostats.yaml +++ b/bundle/manifests/operator.cryostat.io_cryostats.yaml @@ -4602,8 +4602,29 @@ spec: properties: builtInDiscoveryDisabled: description: When true, the Cryostat application will disable - the built-in discovery mechanisms. Defaults to false + the built-in discovery mechanisms. Defaults to false. type: boolean + disableBuiltInPortNames: + description: When true, the Cryostat application will use the + default port name jfr-jmx to look for JMX connectable targets. + type: boolean + disableBuiltInPortNumbers: + description: When true, the Cryostat application will use the + default port number 9091 to look for JMX connectable targets. + type: boolean + discoveryPortNames: + description: List of port names that the Cryostat application + should look for in order to consider a target as JMX connectable. + items: + type: string + type: array + discoveryPortNumbers: + description: List of port numbers that the Cryostat application + should look for in order to consider a target as JMX connectable. + items: + format: int32 + type: integer + type: array type: object trustedCertSecrets: description: List of TLS certificates to trust when connecting to diff --git a/config/crd/bases/operator.cryostat.io_clustercryostats.yaml b/config/crd/bases/operator.cryostat.io_clustercryostats.yaml index 1f0d60c6..9d606b91 100644 --- a/config/crd/bases/operator.cryostat.io_clustercryostats.yaml +++ b/config/crd/bases/operator.cryostat.io_clustercryostats.yaml @@ -4607,8 +4607,29 @@ spec: properties: builtInDiscoveryDisabled: description: When true, the Cryostat application will disable - the built-in discovery mechanisms. Defaults to false + the built-in discovery mechanisms. Defaults to false. type: boolean + disableBuiltInPortNames: + description: When true, the Cryostat application will use the + default port name jfr-jmx to look for JMX connectable targets. + type: boolean + disableBuiltInPortNumbers: + description: When true, the Cryostat application will use the + default port number 9091 to look for JMX connectable targets. + type: boolean + discoveryPortNames: + description: List of port names that the Cryostat application + should look for in order to consider a target as JMX connectable. + items: + type: string + type: array + discoveryPortNumbers: + description: List of port numbers that the Cryostat application + should look for in order to consider a target as JMX connectable. + items: + format: int32 + type: integer + type: array type: object targetNamespaces: description: 'List of namespaces whose workloads Cryostat should be diff --git a/config/crd/bases/operator.cryostat.io_cryostats.yaml b/config/crd/bases/operator.cryostat.io_cryostats.yaml index 93fe3dcf..6cce048f 100644 --- a/config/crd/bases/operator.cryostat.io_cryostats.yaml +++ b/config/crd/bases/operator.cryostat.io_cryostats.yaml @@ -4603,8 +4603,29 @@ spec: properties: builtInDiscoveryDisabled: description: When true, the Cryostat application will disable - the built-in discovery mechanisms. Defaults to false + the built-in discovery mechanisms. Defaults to false. type: boolean + disableBuiltInPortNames: + description: When true, the Cryostat application will use the + default port name jfr-jmx to look for JMX connectable targets. + type: boolean + disableBuiltInPortNumbers: + description: When true, the Cryostat application will use the + default port number 9091 to look for JMX connectable targets. + type: boolean + discoveryPortNames: + description: List of port names that the Cryostat application + should look for in order to consider a target as JMX connectable. + items: + type: string + type: array + discoveryPortNumbers: + description: List of port numbers that the Cryostat application + should look for in order to consider a target as JMX connectable. + items: + format: int32 + type: integer + type: array type: object trustedCertSecrets: description: List of TLS certificates to trust when connecting to diff --git a/config/manifests/bases/cryostat-operator.clusterserviceversion.yaml b/config/manifests/bases/cryostat-operator.clusterserviceversion.yaml index 7b0ccd27..f5d5f8b0 100644 --- a/config/manifests/bases/cryostat-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/cryostat-operator.clusterserviceversion.yaml @@ -394,11 +394,35 @@ spec: displayName: Target Discovery Options path: targetDiscoveryOptions - description: When true, the Cryostat application will disable the built-in - discovery mechanisms. Defaults to false + discovery mechanisms. Defaults to false. displayName: Disable Built-in Discovery path: targetDiscoveryOptions.builtInDiscoveryDisabled x-descriptors: - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: When true, the Cryostat application will use the default port + name jfr-jmx to look for JMX connectable targets. + displayName: Disable Built-in Port Names + path: targetDiscoveryOptions.disableBuiltInPortNames + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: When true, the Cryostat application will use the default port + number 9091 to look for JMX connectable targets. + displayName: Disable Built-in Port Numbers + path: targetDiscoveryOptions.disableBuiltInPortNumbers + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: List of port names that the Cryostat application should look + for in order to consider a target as JMX connectable. + displayName: Discovery Port Names + path: targetDiscoveryOptions.discoveryPortNames + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:fieldDependency:targetDiscoveryOptions.disableBuiltInPortNames:true + - description: List of port numbers that the Cryostat application should look + for in order to consider a target as JMX connectable. + displayName: Discovery Port Numbers + path: targetDiscoveryOptions.discoveryPortNumbers + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:fieldDependency:targetDiscoveryOptions.disableBuiltInPortNumbers:true - description: List of TLS certificates to trust when connecting to targets. displayName: Trusted TLS Certificates path: trustedCertSecrets @@ -774,11 +798,35 @@ spec: displayName: Target Discovery Options path: targetDiscoveryOptions - description: When true, the Cryostat application will disable the built-in - discovery mechanisms. Defaults to false + discovery mechanisms. Defaults to false. displayName: Disable Built-in Discovery path: targetDiscoveryOptions.builtInDiscoveryDisabled x-descriptors: - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: When true, the Cryostat application will use the default port + name jfr-jmx to look for JMX connectable targets. + displayName: Disable Built-in Port Names + path: targetDiscoveryOptions.disableBuiltInPortNames + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: When true, the Cryostat application will use the default port + number 9091 to look for JMX connectable targets. + displayName: Disable Built-in Port Numbers + path: targetDiscoveryOptions.disableBuiltInPortNumbers + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: List of port names that the Cryostat application should look + for in order to consider a target as JMX connectable. + displayName: Discovery Port Names + path: targetDiscoveryOptions.discoveryPortNames + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:fieldDependency:targetDiscoveryOptions.disableBuiltInPortNames:true + - description: List of port numbers that the Cryostat application should look + for in order to consider a target as JMX connectable. + displayName: Discovery Port Numbers + path: targetDiscoveryOptions.discoveryPortNumbers + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:fieldDependency:targetDiscoveryOptions.disableBuiltInPortNumbers:true - description: List of TLS certificates to trust when connecting to targets. displayName: Trusted TLS Certificates path: trustedCertSecrets diff --git a/internal/controllers/common/resource_definitions/resource_definitions.go b/internal/controllers/common/resource_definitions/resource_definitions.go index d2872bd4..5386aea9 100644 --- a/internal/controllers/common/resource_definitions/resource_definitions.go +++ b/internal/controllers/common/resource_definitions/resource_definitions.go @@ -818,12 +818,43 @@ func NewCoreContainer(cr *model.CryostatInstance, specs *ServiceSpecs, imageTag } } - disableBuiltInDiscovery := cr.Spec.TargetDiscoveryOptions != nil && cr.Spec.TargetDiscoveryOptions.BuiltInDiscoveryDisabled - if disableBuiltInDiscovery { - envs = append(envs, corev1.EnvVar{ - Name: "CRYOSTAT_DISABLE_BUILTIN_DISCOVERY", - Value: "true", - }) + if cr.Spec.TargetDiscoveryOptions != nil { + if cr.Spec.TargetDiscoveryOptions.BuiltInDiscoveryDisabled { + envs = append(envs, corev1.EnvVar{ + Name: "CRYOSTAT_DISABLE_BUILTIN_DISCOVERY", + Value: "true", + }) + } + + var portNames string + if len(cr.Spec.TargetDiscoveryOptions.DiscoveryPortNames) > 0 { + portNames = strings.Join(cr.Spec.TargetDiscoveryOptions.DiscoveryPortNames[:], ",") + } else if cr.Spec.TargetDiscoveryOptions.DisableBuiltInPortNames { + portNames = "-" + } + if len(portNames) > 0 { + envs = append(envs, + corev1.EnvVar{ + Name: "CRYOSTAT_DISCOVERY_K8S_PORT_NAMES", + Value: portNames, + }, + ) + } + + portNumbers := "" + if len(cr.Spec.TargetDiscoveryOptions.DiscoveryPortNumbers) > 0 { + portNumbers = strings.Trim(strings.ReplaceAll(fmt.Sprint(cr.Spec.TargetDiscoveryOptions.DiscoveryPortNumbers), " ", ","), "[]") + } else if cr.Spec.TargetDiscoveryOptions.DisableBuiltInPortNumbers { + portNumbers = "0" + } + if len(portNumbers) > 0 { + envs = append(envs, + corev1.EnvVar{ + Name: "CRYOSTAT_DISCOVERY_K8S_PORT_NUMBERS", + Value: portNumbers, + }, + ) + } } if !useEmptyDir(cr) { diff --git a/internal/controllers/reconciler_test.go b/internal/controllers/reconciler_test.go index 156209b2..cdfb547c 100644 --- a/internal/controllers/reconciler_test.go +++ b/internal/controllers/reconciler_test.go @@ -1732,15 +1732,35 @@ func (c *controllerTest) commonTests() { }) }) - Context("with built-in target discovery mechanism disabled", func() { - BeforeEach(func() { - t.objs = append(t.objs, t.NewCryostatWithBuiltInDiscoveryDisabled().Object) - }) + Context("with target discovery options provided", func() { JustBeforeEach(func() { t.reconcileCryostatFully() }) - It("should configure deployment appropriately", func() { - t.expectMainDeployment() + Context("with built-in target discovery mechanism disabled", func() { + BeforeEach(func() { + t.objs = append(t.objs, t.NewCryostatWithBuiltInDiscoveryDisabled().Object) + }) + It("should configure deployment appropriately", func() { + t.expectMainDeployment() + }) + }) + Context("with discovery port configurations", func() { + Context("with built-in values disabled", func() { + BeforeEach(func() { + t.objs = append(t.objs, t.NewCryostatWithBuiltInPortConfigDisabled().Object) + }) + It("should configure deployment appropriately", func() { + t.expectMainDeployment() + }) + }) + Context("containing non-empty lists", func() { + BeforeEach(func() { + t.objs = append(t.objs, t.NewCryostatWithDiscoveryPortConfig().Object) + }) + It("should configure deployment appropriately", func() { + t.expectMainDeployment() + }) + }) }) }) Context("with secret provided for database password", func() { @@ -2723,10 +2743,21 @@ func (t *cryostatTestInput) checkMainPodTemplate(deployment *appsv1.Deployment, 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 builtInDiscoveryDisabled := cr.Spec.TargetDiscoveryOptions != nil && cr.Spec.TargetDiscoveryOptions.BuiltInDiscoveryDisabled + hasPortConfig := cr.Spec.TargetDiscoveryOptions != nil && + len(cr.Spec.TargetDiscoveryOptions.DiscoveryPortNames) > 0 && + len(cr.Spec.TargetDiscoveryOptions.DiscoveryPortNumbers) > 0 + builtInPortConfigDisabled := cr.Spec.TargetDiscoveryOptions != nil && + cr.Spec.TargetDiscoveryOptions.DisableBuiltInPortNames && + cr.Spec.TargetDiscoveryOptions.DisableBuiltInPortNumbers dbSecretProvided := cr.Spec.JmxCredentialsDatabaseOptions != nil && cr.Spec.JmxCredentialsDatabaseOptions.DatabaseSecretName != nil t.checkCoreContainer(&coreContainer, ingress, reportsUrl, - cr.Spec.AuthProperties != nil, emptyDir, builtInDiscoveryDisabled, dbSecretProvided, + cr.Spec.AuthProperties != nil, + emptyDir, + builtInDiscoveryDisabled, + hasPortConfig, + builtInPortConfigDisabled, + dbSecretProvided, t.NewCoreContainerResource(cr), t.NewCoreSecurityContext(cr)) if !t.Minimal { @@ -2882,7 +2913,7 @@ func (t *cryostatTestInput) checkDeploymentHasAuthProperties() { volumeMounts := coreContainer.VolumeMounts expectedVolumeMounts := t.NewVolumeMountsWithAuthProperties() Expect(volumeMounts).To(ConsistOf(expectedVolumeMounts)) - Expect(coreContainer.Env).To(ConsistOf(t.NewCoreEnvironmentVariables("", true, false, false, false, false))) + Expect(coreContainer.Env).To(ConsistOf(t.NewCoreEnvironmentVariables("", true, false, false, false, false, false, false))) } func (t *cryostatTestInput) checkDeploymentHasNoAuthProperties() { @@ -2905,7 +2936,9 @@ func (t *cryostatTestInput) checkDeploymentHasNoAuthProperties() { func (t *cryostatTestInput) checkCoreContainer(container *corev1.Container, ingress bool, reportsUrl string, authProps bool, - emptyDir bool, builtInDiscoveryDisabled bool, dbSecretProvided bool, + emptyDir bool, + builtInDiscoveryDisabled bool, hasPortConfig bool, builtInPortConfigDisabled bool, + dbSecretProvided bool, resources *corev1.ResourceRequirements, securityContext *corev1.SecurityContext) { Expect(container.Name).To(Equal(t.Name)) @@ -2915,7 +2948,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, authProps, ingress, emptyDir, builtInDiscoveryDisabled, dbSecretProvided))) + Expect(container.Env).To(ConsistOf(t.NewCoreEnvironmentVariables(reportsUrl, authProps, ingress, emptyDir, builtInDiscoveryDisabled, hasPortConfig, 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 c9dd11e5..d72f7b30 100644 --- a/internal/test/resources.go +++ b/internal/test/resources.go @@ -550,6 +550,24 @@ func (r *TestResources) NewCryostatWithBuiltInDiscoveryDisabled() *model.Cryosta return cr } +func (r *TestResources) NewCryostatWithDiscoveryPortConfig() *model.CryostatInstance { + cr := r.NewCryostat() + cr.Spec.TargetDiscoveryOptions = &operatorv1beta1.TargetDiscoveryOptions{ + DiscoveryPortNames: []string{"custom-port-name", "another-custom-port-name"}, + DiscoveryPortNumbers: []int32{9092, 9090}, + } + return cr +} + +func (r *TestResources) NewCryostatWithBuiltInPortConfigDisabled() *model.CryostatInstance { + cr := r.NewCryostat() + cr.Spec.TargetDiscoveryOptions = &operatorv1beta1.TargetDiscoveryOptions{ + DisableBuiltInPortNames: true, + DisableBuiltInPortNumbers: true, + } + return cr +} + func newPVCSpec(storageClass string, storageRequest string, accessModes ...corev1.PersistentVolumeAccessMode) *corev1.PersistentVolumeClaimSpec { return &corev1.PersistentVolumeClaimSpec{ @@ -1255,7 +1273,7 @@ func (r *TestResources) NewReportsPorts() []corev1.ContainerPort { } func (r *TestResources) NewCoreEnvironmentVariables(reportsUrl string, authProps bool, ingress bool, - emptyDir bool, builtInDiscoveryDisabled bool, dbSecretProvided bool) []corev1.EnvVar { + emptyDir bool, builtInDiscoveryDisabled bool, hasPortConfig bool, builtInPortConfigDisabled bool, dbSecretProvided bool) []corev1.EnvVar { envs := []corev1.EnvVar{ { Name: "CRYOSTAT_WEB_PORT", @@ -1299,12 +1317,7 @@ func (r *TestResources) NewCoreEnvironmentVariables(reportsUrl string, authProps }, } - if builtInDiscoveryDisabled { - envs = append(envs, corev1.EnvVar{ - Name: "CRYOSTAT_DISABLE_BUILTIN_DISCOVERY", - Value: "true", - }) - } + envs = append(envs, r.NewTargetDiscoveryEnvVar(builtInDiscoveryDisabled, hasPortConfig, builtInPortConfigDisabled)...) if !emptyDir { envs = append(envs, r.DatabaseConfigEnvironmentVariables()...) @@ -1626,6 +1639,42 @@ func (r *TestResources) NewJmxCacheOptionsEnv() []corev1.EnvVar { } } +func (r *TestResources) NewTargetDiscoveryEnvVar(builtInDiscoveryDisabled bool, hasPortConfig bool, builtInPortConfigDisabled bool) []corev1.EnvVar { + envs := make([]corev1.EnvVar, 0) + + if builtInDiscoveryDisabled { + envs = append(envs, corev1.EnvVar{ + Name: "CRYOSTAT_DISABLE_BUILTIN_DISCOVERY", + Value: "true", + }) + } + + if hasPortConfig { + envs = append(envs, + corev1.EnvVar{ + Name: "CRYOSTAT_DISCOVERY_K8S_PORT_NAMES", + Value: "custom-port-name,another-custom-port-name", + }, + corev1.EnvVar{ + Name: "CRYOSTAT_DISCOVERY_K8S_PORT_NUMBERS", + Value: "9092,9090", + }, + ) + } else if builtInPortConfigDisabled { + envs = append(envs, + corev1.EnvVar{ + Name: "CRYOSTAT_DISCOVERY_K8S_PORT_NAMES", + Value: "-", + }, + corev1.EnvVar{ + Name: "CRYOSTAT_DISCOVERY_K8S_PORT_NUMBERS", + Value: "0", + }, + ) + } + return envs +} + func (r *TestResources) NewCoreVolumeMounts() []corev1.VolumeMount { mounts := []corev1.VolumeMount{ {