Skip to content

Commit

Permalink
fix(vips): keep VIP label
Browse files Browse the repository at this point in the history
Closes DCOS-21440
  • Loading branch information
nLight committed Mar 21, 2018
1 parent 2ffb9f9 commit fb33fe8
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ describe("JSONMultiContainer", function() {
name: "container-1",
image: { kind: "DOCKER", id: "jdef/my-web-service-abc:v1.1.1" },
endpoints: [
{
name: "nginx",
hostPort: 0,
protocol: ["tcp"],
labels: {
vipDCOS: "1.2.3.4:80" // Custom VIP
}
},
{
name: "nginx",
hostPort: 0,
Expand Down
2 changes: 1 addition & 1 deletion plugins/services/src/js/reducers/serviceForm/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const containerJSONReducer = combineReducers({

// Convert portDefinitions to portMappings
return this.portDefinitions.map((portDefinition, index) => {
const vipLabel = `VIP_${index}`;
const vipLabel = portDefinition.vipLabel || `VIP_${index}`;
const vipPort = Number(portDefinition.vipPort) || null;
const containerPort = Number(portDefinition.containerPort) || 0;
const servicePort = parseInt(portDefinition.servicePort, 10) || null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function mapEndpoints(endpoints = [], networkType, appState) {
containerPort,
automaticPort,
protocol,
vipLabel,
vipPort,
labels
} = endpoint;
Expand All @@ -49,12 +50,10 @@ function mapEndpoints(endpoints = [], networkType, appState) {
}

if (networkType === CONTAINER) {
const vipLabel = `VIP_${index}`;

labels = VipLabelUtil.generateVipLabel(
appState.id,
endpoint,
vipLabel,
vipLabel || `VIP_${index}`,
vipPort || containerPort || hostPort
);

Expand Down Expand Up @@ -229,12 +228,10 @@ function containersParser(state) {
)
);

const vip = findNestedPropertyInObject(
endpoint,
`labels.VIP_${endpointIndex}`
);
const vip = VipLabelUtil.findVip(endpoint.labels);

if (vip != null) {
const [vipLabel, vipValue] = vip;
memo.push(
new Transaction(
[
Expand All @@ -248,16 +245,23 @@ function containersParser(state) {
)
);

if (!vip.startsWith(`${state.id}:`)) {
memo.push(
new Transaction(
["containers", index, "endpoints", endpointIndex, "vipLabel"],
vipLabel
)
);

if (!vipValue.startsWith(`${state.id}:`)) {
memo.push(
new Transaction(
["containers", index, "endpoints", endpointIndex, "vip"],
vip
vipValue
)
);
}

const vipPortMatch = vip.match(/.+:(\d+)/);
const vipPortMatch = vipValue.match(/.+:(\d+)/);
if (vipPortMatch) {
memo.push(
new Transaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const defaultEndpointsFieldValues = {
},
servicePort: null,
vip: null,
vipPort: null
vipPort: null,
vipLabel: null
};

module.exports = {
Expand Down Expand Up @@ -55,7 +56,8 @@ module.exports = {
"loadBalanced",
"labels",
"vip",
"vipPort"
"vipPort",
"vipLabel"
];
const numericalFiledNames = ["containerPort", "hostPort"];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const FIELDS = [
"name",
"servicePort",
"vip",
"vipPort"
"vipPort",
"vipLabel"
];

function transformPortDefinition(definition) {
Expand Down Expand Up @@ -54,7 +55,8 @@ function PortDefinitionsReducer(state = [], action) {
},
servicePort: null,
vip: null,
vipPort: null
vipPort: null,
vipLabel: null
};
const defaults = { protocol: { tcp: true } };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const FIELDS = [
"name",
"servicePort",
"vip",
"vipPort"
"vipPort",
"vipLabel"
];

/**
Expand Down Expand Up @@ -46,7 +47,8 @@ function PortMappingsReducer(state = [], action) {
},
servicePort: null,
vip: null,
vipPort: null
vipPort: null,
vipLabel: null
}
);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,11 @@ describe("Containers", function() {
true,
SET
),
new Transaction(
["containers", 0, "endpoints", 0, "vipLabel"],
"VIP_0",
SET
),
new Transaction(
["containers", 0, "endpoints", 0, "vip"],
"/:900",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("Endpoints", function() {
name: null,
loadBalanced: false,
vip: null,
vipLabel: null,
vipPort: null,
protocol: {
tcp: true,
Expand Down Expand Up @@ -58,6 +59,7 @@ describe("Endpoints", function() {
name: "foo",
loadBalanced: false,
vip: null,
vipLabel: null,
vipPort: null,
protocol: {
tcp: true,
Expand Down Expand Up @@ -103,6 +105,7 @@ describe("Endpoints", function() {
name: "foo",
loadBalanced: false,
vip: null,
vipLabel: null,
vipPort: null,
protocol: {
tcp: true,
Expand Down Expand Up @@ -142,6 +145,7 @@ describe("Endpoints", function() {
name: null,
loadBalanced: false,
vip: null,
vipLabel: null,
vipPort: null,
protocol: {
tcp: true,
Expand Down Expand Up @@ -181,6 +185,7 @@ describe("Endpoints", function() {
name: null,
loadBalanced: false,
vip: null,
vipLabel: null,
vipPort: null,
protocol: {
tcp: true,
Expand Down Expand Up @@ -216,6 +221,7 @@ describe("Endpoints", function() {
name: null,
loadBalanced: false,
vip: null,
vipLabel: null,
vipPort: null,
protocol: {
tcp: true,
Expand Down Expand Up @@ -252,6 +258,7 @@ describe("Endpoints", function() {
name: "foo",
loadBalanced: false,
vip: null,
vipLabel: null,
vipPort: null,
protocol: {
tcp: true,
Expand Down Expand Up @@ -299,6 +306,7 @@ describe("Endpoints", function() {
name: "foo",
loadBalanced: false,
vip: null,
vipLabel: null,
vipPort: null,
protocol: {
tcp: true,
Expand Down Expand Up @@ -338,6 +346,7 @@ describe("Endpoints", function() {
name: null,
loadBalanced: false,
vip: null,
vipLabel: null,
vipPort: null,
protocol: {
tcp: true,
Expand Down Expand Up @@ -377,6 +386,7 @@ describe("Endpoints", function() {
name: null,
loadBalanced: false,
vip: null,
vipLabel: null,
vipPort: null,
protocol: {
foo: true,
Expand Down Expand Up @@ -417,6 +427,7 @@ describe("Endpoints", function() {
name: null,
loadBalanced: false,
vip: null,
vipLabel: null,
vipPort: null,
protocol: {
tcp: true,
Expand Down Expand Up @@ -464,6 +475,7 @@ describe("Endpoints", function() {
name: null,
loadBalanced: true,
vip: null,
vipLabel: null,
vipPort: null,
protocol: {
tcp: true,
Expand Down Expand Up @@ -502,6 +514,10 @@ describe("Endpoints", function() {
)
);

batch = batch.add(
new Transaction(["containers", 0, "endpoints", 0, "vipLabel"], "vip0")
);

batch = batch.add(
new Transaction(
["containers", 0, "endpoints", 0, "vip"],
Expand All @@ -518,6 +534,7 @@ describe("Endpoints", function() {
name: null,
loadBalanced: true,
vip: "1.3.3.7:8080",
vipLabel: "vip0",
vipPort: null,
protocol: {
tcp: true,
Expand Down Expand Up @@ -567,6 +584,7 @@ describe("Endpoints", function() {
name: null,
loadBalanced: true,
vip: null,
vipLabel: null,
vipPort: null,
protocol: {
tcp: true,
Expand Down Expand Up @@ -605,6 +623,10 @@ describe("Endpoints", function() {
)
);

batch = batch.add(
new Transaction(["containers", 0, "endpoints", 0, "vipLabel"], "vip1")
);

batch = batch.add(
new Transaction(
["containers", 0, "endpoints", 0, "vip"],
Expand All @@ -624,6 +646,7 @@ describe("Endpoints", function() {
loadBalanced: true,
containerPort: 8080,
vip: "1.3.3.7:8080",
vipLabel: "vip1",
vipPort: null,
protocol: {
tcp: true,
Expand Down
18 changes: 12 additions & 6 deletions plugins/services/src/js/reducers/serviceForm/PortDefinitions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ADD_ITEM, SET } from "#SRC/js/constants/TransactionTypes";
import Transaction from "#SRC/js/structs/Transaction";
import Networking from "#SRC/js/constants/Networking";
import { findNestedPropertyInObject } from "#SRC/js/utils/Util";
import PortDefinitionsReducer from "./JSONReducers/PortDefinitionsReducer";
import { PROTOCOLS } from "../../constants/PortDefinitionConstants";
import VipLabelUtil from "../../utils/VipLabelUtil";
Expand Down Expand Up @@ -62,7 +61,7 @@ module.exports = {
// Create JSON port definitions from state
return this.portDefinitions.map((portDefinition, index) => {
const { name } = portDefinition;
const vipLabel = `VIP_${index}`;
const vipLabel = portDefinition.vipLabel || `VIP_${index}`;
const hostPort = portDefinition.hostPort
? Number(portDefinition.hostPort)
: 0;
Expand Down Expand Up @@ -134,19 +133,26 @@ module.exports = {
});
}

const vip = findNestedPropertyInObject(item, `labels.VIP_${index}`);
const vip = VipLabelUtil.findVip(item.labels);

if (vip != null) {
const [vipLabel, vipValue] = vip;

memo.push(
new Transaction(["portDefinitions", index, "loadBalanced"], true, SET)
);

if (!vip.startsWith(`${state.id}:`)) {
memo.push(
new Transaction(["portDefinitions", index, "vipLabel"], vipLabel, SET)
);

if (!vipValue.startsWith(`${state.id}:`)) {
memo.push(
new Transaction(["portDefinitions", index, "vip"], vip, SET)
new Transaction(["portDefinitions", index, "vip"], vipValue, SET)
);
}

const vipPortMatch = vip.match(/.+:(\d+)/);
const vipPortMatch = vipValue.match(/.+:(\d+)/);
if (vipPortMatch) {
memo.push(
new Transaction(
Expand Down
16 changes: 12 additions & 4 deletions plugins/services/src/js/reducers/serviceForm/PortMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { findNestedPropertyInObject } from "#SRC/js/utils/Util";
import { ADD_ITEM, SET } from "#SRC/js/constants/TransactionTypes";
import Transaction from "#SRC/js/structs/Transaction";
import { PROTOCOLS } from "../../constants/PortDefinitionConstants";
import VipLabelUtil from "../../utils/VipLabelUtil";

module.exports = {
/**
Expand Down Expand Up @@ -119,19 +120,26 @@ module.exports = {
});
}

const vip = findNestedPropertyInObject(item, `labels.VIP_${index}`);
const vip = VipLabelUtil.findVip(item.labels);

if (vip != null) {
const [vipLabel, vipValue] = vip;

memo.push(
new Transaction(["portDefinitions", index, "loadBalanced"], true, SET)
);

if (!vip.startsWith(`${state.id}:`)) {
memo.push(
new Transaction(["portDefinitions", index, "vipLabel"], vipLabel, SET)
);

if (!vipValue.startsWith(`${state.id}:`)) {
memo.push(
new Transaction(["portDefinitions", index, "vip"], vip, SET)
new Transaction(["portDefinitions", index, "vip"], vipValue, SET)
);
}

const vipPortMatch = vip.match(/.+:(\d+)/);
const vipPortMatch = vipValue.match(/.+:(\d+)/);
if (vipPortMatch) {
memo.push(
new Transaction(
Expand Down
Loading

0 comments on commit fb33fe8

Please sign in to comment.