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

K3S_DATA_DIR is lost when running kill and uninstall scripts as non-root user #11386

Closed
unguiculus opened this issue Nov 28, 2024 · 3 comments · Fixed by #11378
Closed

K3S_DATA_DIR is lost when running kill and uninstall scripts as non-root user #11386

unguiculus opened this issue Nov 28, 2024 · 3 comments · Fixed by #11378
Assignees

Comments

@unguiculus
Copy link
Contributor

unguiculus commented Nov 28, 2024

Environmental Info:
K3s Version:
v1.31.2+k3s1

Node(s) CPU architecture, OS, and Version:
Any. Not relevant.

Cluster Configuration:
Various configurations. Not relevant.

Describe the bug:
The generated k3s-killall.sh and k3s-uninstall.sh scripts replace the current process with the same but running with sudo. This does not preserve the environment, i.e. a custom data directory using K3S_DATA_DIR is ignored.

Steps To Reproduce:

  • Open a shell as non-root user
  • Export environment variable K3S_DATA_DIR=$HOME/mydata
  • Create a cluster in the same shell
  • Run k3s-uninstall.sh in the same shell

Expected behavior:
Uninstallation should work properly. $K3S_DATA_DIR should be cleaned.

Actual behavior:
Instead of $K3S_DATA_DIR, /var/lib/rancher/k3s is used. $K3S_DATA_DIR is not cleaned. K3s is not properly uninstalled. This can be seen in the logs.

@brandond
Copy link
Member

reopening for QA

@fmoral2 fmoral2 self-assigned this Jan 13, 2025
@fmoral2
Copy link
Contributor

fmoral2 commented Jan 21, 2025

 ---------  1.29.1+k3s1 OK ------------

~$ export K3S_DATA_DIR=$HOME/data

 ~$ curl -fL https://get.k3s.io | INSTALL_K3S_VERSION=v1.29.1+k3s1  sh -s - server 

 ~$sudo  journalctl -xeu k3s -f | grep data
Info msg="Preparing data dir /home/ec2-user/data/data/515ac1d8782af00dd13facb61e43f161fbd415a6c63a656f15df5215d130c54b"


k3s -v
k3s version v1.29.1+k3s1 (6d77b7a9)
go version go1.21.6


~$ kubectl get nodes
NAME               STATUS   ROLES                       AGE   VERSION
ip-     Ready    control-plane,etcd,master   68s   v1.29.1+k3s1


~$ ls -a /home/ec2-user/data
.  ..  agent  data  server


NON-ROOT
 ~$ /usr/local/bin/k3s-uninstall.sh
++ id -u
+ '[' 1000 -eq 0 ']'
+ exec sudo --preserve-env=K3S_DATA_DIR /usr/local/bin/k3s-uninstall.sh
++ id -u
+ '[' 0 -eq 0 ']'
+ K3S_DATA_DIR=/home/ec2-user/data


 $ ls -a /home/ec2-user/data
ls: cannot access '/home/ec2-user/data': No such file or directory


$   k3s -v
-bash: /usr/local/bin/k3s: No such file or directory


 
---------  v1.31.2+k3s1 (6da20424)  OK ------------


kubectl get nodes
NAME               STATUS   ROLES                       AGE   VERSION
   Ready    control-plane,etcd,master   15s      v1.31.2+k3s1 (6da20424)

$ k3s -v
k3s version v1.31.2+k3s1 (6da20424) 


 ~$ sudo journalctl -xeu k3s -f | grep data
 level=info msg="Preparing data dir /home/ec2-user/data/data/00c7d0d96e0371eb6c2459426d978b89619858640b88c83ff3e97b13f0cb920b"



~$ ls -a /home/ec2-user/data
.  ..  agent  data  server


NON-ROOT
 ~$ /usr/local/bin/k3s-uninstall.sh
++ id -u
+ '[' 1000 -eq 0 ']'
+ exec sudo --preserve-env=K3S_DATA_DIR /usr/local/bin/k3s-uninstall.sh
++ id -u
+ '[' 0 -eq 0 ']'
+ K3S_DATA_DIR=/home/ec2-user/data


 $ ls -a /home/ec2-user/data
ls: cannot access '/home/ec2-user/data': No such file or directory


$   k3s -v
-bash: /usr/local/bin/k3s: No such file or directory


$ ls /home/ec2-user/
bin

 

@fmoral2
Copy link
Contributor

fmoral2 commented Jan 21, 2025

Master

k3s -v
k3s version v1.32.1+k3s-a858412c (a858412c)


~$ ls -a /home/ec2-user/data
.  ..  agent  data  server



$ sudo journalctl -xeu k3s -f | grep data
Jan 21 20:14:14 ip-172-31-29-19 k3s[22924]: time="2025-01-21T20:14:14Z" level=info msg="Preparing data dir /home/ec2-user/data/data/70faee4d1185eadf26318b7737b4ef4393f5ab0a472b2920ba08d1a3d0d6d3bb"



$ /usr/local/bin/k3s-uninstall.sh
++ id -u
+ '[' 1000 -eq 0 ']'
+ exec sudo --preserve-env=K3S_DATA_DIR /usr/local/bin/k3s-uninstall.sh
++ id -u
+ '[' 0 -eq 0 ']'
+ K3S_DATA_DIR=/home/ec2-user/data
+ /usr/local/bin/k3s-killall.sh



~$ ls -a /home/ec2-user/data
ls: cannot access '/home/ec2-user/data': No such file or directory

@fmoral2 fmoral2 closed this as completed Jan 21, 2025
@github-project-automation github-project-automation bot moved this from To Test to Done Issue in K3s Development Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done Issue
Development

Successfully merging a pull request may close this issue.

4 participants