Skip to content

Commit

Permalink
[Feature] [Integration] Basic Envs (#1749)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanikow authored Oct 23, 2024
1 parent 846b621 commit f911554
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions docs/integration-sidecar.md
Original file line number Diff line number Diff line change
@@ -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`
50 changes: 47 additions & 3 deletions pkg/deployment/resources/arango_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f911554

Please sign in to comment.