Conversation
| var pubPEM []byte | ||
|
|
||
| resp, code, err := utils.GetHttpContent(e.url+"/setup/signature-key?clusterId="+e.clusterID, headers) | ||
| if err != nil && code != http.StatusNotFound { |
There was a problem hiding this comment.
Can there be any other error code?
Now if err == nil and code == 404 then we are on the happy path? Is that OK also?
There was a problem hiding this comment.
The endpoint does not necessarily exist, so we have to set pubPEM only if it exists. On the other hand err should be nil only if the status is 2XX, so I think the code is correct.
| // TODO would be nice to properly stop refresh. | ||
| go func() { | ||
| for { | ||
| if err := e.client.Refresh(context.Background(), time.Minute); err != nil { |
There was a problem hiding this comment.
What do you think if you
- Make the first refresh in the
e.client.Refreshfunction do a refresh immediately when called and return an appropriate error, then start the loop running after every minute - Drop the
goandfor loophere, and check for the initial refresh error? That would allow you to just return an error fromUpdateLicenceimmediately when the first refresh happens?
Not sure if this has impact on other places, but IMVHO it's a good pattern, if a bit annyoing to code in the e.client.Refresh implementation.
There was a problem hiding this comment.
At this point we have an active connection because the connection has been established to fetch cluster id, so here what we want is to refresh the token until program ends in every minute.
There was a problem hiding this comment.
Right. But inside the Refresh method you have already an infinite loop refreshing the token. so I assumed you've added an infinite loop here because that inner infinite loop might return an error and you want to retry?
There was a problem hiding this comment.
Yes. Our future plan is to watch storageos API credentials secret, and if changes restart the pod. So here until credentials are the same we would like to push refresh until the end.
main.go
Outdated
| } | ||
| }() | ||
|
|
||
| // Periodically send licence. |
There was a problem hiding this comment.
Canceling context on sigterm would do the trick, and it's not that much to code. Assuming that we terminate on exit only? But in that case who cares? And this is just a comment, I have no problem to leave it as is if we would only terminate this goroutine on exit.
There was a problem hiding this comment.
we would only terminate this goroutine on exit and this project is still in a rapidly changing phase, so there are more important things to do.
main.go
Outdated
| currentLicence, err := stosEndpoint.GetLicence() | ||
| if err != nil { | ||
| setupLogger.Error(err, "unable to fetch licence") | ||
| return |
There was a problem hiding this comment.
| return | |
| continue |
?? At least that how it looks to me on a first glance
| } | ||
|
|
||
| // Do selects the right action and executes it. | ||
| func (as *ActionService) Do(rawAction []byte, updateState func(interface{}) error) { |
There was a problem hiding this comment.
That's an interesting way of doing things :)
| $(PROTOC_GEN_GO): | ||
| mkdir -p $(dir $(GOPATH)/src/$(PROTOBUF_PKG)) | ||
| test -d $(GOPATH)/src/$(PROTOBUF_PKG)/.git || git clone https://$(PROTOBUF_PKG) $(GOPATH)/src/$(PROTOBUF_PKG) | ||
| test -d $(GOPATH)/src/$(PROTOBUF_PKG)/.git && (cd $(GOPATH)/src/$(PROTOBUF_PKG); git fetch -a && git reset --hard $(PROTOBUF_VERSION)) || git clone --branch $(PROTOBUF_VERSION) https://$(PROTOBUF_PKG) $(GOPATH)/src/$(PROTOBUF_PKG) |
There was a problem hiding this comment.
Using gopath in 2022 is risky. It works but there are better ways. If you have github.com/golang/protobuf/protoc-gen-go in your go mod (i.e using the tools package officially sanctioned hack) there's a way to grab the path to the source code of the appropriate version using go list --something-using-obscure-template-arg.
I'd add it to the list of the tech debt items if it's not there yet, unless you want to sit down and address it now (I can help ?)
There was a problem hiding this comment.
Could you please add it 🙏
There was a problem hiding this comment.
Ugh, In another PR, sorry! I need to understand first what is really happening here, which will take some time. I've seen a pattern that looks very similar before, but if I were to fix it on my own I'd spend some time trying to understand it.
Now, I am happy to do it, but I need more spare time than I have right now. So, another PR it is.
| func (p *Publisher) PublishState(ctx context.Context, state interface{}) error { | ||
| for _, sink := range p.sinks { | ||
| if err := sink.PublishState(ctx, state); err != nil { | ||
| return errors.Wrap(err, "unable to publish state to sink") |
There was a problem hiding this comment.
Does it matter if the remaining sinks won't get the memo because one is not available? Maybe you could not return early here? Just a speculation. Please ignore if it's irrelevant.
There was a problem hiding this comment.
Good question. I don't really understand why we need multiple message brokers here. So I followed the original designers' same kind of function above. If you ask me, I suggest removing multiple brokers complexity at all, but it isn't the scope of this change.
| Registry: configResp.Registry, | ||
| Region: configResp.Region, | ||
| ServerURL: configResp.MttqURL, | ||
| SignatureKey: string(pubPEM), |
There was a problem hiding this comment.
Ugh, I am not sure about storing raw bytes in a string variable now that I think about it. I dooooont think it will cause bugs, but it looks strange. Not a blocker I think.
There was a problem hiding this comment.
At some point, we have to convert it to string. So I did the conversion as early as possible (once). But lets talk about it.
This change gives the ability to portal manager to apply for licences. It uses device status to send initial status messages about device config acceptance and current licence.