9
9
"fmt"
10
10
"net"
11
11
"strconv"
12
+ "strings"
12
13
13
14
"github.com/pkg/errors"
14
15
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -20,15 +21,38 @@ import (
20
21
"github.com/clastix/cluster-api-control-plane-provider-kamaji/api/v1alpha1"
21
22
)
22
23
23
- func (r * KamajiControlPlaneReconciler ) patchControlPlaneEndpoint ( ctx context. Context , controlPlane * v1alpha1.KamajiControlPlane , hostPort string ) error {
24
- endpoint , strPort , err := net .SplitHostPort (hostPort )
24
+ func (r * KamajiControlPlaneReconciler ) controlPlaneEndpoint ( controlPlane * v1alpha1.KamajiControlPlane , statusEndpoint string ) ( string , int64 , error ) {
25
+ endpoint , strPort , err := net .SplitHostPort (statusEndpoint )
25
26
if err != nil {
26
- return errors .Wrap (err , "cannot split the Kamaji endpoint host port pair" )
27
+ return "" , 0 , errors .Wrap (err , "cannot split the Kamaji endpoint host port pair" )
27
28
}
28
29
29
30
port , pErr := strconv .ParseInt (strPort , 10 , 16 )
30
31
if pErr != nil {
31
- return errors .Wrap (pErr , "cannot convert port to integer" )
32
+ return "" , 0 , errors .Wrap (pErr , "cannot convert port to integer" )
33
+ }
34
+
35
+ if ingress := controlPlane .Spec .Network .Ingress ; ingress != nil {
36
+ if len (strings .Split (ingress .Hostname , ":" )) == 1 {
37
+ ingress .Hostname += ":443"
38
+ }
39
+
40
+ if endpoint , strPort , err = net .SplitHostPort (ingress .Hostname ); err != nil {
41
+ return "" , 0 , errors .Wrap (err , "cannot split the Kamaji Ingress hostname host port pair" )
42
+ }
43
+
44
+ if port , pErr = strconv .ParseInt (strPort , 10 , 64 ); pErr != nil {
45
+ return "" , 0 , errors .Wrap (pErr , "cannot convert Kamaji Ingress hostname port pair" )
46
+ }
47
+ }
48
+
49
+ return endpoint , port , nil
50
+ }
51
+
52
+ func (r * KamajiControlPlaneReconciler ) patchControlPlaneEndpoint (ctx context.Context , controlPlane * v1alpha1.KamajiControlPlane , hostPort string ) error {
53
+ endpoint , port , err := r .controlPlaneEndpoint (controlPlane , hostPort )
54
+ if err != nil {
55
+ return errors .Wrap (err , "cannot retrieve ControlPlaneEndpoint" )
32
56
}
33
57
34
58
if err = retry .RetryOnConflict (retry .DefaultRetry , func () error {
@@ -50,19 +74,14 @@ func (r *KamajiControlPlaneReconciler) patchControlPlaneEndpoint(ctx context.Con
50
74
}
51
75
52
76
//nolint:cyclop
53
- func (r * KamajiControlPlaneReconciler ) patchCluster (ctx context.Context , cluster capiv1beta1.Cluster , hostPort string ) error {
77
+ func (r * KamajiControlPlaneReconciler ) patchCluster (ctx context.Context , cluster capiv1beta1.Cluster , controlPlane * v1alpha1. KamajiControlPlane , hostPort string ) error {
54
78
if cluster .Spec .InfrastructureRef == nil {
55
79
return errors .New ("capiv1beta1.Cluster has no InfrastructureRef" )
56
80
}
57
81
58
- endpoint , strPort , err := net .SplitHostPort (hostPort )
59
- if err != nil {
60
- return errors .Wrap (err , "cannot split the Kamaji endpoint host port pair" )
61
- }
62
-
63
- port , err := strconv .ParseInt (strPort , 10 , 64 )
82
+ endpoint , port , err := r .controlPlaneEndpoint (controlPlane , hostPort )
64
83
if err != nil {
65
- return errors .Wrap (err , "cannot convert Kamaji endpoint port pair " )
84
+ return errors .Wrap (err , "cannot retrieve ControlPlaneEndpoint " )
66
85
}
67
86
68
87
switch cluster .Spec .InfrastructureRef .Kind {
0 commit comments