Skip to content

Commit 2ffd238

Browse files
authored
[Feature] Configurable ArangoD Port (#1199)
1 parent 2ca875d commit 2ffd238

31 files changed

+560
-208
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
- (Feature) Pre OOM Abort function
3535
- (Bugfix) Fix ErrorArray String function
3636
- (Feature) Switch services to Port names
37+
- (Feature) Configurable ArangoD Port
3738

3839
## [1.2.20](https://github.com/arangodb/kube-arangodb/tree/1.2.20) (2022-10-25)
3940
- (Feature) Add action progress

cmd/lifecycle_probes.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@ import (
4343
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
4444
"github.com/arangodb/kube-arangodb/pkg/deployment/pod"
4545
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
46+
"github.com/arangodb/kube-arangodb/pkg/util"
4647
"github.com/arangodb/kube-arangodb/pkg/util/constants"
4748
)
4849

50+
const (
51+
ProbePort util.EnvironmentVariable = "ARANGODB_SERVER_PORT"
52+
)
53+
4954
var (
5055
cmdLifecycleProbe = &cobra.Command{
5156
Use: "probe",
@@ -118,7 +123,9 @@ func probeEndpoint(endpoint string) string {
118123
proto = "https"
119124
}
120125

121-
return fmt.Sprintf("%s://%s:%d%s", proto, "127.0.0.1", shared.ArangoPort, endpoint)
126+
port := ProbePort.GetOrDefault(fmt.Sprintf("%d", shared.ArangoPort))
127+
128+
return fmt.Sprintf("%s://%s:%s%s", proto, "127.0.0.1", port, endpoint)
122129
}
123130

124131
func readJWTFile(file string) ([]byte, error) {

cmd/lifecycle_startup.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ var cmdLifecycleStartup = &cobra.Command{
4040
func cmdLifecycleStartupFunc(cmd *cobra.Command, args []string) error {
4141
var close bool
4242

43+
port := ProbePort.GetOrDefault(fmt.Sprintf("%d", shared.ArangoPort))
44+
4345
server := &http.Server{
44-
Addr: fmt.Sprintf(":%d", shared.ArangoPort),
46+
Addr: fmt.Sprintf(":%s", port),
4547
}
4648

4749
handlers := http.NewServeMux()

pkg/apis/deployment/v1/deployment_spec.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,3 +560,8 @@ func (s DeploymentSpec) GetCoreContainers(group ServerGroup) utils.StringList {
560560

561561
return result
562562
}
563+
564+
func (s DeploymentSpec) GetGroupPort(group ServerGroup) uint16 {
565+
spec := s.GetServerGroupSpec(group)
566+
return spec.GetPort()
567+
}

pkg/apis/deployment/v1/server_group_spec.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ type ServerGroupSpec struct {
160160

161161
// PodModes define additional modes enabled on the Pod level
162162
PodModes *ServerGroupSpecPodMode `json:"podModes,omitempty"`
163+
// Port define Port used by member
164+
Port *uint16 `json:"port,omitempty"`
165+
// ExporterPort define Port used by exporter
166+
ExporterPort *uint16 `json:"exporterPort,omitempty"`
163167
}
164168

165169
// ServerGroupProbesSpec contains specification for probes for pods of the server group
@@ -672,3 +676,30 @@ func (s *ServerGroupSpec) Group() ServerGroup {
672676

673677
return s.group
674678
}
679+
680+
func (s *ServerGroupSpec) GetPort() uint16 {
681+
if s != nil {
682+
if p := s.Port; p != nil {
683+
return *p
684+
}
685+
}
686+
687+
switch s.Group() {
688+
case ServerGroupSyncMasters:
689+
return shared.ArangoSyncMasterPort
690+
case ServerGroupSyncWorkers:
691+
return shared.ArangoSyncWorkerPort
692+
default:
693+
return shared.ArangoPort
694+
}
695+
}
696+
697+
func (s *ServerGroupSpec) GetExporterPort() uint16 {
698+
if s != nil {
699+
if p := s.ExporterPort; p != nil {
700+
return *p
701+
}
702+
}
703+
704+
return shared.ArangoExporterPort
705+
}

pkg/apis/deployment/v1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/deployment/v2alpha1/deployment_spec.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,3 +560,8 @@ func (s DeploymentSpec) GetCoreContainers(group ServerGroup) utils.StringList {
560560

561561
return result
562562
}
563+
564+
func (s DeploymentSpec) GetGroupPort(group ServerGroup) uint16 {
565+
spec := s.GetServerGroupSpec(group)
566+
return spec.GetPort()
567+
}

pkg/apis/deployment/v2alpha1/server_group_spec.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ type ServerGroupSpec struct {
160160

161161
// PodModes define additional modes enabled on the Pod level
162162
PodModes *ServerGroupSpecPodMode `json:"podModes,omitempty"`
163+
// Port define Port used by member
164+
Port *uint16 `json:"port,omitempty"`
165+
// ExporterPort define Port used by exporter
166+
ExporterPort *uint16 `json:"exporterPort,omitempty"`
163167
}
164168

165169
// ServerGroupProbesSpec contains specification for probes for pods of the server group
@@ -672,3 +676,30 @@ func (s *ServerGroupSpec) Group() ServerGroup {
672676

673677
return s.group
674678
}
679+
680+
func (s *ServerGroupSpec) GetPort() uint16 {
681+
if s != nil {
682+
if p := s.Port; p != nil {
683+
return *p
684+
}
685+
}
686+
687+
switch s.Group() {
688+
case ServerGroupSyncMasters:
689+
return shared.ArangoSyncMasterPort
690+
case ServerGroupSyncWorkers:
691+
return shared.ArangoSyncWorkerPort
692+
default:
693+
return shared.ArangoPort
694+
}
695+
}
696+
697+
func (s *ServerGroupSpec) GetExporterPort() uint16 {
698+
if s != nil {
699+
if p := s.ExporterPort; p != nil {
700+
return *p
701+
}
702+
}
703+
704+
return shared.ArangoExporterPort
705+
}

pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/deployment_affinity_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func TestEnsurePod_ArangoDB_AntiAffinity(t *testing.T) {
9797
VolumeMounts: []core.VolumeMount{
9898
k8sutil.ArangodVolumeMount(),
9999
},
100-
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ArangoPort),
100+
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ServerPortName),
101101
ImagePullPolicy: core.PullIfNotPresent,
102102
SecurityContext: securityContext.NewSecurityContext(),
103103
},
@@ -159,7 +159,7 @@ func TestEnsurePod_ArangoDB_AntiAffinity(t *testing.T) {
159159
VolumeMounts: []core.VolumeMount{
160160
k8sutil.ArangodVolumeMount(),
161161
},
162-
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ArangoPort),
162+
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ServerPortName),
163163
ImagePullPolicy: core.PullIfNotPresent,
164164
SecurityContext: securityContext.NewSecurityContext(),
165165
},
@@ -224,7 +224,7 @@ func TestEnsurePod_ArangoDB_AntiAffinity(t *testing.T) {
224224
VolumeMounts: []core.VolumeMount{
225225
k8sutil.ArangodVolumeMount(),
226226
},
227-
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ArangoPort),
227+
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ServerPortName),
228228
ImagePullPolicy: core.PullIfNotPresent,
229229
SecurityContext: securityContext.NewSecurityContext(),
230230
},
@@ -294,7 +294,7 @@ func TestEnsurePod_ArangoDB_AntiAffinity(t *testing.T) {
294294
VolumeMounts: []core.VolumeMount{
295295
k8sutil.ArangodVolumeMount(),
296296
},
297-
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ArangoPort),
297+
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ServerPortName),
298298
ImagePullPolicy: core.PullIfNotPresent,
299299
SecurityContext: securityContext.NewSecurityContext(),
300300
},
@@ -373,7 +373,7 @@ func TestEnsurePod_ArangoDB_Affinity(t *testing.T) {
373373
VolumeMounts: []core.VolumeMount{
374374
k8sutil.ArangodVolumeMount(),
375375
},
376-
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ArangoPort),
376+
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ServerPortName),
377377
ImagePullPolicy: core.PullIfNotPresent,
378378
SecurityContext: securityContext.NewSecurityContext(),
379379
},
@@ -438,7 +438,7 @@ func TestEnsurePod_ArangoDB_Affinity(t *testing.T) {
438438
VolumeMounts: []core.VolumeMount{
439439
k8sutil.ArangodVolumeMount(),
440440
},
441-
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ArangoPort),
441+
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ServerPortName),
442442
ImagePullPolicy: core.PullIfNotPresent,
443443
SecurityContext: securityContext.NewSecurityContext(),
444444
},
@@ -506,7 +506,7 @@ func TestEnsurePod_ArangoDB_Affinity(t *testing.T) {
506506
VolumeMounts: []core.VolumeMount{
507507
k8sutil.ArangodVolumeMount(),
508508
},
509-
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ArangoPort),
509+
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ServerPortName),
510510
ImagePullPolicy: core.PullIfNotPresent,
511511
SecurityContext: securityContext.NewSecurityContext(),
512512
},
@@ -579,7 +579,7 @@ func TestEnsurePod_ArangoDB_Affinity(t *testing.T) {
579579
VolumeMounts: []core.VolumeMount{
580580
k8sutil.ArangodVolumeMount(),
581581
},
582-
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ArangoPort),
582+
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ServerPortName),
583583
ImagePullPolicy: core.PullIfNotPresent,
584584
SecurityContext: securityContext.NewSecurityContext(),
585585
},
@@ -660,7 +660,7 @@ func TestEnsurePod_ArangoDB_NodeAffinity(t *testing.T) {
660660
VolumeMounts: []core.VolumeMount{
661661
k8sutil.ArangodVolumeMount(),
662662
},
663-
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ArangoPort),
663+
LivenessProbe: createTestLivenessProbe(httpProbe, false, "", shared.ServerPortName),
664664
ImagePullPolicy: core.PullIfNotPresent,
665665
SecurityContext: securityContext.NewSecurityContext(),
666666
},

0 commit comments

Comments
 (0)