Estamos tratando de usar github actions y queremos mantener datos confidenciales como kubeconfig dentro de los secrets de github. Creé un secreto de GitHub con el nombre KUBECONFIG1
pasos para reproducir
En el secreto de GitHub, debo almacenar el siguiente archivo que también intenté convertir a JSON con este https://onlineyamltools.com/convert-yaml-to-json
apiVersion: v1 kind: Config clusters: - name: brf cluster: certificate-authority-data: >- LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURTakNBd0t6RXBNQ2NHQTFVRUF4TWdkbWx5ZE2bUljTlRtakFWCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0= server: 'https://vfg.canary.k8s.ondemand.com' users: - name: user1 user: token: >- eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuW1lc3BhY2UiOiJnYXJkZW4tZGV2e contexts: - name: g-root context: cluster: garv user: robot namespace: gking current-context: gaot en el flujo de trabajo de acciones de github mantenemos el contenido del archivo anterior con el nombre KUBECONFIG1 y creamos a partir de él k8s secret.
name: Example action on: [push] jobs: build: runs-on: ubuntu-latest timeout-minutes: 5 steps: - uses: actions/checkout@v2 - name: install k8s run: | curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE=777 sh - cat /etc/rancher/k3s/k3s.yaml mkdir -p ~/.kube cp /etc/rancher/k3s/k3s.yaml ~/.kube/config - run: 'echo -e "$KUBECONFIG1" > ~/.tmpfile.json' shell: bash env: KUBECONFIG1: ${{secrets.KUBECONFIG1}} - name: example shell: bash run: | cd ~/ kubectl create secret generic project-kubecfg --from-file=~/.tmpfile.json -n defaultDespués de ejecutar este flujo de trabajo, recibí el siguiente error:
error: error loading config file "/home/runner/work/_temp/kubeconfig_1617030542039": couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct *** APIVersion string "json:\"apiVersion,omitempty\""; Kind string "json:\"kind,omitempty\"" *** Error: Process completed with exit code 1.También trato de tomar el contenido del archivo y usar https://onlinelinuxtools.com/escape-shell-characters
A medida que trabajamos con Golang, tal vez debería tomar el kubeconfig y usarlo como plantilla y guardar los sensitive-data certificate-authority-data token , etc. como secreto de github y durante el flujo de trabajo actualizar el valor de los secretos en la plantilla, pero no estoy seguro de cómo. ..
Lo que necesito al final necesito que el siguiente comando funcione en el flujo de trabajo
kubectl create secret generic project-kubecfg --from-file=~/.tmpfile.json -n default
El problema es con el siguiente comando
kubectl create secret generic project-kubecfg --from-file=~/.tmpfile.json -n default El problema es que ~ va a kubectl , que no lo expande al directorio de inicio. Entonces, si lo cambias como a continuación, funcionará
kubectl create secret generic project-kubecfg --from-file=/home/runner/.tmpfile.json -n default O más bien use una ruta fija en lugar del directorio de inicio con ~