Skip to content

Update CreatePersistentVolumeClaimController to use getPreferredVersion #2160

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
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
39 changes: 21 additions & 18 deletions app/scripts/controllers/createPersistentVolumeClaim.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ angular.module('openshiftConsole')
$routeParams,
$scope,
$window,
APIService,
ApplicationGenerator,
AuthorizationService,
DataService,
Expand All @@ -34,6 +35,22 @@ angular.module('openshiftConsole')
}
];

var pvcTemplate = {
kind: "PersistentVolumeClaim",
apiVersion: "v1",
metadata: {
name: undefined,
labels: {},
annotations: {}
},
spec: {
resources: {
requests:{}
}
}
};
var createPVCVersion = APIService.objectToResourceGroupVersion(pvcTemplate);

var hideErrorNotifications = function() {
NotificationsService.hideNotification("create-pvc-error");
};
Expand All @@ -48,8 +65,7 @@ angular.module('openshiftConsole')
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.project = project;

if (!AuthorizationService.canI('persistentvolumeclaims', 'create', $routeParams.project)) {
if (!AuthorizationService.canI(createPVCVersion, 'create', $routeParams.project)) {
Navigate.toErrorPage('You do not have authority to create persistent volume claims in project ' + $routeParams.project + '.', 'access_denied');
return;
}
Expand All @@ -59,7 +75,7 @@ angular.module('openshiftConsole')
if ($scope.createPersistentVolumeClaimForm.$valid) {
$scope.disableInputs = true;
var claim = generatePersistentVolumeClaim();
DataService.create('persistentvolumeclaims', null, claim, context)
DataService.create(createPVCVersion, null, claim, context)
.then(function(claim) { // Success
NotificationsService.addNotification({
type: "success",
Expand All @@ -81,21 +97,8 @@ angular.module('openshiftConsole')
};

function generatePersistentVolumeClaim() {
var pvc = {
kind: "PersistentVolumeClaim",
apiVersion: "v1",
metadata: {
name: $scope.claim.name,
labels: {},
annotations: {}
},
spec: {
resources: {
requests:{}
}
}
};

var pvc = angular.copy(pvcTemplate);
pvc.metadata.name = $scope.claim.name;
pvc.spec.accessModes = [$scope.claim.accessModes || "ReadWriteOnce"] ;
var unit = $scope.claim.unit || "Mi";
pvc.spec.resources.requests.storage = $scope.claim.amount + unit;
Expand Down
44 changes: 22 additions & 22 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8709,27 +8709,18 @@ kubernetes: n.VERSION.kubernetes
};
} ]), angular.module("openshiftConsole").controller("CommandLineController", [ "$scope", "DataService", "AuthService", "Constants", function(e, t, n, a) {
n.withUser(), e.cliDownloadURL = a.CLI, e.cliDownloadURLPresent = e.cliDownloadURL && !_.isEmpty(e.cliDownloadURL), e.loginBaseURL = t.openshiftAPIBaseUrl(), a.DISABLE_COPY_LOGIN_COMMAND || (e.sessionToken = n.UserStore().getToken());
} ]), angular.module("openshiftConsole").controller("CreatePersistentVolumeClaimController", [ "$filter", "$routeParams", "$scope", "$window", "ApplicationGenerator", "AuthorizationService", "DataService", "Navigate", "NotificationsService", "ProjectsService", "keyValueEditorUtils", function(e, t, n, a, r, o, i, s, c, l, u) {
} ]), angular.module("openshiftConsole").controller("CreatePersistentVolumeClaimController", [ "$filter", "$routeParams", "$scope", "$window", "APIService", "ApplicationGenerator", "AuthorizationService", "DataService", "Navigate", "NotificationsService", "ProjectsService", "keyValueEditorUtils", function(e, t, n, a, r, o, i, s, c, l, u, d) {
n.projectName = t.project, n.accessModes = "ReadWriteOnce", n.claim = {}, n.breadcrumbs = [ {
title: "Storage",
link: "project/" + n.projectName + "/browse/storage"
}, {
title: "Create Storage"
} ];
var d = function() {
c.hideNotification("create-pvc-error");
};
n.$on("$destroy", d);
var p = function() {
a.history.back();
};
n.cancel = p, l.get(t.project).then(_.spread(function(a, r) {
function l() {
var e = {
var p = {
kind: "PersistentVolumeClaim",
apiVersion: "v1",
metadata: {
name: n.claim.name,
name: void 0,
labels: {},
annotations: {}
},
Expand All @@ -8738,34 +8729,43 @@ resources: {
requests: {}
}
}
}, m = r.objectToResourceGroupVersion(p), f = function() {
l.hideNotification("create-pvc-error");
};
e.spec.accessModes = [ n.claim.accessModes || "ReadWriteOnce" ];
n.$on("$destroy", f);
var g = function() {
a.history.back();
};
n.cancel = g, u.get(t.project).then(_.spread(function(a, r) {
function o() {
var e = angular.copy(p);
e.metadata.name = n.claim.name, e.spec.accessModes = [ n.claim.accessModes || "ReadWriteOnce" ];
var t = n.claim.unit || "Mi";
if (e.spec.resources.requests.storage = n.claim.amount + t, n.claim.selectedLabels) {
var a = u.mapEntries(u.compactEntries(n.claim.selectedLabels));
var a = d.mapEntries(d.compactEntries(n.claim.selectedLabels));
_.isEmpty(a) || _.set(e, "spec.selector.matchLabels", a);
}
return n.claim.storageClass && "No Storage Class" !== n.claim.storageClass.metadata.name && (e.metadata.annotations["volume.beta.kubernetes.io/storage-class"] = n.claim.storageClass.metadata.name), e;
}
n.project = a, o.canI("persistentvolumeclaims", "create", t.project) ? n.createPersistentVolumeClaim = function() {
if (d(), n.createPersistentVolumeClaimForm.$valid) {
n.project = a, i.canI(m, "create", t.project) ? n.createPersistentVolumeClaim = function() {
if (f(), n.createPersistentVolumeClaimForm.$valid) {
n.disableInputs = !0;
var t = l();
i.create("persistentvolumeclaims", null, t, r).then(function(e) {
c.addNotification({
var t = o();
s.create(m, null, t, r).then(function(e) {
l.addNotification({
type: "success",
message: "Persistent volume claim " + e.metadata.name + " successfully created."
}), p();
}), g();
}, function(t) {
n.disableInputs = !1, c.addNotification({
n.disableInputs = !1, l.addNotification({
id: "create-pvc-error",
type: "error",
message: "An error occurred requesting storage.",
details: e("getErrorDetails")(t)
});
});
}
} : s.toErrorPage("You do not have authority to create persistent volume claims in project " + t.project + ".", "access_denied");
} : c.toErrorPage("You do not have authority to create persistent volume claims in project " + t.project + ".", "access_denied");
}));
} ]), angular.module("openshiftConsole").directive("buildClose", [ "$window", function(e) {
var t = function(e) {
Expand Down