-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Create kubeconfig for pipeline
Signed-off-by: Ross Fairbanks <[email protected]>
- Loading branch information
Showing
6 changed files
with
159 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
if [ -z "$1" ]; then | ||
echo "Usage: $0 [pipeline|readonly]" | ||
exit 1 | ||
fi | ||
|
||
ROLE_TYPE="$1" | ||
|
||
kubectl apply -f ${ROLE_TYPE}-kubeconfig-resources.yaml | ||
|
||
USER_TOKEN_VALUE=$(kubectl -n kube-system get secret/${ROLE_TYPE}-account-token -o=go-template='{{.data.token}}' | base64 --decode) | ||
CURRENT_CONTEXT=$(kubectl config current-context) | ||
CURRENT_CLUSTER=$(kubectl config view --raw -o=go-template='{{range .contexts}}{{if eq .name "'''${CURRENT_CONTEXT}'''"}}{{ index .context "cluster" }}{{end}}{{end}}') | ||
CLUSTER_CA=$(kubectl config view --raw -o=go-template='{{range .clusters}}{{if eq .name "'''${CURRENT_CLUSTER}'''"}}"{{with index .cluster "certificate-authority-data" }}{{.}}{{end}}"{{ end }}{{ end }}') | ||
CLUSTER_SERVER=$(kubectl config view --raw -o=go-template='{{range .clusters}}{{if eq .name "'''${CURRENT_CLUSTER}'''"}}{{ .cluster.server }}{{end}}{{ end }}') | ||
|
||
cat << EOF > green-reviews-cluster-${ROLE_TYPE}-config | ||
apiVersion: v1 | ||
kind: Config | ||
current-context: ${CURRENT_CONTEXT} | ||
contexts: | ||
- name: ${CURRENT_CONTEXT} | ||
context: | ||
cluster: ${CURRENT_CONTEXT} | ||
user: ${ROLE_TYPE}-account | ||
clusters: | ||
- name: ${CURRENT_CONTEXT} | ||
cluster: | ||
certificate-authority-data: ${CLUSTER_CA} | ||
server: ${CLUSTER_SERVER} | ||
users: | ||
- name: ${ROLE_TYPE}-account | ||
user: | ||
token: ${USER_TOKEN_VALUE} | ||
EOF |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
############################################################################# | ||
# Add custom resources for pipeline which are not covered by view clusterrole | ||
############################################################################# | ||
# | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: crole-customresources-pipeline | ||
labels: | ||
rbac.authorization.k8s.io/aggregate-to-view: "true" | ||
rules: | ||
- apiGroups: ["source.toolkit.fluxcd.io"] | ||
resources: | ||
- gitrepositories | ||
- helmrepositories | ||
- ocirepositories | ||
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] | ||
- apiGroups: ["helm.toolkit.fluxcd.io"] | ||
resources: | ||
- helmreleases | ||
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] | ||
- apiGroups: ["kustomize.toolkit.fluxcd.io"] | ||
resources: | ||
- kustomizations | ||
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"] | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: pipeline-account | ||
namespace: kube-system | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: crolebinding-pod-pipeline | ||
subjects: | ||
- kind: ServiceAccount | ||
name: pipeline-account | ||
namespace: kube-system | ||
roleRef: | ||
kind: ClusterRole | ||
name: view | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
type: kubernetes.io/service-account-token | ||
metadata: | ||
name: pipeline-account-token | ||
namespace: kube-system | ||
annotations: | ||
kubernetes.io/service-account.name: pipeline-account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
#################################################################### | ||
# Add custom resources which are not covered by view clusterrole | ||
#################################################################### | ||
# | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: crole-customresources-readyonly | ||
labels: | ||
rbac.authorization.k8s.io/aggregate-to-view: "true" | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["pods/portforward"] | ||
verbs: ["create"] | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: readonly-account | ||
namespace: kube-system | ||
--- | ||
|
||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: crolebinding-pod-readyonly | ||
subjects: | ||
- kind: ServiceAccount | ||
name: readonly-account | ||
namespace: kube-system | ||
roleRef: | ||
kind: ClusterRole | ||
name: view | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
type: kubernetes.io/service-account-token | ||
metadata: | ||
name: readonly-account-token | ||
namespace: kube-system | ||
annotations: | ||
kubernetes.io/service-account.name: readonly-account |