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)
| 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. |
| 211 | func 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 | |
| 250 | func mergeConfig(from, to *controller.OperatorConfiguration) { |
| 251 | if to == nil { |
no test coverage detected