Hello, I’m trying to develop on the Pulumi Kubern...
# kubernetes
b
Hello, I’m trying to develop on the Pulumi Kubernetes resource provider to add two features I’d like to have in Helm Chart resource. First, I’d like to have autodiscovery of Kubernetes version and API versions. For this, I’ve modified the provider code and didn’t have to touch the SDKs. I wanted to do a release of my modified provider so that I can use it kind of transparently in my projects. I added a plugin download URL in the schema to point to the GitHub releases of my forked repository and ran make build. First issue, the newly generated sdk/go/kubernetes/helm/v3/pulumiUtilities.go file didn’t contain the right package, helm, but v3. Is there a way to override this? I then used GoReleaser to create a prerelease of my provider (after enabling prerelease publishing and removing blobs publishing in GoReleaser config). Last step, I added a replace line in the go.mod file of my test project (replace github.com/pulumi/pulumi-kubernetes/sdk/v3 v3.21.0 => github.com/yann-soubeyrand/pulumi-kubernetes/sdk/v3 v3.22.0-ys.1) and did a pulumi preview. It did not work, pulumi didn’t download my modified provider. I then force replaced the v3.21.0 tag in my repository to point to my commit and did a release again, adapting my replace line (replace github.com/pulumi/pulumi-kubernetes/sdk/v3 v3.21.0 => github.com/yann-soubeyrand/pulumi-kubernetes/sdk/v3 v3.21.0) and this time pulumi preview worked (it downloaded my plugin and the result was the expected one). I’d like to know if this is the right way to proceed (it seems not)? Second, I’d like to be able to customize the release name used during chart templating. For this, I don’t need to modify the provider since everything is already there, I just have to modify the SDKs. I’ve modified the schema and the Go templates and it seems to work as expected for Go project. But, if I understand correctly, I have to manually modify all the other SDKs, right? What about the Java SDK which doesn’t seem to have templates?
g
First issue, the newly generated sdk/go/kubernetes/helm/v3/pulumiUtilities.go file didn’t contain the right package, helm, but v3. Is there a way to override this?
I don’t quite understand your question here. There is a
pulumiUtilities.go
file at
sdk/go/kubernetes/pulumiUtilities.go
, but not at the path you indicated, so I want to make sure I understand the problem you’re seeing.
… I’d like to know if this is the right way to proceed (it seems not)?
I’ve never tried automatically downloading a plugin from an alternative URL like that since I’m normally developing locally, and already have the plugin binary on my path. That said, I wouldn’t expect you to need a replace directive in your test project. I think you’d want to use your own repo for the SDK, and then it would pull the plugin corresponding to the tag specified in your
go.mod
file. @ancient-policeman-24615 ^ Does that sound right to you?
But, if I understand correctly, I have to manually modify all the other SDKs, right? What about the Java SDK which doesn’t seem to have templates?
If you’re wanting to upstream these changes, then yes, the templates would have to be modified for each SDK. The Helm SDK isn’t currently implemented for Java. This unusual workflow is tech debt, which is tracked in this issue, so sorry for the undocumented differences on the code generation here: https://github.com/pulumi/pulumi-kubernetes/issues/1971
a
We should pick up the plugin correctly if you are using a newly generated SDK and the replace worked. I’m not sure what you mean by force replace. I think Levi is right though, you shouldn’t need the replace in the first place.
b
The tests I’ve done can be seen in this repository https://github.com/yann-soubeyrand/pulumi-kubernetes. First, I created the v3.22.0-ys.1 prerelease: https://github.com/yann-soubeyrand/pulumi-kubernetes/releases/tag/v3.22.0-ys.1. I then tried to use it in my test project with this replace in `go.mod`:
Copy code
replace <http://github.com/pulumi/pulumi-kubernetes/sdk/v3|github.com/pulumi/pulumi-kubernetes/sdk/v3> v3.21.0 => <http://github.com/yann-soubeyrand/pulumi-kubernetes/sdk/v3|github.com/yann-soubeyrand/pulumi-kubernetes/sdk/v3> v3.22.0-ys.1
My modified provider wasn’t downloaded, it kept downloading the official v3.21.0 plugin. Then, I tried to modify the plugin download URL (https://github.com/yann-soubeyrand/pulumi-kubernetes/commit/48e619d65cad33eef255e7cd7319c56c935ca486#diff-4b4c0cf2556342956[…]7b7cd8473ba51435199667) and generate a new SDK. This created a new file (https://github.com/yann-soubeyrand/pulumi-kubernetes/blob/test/sdk/go/kubernetes/helm/v3/pulumiUtilities.go) which had the wrong package name (v3 instead of helm) which I manually fixed. I created a new release: https://github.com/yann-soubeyrand/pulumi-kubernetes/releases/tag/v3.22.0-ys.2 and tried to use it in my test project with
Copy code
replace <http://github.com/pulumi/pulumi-kubernetes/sdk/v3|github.com/pulumi/pulumi-kubernetes/sdk/v3> v3.21.0 => <http://github.com/yann-soubeyrand/pulumi-kubernetes/sdk/v3|github.com/yann-soubeyrand/pulumi-kubernetes/sdk/v3> v3.22.0-ys.2
This still didn’t download my modified provider and kept using the official v3.21.0 provider. I finally force tagged a v3.21.0 version with the same commits (replacing the official v3.21.0 tag) and built a release from it: https://github.com/yann-soubeyrand/pulumi-kubernetes/releases/tag/v3.21.0. I used it in my test project with
Copy code
replace <http://github.com/pulumi/pulumi-kubernetes/sdk/v3|github.com/pulumi/pulumi-kubernetes/sdk/v3> v3.21.0 => <http://github.com/yann-soubeyrand/pulumi-kubernetes/sdk/v3|github.com/yann-soubeyrand/pulumi-kubernetes/sdk/v3> v3.21.0
and it downloaded my modified provider (I had to remove the official provider in
~/.pulumi/plugins
first). I’ll try directly pointing to my modified SDK without using a replace. However, will I be able to seemlessly switch back to the official provider (without having to recreate the resources in my stacks) if I succeed to get my PR merged?
For the SDK modifications for the second feature, I’ll try to do the modifications for all the languages in order to open a PR which has a chance to be merged, but I’m much less confident with Dotnet, Python and Typescript than Go, so maybe it’ll take me some time.
a
You should be able to seamlessly switch between your provider and the official kubernetes provider if and only if the resources they correspond to have the same URN. How you access the SDK (with or without a replace) will not effect the underlying resources.
b
OK, I had a doubt because my modified plugin download URL appears in the provider configuration in the state of my stack, but great if it’ll work seemlessly though 😉
g
For the
pulumiUtilities.go
file issue, it looks like the following code is supposed to modify the location for the Helm resources: https://github.com/pulumi/pulumi-kubernetes/blob/v3.21.0/provider/cmd/pulumi-gen-kubernetes/main.go#L343-L363 I’m guessing there might be a bug there, or perhaps you are building the SDKs differently. I normally run the following from the root directory:
make ensure build
b
Thanks for the hint, this patch fixes my issue 😉
Copy code
diff --git a/provider/cmd/pulumi-gen-kubernetes/main.go b/provider/cmd/pulumi-gen-kubernetes/main.go
index 3b4d5b10..8e66ab94 100644
--- a/provider/cmd/pulumi-gen-kubernetes/main.go
+++ b/provider/cmd/pulumi-gen-kubernetes/main.go
@@ -358,6 +358,7 @@ func writeGoClient(pkg *schema.Package, outdir string, templateDir string) {
                "kubernetes/helm/v3/pulumiTypes.go",
                "kubernetes/helm/v3/init.go",
                "kubernetes/helm/v3/release.go",
+               "kubernetes/helm/v3/pulumiUtilities.go",
        },
                "package v3",
                "package helm")
🎉 2