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

Ensure GVK is properly detected #11

Merged
merged 3 commits into from
Oct 15, 2024
Merged

Conversation

patrickdappollonio
Copy link
Member

@patrickdappollonio patrickdappollonio commented Oct 11, 2024

Description

There's a tiny little issue in the current code: since we're unsafely generating the pluralized version (used in internal Kubernetes URLs) to apply manifests, if we get an object like kind: NetworkPolicy, we "pluralize" it for the server as "networkpolicy" + "s":

Resource: strings.ToLower(gvk.Kind) + "s",

This PR adds a REST unstructured mapper that can map specific objects by asking the Kubernetes API if it knows them.

Today we don't store any NetworkPolicy, and fortunately enough Workflow or Template pluralizes in English correctly by adding s at the end, but that might not always be the case especially if this functions makes its way to other parts of our code.

The Unit Test includes the happy path (submitting a known resource) and the unhappy path (submitting an unknown resource). The previous error was:

Error: error applying templates: error creating resource: the server could not find the requested resource

And the new error is (using the example of not finding what a NetworkPolicy is:

Error: error applying templates: error creating resource: unable to map manifest to a Kubernetes resource: no matches for kind "NetworkPolicy" in version "networking.k8s.io/v1"

(A bit more verbose but it tells you what action was happening and why it couldn't be applied).

This PR also adds a unit test to pull from the API to ensure the response stays correct, although that could've probably been done in a different PR.

Related Issue(s)

Fixes #

How to test

go test -timeout 30s -run ^Test_ApplyManifests$ -count=1 -v ./...

@douglasmakey
Copy link
Contributor

douglasmakey commented Oct 11, 2024

Approved. Just a small note: this function was a temporary solution until we defined the method for delivering the templates. It's just for templates and not for any other resource.

@patrickdappollonio patrickdappollonio changed the title Ensure GVK is properly detected. Ensure GVK is properly detected Oct 15, 2024
@patrickdappollonio patrickdappollonio merged commit 4097b6b into main Oct 15, 2024
@patrickdappollonio patrickdappollonio deleted the fix-gvk-generation branch October 15, 2024 16:42
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