From f91155478ade9200106b7e7045a51962a0f10a02 Mon Sep 17 00:00:00 2001 From: Adam Janikowski <12255597+ajanikow@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:42:32 +0200 Subject: [PATCH] [Feature] [Integration] Basic Envs (#1749) --- CHANGELOG.md | 1 + docs/integration-sidecar.md | 28 ++++++++++++ pkg/deployment/resources/arango_profiles.go | 50 +++++++++++++++++++-- 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 docs/integration-sidecar.md diff --git a/CHANGELOG.md b/CHANGELOG.md index f8566290b..f8b164aa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - (Feature) (Integration) SchedulerV2 Definition - (Maintenance) Proto Lint - (Feature) (Integration) SchedulerV2 +- (Feature) (Integration) Basic Envs ## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14) - (Feature) ArangoRoute CRD diff --git a/docs/integration-sidecar.md b/docs/integration-sidecar.md new file mode 100644 index 000000000..671483eed --- /dev/null +++ b/docs/integration-sidecar.md @@ -0,0 +1,28 @@ +# Integration + +## Profile + +## Sidecar + +### Resource Types + +Integration Sidecar is supported in a few resources managed by Operator: + +- ArangoSchedulerDeployment (scheduler.arangodb.com/v1beta1) +- ArangoSchedulerBatchJob (scheduler.arangodb.com/v1beta1) +- ArangoSchedulerCronJob (scheduler.arangodb.com/v1beta1) +- ArangoSchedulerPod (scheduler.arangodb.com/v1beta1) + +### Envs + +#### ARANGO_DEPLOYMENT_NAME + +ArangoDeployment name. + +Example: `deployment` + +#### ARANGO_DEPLOYMENT_ENDPOINT + +HTTP/S Endpoint of the ArangoDeployment Internal Service. + +Example: `https://deployment.default.svc:8529` diff --git a/pkg/deployment/resources/arango_profiles.go b/pkg/deployment/resources/arango_profiles.go index 51b358f66..4328dc427 100644 --- a/pkg/deployment/resources/arango_profiles.go +++ b/pkg/deployment/resources/arango_profiles.go @@ -25,11 +25,15 @@ import ( "fmt" "time" + core "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" meta "k8s.io/apimachinery/pkg/apis/meta/v1" + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1" + schedulerContainerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container" schedulerContainerResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container/resources" + shared "github.com/arangodb/kube-arangodb/pkg/apis/shared" "github.com/arangodb/kube-arangodb/pkg/deployment/patch" "github.com/arangodb/kube-arangodb/pkg/integrations/sidecar" "github.com/arangodb/kube-arangodb/pkg/metrics" @@ -109,7 +113,7 @@ func (r *Resources) EnsureArangoProfiles(ctx context.Context, cachedStatus inspe integration, err := sidecar.NewIntegration(&schedulerContainerResourcesApi.Image{ Image: util.NewType(r.context.GetOperatorImage()), - }, spec.Integration.GetSidecar(), r.arangoDeploymentProfileTemplate()) + }, spec.Integration.GetSidecar(), r.arangoDeploymentProfileTemplate(cachedStatus)) if err != nil { return "", nil, err } @@ -144,8 +148,48 @@ func (r *Resources) EnsureArangoProfiles(ctx context.Context, cachedStatus inspe return reconcileRequired.Reconcile(ctx) } -func (r *Resources) arangoDeploymentProfileTemplate() *schedulerApi.ProfileTemplate { - return nil +func (r *Resources) arangoDeploymentInternalAddress(cachedStatus inspectorInterface.Inspector) string { + spec := r.context.GetSpec() + apiObject := r.context.GetAPIObject() + deploymentName := apiObject.GetName() + + proto := util.BoolSwitch(spec.IsSecure(), "https", "http") + svc, ok := cachedStatus.Service().V1().GetSimple(deploymentName) + if !ok { + return "" + } + + if spec.CommunicationMethod.Get() == api.DeploymentCommunicationMethodIP { + if ip := svc.Spec.ClusterIP; ip != core.ClusterIPNone && ip != "" { + return fmt.Sprintf("%s://%s:%d", proto, ip, shared.ArangoPort) + } + } + + return fmt.Sprintf("%s://%s:%d", proto, k8sutil.CreateDatabaseClientServiceDNSNameWithDomain(svc, spec.ClusterDomain), shared.ArangoPort) +} + +func (r *Resources) arangoDeploymentProfileTemplate(cachedStatus inspectorInterface.Inspector) *schedulerApi.ProfileTemplate { + apiObject := r.context.GetAPIObject() + deploymentName := apiObject.GetName() + + return &schedulerApi.ProfileTemplate{ + Container: &schedulerApi.ProfileContainerTemplate{ + All: &schedulerContainerApi.Generic{ + Environments: &schedulerContainerResourcesApi.Environments{ + Env: []core.EnvVar{ + { + Name: "ARANGO_DEPLOYMENT_NAME", + Value: deploymentName, + }, + { + Name: "ARANGO_DEPLOYMENT_ENDPOINT", + Value: r.arangoDeploymentInternalAddress(cachedStatus), + }, + }, + }, + }, + }, + } } func (r *Resources) ensureArangoProfilesFactory(ctx context.Context, cachedStatus inspectorInterface.Inspector, expected ...func() (string, *schedulerApi.ArangoProfile, error)) (bool, error) {