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

Kubernetes NamespacePatch - Removing label does not work anymore #2909

Open
Phil1972 opened this issue Mar 26, 2024 · 2 comments
Open

Kubernetes NamespacePatch - Removing label does not work anymore #2909

Phil1972 opened this issue Mar 26, 2024 · 2 comments
Labels
area/docs Improvements or additions to documentation kind/bug Some behavior is incorrect or out of spec

Comments

@Phil1972
Copy link

Phil1972 commented Mar 26, 2024

What happened?

Hi,
Using the latest kubernetes module as well as the latest azure-native.
Code that used to work does not anymore and the documentation does not seem up to date (at least for the c# version) because it crashes with an exception (System.NullReferenceException: Object reference not set to an instance of an object.).

Example

This does not work anymore (see the marking). There is a warning/error that prevents to build. To remove the warning either put a pragma directive or put a 'null!' instead but it still fails with an exception:

image

any help into resolving this would be appreciated.

Output of pulumi about

image image

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@Phil1972 Phil1972 added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Mar 26, 2024
@EronWright EronWright transferred this issue from pulumi/pulumi Mar 26, 2024
@rquitales
Copy link
Contributor

rquitales commented Apr 1, 2024

@Phil1972, I apologize for the delayed response and the inconvenience caused by the issues you've encountered with our documentation. I can confirm that these pages require updating. To clarify, we have never supported setting null or undefined objects for labels and annotations. This was an oversight on our part during the documentation drafting process.

For your specific use case, you can safely remove the { "foo", null }, line from your code. According to the documentation's explanation of and then set it to null/undefined in a subsequent step, in Pulumi programs, omitting the declaration indicates to the engine that we want to drop/delete such fields.

An updated, fully functional example would thus be as follows:

using System.Collections.Generic;
using Pulumi;
using Kubernetes = Pulumi.Kubernetes;

return await Deployment.RunAsync(() =>
{
    var uuid = "ee0d1b94-e749-4de4-ae8a-e4319a7f3ef2"; // Arbitrary UUID

    var provider = new Kubernetes.Provider("provider", new()
    {
        EnableServerSideApply = true,
    });

    var patch1 = new Kubernetes.Core.V1.NamespacePatch("patch1", new()
    {
        Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaPatchArgs
        {
            Name = "foo",
            Annotations =
            {
                { "pulumi.com/patchForce", "true" },
                { "pulumi.com/patchFieldManager", uuid },
            },
            Labels =
            {
                { "foo", "" },
            },
        },
    }, new CustomResourceOptions
    {
        Provider = provider,
    });

    var patch2 = new Kubernetes.Core.V1.NamespacePatch("patch2", new()
    {
        Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaPatchArgs
        {
            Name = "foo",
            Annotations =
            {
                { "pulumi.com/patchForce", "true" },
                { "pulumi.com/patchFieldManager", uuid },
            },
            Labels =
            {
            // Not declaring the label here will cause it to be deleted after the manager has taken control of the field.
            },
        },
    }, new CustomResourceOptions
    {
        Provider = provider,
        DependsOn = new[]
        {
            patch1,
        },
    });
});

I will keep this issue open as a tracker item for us to revise our documentation. Thanks for reporting this!

@rquitales rquitales added area/docs Improvements or additions to documentation and removed needs-triage Needs attention from the triage team labels Apr 1, 2024
@Phil1972
Copy link
Author

Phil1972 commented Apr 2, 2024

Thanks for your time on this. So there is no way to perform this in a single step I guess? Because I fear that pulumi might not like the fact that the label is already there at first. AKS puts that label automaticly on namespaces and we have to remove that label so that istio injection can work properly.

ie: is there a way to run that kubectl command directly using pulumi?

kubectl patch namespace MyNamespace --type='json' -p='[{"op": "remove", "path": "/metadata/labels/kubernetes.azure.com~1managedby"}]'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docs Improvements or additions to documentation kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

2 participants