Skip to content

Commit

Permalink
Merge pull request #78 from luthersystems/local-execution
Browse files Browse the repository at this point in the history
local execution support
  • Loading branch information
jeremy-asher authored Aug 13, 2024
2 parents 64c9b06 + 13cdf2a commit 1c30e9b
Show file tree
Hide file tree
Showing 22 changed files with 90 additions and 11 deletions.
4 changes: 3 additions & 1 deletion ansible-roles/helm/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

- name: helm setup
include_tasks: setup.yml
when: not helm_setup or helm_upgrade
when:
- not helm_setup or helm_upgrade
- not mars_local | default(false)
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ spec:
- name: crypto
mountPath: /crypto
{{- end }}
{{- if not .Values.local }}
nodeSelector:
topology.kubernetes.io/zone: {{ .Values.availabilityZone }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ metadata:
ebs.csi.aws.com/volumeType: {{ .Values.persistentVolume.typeOverride }}
{{- end }}
spec:
{{- if not .Values.local }}
selector:
matchLabels:
app.kubernetes.io/component: {{ .Values.dlt.component }}
type: storage
fabric/organization: {{ .Values.dlt.organization }}
{{- end }}
storageClassName: {{ .Values.persistentVolume.storageClassName }}
accessModes:
- ReadWriteOnce
Expand Down
2 changes: 2 additions & 0 deletions ansible-roles/k8s_fabric_ca/files/fabric-ca/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ affinity: {}
availabilityZone: ""

awsCLIVersion: latest

local: false
1 change: 1 addition & 0 deletions ansible-roles/k8s_fabric_ca/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
idleTimeout: "{{k8s_fabric_ca_lb_idle_timeout}}"
useNLB: "{{k8s_fabric_ca_use_nlb}}"
awsCLIVersion: "{{k8s_fabric_ca_aws_cli_version}}"
local: "{{mars_local | default(false)}}"
environment: "{{ kubectl_env }}"
vars:
availability_zones: "{{[k8s_fabric_ca_az] or k8s_pv_data_replica_azs}}"
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ spec:
runAsUser: 1
allowPrivilegeEscalation: false

{{- if .Values.availabilityZone }}
{{- if and .Values.availabilityZone (not .Values.local) }}
nodeSelector:
topology.kubernetes.io/zone: {{ .Values.availabilityZone }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ env:
ccid: ""

availabilityZone: ""

local: false
17 changes: 9 additions & 8 deletions ansible-roles/k8s_fabric_chaincode/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- name: Check committed chaincode
command:
argv:
- scripts/query-committed.sh
- "{{ k8s_fabric_scripts_dir }}/query-committed.sh"
- "{{ k8s_fabric_chaincode_orgs.0.name }}"
- "{{ k8s_fabric_chaincode_name }}"
- "{{ k8s_fabric_chaincode_version }}"
Expand All @@ -31,7 +31,7 @@
- name: Install chaincode on peers
command:
argv:
- scripts/install-chaincode.sh
- "{{ k8s_fabric_scripts_dir }}/install-chaincode.sh"
- "{{ item.0 }}" # org name
- "{{ item.1 }}" # peer index
- "{{ k8s_fabric_chaincode_name }}"
Expand Down Expand Up @@ -80,6 +80,7 @@
availabilityZone: "{{availability_zones[item.1]}}"
env:
CHAINCODE_LOG_LEVEL: "{{k8s_fabric_chaincode_loglevel}}"
local: "{{mars_local | default(false)}}"
loop: "{{ k8s_fabric_chaincode_orgs | org_peer_pairs }}"
loop_control:
index_var: index
Expand All @@ -93,7 +94,7 @@
- name: Approve chaincode on each org
command:
argv:
- scripts/approve-chaincode.sh
- "{{ k8s_fabric_scripts_dir }}/approve-chaincode.sh"
- "{{ item.name }}"
- "{{ item.msp }}"
- "{{ k8s_fabric_chaincode_name }}"
Expand All @@ -113,7 +114,7 @@
- name: Generate approval script
command:
argv:
- scripts/generate-approval-script.sh
- "{{ k8s_fabric_scripts_dir }}/generate-approval-script.sh"
- "{{ k8s_fabric_chaincode_orgs.0.name }}"
- "{{ k8s_fabric_chaincode_name }}"
- "{{ k8s_fabric_chaincode_version }}"
Expand All @@ -129,7 +130,7 @@
- name: Check chaincode approvals
command:
argv:
- scripts/commit-readiness-report.sh
- "{{ k8s_fabric_scripts_dir }}/commit-readiness-report.sh"
- "{{ k8s_fabric_chaincode_orgs.0.name }}"
- "{{ k8s_fabric_chaincode_name }}"
- "{{ k8s_fabric_chaincode_version }}"
Expand Down Expand Up @@ -157,7 +158,7 @@
- name: Wait for chaincode approvals
command:
argv:
- scripts/commit-readiness.sh
- "{{ k8s_fabric_scripts_dir }}/commit-readiness.sh"
- "{{ k8s_fabric_chaincode_orgs.0.name }}"
- "{{ k8s_fabric_chaincode_name }}"
- "{{ k8s_fabric_chaincode_version }}"
Expand All @@ -181,7 +182,7 @@
chdir: "{{ k8s_fabric_scripts_workdir }}"
vars:
base_args:
- scripts/commit-chaincode.sh
- "{{ k8s_fabric_scripts_dir }}/commit-chaincode.sh"
- "{{ k8s_fabric_chaincode_name }}"
- "{{ k8s_fabric_chaincode_version }}"
- "{{ k8s_fabric_chaincode_endorsement_policy }}"
Expand All @@ -196,7 +197,7 @@
- name: Wait for chaincode commit
command:
argv:
- scripts/query-committed.sh
- "{{ k8s_fabric_scripts_dir }}/query-committed.sh"
- "{{ k8s_fabric_chaincode_orgs.0.name }}"
- "{{ k8s_fabric_chaincode_name }}"
- "{{ k8s_fabric_chaincode_version }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ spec:
- name: collections-config
mountPath: /collections-config
{{- end }}
{{- if not .Values.local }}
nodeSelector:
topology.kubernetes.io/zone: {{ .Values.availabilityZone }}
{{- end }}
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
Expand Down
2 changes: 2 additions & 0 deletions ansible-roles/k8s_fabric_cli/files/fabric-cli/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ tolerations: []
affinity: {}

awsCLIVersion: latest

local: false
1 change: 1 addition & 0 deletions ansible-roles/k8s_fabric_cli/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
dockerChaincode: "{{k8s_fabric_cli_chaincode_docker}}"
availabilityZone: "{{availability_zones[item]}}"
awsCLIVersion: "{{k8s_fabric_cli_aws_cli_version}}"
local: "{{mars_local | default(false)}}"
environment: "{{ kubectl_env }}"
vars:
availability_zones: "{{k8s_fabric_cli_azs}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ spec:
mountPath: /hcs
{{- end }}
{{- end }}
{{- if not .Values.local }}
nodeSelector:
topology.kubernetes.io/zone: {{ .Values.availabilityZone }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ metadata:
ebs.csi.aws.com/volumeType: {{ .Values.persistentVolume.typeOverride }}
{{- end }}
spec:
{{- if not .Values.local }}
selector:
matchLabels:
app.kubernetes.io/component: {{ .Values.dlt.component }}
type: storage
fabric/organization: {{ .Values.dlt.organization }}
replica-index: {{ .Values.dlt.organizationIndex | print | toJson }}
{{- end }}
storageClassName: {{ .Values.persistentVolume.storageClassName }}
accessModes:
- ReadWriteOnce
Expand Down
1 change: 1 addition & 0 deletions ansible-roles/k8s_fabric_orderer/tasks/inner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
useNLB: "{{k8s_fabric_orderer_use_nlb}}"
logGrpc: "{{k8s_fabric_orderer_log_grpc}}"
awsCLIVersion: "{{k8s_fabric_orderer_aws_cli_version}}"
local: "{{mars_local | default(false)}}"
environment: "{{ kubectl_env }}"
vars:
availability_zones: "{{k8s_fabric_orderer_azs or k8s_pv_data_replica_azs}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,10 @@ spec:
- name: tls
mountPath: /tls
{{- end }}
{{- if not .Values.local }}
nodeSelector:
topology.kubernetes.io/zone: {{ .Values.availabilityZone }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ metadata:
ebs.csi.aws.com/volumeType: {{ .Values.persistentVolume.typeOverride }}
{{- end }}
spec:
{{- if not .Values.local }}
selector:
matchLabels:
app.kubernetes.io/component: {{ .Values.dlt.component }}
type: storage
fabric/organization: {{ .Values.dlt.organization }}
replica-index: {{ .Values.dlt.peerIndex | print | toJson }}
{{- end }}
storageClassName: {{ .Values.persistentVolume.storageClassName }}
accessModes:
- ReadWriteOnce
Expand All @@ -37,12 +39,14 @@ metadata:
ebs.csi.aws.com/volumeType: {{ .Values.persistentVolume.typeOverride }}
{{- end }}
spec:
{{- if not .Values.local }}
selector:
matchLabels:
app.kubernetes.io/component: {{ .Values.dlt.component }}
type: dockerstorage
fabric/organization: {{ .Values.dlt.organization }}
replica-index: {{ .Values.dlt.peerIndex | print | toJson }}
{{- end }}
storageClassName: {{ .Values.persistentVolume.storageClassName }}
accessModes:
- ReadWriteOnce
Expand Down
2 changes: 2 additions & 0 deletions ansible-roles/k8s_fabric_peer/files/fabric-peer/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,5 @@ fabricSnapshotArchiver:
pullPolicy: IfNotPresent
version: v0.0.1
resources: {}

local: false
1 change: 1 addition & 0 deletions ansible-roles/k8s_fabric_peer/tasks/inner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
image:
version: "{{k8s_fabric_peer_snapshot_archiver_version}}"
enabled: "{{k8s_fabric_peer_use_snapshot_archiver}}"
local: "{{mars_local | default(false)}}"
environment: "{{ kubectl_env }}"
vars:
availability_zones: "{{k8s_fabric_peer_azs or k8s_pv_data_replica_azs}}"
Expand Down
2 changes: 2 additions & 0 deletions ansible-roles/k8s_fabric_scripts/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
state: directory
recurse: yes
tags: fabric_scripts
when: not mars_local | default(false)

- name: Scripts are uploaded
synchronize:
Expand All @@ -18,3 +19,4 @@
group: no
use_ssh_args: yes
tags: fabric_scripts
when: not mars_local | default(false)
25 changes: 25 additions & 0 deletions ansible-roles/kubectl/tasks/local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: override ansible interpreter
set_fact:
ansible_python_interpreter: "{{ kubectl_python_interpreter }}"
when: kubectl_python_interpreter != ""

- name: use local asset root path
set_fact:
kubectl_asset_root_path: /tmp/k8s

- name: create asset root path
ansible.builtin.file:
path: "{{ kubectl_asset_root_path }}"
state: directory
mode: '0755'

- name: Setup kubectl environment
set_fact:
kubectl_env:
KUBECONFIG: "{{kubectl_config_path}}"
K8S_AUTH_KUBECONFIG: "{{kubectl_config_path}}"

- name: Setup kubectl as configured
set_fact:
kubectl_configured: yes
11 changes: 10 additions & 1 deletion ansible-roles/kubectl/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
when:
- not kubectl_setup or kubectl_upgrade
- not kubectl_configured
- not mars_local | default(false)

- name: kubectl env setup
include_tasks: env.yml
when: not kubectl_configured
when:
- not kubectl_configured
- not mars_local | default(false)

- name: kubectl local setup
include_tasks: local.yml
when:
- not kubectl_configured
- mars_local | default(false)
12 changes: 12 additions & 0 deletions mars_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ if [[ "$MARS_SHELL" == "true" ]]; then
SHELL_OPTS="--entrypoint /bin/bash"
fi

LOCAL_OPTS=
if [[ "$MARS_LOCAL" == "true" ]]; then
LOCAL_OPTS="-e ANSIBLE_TRANSPORT=local -e ANSIBLE_PIPELINING=True"
fi

NETWORK_OPTS=
if [[ -n "$MARS_NETWORK" ]]; then
NETWORK_OPTS="--network ${MARS_NETWORK}"
fi

# include GitHub credentials if available
if command -v gh >/dev/null; then
export GITHUB_TOKEN="$(gh auth token 2>/dev/null)"
Expand Down Expand Up @@ -123,6 +133,8 @@ docker run --rm $DOCKER_TERM_VARS \
-w "$DOCKER_WORK_DIR" \
-e ANSIBLE_LOAD_CALLBACK_PLUGINS=yes \
-e ANSIBLE_STDOUT_CALLBACK=yaml \
$LOCAL_OPTS \
$NETWORK_OPTS \
$SHELL_OPTS \
$PINATA_OPTS \
"$DOCKER_IMAGE:$MARS_VERSION" "$@"

0 comments on commit 1c30e9b

Please sign in to comment.