Skip to content
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

initExistingUsers needs to create ResourceQuotas and Services #281

Open
bodom0015 opened this issue Apr 19, 2019 · 1 comment
Open

initExistingUsers needs to create ResourceQuotas and Services #281

bodom0015 opened this issue Apr 19, 2019 · 1 comment

Comments

@bodom0015
Copy link
Member

bodom0015 commented Apr 19, 2019

Using the cluster-backup repo, I was able to migrate the users from one instance of Workbench to another. The API server throws a 500 exception when trying to pull from /accounts, since the user's ResourceQuota does not exist and cannot be read. Furthermore any existing stacks needed to be wiped out, since their services were not migrated properly.

This could easily be fixed by having the API server create resources where they do exist.

@bodom0015 bodom0015 changed the title initExistingUsers needs to create ResourceQuotas initExistingUsers needs to create ResourceQuotas and Services Apr 19, 2019
@bodom0015
Copy link
Member Author

Got bit by this again during the CHEESEhub production migration/redeploy. PVCs are also now missing for existing users as well.

Solution for services was to not migrate any existing stacks. This created a different problem where etcd imported empty directories as empty files instead. Manually deleting these empty files caused them to be recreated properly the next time.

For now, the other resources can be created using a script I threw together (be sure to include userreg.yaml in the same directory):

ubuntu@cheesehub-master:~$ cat post-migration.sh 
#
# Given a list of names from etcd, ensure they have a namespace and PVC available
#
# Usage: ./post-migration.sh
#
#
set -e

# Fetch a sorted list of users from etcd
usernames=$(kubectl exec -it deploy/workbench -c etcd -- etcdctl ls /ndslabs/accounts | awk -F '[/\r]' '{print $4}')
echo Importing the following users:
echo "$usernames"

read -p "Press enter to continue or Ctrl+C to abort" || echo

# Fail-fast for empty list or error
if [ "$usernames" == "" ]; then
	echo "No usernames given for import... aborting."
	exit 1
fi

# For each username, apply a PVC and NS to ensure that one exists
for username in $usernames; do
	echo "Importing $username..."
	cat userreg.yaml  | sed -e "s#{{USERNAME}}#$username#g" | kubectl apply -f -
done

ubuntu@cheesehub-master:~$ cat userreg.yaml 
---
apiVersion: v1
kind: Namespace
metadata:
  name: {{USERNAME}}
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: {{USERNAME}}-home
  namespace: {{USERNAME}}
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Mi
---
apiVersion: v1
kind: ResourceQuota
metadata:
  name: quota
  namespace: {{USERNAME}}
spec:
  hard:
    cpu: "2"
    memory: 8196M
status:
  hard:
    cpu: "2"
    memory: 8196M

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant