Skip to content

Conversation

@peterbroadhurst
Copy link
Contributor

@peterbroadhurst peterbroadhurst commented Oct 26, 2021

Adds a couple of simple jobs, with configuration options to enable them:

  • config.postgresMigrationJob: true
    • Creates a k8s Job to perform the migrations, which runs on each new FireFly tag deployed
  • config.registrationJob: true
    • Creates a k8s Job to ensure registration is performed, which runs once (unless the org name changes)

Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Copy link
Contributor

@nguyer nguyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't speak for the actual kubernetes things going on here, but everything going on inside it in terms of migrations and registration looks good to me.

- sh
- -ce
- |
# Install deps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make this a proper script in a scripts folder and then template it into this job like so (or something along these lines):

{{ (.Files.Glob "scripts/ff-db-migrations.sh") | indent 2 }}

that way when folks are editing this script they can have their editor help them w/ the shell syntax rather than dealing w/ writing shell w/in yaml

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

Copy link
Contributor Author

@peterbroadhurst peterbroadhurst Oct 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a few extra changes to get this right @hfuss - but it's there now.
Asked for a re-review if you have a min to double check.

I also found through testing that we should handle the situation where the org is registered, but the node isn't.

The common case is as follows:

  • You run the job, while the events are syncing with the chain
  • The job times and out and re-runs
  • Eventually all is caught up - the original Org registration works
  • The script ties to re-register the org, and fails - which it doesn't need to do

You should see this handled in the script now.

Copy link
Contributor

@onelapahead onelapahead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, was going to say we could use the go-migrate image but I see we're taking advantage of the fact that the sql migrations are bundled into the core FF container 👍🏻

Perhaps we could make a firefly-utility image on top of the core image that has postgres-client, jq, and go-migrate preinstalled.

@peterbroadhurst
Copy link
Contributor Author

Perhaps we could make a firefly-utility image on top of the core image that has postgres-client, jq, and go-migrate preinstalled.

Think this is a great suggestion, although I might need to leave the next step on that one with you or @nguyer

Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
@codecov-commenter
Copy link

codecov-commenter commented Oct 26, 2021

Codecov Report

Merging #294 (283b4a2) into main (ce74fe3) will not change coverage.
The diff coverage is n/a.

❗ Current head 283b4a2 differs from pull request most recent head ebc9922. Consider uploading reports for the commit ebc9922 to get more accurate results
Impacted file tree graph

@@            Coverage Diff            @@
##              main      #294   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          224       224           
  Lines        12387     12387           
=========================================
  Hits         12387     12387           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce74fe3...ebc9922. Read the comment docs.

Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Copy link
Contributor

@onelapahead onelapahead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only asking for removing the unnecessary env var and renaming the container in the registration job manifest, everything else is speculation or a suggestion.

PSQL_URL_NO_DB=`echo ${PSQL_URL} | sed "s/\/${DB_NAME}//"`

# Check we can connect to the PSQL Server
while ! psql -c "SELECT 1;" ${PSQL_URL_NO_DB}; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do until rather than while ! to avoid the negation logic. It's six or half a dozen but I always prefer to avoid negations for readability.

Unless there's no until in sh and its bashism 🤷🏻‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed until is in BusyBox

org:
name: {{ .Values.config.organizationName }}
identity: {{ .Values.config.organizationIdentity }}
key: {{ .Values.config.organizationIdentity }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename the value to match? i.e. organizationKey ?

In eth this is an address right? But for fabric its something else... a channel? And I guess the rename was to avoid confusion w/ the new identity plugin?

env:
- name: FF_URL
value: "http://{{ include "firefly.fullname" . }}:{{ .Values.core.service.httpPort }}"
- name: PSQL_URL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't believe this one is needed for this job / script

template:
spec:
containers:
- name: migration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- name: migration
- name: registration

echo "Registering organization"
HTTP_CODE=`curl --silent --output /dev/stderr --write-out "%{http_code}" \
-X POST -d '{}' -H 'Content-Type: application/json' \
"${FF_URL}/api/v1/network/organizations/self?confirm"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this API synchronous now?

I remember when we wrote the original internal registration job, mimicking what was in ff-cli, we'd poll after org registration to ensure that the org had be published before going onto the node registration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was answered by #294 (comment) but could use confirmation from @peterbroadhurst

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this API synchronous now?

Yep, with the confirm option

@@ -0,0 +1,40 @@
# Install deps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly doesn't affect the actual job from running but to make the script executable locally would ask the shebang get added.


apk add curl jq

while ! STATUS=$(curl ${FF_URL}/api/v1/status); do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here for until if you care

Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
@nguyer
Copy link
Contributor

nguyer commented Oct 28, 2021

Perhaps we could make a firefly-utility image on top of the core image that has postgres-client, jq, and go-migrate preinstalled.

Think this is a great suggestion, although I might need to leave the next step on that one with you or @nguyer

Sounds like a good idea. Scope for a different PR though?

@peterbroadhurst
Copy link
Contributor Author

Great review comments, thanks @hfuss
All addressed now.

Copy link
Contributor

@onelapahead onelapahead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for addressing all the particulars and answering my questions! :shipit:

@peterbroadhurst peterbroadhurst merged commit 638711f into hyperledger:main Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants