question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add [IgnorePropertyAttribute] that ignores a property when generating CRDs or support TimeSpan properties

See original GitHub issue

Is your feature request related to a problem? Please describe. I’d like to add TimeSpan properties my custom resource spec and status properties. This isn’t supported out of the box:

[KubeOps.Operator.Errors.CrdConversionException]: During conversion of the property "Spec" with type "TaskSpec", an error occured. [inner:KubeOps.Operator.Errors.CrdConversionException: During conversion of the property "RetentionTime" with type "TimeSpan", an error occured.]

I was hoping to define TimeSpan properties with a type converter that converted to/from GOLANG duration format, but TimeSpan isn’t supported at all.

As a workaround, I thought I could define the CRD properties as strings and then add hidden properties that did the conversion to/from the string properties, something like:

public class MySpec
{
    public string Timeout { get; set;}

    [IgnoreProperty]
    public TimeSpan TimeoutTimeSpan
    {
        get => GoDuration.Parse(Timeout);
        set => Timeout = GoDuration.FromTimeSpan(value).ToString();
    }
}

This wouldn’t actually be too bad, but KubeOps has no [IgnoreProperty] attribute that I can see.

My next workaround is to add GetTimeout() and SetTimeout() methods (not horrible, but feels like Java).

Describe the solution you’d like

  1. Ideally, KubeOps could handle TimeSpan properties natively by parsing GOLANG style durations
  2. Add and implement an [IgnoreProperty] attribute

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jefflillcommented, Jun 17, 2022

I agree. I just re-read the API conventions and they explicitly say it’s best to encode durations as seconds or something rather than requiring that programs in other languages be able to parse golang durations.

0reactions
buehlercommented, Jun 16, 2022

While that may be true, I’d like to stick to the standard. When we diverge from the standards that are implemented in Kubernetes, every change from K8S may result in a break.

I think the Ignore and Converter attributes are the way to go.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure.Data.Tables doesn't honour IgnorePropertyAttribute
It seems that the attribute IgnorePropertyAttribute should be used to decorate the properties to ignore. However this attribute is in a ...
Read more >
IgnorePropertyAttribute Class (Microsoft.Azure.Cosmos. ...
Represents a custom attribute that can be used to ignore entity properties during serialization/de-serialization.
Read more >
Ignore property attribute · Issue #678 · Azure/azure-cosmos ...
My collection is schema-free for example, I have a string property called "visit_history" but it stores as serialized string format value ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found