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
Expand Up @@ -5,6 +5,7 @@
- Fix Core InitContainers check
- Remove unused `status.members.<group>.sidecars-specs` variable
- Keep only recent terminations
- Add endpoint into member status

## [1.2.6](https://github.com/arangodb/kube-arangodb/tree/1.2.6) (2021-12-15)
- Add ArangoBackup backoff functionality
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/deployment/v1/arango_member_pod_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type ArangoMemberPodTemplate struct {
PodSpec *core.PodTemplateSpec `json:"podSpec,omitempty"`
PodSpecChecksum string `json:"podSpecChecksum,omitempty"`
Checksum string `json:"checksum,omitempty"`

Endpoint *string `json:"endpoint,omitempty"`
}

func (a *ArangoMemberPodTemplate) GetChecksum() string {
Expand Down
12 changes: 12 additions & 0 deletions pkg/apis/deployment/v1/server_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ import (
"time"
)

type ServerGroups []ServerGroup

func (s ServerGroups) Contains(group ServerGroup) bool {
for _, a := range s {
if a == group {
return true
}
}

return false
}

type ServerGroup int

func (g *ServerGroup) UnmarshalJSON(bytes []byte) error {
Expand Down
25 changes: 25 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.

2 changes: 2 additions & 0 deletions pkg/apis/deployment/v2alpha1/arango_member_pod_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type ArangoMemberPodTemplate struct {
PodSpec *core.PodTemplateSpec `json:"podSpec,omitempty"`
PodSpecChecksum string `json:"podSpecChecksum,omitempty"`
Checksum string `json:"checksum,omitempty"`

Endpoint *string `json:"endpoint,omitempty"`
}

func (a *ArangoMemberPodTemplate) GetChecksum() string {
Expand Down
12 changes: 12 additions & 0 deletions pkg/apis/deployment/v2alpha1/server_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ import (
"time"
)

type ServerGroups []ServerGroup

func (s ServerGroups) Contains(group ServerGroup) bool {
for _, a := range s {
if a == group {
return true
}
}

return false
}

type ServerGroup int

func (g *ServerGroup) UnmarshalJSON(bytes []byte) error {
Expand Down
25 changes: 25 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.

39 changes: 28 additions & 11 deletions pkg/deployment/client/client_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"strconv"
"sync"

"github.com/arangodb/kube-arangodb/pkg/deployment/resources"

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

"github.com/arangodb/go-driver/agency"
Expand All @@ -48,16 +50,21 @@ type Cache interface {
GetAgency(ctx context.Context) (agency.Agency, error)
}

func NewClientCache(apiObjectGetter func() *api.ArangoDeployment, factory conn.Factory) Cache {
type CacheGen interface {
resources.DeploymentEndpoints
resources.DeploymentInfoGetter
}

func NewClientCache(in CacheGen, factory conn.Factory) Cache {
return &cache{
apiObjectGetter: apiObjectGetter,
factory: factory,
in: in,
factory: factory,
}
}

type cache struct {
mutex sync.Mutex
apiObjectGetter func() *api.ArangoDeployment
mutex sync.Mutex
in CacheGen

factory conn.Factory
}
Expand All @@ -68,17 +75,22 @@ func (cc *cache) Connection(ctx context.Context, host string) (driver.Connection

func (cc *cache) extendHost(host string) string {
scheme := "http"
if cc.apiObjectGetter().Spec.TLS.IsSecure() {
if cc.in.GetSpec().TLS.IsSecure() {
scheme = "https"
}

return scheme + "://" + net.JoinHostPort(host, strconv.Itoa(k8sutil.ArangoPort))
}

func (cc *cache) getClient(group api.ServerGroup, id string) (driver.Client, error) {
m, _, _ := cc.apiObjectGetter().Status.Members.ElementByID(id)
m, _, _ := cc.in.GetStatusSnapshot().Members.ElementByID(id)

c, err := cc.factory.Client(cc.extendHost(m.GetEndpoint(k8sutil.CreatePodDNSName(cc.apiObjectGetter(), group.AsRole(), id))))
endpoint, err := cc.in.GenerateMemberEndpoint(group, m)
if err != nil {
return nil, err
}

c, err := cc.factory.Client(cc.extendHost(m.GetEndpoint(endpoint)))
if err != nil {
return nil, errors.WithStack(err)
}
Expand Down Expand Up @@ -114,7 +126,7 @@ func (cc *cache) GetAuth() conn.Auth {
}

func (cc *cache) getDatabaseClient() (driver.Client, error) {
c, err := cc.factory.Client(cc.extendHost(k8sutil.CreateDatabaseClientServiceDNSName(cc.apiObjectGetter())))
c, err := cc.factory.Client(cc.extendHost(k8sutil.CreateDatabaseClientServiceDNSName(cc.in.GetAPIObject())))
if err != nil {
return nil, errors.WithStack(err)
}
Expand Down Expand Up @@ -148,8 +160,13 @@ func (cc *cache) GetDatabase(ctx context.Context) (driver.Client, error) {
func (cc *cache) getAgencyClient() (agency.Agency, error) {
// Not found, create a new client
var dnsNames []string
for _, m := range cc.apiObjectGetter().Status.Members.Agents {
dnsNames = append(dnsNames, cc.extendHost(m.GetEndpoint(k8sutil.CreatePodDNSName(cc.apiObjectGetter(), api.ServerGroupAgents.AsRole(), m.ID))))
for _, m := range cc.in.GetStatusSnapshot().Members.Agents {
endpoint, err := cc.in.GenerateMemberEndpoint(api.ServerGroupAgents, m)
if err != nil {
return nil, err
}

dnsNames = append(dnsNames, cc.extendHost(m.GetEndpoint(endpoint)))
}

if len(dnsNames) == 0 {
Expand Down
6 changes: 1 addition & 5 deletions pkg/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func New(config Config, deps Dependencies, apiObject *api.ArangoDeployment) (*De
agencyCache: agency.NewCache(apiObject.Spec.Mode),
}

d.clientCache = deploymentClient.NewClientCache(d.getArangoDeployment, conn.NewFactory(d.getAuth, d.getConnConfig))
d.clientCache = deploymentClient.NewClientCache(d, conn.NewFactory(d.getAuth, d.getConnConfig))

d.status.last = *(apiObject.Status.DeepCopy())
d.reconciler = reconcile.NewReconciler(deps.Log, d)
Expand Down Expand Up @@ -628,10 +628,6 @@ func (d *Deployment) SetNumberOfServers(ctx context.Context, noCoordinators, noD
return nil
}

func (d *Deployment) getArangoDeployment() *api.ArangoDeployment {
return d.apiObject
}

func (d *Deployment) ApplyPatch(ctx context.Context, p ...patch.Item) error {
parser := patch.Patch(p)

Expand Down
2 changes: 1 addition & 1 deletion pkg/deployment/deployment_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func createTestDeployment(t *testing.T, config Config, arangoDeployment *api.Ara
eventCh: make(chan *deploymentEvent, deploymentEventQueueSize),
stopCh: make(chan struct{}),
}
d.clientCache = client.NewClientCache(d.getArangoDeployment, conn.NewFactory(d.getAuth, d.getConnConfig))
d.clientCache = client.NewClientCache(d, conn.NewFactory(d.getAuth, d.getConnConfig))

cachedStatus, err := inspector.NewInspector(context.Background(), d.getKubeCli(), d.getMonitoringV1Cli(), d.getArangoCli(), d.GetNamespace())
require.NoError(t, err)
Expand Down
10 changes: 6 additions & 4 deletions pkg/deployment/reconcile/action_arango_member_update_pod_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ package reconcile
import (
"context"

"github.com/arangodb/kube-arangodb/pkg/deployment/pod"

"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -82,15 +80,14 @@ func (a *actionArangoMemberUpdatePodSpec) Start(ctx context.Context) (bool, erro
return false, err
}

endpoint, err := pod.GenerateMemberEndpoint(a.actionCtx.GetCachedStatus(), a.actionCtx.GetAPIObject(), spec, a.action.Group, m)
endpoint, err := a.actionCtx.GenerateMemberEndpoint(a.action.Group, m)
if err != nil {
log.Error().Err(err).Msg("Unable to render endpoint")
return false, err
}

if m.Endpoint == nil || *m.Endpoint != endpoint {
// Update endpoint
m.Endpoint = &endpoint
if err := status.Members.Update(m, a.action.Group); err != nil {
log.Error().Err(err).Msg("Unable to update endpoint")
return false, err
Expand Down Expand Up @@ -127,6 +124,11 @@ func (a *actionArangoMemberUpdatePodSpec) Start(ctx context.Context) (bool, erro
return false, err
}

if z := m.Endpoint; z != nil {
q := *z
template.Endpoint = &q
}

if err := a.actionCtx.WithArangoMemberUpdate(context.Background(), member.GetNamespace(), member.GetName(), func(member *api.ArangoMember) bool {
if !member.Spec.Template.Equals(template) {
member.Spec.Template = template.DeepCopy()
Expand Down