2323package v1alpha
2424
2525import (
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
5570func (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.
82106func (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}
0 commit comments