From 632b0157eec80eb771ee6bdbe60dc94614f9abb2 Mon Sep 17 00:00:00 2001 From: Samuel Padgett Date: Mon, 5 Feb 2018 14:54:57 -0500 Subject: [PATCH] Bug 1540916: Set correct group in HPA scale target Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1540916 --- app/scripts/controllers/edit/autoscaler.js | 83 +++++++++++----------- dist/scripts/scripts.js | 79 ++++++++++---------- 2 files changed, 80 insertions(+), 82 deletions(-) diff --git a/app/scripts/controllers/edit/autoscaler.js b/app/scripts/controllers/edit/autoscaler.js index 5a720ab7c2..093be48d15 100644 --- a/app/scripts/controllers/edit/autoscaler.js +++ b/app/scripts/controllers/edit/autoscaler.js @@ -90,48 +90,6 @@ angular.module('openshiftConsole') return; } - var createHPA = function() { - $scope.disableInputs = true; - hideErrorNotifications(); - var hpa = { - apiVersion: "autoscaling/v1", - kind: "HorizontalPodAutoscaler", - metadata: { - name: $scope.autoscaling.name, - labels: keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries($scope.labels)) - }, - spec: { - scaleTargetRef: { - kind: $routeParams.kind, - name: $routeParams.name, - apiVersion: "extensions/v1beta1", - subresource: "scale" - }, - minReplicas: $scope.autoscaling.minReplicas, - maxReplicas: $scope.autoscaling.maxReplicas, - targetCPUUtilizationPercentage: $scope.autoscaling.targetCPU - } - }; - - DataService.create(horizontalPodAutoscalerVersion, null, hpa, context) - .then(function(hpa) { // Success - NotificationsService.addNotification({ - type: 'success', - message: 'Horizontal pod autoscaler ' + hpa.metadata.name + ' successfully created.' - }); - - navigateBack(); - }, function(result) { // Failure - $scope.disableInputs = false; - NotificationsService.addNotification({ - id: 'edit-hpa-error', - type: 'error', - message: 'An error occurred creating the horizontal pod autoscaler.', - details: getErrorDetails(result) - }); - }); - }; - var updateHPA = function(hpa) { $scope.disableInputs = true; @@ -177,6 +135,47 @@ angular.module('openshiftConsole') } DataService.get(resourceGroup, $routeParams.name, context).then(function(resource) { + var createHPA = function() { + $scope.disableInputs = true; + hideErrorNotifications(); + var hpa = { + apiVersion: "autoscaling/v1", + kind: "HorizontalPodAutoscaler", + metadata: { + name: $scope.autoscaling.name, + labels: keyValueEditorUtils.mapEntries(keyValueEditorUtils.compactEntries($scope.labels)) + }, + spec: { + scaleTargetRef: { + kind: resource.kind, + name: resource.metadata.name, + apiVersion: resource.apiVersion + }, + minReplicas: $scope.autoscaling.minReplicas, + maxReplicas: $scope.autoscaling.maxReplicas, + targetCPUUtilizationPercentage: $scope.autoscaling.targetCPU + } + }; + + DataService.create(horizontalPodAutoscalerVersion, null, hpa, context) + .then(function(hpa) { // Success + NotificationsService.addNotification({ + type: 'success', + message: 'Horizontal pod autoscaler ' + hpa.metadata.name + ' successfully created.' + }); + + navigateBack(); + }, function(result) { // Failure + $scope.disableInputs = false; + NotificationsService.addNotification({ + id: 'edit-hpa-error', + type: 'error', + message: 'An error occurred creating the horizontal pod autoscaler.', + details: getErrorDetails(result) + }); + }); + }; + $scope.labels = _.map( _.get(resource, 'metadata.labels', {}), function(val, key) { diff --git a/dist/scripts/scripts.js b/dist/scripts/scripts.js index 2f72476c04..8bec0120fd 100644 --- a/dist/scripts/scripts.js +++ b/dist/scripts/scripts.js @@ -7637,41 +7637,7 @@ if (o.canI({ resource: "horizontalpodautoscalers", group: "autoscaling" }, l, n.project)) { -var m = function() { -e.disableInputs = !0, h(); -var t = { -apiVersion: "autoscaling/v1", -kind: "HorizontalPodAutoscaler", -metadata: { -name: e.autoscaling.name, -labels: p.mapEntries(p.compactEntries(e.labels)) -}, -spec: { -scaleTargetRef: { -kind: n.kind, -name: n.name, -apiVersion: "extensions/v1beta1", -subresource: "scale" -}, -minReplicas: e.autoscaling.minReplicas, -maxReplicas: e.autoscaling.maxReplicas, -targetCPUUtilizationPercentage: e.autoscaling.targetCPU -} -}; -s.create(y, null, t, r).then(function(e) { -d.addNotification({ -type: "success", -message: "Horizontal pod autoscaler " + e.metadata.name + " successfully created." -}), v(); -}, function(t) { -e.disableInputs = !1, d.addNotification({ -id: "edit-hpa-error", -type: "error", -message: "An error occurred creating the horizontal pod autoscaler.", -details: g(t) -}); -}); -}, f = function(t) { +var m = function(t) { e.disableInputs = !0, (t = angular.copy(t)).metadata.labels = p.mapEntries(p.compactEntries(e.labels)), t.spec.minReplicas = e.autoscaling.minReplicas, t.spec.maxReplicas = e.autoscaling.maxReplicas, t.spec.targetCPUUtilizationPercentage = e.autoscaling.targetCPU, s.update(y, t.metadata.name, t, r).then(function(e) { d.addNotification({ type: "success", @@ -7685,15 +7651,15 @@ message: "An error occurred creating the horizontal pod autoscaler.", details: g(t) }); }); -}, S = {}; -S = "HorizontalPodAutoscaler" === n.kind ? { +}, f = {}; +f = "HorizontalPodAutoscaler" === n.kind ? { resource: "horizontalpodautoscalers", group: "autoscaling", version: "v1" } : { resource: a.kindToResource(n.kind), group: n.group -}, s.get(S, n.name, r).then(function(a) { +}, s.get(f, n.name, r).then(function(a) { if (e.labels = _.map(_.get(a, "metadata.labels", {}), function(e, t) { return { name: t, @@ -7704,7 +7670,7 @@ minReplicas: _.get(a, "spec.minReplicas"), maxReplicas: _.get(a, "spec.maxReplicas"), targetCPU: _.get(a, "spec.targetCPUUtilizationPercentage") }), e.disableInputs = !1, e.save = function() { -f(a); +m(a); }, e.breadcrumbs = i.getBreadcrumbs({ name: e.targetName, kind: e.targetKind, @@ -7716,7 +7682,40 @@ e.breadcrumbs = i.getBreadcrumbs({ object: a, project: t, subpage: "Autoscale" -}), e.save = m; +}), e.save = function() { +e.disableInputs = !0, h(); +var t = { +apiVersion: "autoscaling/v1", +kind: "HorizontalPodAutoscaler", +metadata: { +name: e.autoscaling.name, +labels: p.mapEntries(p.compactEntries(e.labels)) +}, +spec: { +scaleTargetRef: { +kind: a.kind, +name: a.metadata.name, +apiVersion: a.apiVersion +}, +minReplicas: e.autoscaling.minReplicas, +maxReplicas: e.autoscaling.maxReplicas, +targetCPUUtilizationPercentage: e.autoscaling.targetCPU +} +}; +s.create(y, null, t, r).then(function(e) { +d.addNotification({ +type: "success", +message: "Horizontal pod autoscaler " + e.metadata.name + " successfully created." +}), v(); +}, function(t) { +e.disableInputs = !1, d.addNotification({ +id: "edit-hpa-error", +type: "error", +message: "An error occurred creating the horizontal pod autoscaler.", +details: g(t) +}); +}); +}; var o = {}, l = function() { var n = _.get(a, "spec.template.spec.containers", []); e.showCPURequestWarning = !c.hasCPURequest(n, o, t);