use of org.eclipse.che.workspace.infrastructure.kubernetes.server.external.GatewayRouteConfigGenerator in project che-server by eclipse-che.
the class GatewayRouterProvisioner method provision.
@Override
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
for (Entry<String, ConfigMap> configMapEntry : k8sEnv.getConfigMaps().entrySet()) {
if (configmapLabels.isGatewayConfig(configMapEntry.getValue())) {
ConfigMap gatewayConfigMap = configMapEntry.getValue();
Map<String, ServerConfigImpl> servers = new Annotations.Deserializer(gatewayConfigMap.getMetadata().getAnnotations()).servers();
if (servers.size() != 1) {
throw new InfrastructureException("Expected exactly 1 server in gateway config ConfigMap's '" + gatewayConfigMap.getMetadata().getName() + "' annotations. This is a bug, please report.");
}
Entry<String, ServerConfigImpl> serverConfigEntry = servers.entrySet().iterator().next();
ServerConfigImpl server = serverConfigEntry.getValue();
if (!server.getAttributes().containsKey(SERVICE_NAME_ATTRIBUTE) || !server.getAttributes().containsKey(SERVICE_PORT_ATTRIBUTE)) {
throw new InfrastructureException("Expected `serviceName` and `servicePort` in gateway config ServerConfig attributes for gateway config Configmap '" + gatewayConfigMap.getMetadata().getName() + "'. This is a bug, please report.");
}
// We're now creating only 1 gateway route configuration per ConfigMap, so we need to create
// generator in each loop iteration.
GatewayRouteConfigGenerator gatewayRouteConfigGenerator = configGeneratorFactory.create();
gatewayRouteConfigGenerator.addRouteConfig(configMapEntry.getKey(), gatewayConfigMap);
Map<String, String> gatewayConfiguration = gatewayRouteConfigGenerator.generate(identity.getInfrastructureNamespace());
gatewayConfigMap.setData(gatewayConfiguration);
// Configuration is now generated, so remove these internal attributes
server.getAttributes().remove(SERVICE_NAME_ATTRIBUTE);
server.getAttributes().remove(SERVICE_PORT_ATTRIBUTE);
gatewayConfigMap.getMetadata().getAnnotations().putAll(new Annotations.Serializer().server(serverConfigEntry.getKey(), server).annotations());
}
}
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.server.external.GatewayRouteConfigGenerator in project devspaces-images by redhat-developer.
the class GatewayRouterProvisioner method provision.
@Override
public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
for (Entry<String, ConfigMap> configMapEntry : k8sEnv.getConfigMaps().entrySet()) {
if (configmapLabels.isGatewayConfig(configMapEntry.getValue())) {
ConfigMap gatewayConfigMap = configMapEntry.getValue();
Map<String, ServerConfigImpl> servers = new Annotations.Deserializer(gatewayConfigMap.getMetadata().getAnnotations()).servers();
if (servers.size() != 1) {
throw new InfrastructureException("Expected exactly 1 server in gateway config ConfigMap's '" + gatewayConfigMap.getMetadata().getName() + "' annotations. This is a bug, please report.");
}
Entry<String, ServerConfigImpl> serverConfigEntry = servers.entrySet().iterator().next();
ServerConfigImpl server = serverConfigEntry.getValue();
if (!server.getAttributes().containsKey(SERVICE_NAME_ATTRIBUTE) || !server.getAttributes().containsKey(SERVICE_PORT_ATTRIBUTE)) {
throw new InfrastructureException("Expected `serviceName` and `servicePort` in gateway config ServerConfig attributes for gateway config Configmap '" + gatewayConfigMap.getMetadata().getName() + "'. This is a bug, please report.");
}
// We're now creating only 1 gateway route configuration per ConfigMap, so we need to create
// generator in each loop iteration.
GatewayRouteConfigGenerator gatewayRouteConfigGenerator = configGeneratorFactory.create();
gatewayRouteConfigGenerator.addRouteConfig(configMapEntry.getKey(), gatewayConfigMap);
Map<String, String> gatewayConfiguration = gatewayRouteConfigGenerator.generate(identity.getInfrastructureNamespace());
gatewayConfigMap.setData(gatewayConfiguration);
// Configuration is now generated, so remove these internal attributes
server.getAttributes().remove(SERVICE_NAME_ATTRIBUTE);
server.getAttributes().remove(SERVICE_PORT_ATTRIBUTE);
gatewayConfigMap.getMetadata().getAnnotations().putAll(new Annotations.Serializer().server(serverConfigEntry.getKey(), server).annotations());
}
}
}
Aggregations