Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go.mod: Revert version bump of CEL #4587

Merged
merged 1 commit into from Feb 19, 2022
Merged

go.mod: Revert version bump of CEL #4587

merged 1 commit into from Feb 19, 2022

Conversation

francislavoie
Copy link
Member

@francislavoie francislavoie commented Feb 19, 2022

Workaround for #4331, for now

Unfortunately, bumping CEL will cause all Caddy plugins to no longer build with the latest version of Caddy, if they have an earlier version of Caddy in their go.mod.

I don't know what our long-term solution will be, so this will require more research before we can safely bump CEL to a newer version.

@francislavoie francislavoie added bug 🐞 Something isn't working CI/CD 🔩 Automated tests, releases labels Feb 19, 2022
@francislavoie francislavoie added this to the v2.5.0 milestone Feb 19, 2022
@mholt
Copy link
Member

mholt commented Feb 19, 2022

That's so weird. The new commits of CEL supposedly fixed that issue. Is it because plugins refer to older versions of Caddy?

@francislavoie
Copy link
Member Author

Yes, it's because plugins require an older version of Caddy, which requires an older version of CEL which requires the wrong version of antlr. The Go compiler complains because there's two different antlr (ambiguous) in the build and it explodes.

I don't really understand why this issue happens, it seems like a Go module problem.

But if we do bump the CEL version for v2.5.0, I don't think any plugins will build with v2.5.0 unless the plugins also update their go.mod to Caddy v2.5.0.

We'll need to do more research, get help from experts on Go modules to figure out a solution that won't cause a hard line in the sand for plugins. Because that would really, really suck.

@mholt
Copy link
Member

mholt commented Feb 19, 2022

I just saw your message in Slack. Yeah, that makes sense. This smells like MVS to me. (Minimal Version Selection).

It looks like cel-go created an invalid module after v0.7.3. I don't fully understand the behavior of the Go tooling here, but I don't know if this can ever be fixed.

I think if cel-go released a v2 of their module, this might be fixable. Plugins that still refer to old versions of Caddy will use the pre-v1 module, and Caddy will use the new /v2 module, so MVS might not apply (or is applied differently, I suspect, as /v2 is viewed as a separate module, given the addition of /v2 to the package path). This is just a hunch/hope, I don't know if this is actually true though.

I'm not sure it's a good idea to keep using a dependency we cannot upgrade. It might be best long-term to either remove the CEL functionality or create an entirely new module with a clean history (no invalid versions) and use that instead.

But in the meantime, downgrading is acceptable so we don't block the release of v2.5.

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Unfortunate, but apparently necessary. Thanks.

@mholt mholt merged commit 0de5159 into master Feb 19, 2022
@mholt mholt deleted the revert-cel-update branch February 19, 2022 22:09
@TristonianJones
Copy link
Contributor

@mholt @francislavoie At some point Antlr introduced a proper go.mod and people who were using it and the legacy directory that cel-go pointed at had issues. CEL moved to the official ANTLR go module to address the issue, but as I understand it, this is now causing problems for Caddy?

@francislavoie
Copy link
Member Author

Unfortunately, yes 😢

The problem is plugins for Caddy reference an older version of Caddy in their go.mod so both the latest and the older versions of Caddy are pulled into the build, which means both versions of CEL as well, which means both ANTLR, and that triggers a built error. 😬

I'm not sure what the solution is. I think maybe both ANTLR and CEL would need a v2 or something to unbreak it. But I realize that might be too big an ask. I'm not sure what to do.

@TristonianJones
Copy link
Contributor

TristonianJones commented Mar 9, 2022

Could you give me some more context on what's required for a v2 of the plugin? I'm happy to upgrade it if needed. I realized I missed your earlier reply to me about ways to better integrate CEL @francislavoie, so I just happened to spot this. I think there was some desire for additional functionality, so a v2 makes sense to me.

Also, we just did a ton of upgrades for cel-go v0.10.0 for Kubernetes, so it's probably a good time to bump.

@TristonianJones
Copy link
Contributor

In talking with the team, we're going to go mod vendor ANTLR into cel-go which should remove it from the dependency list and bypass any issues with conflicting modules (I hope)

@francislavoie
Copy link
Member Author

I'll be honest, I don't truly understand what considerations Go's module system makes that causes the problem, so I'm not certain what to expect as the outcome of changes to the upstream packages.

Vendoring sounds like an interesting plan though, if that would avoid the ambiguity problem.

If you need a reproduce case to help figure this out, I set up a branch https://github.com/caddyserver/caddy/compare/cel-upgrade which would let you use xcaddy to try to make a build of Caddy which includes a plugin that lists an earlier version of Caddy in its go.mod, which is where the problem was triggered.

You can run this to see the error happen:

xcaddy build cel-upgrade --with github.com/mastercactapus/caddy2-proxyprotocol

Using https://github.com/caddyserver/xcaddy which is our build tool (basically just a wrapper over go commands to make it easier to use plugins -- you can set XCADDY_SKIP_CLEANUP=1 env to inspect the temp build directory (i.e. go mod init etc) to run go build yourself if you need.

@francislavoie
Copy link
Member Author

Btw maybe we should move the discussion to #4331 which is the actual open issue for this 😅

@TristonianJones
Copy link
Contributor

@francislavoie Thanks for the pointer to the branch. I have vendoring staged locally and am curious if it addresses the upgrade issue.

@francislavoie
Copy link
Member Author

If you have a branch of cel I can put in the go.mod to try it out, I could confirm

@TristonianJones
Copy link
Contributor

@francislavoie It looks like the vendoring works out and makes the cel dependencies hermetic. I was able to successfully run the xcaddy command against my local copy of the cel-upgrade branch with the vendored cel-go being used via a go mod replace directive:

xcaddy build  --with github.com/mastercactapus/caddy2-proxyprotocol

I could be mistaken as I'm not super familiar with the xcaddy tool, so if you'd like to confirm my copy of the source with the vendored dependencies is located here: https://github.com/TristonianJones/cel-go/tree/vendor-antlr

@francislavoie
Copy link
Member Author

francislavoie commented Mar 13, 2022

I updated the cel-upgrade branch to have a replace line, but it's still giving me an error with xcaddy when building against cel-upgrade. 🤔

$ xcaddy.exe build cel-upgrade --with github.com/mastercactapus/caddy2-proxyprotocol
...
caddy imports
        github.com/caddyserver/caddy/v2/modules/standard imports
        github.com/caddyserver/caddy/v2/modules/caddyhttp/standard imports
        github.com/caddyserver/caddy/v2/modules/caddyhttp imports
        github.com/google/cel-go/cel imports
        github.com/google/cel-go/parser imports
        github.com/antlr/antlr4/runtime/Go/antlr: ambiguous import: found package github.com/antlr/antlr4/runtime/Go/antlr in multiple modules:
        github.com/antlr/antlr4 v0.0.0-20200503195918-621b933c7a7f (C:\Users\lavof\go\pkg\mod\github.com\antlr\antlr4@v0.0.0-20200503195918-621b933c7a7f\runtime\Go\antlr)
        github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210826220005-b48c857c3a0e (C:\Users\lavof\go\pkg\mod\github.com\antlr\antlr4\runtime\!go\antlr@v0.0.0-20210826220005-b48c857c3a0e)

@francislavoie
Copy link
Member Author

Oh, I think the replace might be ignored when building against a target branch, for some reason.

@francislavoie
Copy link
Member Author

Trying this doesn't work either:

$ xcaddy.exe build cel-upgrade --with github.com/mastercactapus/caddy2-proxyprotocol --with github.com/google/cel-go=github.com/TristonianJones/cel-go@vendor-antlr
...
go: finding module for package github.com/google/cel-go
caddy imports
        github.com/google/cel-go: module github.com/google/cel-go@latest found (v0.10.1, replaced by github.com/TristonianJones/cel-go@v0.0.0-20220313061635-0a41511c52b7), but does not contain package github.com/google/cel-go

@francislavoie
Copy link
Member Author

Anyways to clarify, running xcaddy build without another argument doesn't look at your current directory at all, it will try to build from the latest tagged release of Caddy instead. So what you tried built successfully cause it just built v2.4.6 basically.

@TristonianJones
Copy link
Contributor

@francislavoie looks like the error is complaining about the GitHub repo being my fork. I'll put up a PR to vendor dependencies, and will try again with a pre-release candidate once someone from my team has had a look.

@francislavoie
Copy link
Member Author

@TristonianJones are you able to make a branch on the cel-go repo? Might work better to try

@TristonianJones
Copy link
Contributor

I finally moved the commentary over to the issue, but I've noticed that we can probably solve the ANTLR upgrade path with a patch into xcaddy to do a default replacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working CI/CD 🔩 Automated tests, releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants