Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change Log

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

## [1.1.7](https://github.com/arangodb/kube-arangodb/tree/1.1.7) (2021-04-14)
- Bump Kubernetes Dependencies to 1.19.x
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/deployment/v1/server_group_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ type ServerGroupSpec struct {
ShutdownMethod *ServerGroupShutdownMethod `json:"shutdownMethod,omitempty"`
// ShutdownDelay define how long operator should delay finalizer removal after shutdown
ShutdownDelay *int `json:"shutdownDelay,omitempty"`
// InternalPort define port used in internal communication, can be accessed over localhost via sidecar
InternalPort *int `json:"internalPort,omitempty"`
}

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

Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/deployment/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions pkg/apis/deployment/v2alpha1/arango_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package v2alpha1

import (
"github.com/arangodb/kube-arangodb/pkg/apis/deployment"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -47,3 +48,17 @@ type ArangoMember struct {
Spec ArangoMemberSpec `json:"spec,omitempty"`
Status ArangoMemberStatus `json:"status,omitempty"`
}

// AsOwner creates an OwnerReference for the given member
func (a *ArangoMember) AsOwner() meta.OwnerReference {
trueVar := true
return meta.OwnerReference{
APIVersion: SchemeGroupVersion.String(),
Kind: deployment.ArangoMemberResourceKind,
Name: a.Name,
UID: a.UID,
Controller: &trueVar,
// For now BlockOwnerDeletion does not work on OpenShift, so we leave it out.
//BlockOwnerDeletion: &trueVar,
}
}
16 changes: 16 additions & 0 deletions pkg/apis/deployment/v2alpha1/deployment_status_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,19 @@ func (ds DeploymentStatusMembers) MembersOfGroup(group ServerGroup) MemberStatus
return MemberStatusList{}
}
}

// PodNames returns all members pod names
func (ds DeploymentStatusMembers) PodNames() []string {
var n []string

ds.ForeachServerGroup(func(group ServerGroup, list MemberStatusList) error {
for _, m := range list {
if m.PodName != "" {
n = append(n, m.PodName)
}
}
return nil
})

return n
}
5 changes: 5 additions & 0 deletions pkg/apis/deployment/v2alpha1/member_phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ func (p MemberPhase) IsFailed() bool {
func (p MemberPhase) IsCreatedOrDrain() bool {
return p == MemberPhaseCreated || p == MemberPhaseDrain
}

// String returns string from MemberPhase
func (p MemberPhase) String() string {
return string(p)
}
7 changes: 7 additions & 0 deletions pkg/apis/deployment/v2alpha1/member_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"reflect"
"time"

"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"

"k8s.io/apimachinery/pkg/types"

driver "github.com/arangodb/go-driver"
Expand Down Expand Up @@ -155,3 +157,8 @@ func (s MemberStatus) IsNotReadySince(timestamp time.Time) bool {
// A
return s.CreatedAt.Time.Before(timestamp)
}

// ArangoMemberName create member name from given member
func (s MemberStatus) ArangoMemberName(deploymentName string, group ServerGroup) string {
return k8sutil.CreatePodHostName(deploymentName, group.AsRole(), s.ID)
}
12 changes: 9 additions & 3 deletions pkg/apis/deployment/v2alpha1/server_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package v2alpha1

import (
"encoding/json"
"time"
)

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

*g = ServerGroupFromRole(string(bytes))
var s string

if err := json.Unmarshal(bytes, &s); err != nil {
return err
}

*g = ServerGroupFromRole(s)

return nil
}

func (g ServerGroup) MarshalJSON() ([]byte, error) {
s := g.AsRole()
return []byte(s), nil
return json.Marshal(g.AsRole())
}

const (
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/deployment/v2alpha1/server_group_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ type ServerGroupSpec struct {
InitContainers *ServerGroupInitContainers `json:"initContainers,omitempty"`
// ShutdownMethod describe procedure of member shutdown taken by Operator
ShutdownMethod *ServerGroupShutdownMethod `json:"shutdownMethod,omitempty"`
// ShutdownDelay define how long operator should delay finalizer removal after shutdown
ShutdownDelay *int `json:"shutdownDelay,omitempty"`
// InternalPort define port used in internal communication, can be accessed over localhost via sidecar
InternalPort *int `json:"internalPort,omitempty"`
}

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

Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 18 additions & 29 deletions pkg/deployment/resources/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@
package resources

import (
"fmt"
"path/filepath"
"sort"
"strconv"

"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/probes"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/probes"

"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
Expand Down Expand Up @@ -63,39 +59,32 @@ func ArangodbExporterContainer(image string, args []string, livenessProbe *probe
return c
}

func createExporterArgs(spec api.DeploymentSpec) []string {
func createExporterArgs(spec api.DeploymentSpec, groupSpec api.ServerGroupSpec) []string {
tokenpath := filepath.Join(k8sutil.ExporterJWTVolumeMountDir, constants.SecretKeyToken)
options := make([]k8sutil.OptionPair, 0, 64)
scheme := "http"
if spec.IsSecure() {
scheme = "https"
options := k8sutil.CreateOptionPairs(64)

options.Add("--arangodb.jwt-file", tokenpath)

if port := groupSpec.InternalPort; port == nil {
scheme := "http"
if spec.IsSecure() {
scheme = "https"
}
options.Addf("--arangodb.endpoint", "%s://localhost:%d", scheme, k8sutil.ArangoPort)
} else {
options.Addf("--arangodb.endpoint", "http://localhost:%d", *port)
}
options = append(options,
k8sutil.OptionPair{Key: "--arangodb.jwt-file", Value: tokenpath},
k8sutil.OptionPair{Key: "--arangodb.endpoint", Value: scheme + "://localhost:" + strconv.Itoa(k8sutil.ArangoPort)},
)

keyPath := filepath.Join(k8sutil.TLSKeyfileVolumeMountDir, constants.SecretTLSKeyfile)
if spec.IsSecure() && spec.Metrics.IsTLS() {
options = append(options,
k8sutil.OptionPair{Key: "--ssl.keyfile", Value: keyPath},
)
options.Add("--ssl.keyfile", keyPath)
}

if port := spec.Metrics.GetPort(); port != k8sutil.ArangoExporterPort {
options = append(options,
k8sutil.OptionPair{Key: "--server.address", Value: fmt.Sprintf(":%d", port)},
)
}

args := make([]string, 0, 2+len(options))
sort.Slice(options, func(i, j int) bool {
return options[i].CompareTo(options[j]) < 0
})
for _, o := range options {
args = append(args, o.Key+"="+o.Value)
options.Addf("--server.address", ":%d", port)
}

return args
return options.Sort().AsArgs()
}

func createExporterLivenessProbe(isSecure bool) *probes.HTTPProbeConfig {
Expand Down
5 changes: 4 additions & 1 deletion pkg/deployment/resources/pod_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func createArangodArgs(input pod.Input, additionalOptions ...k8sutil.OptionPair)
}

options.Addf("--server.endpoint", "%s://%s:%d", scheme, input.Deployment.GetListenAddr(), k8sutil.ArangoPort)
if port := input.GroupSpec.InternalPort; port != nil {
options.Addf("--server.endpoint", "tcp://127.0.0.1:%d", *port)
}

// Authentication
options.Merge(pod.JWT().Args(input))
Expand Down Expand Up @@ -230,7 +233,7 @@ func createArangoSyncArgs(apiObject metav1.Object, spec api.DeploymentSpec, grou
runCmd,
}

args = append(args, options.Sort().AsArgs()...)
args = append(args, options.Copy().Sort().AsArgs()...)

if len(groupSpec.Args) > 0 {
args = append(args, groupSpec.Args...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/deployment/resources/pod_creator_arangod.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ func (m *MemberArangoDPod) createMetricsExporterSidecar() *core.Container {
image = m.spec.Metrics.GetImage()
}

args := createExporterArgs(m.spec)
args := createExporterArgs(m.spec, m.groupSpec)
if m.spec.Metrics.Mode.Get() == api.MetricsModeSidecar {
args = append(args, "--mode=passthru")
}
Expand Down