@@ -25,11 +25,15 @@ import (
2525 "fmt"
2626 "time"
2727
28+ core "k8s.io/api/core/v1"
2829 "k8s.io/apimachinery/pkg/api/equality"
2930 meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3031
32+ api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
3133 schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
34+ schedulerContainerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container"
3235 schedulerContainerResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container/resources"
36+ shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
3337 "github.com/arangodb/kube-arangodb/pkg/deployment/patch"
3438 "github.com/arangodb/kube-arangodb/pkg/integrations/sidecar"
3539 "github.com/arangodb/kube-arangodb/pkg/metrics"
@@ -109,7 +113,7 @@ func (r *Resources) EnsureArangoProfiles(ctx context.Context, cachedStatus inspe
109113
110114 integration , err := sidecar .NewIntegration (& schedulerContainerResourcesApi.Image {
111115 Image : util .NewType (r .context .GetOperatorImage ()),
112- }, spec .Integration .GetSidecar (), r .arangoDeploymentProfileTemplate ())
116+ }, spec .Integration .GetSidecar (), r .arangoDeploymentProfileTemplate (cachedStatus ))
113117 if err != nil {
114118 return "" , nil , err
115119 }
@@ -144,8 +148,48 @@ func (r *Resources) EnsureArangoProfiles(ctx context.Context, cachedStatus inspe
144148 return reconcileRequired .Reconcile (ctx )
145149}
146150
147- func (r * Resources ) arangoDeploymentProfileTemplate () * schedulerApi.ProfileTemplate {
148- return nil
151+ func (r * Resources ) arangoDeploymentInternalAddress (cachedStatus inspectorInterface.Inspector ) string {
152+ spec := r .context .GetSpec ()
153+ apiObject := r .context .GetAPIObject ()
154+ deploymentName := apiObject .GetName ()
155+
156+ proto := util .BoolSwitch (spec .IsSecure (), "https" , "http" )
157+ svc , ok := cachedStatus .Service ().V1 ().GetSimple (deploymentName )
158+ if ! ok {
159+ return ""
160+ }
161+
162+ if spec .CommunicationMethod .Get () == api .DeploymentCommunicationMethodIP {
163+ if ip := svc .Spec .ClusterIP ; ip != core .ClusterIPNone && ip != "" {
164+ return fmt .Sprintf ("%s://%s:%d" , proto , ip , shared .ArangoPort )
165+ }
166+ }
167+
168+ return fmt .Sprintf ("%s://%s:%d" , proto , k8sutil .CreateDatabaseClientServiceDNSNameWithDomain (svc , spec .ClusterDomain ), shared .ArangoPort )
169+ }
170+
171+ func (r * Resources ) arangoDeploymentProfileTemplate (cachedStatus inspectorInterface.Inspector ) * schedulerApi.ProfileTemplate {
172+ apiObject := r .context .GetAPIObject ()
173+ deploymentName := apiObject .GetName ()
174+
175+ return & schedulerApi.ProfileTemplate {
176+ Container : & schedulerApi.ProfileContainerTemplate {
177+ All : & schedulerContainerApi.Generic {
178+ Environments : & schedulerContainerResourcesApi.Environments {
179+ Env : []core.EnvVar {
180+ {
181+ Name : "ARANGO_DEPLOYMENT_NAME" ,
182+ Value : deploymentName ,
183+ },
184+ {
185+ Name : "ARANGO_DEPLOYMENT_ENDPOINT" ,
186+ Value : r .arangoDeploymentInternalAddress (cachedStatus ),
187+ },
188+ },
189+ },
190+ },
191+ },
192+ }
149193}
150194
151195func (r * Resources ) ensureArangoProfilesFactory (ctx context.Context , cachedStatus inspectorInterface.Inspector , expected ... func () (string , * schedulerApi.ArangoProfile , error )) (bool , error ) {
0 commit comments