Skip to content

Commit 76a44ff

Browse files
Merge pull request #2708 from benjaminapetersen/trello/hpa/v2beta1/new-api-warning
Automatic merge from submit-queue. hpa v2beta1 api warning on DC & edit autoscaler pages This PR depends on [common 285](openshift/origin-web-common#285). [WIP] notes: `bower link origin-web-common` with the above PR or the tests will fail. On the DC page: ![screen shot 2018-01-23 at 6 21 58 pm](https://user-images.githubusercontent.com/280512/35306332-132de372-006b-11e8-8552-ee94bd4673a2.png) - probably only want to show the v2beta1 message, will hide the other On the edit autoscaler page: ![screen shot 2018-01-23 at 6 25 12 pm](https://user-images.githubusercontent.com/280512/35306333-1337b924-006b-11e8-9cc7-3abacf3a6e91.png) - shows a message w/a link to CLI - hides the CPU request input as editing this is probably not what the user wants to do TODO (perhaps follow-on PR): - Update the warning message to show the user the data from the `metrics` annotation so they can easily see what the autoscaler is using to scale the resource.
2 parents 0ea0ca4 + 1033756 commit 76a44ff

File tree

8 files changed

+159
-79
lines changed

8 files changed

+159
-79
lines changed

Diff for: app/scripts/controllers/edit/autoscaler.js

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ angular.module('openshiftConsole')
7878
var horizontalPodAutoscalerVersion = APIService.getPreferredVersion('horizontalpodautoscalers');
7979
var limitRangesVersion = APIService.getPreferredVersion('limitranges');
8080

81+
8182
ProjectsService
8283
.get($routeParams.project)
8384
.then(_.spread(function(project, context) {
@@ -186,6 +187,8 @@ angular.module('openshiftConsole')
186187
};
187188
});
188189

190+
$scope.usesV2Metrics = HPAService.usesV2Metrics(resource);
191+
189192
// Are we editing an existing HPA?
190193
if ($routeParams.kind === "HorizontalPodAutoscaler") {
191194
$scope.targetKind = _.get(resource, 'spec.scaleTargetRef.kind');

Diff for: app/scripts/directives/oscAutoscaling.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ angular.module("openshiftConsole")
1313
scope: {
1414
autoscaling: "=model",
1515
showNameInput: "=?",
16-
nameReadOnly: "=?"
16+
nameReadOnly: "=?",
17+
showRequestInput: "=?"
1718
},
1819
templateUrl: 'views/directives/osc-autoscaling.html',
19-
link: function(scope) {
20+
link: function(scope, elem, attrs) {
2021
scope.nameValidation = DNS1123_SUBDOMAIN_VALIDATION;
2122

2223
// Prefill a default value if DEFAULT_HPA_CPU_TARGET_PERCENT is set and
@@ -26,6 +27,10 @@ angular.module("openshiftConsole")
2627
if (_.isNil(targetCPU) && defaultTargetCPU) {
2728
_.set(scope, 'autoscaling.targetCPU', defaultTargetCPU);
2829
}
30+
// true if not present
31+
if( !('showRequestInput' in attrs) ) {
32+
scope.showRequestInput = true;
33+
}
2934
}
3035
};
3136
});

Diff for: app/scripts/services/hpa.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
angular.module("openshiftConsole")
44
.factory("HPAService", function($filter, $q, LimitRangesService, MetricsService) {
5+
6+
var annotation = $filter('annotation');
7+
58
// Checks if all containers have a value set for the compute resource request or limit.
69
//
710
// computeResource - 'cpu' or 'memory'
@@ -99,6 +102,13 @@ angular.module("openshiftConsole")
99102
};
100103

101104

105+
var hasV2HPAAnnotations = function(hpaResources) {
106+
return _.some(hpaResources, function(hpa) {
107+
return annotation(hpa, 'autoscaling.alpha.kubernetes.io/metrics');
108+
});
109+
};
110+
111+
102112
var hasCompetingAutoscalersWarning = function(hpaResources) {
103113
if (_.size(hpaResources) > 1) {
104114
return {
@@ -146,15 +156,19 @@ angular.module("openshiftConsole")
146156
return $q.when([]);
147157
}
148158
return MetricsService.isAvailable().then(function(metricsAvailable) {
159+
var isV2HPA = hasV2HPAAnnotations(hpaResources);
149160
return _.compact([
150161
hasMetricsAvailableWarning(metricsAvailable),
151-
hasCPURequestWarning(scaleTarget, limitRanges, project),
162+
// we don't need to show this warning, but if we have it, we should also
163+
// not show the cpuRequestWarning, until we update to the newer API
164+
isV2HPA ? false : hasCPURequestWarning(scaleTarget, limitRanges, project),
152165
hasCompetingAutoscalersWarning(hpaResources),
153166
hasCompetingDCAndAutoscalerWarning(scaleTarget, hpaResources)
154167
]);
155168
});
156169
};
157170

171+
158172
// Group HPAs by the object they scale.
159173
//
160174
// Returns an hpaByResource map with
@@ -185,7 +199,13 @@ angular.module("openshiftConsole")
185199
return hpaByResource;
186200
};
187201

202+
// currently unsupported by the webconsole
203+
var usesV2Metrics = function(hpa) {
204+
return hasV2HPAAnnotations([hpa]);
205+
};
206+
188207
return {
208+
usesV2Metrics: usesV2Metrics,
189209
hasCPURequest: hasCPURequest,
190210
filterHPA: filterHPA,
191211
getHPAWarnings: getHPAWarnings,

Diff for: app/views/directives/osc-autoscaling.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
</span>
100100
</div>
101101
</div>
102-
<div class="form-group">
102+
<div ng-show="showRequestInput" class="form-group">
103103
<label>
104104
CPU Request Target
105105
</label>

Diff for: app/views/edit/autoscaler.html

+11-1
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,21 @@ <h1>
3838
<span ng-if="!('cpu' | isRequestCalculated : project)">request.</span>
3939
</div>
4040

41+
<!-- Warning: V2Beta1 HPA -->
42+
<div ng-if="usesV2Metrics" class="alert alert-warning">
43+
<span class="pficon pficon-warning-triangle-o" aria-hidden="true"></span>
44+
<span class="sr-only">Warning:</span>
45+
This autoscaler uses a newer API, consider editing it with the
46+
<a href="command-line" target="_blank">command line tools</a>.
47+
</div>
48+
49+
4150
<fieldset ng-disabled="disableInputs" class="gutter-top">
4251
<osc-autoscaling
4352
model="autoscaling"
4453
show-name-input="true"
45-
name-read-only="kind === 'HorizontalPodAutoscaler'">
54+
name-read-only="kind === 'HorizontalPodAutoscaler'"
55+
show-request-input="autoscaling.targetCPU">
4656
</osc-autoscaling>
4757

4858
<label-editor

Diff for: dist/scripts/scripts.js

+32-23
Original file line numberDiff line numberDiff line change
@@ -3109,40 +3109,44 @@ controller: "SetHomePageModalController"
31093109
}
31103110
};
31113111
} ]), angular.module("openshiftConsole").factory("HPAService", [ "$filter", "$q", "LimitRangesService", "MetricsService", function(e, t, n, r) {
3112-
var a = function(e, t, n) {
3112+
var a = e("annotation"), o = function(e, t, n) {
31133113
return _.every(n, function(n) {
31143114
return _.get(n, [ "resources", t, e ]);
31153115
});
3116-
}, o = function(e, t) {
3117-
return a(e, "requests", t);
31183116
}, i = function(e, t) {
3119-
return a(e, "limits", t);
3120-
}, s = function(e, t, r) {
3117+
return o(e, "requests", t);
3118+
}, s = function(e, t) {
3119+
return o(e, "limits", t);
3120+
}, c = function(e, t, r) {
31213121
return !!n.getEffectiveLimitRange(r, e, "Container")[t];
3122-
}, c = function(e, t) {
3123-
return s(e, "defaultRequest", t);
31243122
}, l = function(e, t) {
3125-
return s(e, "defaultLimit", t);
3126-
}, u = function(e, t, r) {
3127-
return !!n.hasClusterResourceOverrides(r) || (!(!o("cpu", e) && !c("cpu", t)) || !(!i("cpu", e) && !l("cpu", t)));
3128-
}, d = e("humanizeKind"), m = e("hasDeploymentConfig"), p = function(e) {
3123+
return c(e, "defaultRequest", t);
3124+
}, u = function(e, t) {
3125+
return c(e, "defaultLimit", t);
3126+
}, d = function(e, t, r) {
3127+
return !!n.hasClusterResourceOverrides(r) || (!(!i("cpu", e) && !l("cpu", t)) || !(!s("cpu", e) && !u("cpu", t)));
3128+
}, m = e("humanizeKind"), p = e("hasDeploymentConfig"), f = function(e) {
31293129
if (!e) return {
31303130
message: "Metrics might not be configured by your cluster administrator. Metrics are required for autoscaling.",
31313131
reason: "MetricsNotAvailable"
31323132
};
3133-
}, f = function(e, t, n) {
3133+
}, g = function(e, t, n) {
31343134
var r, a = _.get(e, "spec.template.spec.containers", []);
3135-
if (!u(a, t, n)) return r = d(e.kind), {
3135+
if (!d(a, t, n)) return r = m(e.kind), {
31363136
message: "This " + r + " does not have any containers with a CPU request set. Autoscaling will not work without a CPU request.",
31373137
reason: "NoCPURequest"
31383138
};
3139-
}, g = function(e) {
3139+
}, v = function(e) {
3140+
return _.some(e, function(e) {
3141+
return a(e, "autoscaling.alpha.kubernetes.io/metrics");
3142+
});
3143+
}, h = function(e) {
31403144
if (_.size(e) > 1) return {
31413145
message: "More than one autoscaler is scaling this resource. This is not recommended because they might compete with each other. Consider removing all but one autoscaler.",
31423146
reason: "MultipleHPA"
31433147
};
3144-
}, v = function(e, t) {
3145-
if ("ReplicationController" === e.kind && m(e) && _.some(t, function() {
3148+
}, y = function(e, t) {
3149+
if ("ReplicationController" === e.kind && p(e) && _.some(t, function() {
31463150
return _.some(t, function(e) {
31473151
return "ReplicationController" === _.get(e, "spec.scaleTargetRef.kind");
31483152
});
@@ -3152,15 +3156,19 @@ reason: "DeploymentHasHPA"
31523156
};
31533157
};
31543158
return {
3155-
hasCPURequest: u,
3159+
usesV2Metrics: function(e) {
3160+
return v([ e ]);
3161+
},
3162+
hasCPURequest: d,
31563163
filterHPA: function(e, t, n) {
31573164
return _.filter(e, function(e) {
31583165
return e.spec.scaleTargetRef.kind === t && e.spec.scaleTargetRef.name === n;
31593166
});
31603167
},
31613168
getHPAWarnings: function(e, n, a, o) {
31623169
return !e || _.isEmpty(n) ? t.when([]) : r.isAvailable().then(function(t) {
3163-
return _.compact([ p(t), f(e, a, o), g(n), v(e, n) ]);
3170+
var r = v(n);
3171+
return _.compact([ f(t), !r && g(e, a, o), h(n), y(e, n) ]);
31643172
});
31653173
},
31663174
groupHPAs: function(e) {
@@ -7699,7 +7707,7 @@ return {
76997707
name: t,
77007708
value: e
77017709
};
7702-
}), "HorizontalPodAutoscaler" === n.kind) e.targetKind = _.get(a, "spec.scaleTargetRef.kind"), e.targetName = _.get(a, "spec.scaleTargetRef.name"), _.assign(e.autoscaling, {
7710+
}), e.usesV2Metrics = c.usesV2Metrics(a), "HorizontalPodAutoscaler" === n.kind) e.targetKind = _.get(a, "spec.scaleTargetRef.kind"), e.targetName = _.get(a, "spec.scaleTargetRef.name"), _.assign(e.autoscaling, {
77037711
minReplicas: _.get(a, "spec.minReplicas"),
77047712
maxReplicas: _.get(a, "spec.maxReplicas"),
77057713
targetCPU: _.get(a, "spec.targetCPUUtilizationPercentage")
@@ -10257,13 +10265,14 @@ restrict: "E",
1025710265
scope: {
1025810266
autoscaling: "=model",
1025910267
showNameInput: "=?",
10260-
nameReadOnly: "=?"
10268+
nameReadOnly: "=?",
10269+
showRequestInput: "=?"
1026110270
},
1026210271
templateUrl: "views/directives/osc-autoscaling.html",
10263-
link: function(t) {
10272+
link: function(t, r, a) {
1026410273
t.nameValidation = n;
10265-
var r = e.DEFAULT_HPA_CPU_TARGET_PERCENT, a = _.get(t, "autoscaling.targetCPU");
10266-
_.isNil(a) && r && _.set(t, "autoscaling.targetCPU", r);
10274+
var o = e.DEFAULT_HPA_CPU_TARGET_PERCENT, i = _.get(t, "autoscaling.targetCPU");
10275+
_.isNil(i) && o && _.set(t, "autoscaling.targetCPU", o), "showRequestInput" in a || (t.showRequestInput = !0);
1026710276
}
1026810277
};
1026910278
} ]), angular.module("openshiftConsole").directive("oscSecrets", [ "$uibModal", "$filter", "APIService", "DataService", "SecretsService", function(e, t, n, r, a) {

Diff for: dist/scripts/templates.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -8086,7 +8086,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
80868086
"</span>\n" +
80878087
"</div>\n" +
80888088
"</div>\n" +
8089-
"<div class=\"form-group\">\n" +
8089+
"<div ng-show=\"showRequestInput\" class=\"form-group\">\n" +
80908090
"<label>\n" +
80918091
"CPU Request Target\n" +
80928092
"</label>\n" +
@@ -9492,8 +9492,15 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
94929492
"<span ng-if=\"'cpu' | isRequestCalculated : project\">limit.</span>\n" +
94939493
"<span ng-if=\"!('cpu' | isRequestCalculated : project)\">request.</span>\n" +
94949494
"</div>\n" +
9495+
"\n" +
9496+
"<div ng-if=\"usesV2Metrics\" class=\"alert alert-warning\">\n" +
9497+
"<span class=\"pficon pficon-warning-triangle-o\" aria-hidden=\"true\"></span>\n" +
9498+
"<span class=\"sr-only\">Warning:</span>\n" +
9499+
"This autoscaler uses a newer API, consider editing it with the\n" +
9500+
"<a href=\"command-line\" target=\"_blank\">command line tools</a>.\n" +
9501+
"</div>\n" +
94959502
"<fieldset ng-disabled=\"disableInputs\" class=\"gutter-top\">\n" +
9496-
"<osc-autoscaling model=\"autoscaling\" show-name-input=\"true\" name-read-only=\"kind === 'HorizontalPodAutoscaler'\">\n" +
9503+
"<osc-autoscaling model=\"autoscaling\" show-name-input=\"true\" name-read-only=\"kind === 'HorizontalPodAutoscaler'\" show-request-input=\"autoscaling.targetCPU\">\n" +
94979504
"</osc-autoscaling>\n" +
94989505
"<label-editor labels=\"labels\" expand=\"true\" can-toggle=\"false\"></label-editor>\n" +
94999506
"<div class=\"buttons gutter-top gutter-bottom\">\n" +

0 commit comments

Comments
 (0)