Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't set public url value to internal url settings. #891

Merged
merged 3 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 17 additions & 24 deletions pkg/deploy/server/server_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type CheConfigMap struct {
CheApi string `json:"CHE_API"`
CheApiInternal string `json:"CHE_API_INTERNAL"`
CheWebSocketEndpoint string `json:"CHE_WEBSOCKET_ENDPOINT"`
CheWebSocketInternalEndpoint string `json:"CHE_WEBSOCKET_INTERNAL_ENDPOINT"`
CheDebugServer string `json:"CHE_DEBUG_SERVER"`
CheMetricsEnabled string `json:"CHE_METRICS_ENABLED"`
CheInfrastructureActive string `json:"CHE_INFRASTRUCTURE_ACTIVE"`
Expand Down Expand Up @@ -76,6 +77,7 @@ type CheConfigMap struct {
DevfileRegistryUrl string `json:"CHE_WORKSPACE_DEVFILE__REGISTRY__URL,omitempty"`
DevfileRegistryInternalUrl string `json:"CHE_WORKSPACE_DEVFILE__REGISTRY__INTERNAL__URL,omitempty"`
WebSocketEndpointMinor string `json:"CHE_WEBSOCKET_ENDPOINT__MINOR"`
WebSocketInternalEndpointMinir string `json:"CHE_WEBSOCKET_INTERNAL_ENDPOINT__MINOR"`
AndrienkoAleksandr marked this conversation as resolved.
Show resolved Hide resolved
CheWorkspacePluginBrokerMetadataImage string `json:"CHE_WORKSPACE_PLUGIN__BROKER_METADATA_IMAGE,omitempty"`
CheWorkspacePluginBrokerArtifactsImage string `json:"CHE_WORKSPACE_PLUGIN__BROKER_ARTIFACTS_IMAGE,omitempty"`
CheServerSecureExposerJwtProxyImage string `json:"CHE_SERVER_SECURE__EXPOSER_JWTPROXY_IMAGE,omitempty"`
Expand Down Expand Up @@ -187,45 +189,34 @@ func (s *Server) getCheConfigMapData() (cheEnv map[string]string, err error) {
workspaceNamespaceDefault := util.GetWorkspaceNamespaceDefault(s.deployContext.CheCluster)

cheAPI := protocol + "://" + cheHost + "/api"
var keycloakInternalURL, pluginRegistryInternalURL, devfileRegistryInternalURL, cheInternalAPI, webSocketEndpoint, webSocketEndpointMinor string
var webSocketEndpoint, webSocketEndpointMinor string
var keycloakInternalURL, pluginRegistryInternalURL, devfileRegistryInternalURL, cheInternalAPI, webSocketInternalEndpoint, webSocketInternalEndpointMinor string

if s.deployContext.CheCluster.IsInternalClusterSVCNamesEnabled() && !s.deployContext.CheCluster.Spec.Auth.ExternalIdentityProvider {
keycloakInternalURL = fmt.Sprintf("%s://%s.%s.svc:8080/auth", "http", deploy.IdentityProviderName, s.deployContext.CheCluster.Namespace)
} else {
keycloakInternalURL = keycloakURL
}

// If there is a devfile registry deployed by operator
if !s.deployContext.CheCluster.Spec.Server.ExternalDevfileRegistry {
if s.deployContext.CheCluster.IsInternalClusterSVCNamesEnabled() {
devfileRegistryInternalURL = fmt.Sprintf("http://%s.%s.svc:8080", deploy.DevfileRegistryName, s.deployContext.CheCluster.Namespace)
} else {
devfileRegistryInternalURL = s.deployContext.CheCluster.Status.DevfileRegistryURL
}
if s.deployContext.CheCluster.IsInternalClusterSVCNamesEnabled() && !s.deployContext.CheCluster.Spec.Server.ExternalDevfileRegistry {
devfileRegistryInternalURL = fmt.Sprintf("http://%s.%s.svc:8080", deploy.DevfileRegistryName, s.deployContext.CheCluster.Namespace)
}

if s.deployContext.CheCluster.IsInternalClusterSVCNamesEnabled() && !s.deployContext.CheCluster.Spec.Server.ExternalPluginRegistry {
pluginRegistryInternalURL = fmt.Sprintf("http://%s.%s.svc:8080/v3", deploy.PluginRegistryName, s.deployContext.CheCluster.Namespace)
} else {
pluginRegistryInternalURL = pluginRegistryURL
}

if s.deployContext.CheCluster.IsInternalClusterSVCNamesEnabled() {
cheInternalAPI = fmt.Sprintf("http://%s.%s.svc:8080/api", deploy.CheServiceName, s.deployContext.CheCluster.Namespace)
webSocketEndpoint = fmt.Sprintf("ws://%s.%s.svc:8080/api/websocket", deploy.CheServiceName, s.deployContext.CheCluster.Namespace)
webSocketEndpointMinor = fmt.Sprintf("ws://%s.%s.svc:8080/api/websocket-minor", deploy.CheServiceName, s.deployContext.CheCluster.Namespace)
} else {
cheInternalAPI = cheAPI

wsprotocol := "ws"

if tlsSupport {
wsprotocol = "wss"
}

webSocketEndpoint = wsprotocol + "://" + cheHost + "/api/websocket"
webSocketEndpointMinor = wsprotocol + "://" + cheHost + "/api/websocket-minor"
webSocketInternalEndpoint = fmt.Sprintf("ws://%s.%s.svc:8080/api/websocket", deploy.CheServiceName, s.deployContext.CheCluster.Namespace)
webSocketInternalEndpointMinor = fmt.Sprintf("ws://%s.%s.svc:8080/api/websocket-minor", deploy.CheServiceName, s.deployContext.CheCluster.Namespace)
}

wsprotocol := "ws"
if tlsSupport {
wsprotocol = "wss"
}
webSocketEndpoint = wsprotocol + "://" + cheHost + "/api/websocket"
webSocketEndpointMinor = wsprotocol + "://" + cheHost + "/api/websocket-minor"

data := &CheConfigMap{
CheMultiUser: cheMultiUser,
Expand All @@ -234,7 +225,9 @@ func (s *Server) getCheConfigMapData() (cheEnv map[string]string, err error) {
CheApi: cheAPI,
CheApiInternal: cheInternalAPI,
CheWebSocketEndpoint: webSocketEndpoint,
CheWebSocketInternalEndpoint: webSocketInternalEndpoint,
WebSocketEndpointMinor: webSocketEndpointMinor,
WebSocketInternalEndpointMinir: webSocketInternalEndpointMinor,
CheDebugServer: cheDebug,
CheInfrastructureActive: infra,
CheInfraKubernetesServiceAccountName: "che-workspace",
Expand Down
56 changes: 37 additions & 19 deletions pkg/deploy/server/server_configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,24 @@ func TestConfigMap(t *testing.T) {
"CHE_INFRA_KUBERNETES_TLS__KEY": "KEY",
},
},
{
name: "Test k8s data, check public url when internal network enabled.",
cheCluster: &orgv1.CheCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "eclipse-che",
Namespace: "eclipse-che",
},
Spec: orgv1.CheClusterSpec{
Server: orgv1.CheClusterSpecServer{
CheHost: "che-host",
},
},
},
expectedData: map[string]string{
"CHE_WEBSOCKET_ENDPOINT": "ws://che-host/api/websocket",
"CHE_WEBSOCKET_ENDPOINT__MINOR": "ws://che-host/api/websocket-minor",
},
},
{
name: "Test k8s data, with internal cluster svc names",
cheCluster: &orgv1.CheCluster{
Expand All @@ -161,8 +179,8 @@ func TestConfigMap(t *testing.T) {
},
},
expectedData: map[string]string{
"CHE_WEBSOCKET_ENDPOINT": "ws://che-host.eclipse-che.svc:8080/api/websocket",
"CHE_WEBSOCKET_ENDPOINT__MINOR": "ws://che-host.eclipse-che.svc:8080/api/websocket-minor",
"CHE_WEBSOCKET_INTERNAL_ENDPOINT": "ws://che-host.eclipse-che.svc:8080/api/websocket",
"CHE_WEBSOCKET_INTERNAL_ENDPOINT__MINOR": "ws://che-host.eclipse-che.svc:8080/api/websocket-minor",
},
},
{
Expand Down Expand Up @@ -444,7 +462,7 @@ func TestShouldSetUpCorrectlyDevfileRegistryURL(t *testing.T) {
},
},
expectedData: map[string]string{
"CHE_WORKSPACE_DEVFILE__REGISTRY__INTERNAL__URL": "http://devfile-registry.internal",
"CHE_WORKSPACE_DEVFILE__REGISTRY__INTERNAL__URL": "",
"CHE_WORKSPACE_DEVFILE__REGISTRY__URL": "http://devfile-registry.internal",
},
},
Expand Down Expand Up @@ -473,7 +491,7 @@ func TestShouldSetUpCorrectlyDevfileRegistryURL(t *testing.T) {
},
},
{
name: "Test devfile registry urls #5",
name: "Test devfile registry urls #6",
cheCluster: &orgv1.CheCluster{
TypeMeta: metav1.TypeMeta{
Kind: "CheCluster",
Expand All @@ -497,12 +515,12 @@ func TestShouldSetUpCorrectlyDevfileRegistryURL(t *testing.T) {
},
},
expectedData: map[string]string{
"CHE_WORKSPACE_DEVFILE__REGISTRY__INTERNAL__URL": "http://devfile-registry.internal",
"CHE_WORKSPACE_DEVFILE__REGISTRY__INTERNAL__URL": "",
"CHE_WORKSPACE_DEVFILE__REGISTRY__URL": "http://devfile-registry.internal http://devfile-registry.external.1 http://devfile-registry.external.2",
},
},
{
name: "Test devfile registry urls #6",
name: "Test devfile registry urls #7",
cheCluster: &orgv1.CheCluster{
TypeMeta: metav1.TypeMeta{
Kind: "CheCluster",
Expand Down Expand Up @@ -582,7 +600,7 @@ func TestShouldSetUpCorrectlyInternalPluginRegistryServiceURL(t *testing.T) {
},
},
expectedData: map[string]string{
"CHE_WORKSPACE_PLUGIN__REGISTRY__INTERNAL__URL": "http://external-plugin-registry",
"CHE_WORKSPACE_PLUGIN__REGISTRY__INTERNAL__URL": "",
},
},
{
Expand All @@ -609,7 +627,7 @@ func TestShouldSetUpCorrectlyInternalPluginRegistryServiceURL(t *testing.T) {
},
},
expectedData: map[string]string{
"CHE_WORKSPACE_PLUGIN__REGISTRY__INTERNAL__URL": "http://external-plugin-registry",
"CHE_WORKSPACE_PLUGIN__REGISTRY__INTERNAL__URL": "",
},
},
{
Expand All @@ -636,7 +654,7 @@ func TestShouldSetUpCorrectlyInternalPluginRegistryServiceURL(t *testing.T) {
},
},
expectedData: map[string]string{
"CHE_WORKSPACE_PLUGIN__REGISTRY__INTERNAL__URL": "http://plugin-registry/v3",
"CHE_WORKSPACE_PLUGIN__REGISTRY__INTERNAL__URL": "",
},
},
{
Expand Down Expand Up @@ -696,7 +714,7 @@ func TestShouldSetUpCorrectlyInternalCheServerURL(t *testing.T) {

testCases := []testCase{
{
name: "Should use public che-server url, when internal network is disabled",
name: "Should be an empty when internal network is disabled",
cheCluster: &orgv1.CheCluster{
TypeMeta: metav1.TypeMeta{
Kind: "CheCluster",
Expand All @@ -716,7 +734,7 @@ func TestShouldSetUpCorrectlyInternalCheServerURL(t *testing.T) {
},
},
expectedData: map[string]string{
"CHE_API_INTERNAL": "http://che-host/api",
"CHE_API_INTERNAL": "",
},
},
{
Expand Down Expand Up @@ -773,7 +791,7 @@ func TestShouldSetUpCorrectlyInternalIdentityProviderServiceURL(t *testing.T) {

testCases := []testCase{
{
name: "Should use 'external' public identity provider url, when internal network is enabled #1",
name: "Should be an empty when enabled 'external' public identity provider url and internal network is enabled #1",
cheCluster: &orgv1.CheCluster{
TypeMeta: metav1.TypeMeta{
Kind: "CheCluster",
Expand All @@ -791,12 +809,12 @@ func TestShouldSetUpCorrectlyInternalIdentityProviderServiceURL(t *testing.T) {
},
},
expectedData: map[string]string{
"CHE_KEYCLOAK_AUTH__INTERNAL__SERVER__URL": "http://external-keycloak/auth",
"CHE_KEYCLOAK_AUTH__INTERNAL__SERVER__URL": "",
"CHE_KEYCLOAK_AUTH__SERVER__URL": "http://external-keycloak/auth",
},
},
{
name: "Should use 'external' public identity provider url, when internal network is enabled #2",
name: "Should be an empty when enabled 'external' public identity provider url and internal network is enabled #2",
cheCluster: &orgv1.CheCluster{
TypeMeta: metav1.TypeMeta{
Kind: "CheCluster",
Expand All @@ -814,12 +832,12 @@ func TestShouldSetUpCorrectlyInternalIdentityProviderServiceURL(t *testing.T) {
},
},
expectedData: map[string]string{
"CHE_KEYCLOAK_AUTH__INTERNAL__SERVER__URL": "http://external-keycloak/auth",
"CHE_KEYCLOAK_AUTH__INTERNAL__SERVER__URL": "",
"CHE_KEYCLOAK_AUTH__SERVER__URL": "http://external-keycloak/auth",
},
},
{
name: "Should use 'external' public identity provider url, when internal network is disabled",
name: "Should be and empty when enabled 'external' public identity provider url and internal network is disabled",
cheCluster: &orgv1.CheCluster{
TypeMeta: metav1.TypeMeta{
Kind: "CheCluster",
Expand All @@ -840,12 +858,12 @@ func TestShouldSetUpCorrectlyInternalIdentityProviderServiceURL(t *testing.T) {
},
},
expectedData: map[string]string{
"CHE_KEYCLOAK_AUTH__INTERNAL__SERVER__URL": "http://external-keycloak/auth",
"CHE_KEYCLOAK_AUTH__INTERNAL__SERVER__URL": "",
"CHE_KEYCLOAK_AUTH__SERVER__URL": "http://external-keycloak/auth",
},
},
{
name: "Should use public identity provider url, when internal network is disabled",
name: "Should be an empty when internal network is disabled",
cheCluster: &orgv1.CheCluster{
TypeMeta: metav1.TypeMeta{
Kind: "CheCluster",
Expand All @@ -866,7 +884,7 @@ func TestShouldSetUpCorrectlyInternalIdentityProviderServiceURL(t *testing.T) {
},
},
expectedData: map[string]string{
"CHE_KEYCLOAK_AUTH__INTERNAL__SERVER__URL": "http://keycloak/auth",
"CHE_KEYCLOAK_AUTH__INTERNAL__SERVER__URL": "",
"CHE_KEYCLOAK_AUTH__SERVER__URL": "http://keycloak/auth",
},
},
Expand Down