@@ -54,10 +54,14 @@ const (
54
54
antiAffinityLabelValue = "exclusive"
55
55
56
56
// Name of config map containing tmpnet defaults
57
- kubeRuntimeConfigMapName = "tmpnet"
57
+ defaultsConfigMapName = "tmpnet-defaults"
58
+ ingressHostKey = "ingressHost"
58
59
)
59
60
60
- var errMissingSchedulingLabels = errors .New ("--kube-scheduling-label-key and --kube-scheduling-label-value are required when exclusive scheduling is enabled" )
61
+ var (
62
+ errMissingSchedulingLabels = errors .New ("--kube-scheduling-label-key and --kube-scheduling-label-value are required when exclusive scheduling is enabled" )
63
+ errMissingIngressHost = errors .New ("IngressHost is a required value. Ensure the " + defaultsConfigMapName + " ConfigMap contains an entry for " + ingressHostKey )
64
+ )
61
65
62
66
type KubeRuntimeConfig struct {
63
67
// Path to the kubeconfig file identifying the target cluster
@@ -78,14 +82,18 @@ type KubeRuntimeConfig struct {
78
82
SchedulingLabelKey string `json:"schedulingLabelKey,omitempty"`
79
83
// Label value to use for exclusive scheduling for node selection and toleration
80
84
SchedulingLabelValue string `json:"schedulingLabelValue,omitempty"`
81
- // Base URI for constructing node URIs when running outside of the cluster hosting nodes (e.g., "http://localhost:30791")
82
- BaseAccessibleURI string `json:"baseAccessibleURI,omitempty"`
85
+ // Host for ingress rules (e.g., "localhost:30791" for kind, "tmpnet.example.com" for EKS)
86
+ IngressHost string `json:"ingressHost,omitempty"`
87
+ // TLS secret name for ingress (empty for HTTP, populated for HTTPS)
88
+ IngressSecret string `json:"ingressSecret,omitempty"`
83
89
}
84
90
85
91
// ensureDefaults sets cluster-specific defaults for fields not already set by flags.
86
92
func (c * KubeRuntimeConfig ) ensureDefaults (ctx context.Context , log logging.Logger ) error {
93
+ // Only read defaults if necessary
87
94
requireSchedulingDefaults := c .UseExclusiveScheduling && (len (c .SchedulingLabelKey ) == 0 || len (c .SchedulingLabelValue ) == 0 )
88
- if ! requireSchedulingDefaults {
95
+ requireIngressDefaults := ! IsRunningInCluster () && len (c .IngressHost ) == 0
96
+ if ! requireSchedulingDefaults && ! requireIngressDefaults {
89
97
return nil
90
98
}
91
99
@@ -96,34 +104,55 @@ func (c *KubeRuntimeConfig) ensureDefaults(ctx context.Context, log logging.Logg
96
104
97
105
log .Info ("attempting to retrieve configmap containing tmpnet defaults" ,
98
106
zap .String ("namespace" , c .Namespace ),
99
- zap .String ("configMap" , kubeRuntimeConfigMapName ),
107
+ zap .String ("configMap" , defaultsConfigMapName ),
100
108
)
101
109
102
- configMap , err := clientset .CoreV1 ().ConfigMaps (c .Namespace ).Get (ctx , kubeRuntimeConfigMapName , metav1.GetOptions {})
110
+ configMap , err := clientset .CoreV1 ().ConfigMaps (c .Namespace ).Get (ctx , defaultsConfigMapName , metav1.GetOptions {})
103
111
if err != nil {
104
112
return fmt .Errorf ("failed to get ConfigMap: %w" , err )
105
113
}
106
114
107
- var (
108
- schedulingLabelKey = configMap .Data ["schedulingLabelKey" ]
109
- schedulingLabelValue = configMap .Data ["schedulingLabelValue" ]
110
- )
111
- if len (c .SchedulingLabelKey ) == 0 && len (schedulingLabelKey ) > 0 {
112
- log .Info ("setting default value for SchedulingLabelKey" ,
113
- zap .String ("schedulingLabelKey" , schedulingLabelKey ),
115
+ if requireSchedulingDefaults {
116
+ var (
117
+ schedulingLabelKey = configMap .Data ["schedulingLabelKey" ]
118
+ schedulingLabelValue = configMap .Data ["schedulingLabelValue" ]
114
119
)
115
- c .SchedulingLabelKey = schedulingLabelKey
120
+ if len (c .SchedulingLabelKey ) == 0 && len (schedulingLabelKey ) > 0 {
121
+ log .Info ("setting default value for SchedulingLabelKey" ,
122
+ zap .String ("schedulingLabelKey" , schedulingLabelKey ),
123
+ )
124
+ c .SchedulingLabelKey = schedulingLabelKey
125
+ }
126
+ if len (c .SchedulingLabelValue ) == 0 && len (schedulingLabelValue ) > 0 {
127
+ log .Info ("setting default value for SchedulingLabelValue" ,
128
+ zap .String ("schedulingLabelValue" , schedulingLabelValue ),
129
+ )
130
+ c .SchedulingLabelValue = schedulingLabelValue
131
+ }
132
+ if len (c .SchedulingLabelKey ) == 0 || len (c .SchedulingLabelValue ) == 0 {
133
+ return errMissingSchedulingLabels
134
+ }
116
135
}
117
- if len (c .SchedulingLabelValue ) == 0 && len (schedulingLabelValue ) > 0 {
118
- log .Info ("setting default value for SchedulingLabelValue" ,
119
- zap .String ("schedulingLabelValue" , schedulingLabelValue ),
136
+ if requireIngressDefaults {
137
+ var (
138
+ ingressHost = configMap .Data [ingressHostKey ]
139
+ ingressSecret = configMap .Data ["ingressSecret" ]
120
140
)
121
- c .SchedulingLabelValue = schedulingLabelValue
122
- }
123
-
124
- // Validate that the scheduling labels are now set
125
- if len (c .SchedulingLabelKey ) == 0 || len (c .SchedulingLabelValue ) == 0 {
126
- return errMissingSchedulingLabels
141
+ if len (c .IngressHost ) == 0 && len (ingressHost ) > 0 {
142
+ log .Info ("setting default value for IngressHost" ,
143
+ zap .String ("ingressHost" , ingressHost ),
144
+ )
145
+ c .IngressHost = ingressHost
146
+ }
147
+ if len (c .IngressSecret ) == 0 && len (ingressSecret ) > 0 {
148
+ log .Info ("setting default value for IngressSecret" ,
149
+ zap .String ("ingressSecret" , ingressSecret ),
150
+ )
151
+ c .IngressSecret = ingressSecret
152
+ }
153
+ if len (c .IngressHost ) == 0 {
154
+ return errMissingIngressHost
155
+ }
127
156
}
128
157
129
158
return nil
@@ -150,8 +179,8 @@ func (p *KubeRuntime) readState(ctx context.Context) error {
150
179
)
151
180
152
181
// Validate that it will be possible to construct accessible URIs when running external to the kube cluster
153
- if ! IsRunningInCluster () && len (runtimeConfig .BaseAccessibleURI ) == 0 {
154
- return errors .New ("BaseAccessibleURI must be set when running outside of the kubernetes cluster" )
182
+ if ! IsRunningInCluster () && len (runtimeConfig .IngressHost ) == 0 {
183
+ return errors .New ("IngressHost must be set when running outside of the kubernetes cluster" )
155
184
}
156
185
157
186
clientset , err := p .getClientset ()
@@ -207,11 +236,18 @@ func (p *KubeRuntime) GetAccessibleURI() string {
207
236
return p .node .URI
208
237
}
209
238
210
- baseURI := p .runtimeConfig ().BaseAccessibleURI
211
- nodeID := p .node .NodeID .String ()
212
- networkUUID := p .node .network .UUID
239
+ var (
240
+ protocol = "http"
241
+ nodeID = p .node .NodeID .String ()
242
+ networkUUID = p .node .network .UUID
243
+ runtimeConfig = p .runtimeConfig ()
244
+ )
245
+ // Assume tls is configured for an ingress secret
246
+ if len (runtimeConfig .IngressSecret ) > 0 {
247
+ protocol = "https"
248
+ }
213
249
214
- return fmt .Sprintf ("%s/ networks/%s/%s" , baseURI , networkUUID , nodeID )
250
+ return fmt .Sprintf ("%s://%s/ networks/%s/%s" , protocol , runtimeConfig . IngressHost , networkUUID , nodeID )
215
251
}
216
252
217
253
// GetAccessibleStakingAddress retrieves a StakingAddress for the node intended to be
@@ -993,6 +1029,35 @@ func (p *KubeRuntime) createNodeIngress(ctx context.Context, serviceName string)
993
1029
pathType = networkingv1 .PathTypeImplementationSpecific
994
1030
)
995
1031
1032
+ // Build the ingress rules
1033
+ ingressRules := []networkingv1.IngressRule {
1034
+ {
1035
+ IngressRuleValue : networkingv1.IngressRuleValue {
1036
+ HTTP : & networkingv1.HTTPIngressRuleValue {
1037
+ Paths : []networkingv1.HTTPIngressPath {
1038
+ {
1039
+ Path : pathPattern ,
1040
+ PathType : & pathType ,
1041
+ Backend : networkingv1.IngressBackend {
1042
+ Service : & networkingv1.IngressServiceBackend {
1043
+ Name : serviceName ,
1044
+ Port : networkingv1.ServiceBackendPort {
1045
+ Number : config .DefaultHTTPPort ,
1046
+ },
1047
+ },
1048
+ },
1049
+ },
1050
+ },
1051
+ },
1052
+ },
1053
+ },
1054
+ }
1055
+
1056
+ // Add host if not localhost
1057
+ if ! strings .HasPrefix (runtimeConfig .IngressHost , "localhost" ) {
1058
+ ingressRules [0 ].Host = runtimeConfig .IngressHost
1059
+ }
1060
+
996
1061
ingress := & networkingv1.Ingress {
997
1062
ObjectMeta : metav1.ObjectMeta {
998
1063
Name : serviceName ,
@@ -1012,31 +1077,20 @@ func (p *KubeRuntime) createNodeIngress(ctx context.Context, serviceName string)
1012
1077
},
1013
1078
Spec : networkingv1.IngressSpec {
1014
1079
IngressClassName : & ingressClassName ,
1015
- Rules : []networkingv1.IngressRule {
1016
- {
1017
- IngressRuleValue : networkingv1.IngressRuleValue {
1018
- HTTP : & networkingv1.HTTPIngressRuleValue {
1019
- Paths : []networkingv1.HTTPIngressPath {
1020
- {
1021
- Path : pathPattern ,
1022
- PathType : & pathType ,
1023
- Backend : networkingv1.IngressBackend {
1024
- Service : & networkingv1.IngressServiceBackend {
1025
- Name : serviceName ,
1026
- Port : networkingv1.ServiceBackendPort {
1027
- Number : config .DefaultHTTPPort ,
1028
- },
1029
- },
1030
- },
1031
- },
1032
- },
1033
- },
1034
- },
1035
- },
1036
- },
1080
+ Rules : ingressRules ,
1037
1081
},
1038
1082
}
1039
1083
1084
+ // Add TLS configuration if IngressSecret is set
1085
+ if len (runtimeConfig .IngressSecret ) > 0 && ! strings .HasPrefix (runtimeConfig .IngressHost , "localhost" ) {
1086
+ ingress .Spec .TLS = []networkingv1.IngressTLS {
1087
+ {
1088
+ Hosts : []string {runtimeConfig .IngressHost },
1089
+ SecretName : runtimeConfig .IngressSecret ,
1090
+ },
1091
+ }
1092
+ }
1093
+
1040
1094
_ , err = clientset .NetworkingV1 ().Ingresses (namespace ).Create (ctx , ingress , metav1.CreateOptions {})
1041
1095
if err != nil {
1042
1096
return fmt .Errorf ("failed to create Ingress: %w" , err )
0 commit comments