@@ -17,10 +17,7 @@ limitations under the License.
1717package backend
1818
1919import (
20- "context"
2120 "fmt"
22- "net/url"
23- "strings"
2421
2522 "github.com/kcp-dev/multicluster-provider/apiexport"
2623 apisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
@@ -49,8 +46,9 @@ type Config struct {
4946
5047 Provider multicluster.Provider
5148 ExternalAddressGenerator kuberesources.ExternalAddressGeneratorFunc
52- Manager mcmanager.Manager
53- Scheme * runtime.Scheme
49+
50+ Manager mcmanager.Manager
51+ Scheme * runtime.Scheme
5452
5553 ClientConfig * rest.Config
5654}
@@ -106,7 +104,7 @@ func NewConfig(options *options.CompletedOptions) (*Config, error) {
106104 return nil , fmt .Errorf ("error setting up kcp provider: %w" , err )
107105 }
108106
109- gen , err := newKCPExternalAddressGenerator (options .ExternalAddress )
107+ gen , err := kcpprovider . NewKCPExternalAddressGenerator (options .ExternalAddress )
110108 if err != nil {
111109 return nil , err
112110 }
@@ -137,44 +135,3 @@ func NewConfig(options *options.CompletedOptions) (*Config, error) {
137135
138136 return config , nil
139137}
140-
141- func newKCPExternalAddressGenerator (externalAddress string ) (kuberesources.ExternalAddressGeneratorFunc , error ) {
142- var extURL * url.URL
143- if externalAddress != "" {
144- var err error
145-
146- extURL , err = url .Parse (externalAddress )
147- if err != nil {
148- return nil , fmt .Errorf ("invalid --external-address: %w" , err )
149- }
150- }
151-
152- return func (_ context.Context , clusterConfig * rest.Config ) (string , error ) {
153- // In kcp case, we are talking via apiexport so clientconfig will be pointing to
154- // https://192.168.2.166:6443/services/apiexport/root:org:ws/<apiexport-name>/clusters/2p0rtkf7b697s6mj
155- // We need to extract host and /clusters/... part
156- u , err := url .Parse (clusterConfig .Host )
157- if err != nil {
158- return "" , err
159- }
160-
161- // Extract cluster ID from the path
162- // Path format: /services/apiexport/root:org:ws/<apiexport-name>/clusters/{cluster-id}
163- pathParts := strings .Split (strings .Trim (u .Path , "/" ), "/" )
164- if len (pathParts ) < 6 || pathParts [4 ] != "clusters" {
165- return "" , fmt .Errorf ("invalid apiexport URL format" )
166- }
167-
168- clusterID := pathParts [5 ]
169-
170- // Construct new URL with cluster path
171- var finalURL = u
172- if extURL != nil {
173- finalURL = extURL
174- }
175-
176- finalURL .Path = "/clusters/" + clusterID
177-
178- return finalURL .String (), nil
179- }, nil
180- }
0 commit comments