Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Ability to apply licence#63

Merged
mhmxs merged 16 commits intomainfrom
apply-licence
May 26, 2022
Merged

Ability to apply licence#63
mhmxs merged 16 commits intomainfrom
apply-licence

Conversation

@mhmxs
Copy link
Contributor

@mhmxs mhmxs commented Apr 13, 2022

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.

@mhmxs mhmxs marked this pull request as ready for review May 25, 2022 09:40
var pubPEM []byte

resp, code, err := utils.GetHttpContent(e.url+"/setup/signature-key?clusterId="+e.clusterID, headers)
if err != nil && code != http.StatusNotFound {
Copy link

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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 {
Copy link

Choose a reason for hiding this comment

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

What do you think if you

  1. Make the first refresh in the e.client.Refresh function do a refresh immediately when called and return an appropriate error, then start the loop running after every minute
  2. Drop the go and for loop here, and check for the initial refresh error? That would allow you to just return an error from UpdateLicence immediately 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.
Copy link

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link

Choose a reason for hiding this comment

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

Suggested change
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) {
Copy link

Choose a reason for hiding this comment

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

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)
Copy link

Choose a reason for hiding this comment

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

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 ?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you please add it 🙏

Copy link

Choose a reason for hiding this comment

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

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")
Copy link

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@mhmxs mhmxs requested a review from szank May 26, 2022 13:10
Registry: configResp.Registry,
Region: configResp.Region,
ServerURL: configResp.MttqURL,
SignatureKey: string(pubPEM),
Copy link

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@mhmxs mhmxs merged commit 825d7de into main May 26, 2022
@mhmxs mhmxs deleted the apply-licence branch May 26, 2022 14:20
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.

2 participants