99
1010 rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
1111 topology "github.com/rabbitmq/messaging-topology-operator/api/v1beta1"
12+ "gopkg.in/ini.v1"
1213 corev1 "k8s.io/api/core/v1"
1314 "k8s.io/apimachinery/pkg/types"
1415 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -99,7 +100,12 @@ func ParseReference(ctx context.Context, c client.Client, rmq topology.RabbitmqC
99100 return nil , false , err
100101 }
101102
102- endpoint , err := managementURI (svc , cluster .TLSEnabled (), clusterDomain )
103+ pathPrefix , err := readClusterPathPrefix (cluster )
104+ if err != nil {
105+ return nil , false , fmt .Errorf ("unable to parse additionconfig setting from the rabbitmqcluster resource: %w" , err )
106+ }
107+
108+ endpoint , err := managementURI (svc , cluster .TLSEnabled (), clusterDomain , pathPrefix )
103109 if err != nil {
104110 return nil , false , fmt .Errorf ("failed to get endpoint from specified rabbitmqcluster: %w" , err )
105111 }
@@ -161,6 +167,33 @@ func readCredentialsFromKubernetesSecret(secret *corev1.Secret) (ConnectionCrede
161167 }, tlsEnabled , nil
162168}
163169
170+ func readClusterPathPrefix (cluster * rabbitmqv1beta1.RabbitmqCluster ) (string , error ) {
171+ additionalConfig := cluster .Spec .Rabbitmq .AdditionalConfig
172+
173+ var err error
174+ if additionalConfig == "" {
175+ return "" , err
176+ }
177+
178+ path_prefix , err := readIniConfig (additionalConfig , "management" , "path_prefix" )
179+ if err != nil {
180+ return "" , err
181+ }
182+
183+ return path_prefix , nil
184+ }
185+
186+ func readIniConfig (config string , section string , key string ) (string , error ) {
187+ cfg , err := ini .LoadSources (ini.LoadOptions {
188+ SkipUnrecognizableLines : false ,
189+ }, []byte (config ))
190+ if err != nil {
191+ return "" , err
192+ }
193+
194+ return cfg .Section (section ).Key (key ).String (), nil
195+ }
196+
164197func readUsernamePassword (secret * corev1.Secret ) (string , string , error ) {
165198 if secret == nil {
166199 return "" , "" , errors .New ("unable to extract data from nil secret" )
@@ -169,7 +202,7 @@ func readUsernamePassword(secret *corev1.Secret) (string, string, error) {
169202 return string (secret .Data ["username" ]), string (secret .Data ["password" ]), nil
170203}
171204
172- func managementURI (svc * corev1.Service , tlsEnabled bool , clusterDomain string ) (string , error ) {
205+ func managementURI (svc * corev1.Service , tlsEnabled bool , clusterDomain string , pathPrefix string ) (string , error ) {
173206 var managementUiPort int
174207 for _ , port := range svc .Spec .Ports {
175208 if port .Name == "management-tls" {
@@ -190,5 +223,11 @@ func managementURI(svc *corev1.Service, tlsEnabled bool, clusterDomain string) (
190223 if tlsEnabled {
191224 scheme = "https"
192225 }
193- return fmt .Sprintf ("%s://%s.%s.svc%s:%d" , scheme , svc .Name , svc .Namespace , clusterDomain , managementUiPort ), nil
226+ url := url.URL {
227+ Scheme : scheme ,
228+ Host : fmt .Sprintf ("%s.%s.svc%s:%d" , svc .Name , svc .Namespace , clusterDomain , managementUiPort ),
229+ Path : pathPrefix ,
230+ }
231+ return url .String (), nil
232+ // return fmt.Sprintf("%s://%s.%s.svc%s:%d", scheme, svc.Name, svc.Namespace, clusterDomain, pathPrefix, managementUiPort), nil
194233}
0 commit comments