MCPcopy Create free account
hub / github.com/devfile/devworkspace-operator / discoverRouteSuffix

Function discoverRouteSuffix

pkg/config/sync.go:211–248  ·  view source on GitHub ↗

discoverRouteSuffix attempts to determine a clusterHostSuffix that is compatible with the current cluster. On OpenShift, this is done by creating a temporary route and reading the auto-filled .spec.host. On Kubernetes, there's no way to determine this value automatically so ("", nil) is returned.

(client crclient.Client)

Source from the content-addressed store, hash-verified

209// On OpenShift, this is done by creating a temporary route and reading the auto-filled .spec.host. On Kubernetes,
210// there's no way to determine this value automatically so ("", nil) is returned.
211func discoverRouteSuffix(client crclient.Client) (string, error) {
212 if !infrastructure.IsOpenShift() {
213 return "", nil
214 }
215
216 testRoute := &routeV1.Route{
217 ObjectMeta: metav1.ObjectMeta{
218 Namespace: configNamespace,
219 Name: openShiftTestRouteName,
220 },
221 Spec: routeV1.RouteSpec{
222 To: routeV1.RouteTargetReference{
223 Kind: "Service",
224 Name: "devworkspace-controller-test-route",
225 },
226 },
227 }
228
229 err := client.Create(context.TODO(), testRoute)
230 if err != nil {
231 if k8sErrors.IsAlreadyExists(err) {
232 err := client.Get(context.TODO(), types.NamespacedName{
233 Name: openShiftTestRouteName,
234 Namespace: configNamespace,
235 }, testRoute)
236 if err != nil {
237 return "", err
238 }
239 } else {
240 return "", err
241 }
242 }
243 defer client.Delete(context.TODO(), testRoute)
244 host := testRoute.Spec.Host
245 prefixToRemove := fmt.Sprintf("%s-%s.", openShiftTestRouteName, configNamespace)
246 host = strings.TrimPrefix(host, prefixToRemove)
247 return host, nil
248}
249
250func mergeConfig(from, to *controller.OperatorConfiguration) {
251 if to == nil {

Callers 1

SetupControllerConfigFunction · 0.85

Calls 2

IsOpenShiftFunction · 0.92
GetMethod · 0.65

Tested by

no test coverage detected