diff --git a/ansible-roles/helm/tasks/main.yml b/ansible-roles/helm/tasks/main.yml index a7a8b21..d1b38f7 100644 --- a/ansible-roles/helm/tasks/main.yml +++ b/ansible-roles/helm/tasks/main.yml @@ -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) diff --git a/ansible-roles/k8s_fabric_ca/files/fabric-ca/templates/deployment.yaml b/ansible-roles/k8s_fabric_ca/files/fabric-ca/templates/deployment.yaml index 350b3c7..30ac9ef 100644 --- a/ansible-roles/k8s_fabric_ca/files/fabric-ca/templates/deployment.yaml +++ b/ansible-roles/k8s_fabric_ca/files/fabric-ca/templates/deployment.yaml @@ -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 }} diff --git a/ansible-roles/k8s_fabric_ca/files/fabric-ca/templates/pvc.yaml b/ansible-roles/k8s_fabric_ca/files/fabric-ca/templates/pvc.yaml index 0726259..b1a6dd9 100644 --- a/ansible-roles/k8s_fabric_ca/files/fabric-ca/templates/pvc.yaml +++ b/ansible-roles/k8s_fabric_ca/files/fabric-ca/templates/pvc.yaml @@ -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 diff --git a/ansible-roles/k8s_fabric_ca/files/fabric-ca/values.yaml b/ansible-roles/k8s_fabric_ca/files/fabric-ca/values.yaml index cf71d01..2b9b88e 100644 --- a/ansible-roles/k8s_fabric_ca/files/fabric-ca/values.yaml +++ b/ansible-roles/k8s_fabric_ca/files/fabric-ca/values.yaml @@ -83,3 +83,5 @@ affinity: {} availabilityZone: "" awsCLIVersion: latest + +local: false diff --git a/ansible-roles/k8s_fabric_ca/tasks/main.yml b/ansible-roles/k8s_fabric_ca/tasks/main.yml index 916dda9..45adb82 100644 --- a/ansible-roles/k8s_fabric_ca/tasks/main.yml +++ b/ansible-roles/k8s_fabric_ca/tasks/main.yml @@ -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}}" diff --git a/ansible-roles/k8s_fabric_chaincode/files/chaincode/templates/deployment.yaml b/ansible-roles/k8s_fabric_chaincode/files/chaincode/templates/deployment.yaml index 6c5ab02..21f4442 100644 --- a/ansible-roles/k8s_fabric_chaincode/files/chaincode/templates/deployment.yaml +++ b/ansible-roles/k8s_fabric_chaincode/files/chaincode/templates/deployment.yaml @@ -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 }} diff --git a/ansible-roles/k8s_fabric_chaincode/files/chaincode/values.yaml b/ansible-roles/k8s_fabric_chaincode/files/chaincode/values.yaml index 83fd607..481b66a 100644 --- a/ansible-roles/k8s_fabric_chaincode/files/chaincode/values.yaml +++ b/ansible-roles/k8s_fabric_chaincode/files/chaincode/values.yaml @@ -49,3 +49,5 @@ env: ccid: "" availabilityZone: "" + +local: false diff --git a/ansible-roles/k8s_fabric_chaincode/tasks/main.yml b/ansible-roles/k8s_fabric_chaincode/tasks/main.yml index 1ef3945..77e8124 100644 --- a/ansible-roles/k8s_fabric_chaincode/tasks/main.yml +++ b/ansible-roles/k8s_fabric_chaincode/tasks/main.yml @@ -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 }}" @@ -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 }}" @@ -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 @@ -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 }}" @@ -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 }}" @@ -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 }}" @@ -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 }}" @@ -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 }}" @@ -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 }}" diff --git a/ansible-roles/k8s_fabric_cli/files/fabric-cli/templates/deployment.yaml b/ansible-roles/k8s_fabric_cli/files/fabric-cli/templates/deployment.yaml index 89a6cf1..1000891 100644 --- a/ansible-roles/k8s_fabric_cli/files/fabric-cli/templates/deployment.yaml +++ b/ansible-roles/k8s_fabric_cli/files/fabric-cli/templates/deployment.yaml @@ -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: diff --git a/ansible-roles/k8s_fabric_cli/files/fabric-cli/values.yaml b/ansible-roles/k8s_fabric_cli/files/fabric-cli/values.yaml index 87589d7..433952d 100644 --- a/ansible-roles/k8s_fabric_cli/files/fabric-cli/values.yaml +++ b/ansible-roles/k8s_fabric_cli/files/fabric-cli/values.yaml @@ -88,3 +88,5 @@ tolerations: [] affinity: {} awsCLIVersion: latest + +local: false diff --git a/ansible-roles/k8s_fabric_cli/tasks/main.yml b/ansible-roles/k8s_fabric_cli/tasks/main.yml index 3e51b48..5b59616 100644 --- a/ansible-roles/k8s_fabric_cli/tasks/main.yml +++ b/ansible-roles/k8s_fabric_cli/tasks/main.yml @@ -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}}" diff --git a/ansible-roles/k8s_fabric_orderer/files/fabric-orderer/templates/deployment.yaml b/ansible-roles/k8s_fabric_orderer/files/fabric-orderer/templates/deployment.yaml index 630b3f4..62155f4 100644 --- a/ansible-roles/k8s_fabric_orderer/files/fabric-orderer/templates/deployment.yaml +++ b/ansible-roles/k8s_fabric_orderer/files/fabric-orderer/templates/deployment.yaml @@ -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 }} diff --git a/ansible-roles/k8s_fabric_orderer/files/fabric-orderer/templates/pvc.yaml b/ansible-roles/k8s_fabric_orderer/files/fabric-orderer/templates/pvc.yaml index 45c754d..108d24e 100644 --- a/ansible-roles/k8s_fabric_orderer/files/fabric-orderer/templates/pvc.yaml +++ b/ansible-roles/k8s_fabric_orderer/files/fabric-orderer/templates/pvc.yaml @@ -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 diff --git a/ansible-roles/k8s_fabric_orderer/tasks/inner.yml b/ansible-roles/k8s_fabric_orderer/tasks/inner.yml index 05252aa..093f281 100644 --- a/ansible-roles/k8s_fabric_orderer/tasks/inner.yml +++ b/ansible-roles/k8s_fabric_orderer/tasks/inner.yml @@ -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}}" diff --git a/ansible-roles/k8s_fabric_peer/files/fabric-peer/templates/deployment.yaml b/ansible-roles/k8s_fabric_peer/files/fabric-peer/templates/deployment.yaml index b7c3ea0..878c713 100644 --- a/ansible-roles/k8s_fabric_peer/files/fabric-peer/templates/deployment.yaml +++ b/ansible-roles/k8s_fabric_peer/files/fabric-peer/templates/deployment.yaml @@ -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 }} diff --git a/ansible-roles/k8s_fabric_peer/files/fabric-peer/templates/pvc.yaml b/ansible-roles/k8s_fabric_peer/files/fabric-peer/templates/pvc.yaml index ddcbf4e..005c754 100644 --- a/ansible-roles/k8s_fabric_peer/files/fabric-peer/templates/pvc.yaml +++ b/ansible-roles/k8s_fabric_peer/files/fabric-peer/templates/pvc.yaml @@ -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 @@ -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 diff --git a/ansible-roles/k8s_fabric_peer/files/fabric-peer/values.yaml b/ansible-roles/k8s_fabric_peer/files/fabric-peer/values.yaml index aab95a4..e157dad 100644 --- a/ansible-roles/k8s_fabric_peer/files/fabric-peer/values.yaml +++ b/ansible-roles/k8s_fabric_peer/files/fabric-peer/values.yaml @@ -129,3 +129,5 @@ fabricSnapshotArchiver: pullPolicy: IfNotPresent version: v0.0.1 resources: {} + +local: false diff --git a/ansible-roles/k8s_fabric_peer/tasks/inner.yml b/ansible-roles/k8s_fabric_peer/tasks/inner.yml index 308c7a4..5e13a26 100644 --- a/ansible-roles/k8s_fabric_peer/tasks/inner.yml +++ b/ansible-roles/k8s_fabric_peer/tasks/inner.yml @@ -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}}" diff --git a/ansible-roles/k8s_fabric_scripts/tasks/main.yml b/ansible-roles/k8s_fabric_scripts/tasks/main.yml index 2443a60..a12dda2 100644 --- a/ansible-roles/k8s_fabric_scripts/tasks/main.yml +++ b/ansible-roles/k8s_fabric_scripts/tasks/main.yml @@ -7,6 +7,7 @@ state: directory recurse: yes tags: fabric_scripts + when: not mars_local | default(false) - name: Scripts are uploaded synchronize: @@ -18,3 +19,4 @@ group: no use_ssh_args: yes tags: fabric_scripts + when: not mars_local | default(false) diff --git a/ansible-roles/kubectl/tasks/local.yml b/ansible-roles/kubectl/tasks/local.yml new file mode 100644 index 0000000..1a0ce4e --- /dev/null +++ b/ansible-roles/kubectl/tasks/local.yml @@ -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 diff --git a/ansible-roles/kubectl/tasks/main.yml b/ansible-roles/kubectl/tasks/main.yml index 2f6431e..dbf2c1c 100644 --- a/ansible-roles/kubectl/tasks/main.yml +++ b/ansible-roles/kubectl/tasks/main.yml @@ -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) diff --git a/mars_macos.sh b/mars_macos.sh index bb9b8c4..0896019 100755 --- a/mars_macos.sh +++ b/mars_macos.sh @@ -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)" @@ -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" "$@"