Skip to content

Fix error changing route termination to passthrough #1183

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
43 changes: 30 additions & 13 deletions app/scripts/controllers/edit/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,51 +103,68 @@ angular.module('openshiftConsole')

// Update the fields in the route from what was entered in the form.
var updateRouteFields = function() {
// Make a second copy of the route before making the PUT request.
// This way if the PUT fails and the user switches termination types,
// we haven't lost the previously-entered certificates values.
var updated = angular.copy(route);
var serviceName = _.get($scope, 'routing.to.service.metadata.name');
_.set(route, 'spec.to.name', serviceName);
_.set(updated, 'spec.to.name', serviceName);
var weight = _.get($scope, 'routing.to.weight');
if (!isNaN(weight)) {
_.set(route, 'spec.to.weight', weight);
_.set(updated, 'spec.to.weight', weight);
}

route.spec.path = $scope.routing.path;
updated.spec.path = $scope.routing.path;

var targetPort = $scope.routing.targetPort;
if (targetPort) {
_.set(route, 'spec.port.targetPort', targetPort);
_.set(updated, 'spec.port.targetPort', targetPort);
} else {
delete route.spec.port;
delete updated.spec.port;
}

if (_.get($scope, 'routing.tls.termination')) {
route.spec.tls = $scope.routing.tls;
if (route.spec.tls.termination !== 'edge') {
updated.spec.tls = $scope.routing.tls;
if (updated.spec.tls.termination !== 'edge') {
// insecureEdgeTerminationPolicy only applies to edge routes.
delete route.spec.tls.insecureEdgeTerminationPolicy;
delete updated.spec.tls.insecureEdgeTerminationPolicy;
}

if (updated.spec.tls.termination === 'passthrough') {
delete updated.spec.path;
delete updated.spec.tls.certificate;
delete updated.spec.tls.key;
delete updated.spec.tls.caCertificate;
}

if (updated.spec.tls.termination !== 'reencrypt') {
delete updated.spec.tls.destinationCACertificate;
}
} else {
delete route.spec.tls;
delete updated.spec.tls;
}

var alternateServices = _.get($scope, 'routing.alternateServices', []);
if (_.isEmpty(alternateServices)) {
delete route.spec.alternateBackends;
delete updated.spec.alternateBackends;
} else {
route.spec.alternateBackends = _.map(alternateServices, function(alternate) {
updated.spec.alternateBackends = _.map(alternateServices, function(alternate) {
return {
kind: 'Service',
name: _.get(alternate, 'service.metadata.name'),
weight: alternate.weight
};
});
}

return updated;
};

$scope.updateRoute = function() {
if ($scope.form.$valid) {
$scope.disableInputs = true;
updateRouteFields();
DataService.update('routes', $scope.routeName, route, context)
var updated = updateRouteFields();
DataService.update('routes', $scope.routeName, updated, context)
.then(function() { // Success
AlertMessageService.addAlert({
name: $scope.routeName,
Expand Down
26 changes: 15 additions & 11 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7888,23 +7888,26 @@ weight:a.weight
h.toErrorPage("Could not load route " + d.routeName + ".");
});
var n = function() {
var a = _.get(d, "routing.to.service.metadata.name");
_.set(l, "spec.to.name", a);
var b = _.get(d, "routing.to.weight");
isNaN(b) || _.set(l, "spec.to.weight", b), l.spec.path = d.routing.path;
var c = d.routing.targetPort;
c ? _.set(l, "spec.port.targetPort", c) :delete l.spec.port, _.get(d, "routing.tls.termination") ? (l.spec.tls = d.routing.tls, "edge" !== l.spec.tls.termination && delete l.spec.tls.insecureEdgeTerminationPolicy) :delete l.spec.tls;
var e = _.get(d, "routing.alternateServices", []);
_.isEmpty(e) ? delete l.spec.alternateBackends :l.spec.alternateBackends = _.map(e, function(a) {
var a = angular.copy(l), b = _.get(d, "routing.to.service.metadata.name");
_.set(a, "spec.to.name", b);
var c = _.get(d, "routing.to.weight");
isNaN(c) || _.set(a, "spec.to.weight", c), a.spec.path = d.routing.path;
var e = d.routing.targetPort;
e ? _.set(a, "spec.port.targetPort", e) :delete a.spec.port, _.get(d, "routing.tls.termination") ? (a.spec.tls = d.routing.tls, "edge" !== a.spec.tls.termination && delete a.spec.tls.insecureEdgeTerminationPolicy, "passthrough" === a.spec.tls.termination && (delete a.spec.path, delete a.spec.tls.certificate, delete a.spec.tls.key, delete a.spec.tls.caCertificate), "reencrypt" !== a.spec.tls.termination && delete a.spec.tls.destinationCACertificate) :delete a.spec.tls;
var f = _.get(d, "routing.alternateServices", []);
return _.isEmpty(f) ? delete a.spec.alternateBackends :a.spec.alternateBackends = _.map(f, function(a) {
return {
kind:"Service",
name:_.get(a, "service.metadata.name"),
weight:a.weight
};
});
}), a;
};
d.updateRoute = function() {
d.form.$valid && (d.disableInputs = !0, n(), g.update("routes", d.routeName, l, k).then(function() {
if (d.form.$valid) {
d.disableInputs = !0;
var c = n();
g.update("routes", d.routeName, c, k).then(function() {
e.addAlert({
name:d.routeName,
data:{
Expand All @@ -7918,7 +7921,8 @@ type:"error",
message:"An error occurred updating route " + d.routeName + ".",
details:a("getErrorDetails")(b)
};
}));
});
}
};
}));
} ]), angular.module("openshiftConsole").controller("EditYAMLController", [ "$scope", "$filter", "$location", "$routeParams", "$window", "AlertMessageService", "APIService", "AuthorizationService", "BreadcrumbsService", "DataService", "Navigate", "ProjectsService", function(a, b, c, d, e, f, g, h, i, j, k, l) {
Expand Down