upgrade CNPG give a permission error on running bash tcdbinfo.sh

mvdheijkant

Dabbler
Joined
Feb 19, 2023
Messages
10
I'm trying to follow the upgrade plan for CNPG Operator on this page https://truecharts.org/manual/SCALE/guides/cnpg-migration-guide
I'm not that experienced with truenas and consider myself a beginner.
So I wanted to try and follow the guide and do only the first nondestructive actions, to gain a bit more confidence to follow through.
But already after running bash tcdbinfo.sh I get the error below.

Is this a common issue when running this script, and how can I resolve this.

admin@truenas[/mnt/tank/appconfig/pgadmin]$ bash tcdbinfo.sh
WARN[0000] Unable to read /etc/rancher/k3s/k3s.yaml, please start server with --write-kubeconfig-mode to modify kube config permissions
error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied
WARN[0000] Unable to read /etc/rancher/k3s/k3s.yaml, please start server with --write-kubeconfig-mode to modify kube config permissions
error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied
Application Username Password Address Port
..svc.cluster.local
 

mvdheijkant

Dabbler
Joined
Feb 19, 2023
Messages
10
Found this url "https://0to1.nl/post/k3s-kubectl-permission/" and ran command:
sudo chmod 644 /etc/rancher/k3s/k3s.yaml
but after running bash tcdbinfo.sh I ran again into the next error:

admin@truenas[/mnt/tank/appconfig/pgadmin]$ bash tcdbinfo.sh
error: arguments in resource/name form must have a single resource and name
Application Username Password Address Port
..svc.cluster.local

The script looks like this.
Its the script from https://truecharts.org/manual/SCALE...-list-database-login-info-for-truecharts-apps

What do you recommend on how to proceed with this?

Code:
#!/bin/bash

# get namespaces
namespaces=$(k3s kubectl get secrets -A | grep -E "dbcreds|cnpg-main-urls" | awk '{print $1, $2}')

# iterate over namespaces
( printf "Application | Username | Password | Address | Port\n"
echo "$namespaces" | while read ns secret; do
    # extract application name
    app_name=$(echo "$ns" | sed 's/^ix-//')
    if [ "$secret" = "dbcreds" ]; then
        creds=$(k3s kubectl get secret/$secret --namespace "$ns" -o jsonpath='{.data.url}' | base64 -d)
    else
        creds=$(k3s kubectl get secret/$secret --namespace "$ns" -o jsonpath='{.data.std}' | base64 -d)
    fi
    
    # get username, password, addresspart, and port
    username=$(echo "$creds" | awk -F '//' '{print $2}' | awk -F ':' '{print $1}')
    password=$(echo "$creds" | awk -F ':' '{print $3}' | awk -F '@' '{print $1}')
    addresspart=$(echo "$creds" | awk -F '@' '{print $2}' | awk -F ':' '{print $1}')
    port=$(echo "$creds" | awk -F ':' '{print $4}' | awk -F '/' '{print $1}')

    # construct full address
    full_address="${addresspart}.${ns}.svc.cluster.local"

    # print results with aligned columns
    printf "%s | %s | %s | %s | %s\n" "$app_name" "$username" "$password" "$full_address" "$port"
done ) | column -t -s "|"
 

truecharts

Guru
Joined
Aug 19, 2021
Messages
788
Had a discussion on Discord. It seemed I had no apps using the database on https://truecharts.org/manual/SCALE/guides/cnpg-migration-guide/
So I took a gamble because I don't know much about Kubernetes and went strait for this command and continued with the remaing part of the guid. "k3s kubectl delete --grace-period 30 --v=4 -k https://github.com/truecharts/manifests/delete2"

We've since updated the guide to reflect weither a user is actually using any applications consuming cnpg databases and have added a note for users from which date onwards they need to do the migration steps at-all.

Thanks for your feedback!
 
Top