Skip to content

Commit e183277

Browse files
author
lamai93
committed
Advertise endpoint if set in spec. Immutable.
1 parent 89564fe commit e183277

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

pkg/apis/deployment/v1alpha/external_access_spec.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
package v1alpha
2424

2525
import (
26+
"fmt"
27+
"net/url"
28+
2629
"github.com/arangodb/kube-arangodb/pkg/util"
2730
)
2831

@@ -34,6 +37,8 @@ type ExternalAccessSpec struct {
3437
NodePort *int `json:"nodePort,omitempty"`
3538
// Optional IP used to configure a load-balancer on, in case of Auto or LoadBalancer type.
3639
LoadBalancerIP *string `json:"loadBalancerIP,omitempty"`
40+
// Advertised Endpoint is passed to the coordinators/single servers for advertising a specific endpoint
41+
AdvertisedEndpoint *string `json:"advertisedEndpoint,omitempty"`
3742
}
3843

3944
// GetType returns the value of type.
@@ -51,11 +56,27 @@ func (s ExternalAccessSpec) GetLoadBalancerIP() string {
5156
return util.StringOrDefault(s.LoadBalancerIP)
5257
}
5358

59+
// GetAdvertisedEndpoint returns the advertised endpoint or empty string if none was specified
60+
func (s ExternalAccessSpec) GetAdvertisedEndpoint() string {
61+
return util.StringOrDefault(s.AdvertisedEndpoint)
62+
}
63+
64+
// HasAdvertisedEndpoint return whether an advertised endpoint was specified or not
65+
func (s ExternalAccessSpec) HasAdvertisedEndpoint() bool {
66+
return s.AdvertisedEndpoint != nil
67+
}
68+
5469
// Validate the given spec
5570
func (s ExternalAccessSpec) Validate() error {
5671
if err := s.GetType().Validate(); err != nil {
5772
return maskAny(err)
5873
}
74+
if s.AdvertisedEndpoint != nil {
75+
ep := s.GetAdvertisedEndpoint()
76+
if _, err := url.Parse(ep); err != nil {
77+
return maskAny(fmt.Errorf("Failed to parse advertised endpoint '%s': %s", ep, err))
78+
}
79+
}
5980
return nil
6081
}
6182

@@ -74,11 +95,21 @@ func (s *ExternalAccessSpec) SetDefaultsFrom(source ExternalAccessSpec) {
7495
if s.LoadBalancerIP == nil {
7596
s.LoadBalancerIP = util.NewStringOrNil(source.LoadBalancerIP)
7697
}
98+
if s.AdvertisedEndpoint == nil {
99+
s.AdvertisedEndpoint = source.AdvertisedEndpoint
100+
}
77101
}
78102

79103
// ResetImmutableFields replaces all immutable fields in the given target with values from the source spec.
80104
// It returns a list of fields that have been reset.
81105
// Field names are relative to given field prefix.
82106
func (s ExternalAccessSpec) ResetImmutableFields(fieldPrefix string, target *ExternalAccessSpec) []string {
107+
var resetFields []string
108+
109+
// THIS SHOULD NOT BE IMMUTABLE!
110+
if s.GetAdvertisedEndpoint() != target.GetAdvertisedEndpoint() {
111+
target.AdvertisedEndpoint = util.NewStringOrNil(s.AdvertisedEndpoint)
112+
resetFields = append(resetFields, fieldPrefix+".advertisedEndpoint")
113+
}
83114
return nil
84115
}

pkg/apis/deployment/v1alpha/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/deployment/reconcile/action_cleanout_member.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (a *actionCleanoutMember) CheckProgress(ctx context.Context) (bool, bool, e
9797
}
9898
// do not try to clean out a pod that was not initialized
9999
if !m.IsInitialized {
100-
return false, true, nil
100+
return true, false, nil
101101
}
102102
c, err := a.actionCtx.GetDatabaseClient(ctx)
103103
if err != nil {

pkg/deployment/resources/pod_creator.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ func createArangodArgs(apiObject metav1.Object, deplSpec api.DeploymentSpec, gro
180180
optionPair{"--foxx.queues", "true"},
181181
optionPair{"--server.statistics", "true"},
182182
)
183+
if deplSpec.ExternalAccess.HasAdvertisedEndpoint() {
184+
options = append(options,
185+
optionPair{"--cluster.my-advertised-endpoint", deplSpec.ExternalAccess.GetAdvertisedEndpoint()},
186+
)
187+
}
183188
case api.ServerGroupSingle:
184189
options = append(options,
185190
optionPair{"--foxx.queues", "true"},
@@ -192,6 +197,11 @@ func createArangodArgs(apiObject metav1.Object, deplSpec api.DeploymentSpec, gro
192197
optionPair{"--cluster.my-address", myTCPURL},
193198
optionPair{"--cluster.my-role", "SINGLE"},
194199
)
200+
if deplSpec.ExternalAccess.HasAdvertisedEndpoint() {
201+
options = append(options,
202+
optionPair{"--cluster.my-advertised-endpoint", deplSpec.ExternalAccess.GetAdvertisedEndpoint()},
203+
)
204+
}
195205
}
196206
}
197207
if addAgentEndpoints {

0 commit comments

Comments
 (0)