Skip to content

Commit 1657121

Browse files
authored
[Feature] Add Internal Port (#713)
1 parent 9c15653 commit 1657121

File tree

13 files changed

+109
-34
lines changed

13 files changed

+109
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
4+
- Add InternalPort to ServerGroupSpec to allow user to expose tcp connection over localhost for sidecars
45

56
## [1.1.7](https://github.com/arangodb/kube-arangodb/tree/1.1.7) (2021-04-14)
67
- Bump Kubernetes Dependencies to 1.19.x

pkg/apis/deployment/v1/server_group_spec.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ type ServerGroupSpec struct {
139139
ShutdownMethod *ServerGroupShutdownMethod `json:"shutdownMethod,omitempty"`
140140
// ShutdownDelay define how long operator should delay finalizer removal after shutdown
141141
ShutdownDelay *int `json:"shutdownDelay,omitempty"`
142+
// InternalPort define port used in internal communication, can be accessed over localhost via sidecar
143+
InternalPort *int `json:"internalPort,omitempty"`
142144
}
143145

144146
// ServerGroupSpecSecurityContext contains specification for pod security context
@@ -499,6 +501,12 @@ func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentM
499501
} else if s.GetCount() != 0 {
500502
return errors.WithStack(errors.Wrapf(ValidationError, "Invalid count value %d for un-used group. Expected 0", s.GetCount()))
501503
}
504+
if port := s.InternalPort; port != nil {
505+
switch p := *port; p {
506+
case 8529:
507+
return errors.WithStack(errors.Wrapf(ValidationError, "Port %d already in use", p))
508+
}
509+
}
502510
return nil
503511
}
504512

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

Lines changed: 5 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/arango_member.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package v2alpha1
2424

2525
import (
26+
"github.com/arangodb/kube-arangodb/pkg/apis/deployment"
2627
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
)
2829

@@ -47,3 +48,17 @@ type ArangoMember struct {
4748
Spec ArangoMemberSpec `json:"spec,omitempty"`
4849
Status ArangoMemberStatus `json:"status,omitempty"`
4950
}
51+
52+
// AsOwner creates an OwnerReference for the given member
53+
func (a *ArangoMember) AsOwner() meta.OwnerReference {
54+
trueVar := true
55+
return meta.OwnerReference{
56+
APIVersion: SchemeGroupVersion.String(),
57+
Kind: deployment.ArangoMemberResourceKind,
58+
Name: a.Name,
59+
UID: a.UID,
60+
Controller: &trueVar,
61+
// For now BlockOwnerDeletion does not work on OpenShift, so we leave it out.
62+
//BlockOwnerDeletion: &trueVar,
63+
}
64+
}

pkg/apis/deployment/v2alpha1/deployment_status_members.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,19 @@ func (ds DeploymentStatusMembers) MembersOfGroup(group ServerGroup) MemberStatus
285285
return MemberStatusList{}
286286
}
287287
}
288+
289+
// PodNames returns all members pod names
290+
func (ds DeploymentStatusMembers) PodNames() []string {
291+
var n []string
292+
293+
ds.ForeachServerGroup(func(group ServerGroup, list MemberStatusList) error {
294+
for _, m := range list {
295+
if m.PodName != "" {
296+
n = append(n, m.PodName)
297+
}
298+
}
299+
return nil
300+
})
301+
302+
return n
303+
}

pkg/apis/deployment/v2alpha1/member_phase.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@ func (p MemberPhase) IsFailed() bool {
5757
func (p MemberPhase) IsCreatedOrDrain() bool {
5858
return p == MemberPhaseCreated || p == MemberPhaseDrain
5959
}
60+
61+
// String returns string from MemberPhase
62+
func (p MemberPhase) String() string {
63+
return string(p)
64+
}

pkg/apis/deployment/v2alpha1/member_status.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"reflect"
2727
"time"
2828

29+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
30+
2931
"k8s.io/apimachinery/pkg/types"
3032

3133
driver "github.com/arangodb/go-driver"
@@ -155,3 +157,8 @@ func (s MemberStatus) IsNotReadySince(timestamp time.Time) bool {
155157
// A
156158
return s.CreatedAt.Time.Before(timestamp)
157159
}
160+
161+
// ArangoMemberName create member name from given member
162+
func (s MemberStatus) ArangoMemberName(deploymentName string, group ServerGroup) string {
163+
return k8sutil.CreatePodHostName(deploymentName, group.AsRole(), s.ID)
164+
}

pkg/apis/deployment/v2alpha1/server_group.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package v2alpha1
2424

2525
import (
26+
"encoding/json"
2627
"time"
2728
)
2829

@@ -34,14 +35,19 @@ func (g *ServerGroup) UnmarshalJSON(bytes []byte) error {
3435
return nil
3536
}
3637

37-
*g = ServerGroupFromRole(string(bytes))
38+
var s string
39+
40+
if err := json.Unmarshal(bytes, &s); err != nil {
41+
return err
42+
}
43+
44+
*g = ServerGroupFromRole(s)
3845

3946
return nil
4047
}
4148

4249
func (g ServerGroup) MarshalJSON() ([]byte, error) {
43-
s := g.AsRole()
44-
return []byte(s), nil
50+
return json.Marshal(g.AsRole())
4551
}
4652

4753
const (

pkg/apis/deployment/v2alpha1/server_group_spec.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ type ServerGroupSpec struct {
137137
InitContainers *ServerGroupInitContainers `json:"initContainers,omitempty"`
138138
// ShutdownMethod describe procedure of member shutdown taken by Operator
139139
ShutdownMethod *ServerGroupShutdownMethod `json:"shutdownMethod,omitempty"`
140+
// ShutdownDelay define how long operator should delay finalizer removal after shutdown
141+
ShutdownDelay *int `json:"shutdownDelay,omitempty"`
142+
// InternalPort define port used in internal communication, can be accessed over localhost via sidecar
143+
InternalPort *int `json:"internalPort,omitempty"`
140144
}
141145

142146
// ServerGroupSpecSecurityContext contains specification for pod security context
@@ -497,6 +501,12 @@ func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentM
497501
} else if s.GetCount() != 0 {
498502
return errors.WithStack(errors.Wrapf(ValidationError, "Invalid count value %d for un-used group. Expected 0", s.GetCount()))
499503
}
504+
if port := s.InternalPort; port != nil {
505+
switch p := *port; p {
506+
case 8529:
507+
return errors.WithStack(errors.Wrapf(ValidationError, "Port %d already in use", p))
508+
}
509+
}
500510
return nil
501511
}
502512

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.

0 commit comments

Comments
 (0)