Search in sources :

Example 1 with GatewayRouteConfigGenerator

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());
        }
    }
}
Also used : Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) GatewayRouteConfigGenerator(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.GatewayRouteConfigGenerator) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 2 with GatewayRouteConfigGenerator

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());
        }
    }
}
Also used : Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) GatewayRouteConfigGenerator(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.GatewayRouteConfigGenerator) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Aggregations

ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)2 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)2 Annotations (org.eclipse.che.workspace.infrastructure.kubernetes.Annotations)2 GatewayRouteConfigGenerator (org.eclipse.che.workspace.infrastructure.kubernetes.server.external.GatewayRouteConfigGenerator)2