diff --git a/nordvpn-autoconfigure.jenkins b/nordvpn-autoconfigure.jenkins index fe9ee67..a926e72 100644 --- a/nordvpn-autoconfigure.jenkins +++ b/nordvpn-autoconfigure.jenkins @@ -5,7 +5,7 @@ def registry = "registry.c.test-chamber-13.lan" def alpineImage = "${registry}/library/alpine" def alpineTag = "latest" -def kubectlCreds = "rancher-admin-token" +def kubectlCreds = "k8s-dl-automation-access" def nordCreds = "nordvpn-login-creds" def nordURLs = [ @@ -32,9 +32,9 @@ def kubeNamespace = "dl-automation" def kubeSecret = "openvpn" podTemplate( - label: label, - name: "pipeline-worker", - yaml: """--- + label: label, + name: "pipeline-worker", + yaml: """--- apiVersion: v1 kind: Pod metadata: @@ -49,55 +49,55 @@ spec: - /bin/sh """, ) { - node (label) { - def workspace = pwd() + node (label) { + def workspace = pwd() stage ("Update Secret") { container ("alpine") { - sh """ - apk add --no-cache curl jq sed - KUBE_VERSION="\$(curl --location --silent https://dl.k8s.io/release/stable.txt)" - curl \ - --location \ - --silent \ - --output /usr/local/bin/kubectl \ - "https://dl.k8s.io/release/\${KUBE_VERSION}/bin/linux/amd64/kubectl" - chmod +x /usr/local/bin/kubectl - """ + sh """ + apk add --no-cache curl jq sed + KUBE_VERSION="\$(curl --location --silent https://dl.k8s.io/release/stable.txt)" + curl \ + --location \ + --silent \ + --output /usr/local/bin/kubectl \ + "https://dl.k8s.io/release/\${KUBE_VERSION}/bin/linux/amd64/kubectl" + chmod +x /usr/local/bin/kubectl + """ - withCredentials([string( - credentialsId: nordCreds, - variable: "NORD_CREDS", - )]) { + withCredentials([string( + credentialsId: nordCreds, + variable: "NORD_CREDS", + )]) { withKubeConfig([ - credentialsId: kubectlCreds, - serverUrl: "https://rancher.test-chamber-13.lan/k8s/clusters/c-mc9cq", - namespace: "webservers" - ]) { - sh """ - # Get OpenVPN Config - OPENVPN_CONFIG="\$( - curl \ - --silent \ - --location \ - --fail \ - "https://downloads.nordcdn.com/configs/files/ovpn_tcp/servers/\$( - curl \ - --silent \ - --location \ - --fail \ - '""" + nordURL + """' \ - | jq \ - --raw-output \ - '[.[] | select(.technologies[] | .identifier == "openvpn_tcp")][0] | .hostname' \ - ).tcp.ovpn" \ - | sed \ - --regexp-extended \ - --expression='s/auth-user-pass/auth-user-pass \\/etc\\/openvpn\\/client\\/openvpn-credentials.txt/' \ - | base64 -w 0 - )" - printf '%s\n' \ + credentialsId: kubectlCreds, + serverUrl: "https://kubernetes.test-chamber-13.lan:6443", + namespace: "webservers" + ]) { + sh """ + # Get OpenVPN Config + OPENVPN_CONFIG="\$( + curl \ + --silent \ + --location \ + --fail \ + "https://downloads.nordcdn.com/configs/files/ovpn_tcp/servers/\$( + curl \ + --silent \ + --location \ + --fail \ + '""" + nordURL + """' \ + | jq \ + --raw-output \ + '[.[] | select(.technologies[] | .identifier == "openvpn_tcp")][0] | .hostname' \ + ).tcp.ovpn" \ + | sed \ + --regexp-extended \ + --expression='s/auth-user-pass/auth-user-pass \\/etc\\/openvpn\\/client\\/openvpn-credentials.txt/' \ + | base64 -w 0 + )" + printf '%s\n' \ "apiVersion: v1" \ "kind: Secret" \ "metadata:" \ @@ -107,14 +107,14 @@ spec: " openvpn-credentials.txt: \${NORD_CREDS}" \ " us5766.nordvpn.com.tcp.ovpn: \${OPENVPN_CONFIG}" > /tmp/openvpn-secret.kubectl - kubectl apply --namespace """ + kubeNamespace + """ -f /tmp/openvpn-secret.kubectl + kubectl apply --namespace """ + kubeNamespace + """ -f /tmp/openvpn-secret.kubectl for i in \$(kubectl get pods --namespace """ + kubeNamespace + """ --selector app="deluge" -o name); do kubectl delete --namespace """ + kubeNamespace + """ \${i} done """ - } + } } - } - } - } + } + } + } } \ No newline at end of file