Skip to content

Commit

Permalink
chore: upgrade src to c#12
Browse files Browse the repository at this point in the history
This closes #659.
  • Loading branch information
buehler committed Jan 17, 2024
1 parent b507125 commit 684d1d3
Show file tree
Hide file tree
Showing 44 changed files with 174 additions and 468 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ end_of_line = crlf
insert_final_newline = true

#### Custom Analyzer Rules ####
# Until https://github.com/SonarSource/sonar-dotnet/issues/7624 is shipped.
dotnet_diagnostic.S3604.severity = none

dotnet_diagnostic.SA0001.severity = none
dotnet_diagnostic.SA1600.severity = none
Expand Down
25 changes: 7 additions & 18 deletions examples/Operator/Controller/V1TestEntityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,23 @@
namespace Operator.Controller;

[EntityRbac(typeof(V1TestEntity), Verbs = RbacVerb.All)]
public class V1TestEntityController : IEntityController<V1TestEntity>
{
private readonly ILogger<V1TestEntityController> _logger;
private readonly EntityRequeue<V1TestEntity> _requeue;
private readonly EventPublisher _eventPublisher;

public V1TestEntityController(
ILogger<V1TestEntityController> logger,
public class V1TestEntityController(ILogger<V1TestEntityController> logger,
EntityRequeue<V1TestEntity> requeue,
EventPublisher eventPublisher)
{
_logger = logger;
_requeue = requeue;
_eventPublisher = eventPublisher;
}

: IEntityController<V1TestEntity>
{
public async Task ReconcileAsync(V1TestEntity entity)
{
_logger.LogInformation("Reconciling entity {Entity}.", entity);
logger.LogInformation("Reconciling entity {Entity}.", entity);

await _eventPublisher(entity, "RECONCILED", "Entity was reconciled.");
await eventPublisher(entity, "RECONCILED", "Entity was reconciled.");

_requeue(entity, TimeSpan.FromSeconds(5));
requeue(entity, TimeSpan.FromSeconds(5));
}

public Task DeletedAsync(V1TestEntity entity)
{
_logger.LogInformation("Deleting entity {Entity}.", entity);
logger.LogInformation("Deleting entity {Entity}.", entity);
return Task.CompletedTask;
}
}
14 changes: 3 additions & 11 deletions examples/WebhookOperator/Controller/V1TestEntityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,17 @@
namespace WebhookOperator.Controller;

[EntityRbac(typeof(V1TestEntity), Verbs = RbacVerb.All)]
public class V1TestEntityController : IEntityController<V1TestEntity>
public class V1TestEntityController(ILogger<V1TestEntityController> logger) : IEntityController<V1TestEntity>
{
private readonly ILogger<V1TestEntityController> _logger;

public V1TestEntityController(
ILogger<V1TestEntityController> logger)
{
_logger = logger;
}

public Task ReconcileAsync(V1TestEntity entity)
{
_logger.LogInformation("Reconciling entity {Entity}.", entity);
logger.LogInformation("Reconciling entity {Entity}.", entity);
return Task.CompletedTask;
}

public Task DeletedAsync(V1TestEntity entity)
{
_logger.LogInformation("Deleted entity {Entity}.", entity);
logger.LogInformation("Deleted entity {Entity}.", entity);
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
/// Defines a property as an additional printer column.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class AdditionalPrinterColumnAttribute : Attribute
public class AdditionalPrinterColumnAttribute(PrinterColumnPriority priority = default, string? name = null)
: Attribute
{
public AdditionalPrinterColumnAttribute(PrinterColumnPriority priority = default, string? name = null)
{
Name = name;
Priority = priority;
}

/// <summary>
/// The name of the column. Defaults to the property-name.
/// </summary>
public string? Name { get; }
public string? Name => name;

/// <summary>
/// The priority of the additional printer column.
Expand All @@ -31,5 +26,5 @@ public AdditionalPrinterColumnAttribute(PrinterColumnPriority priority = default
/// </item>
/// </list>
/// </summary>
public PrinterColumnPriority Priority { get; }
public PrinterColumnPriority Priority => priority;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
/// XML documentation file.
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class)]
public class DescriptionAttribute : Attribute
public class DescriptionAttribute(string description) : Attribute
{
public DescriptionAttribute(string description) => Description = description;

/// <summary>
/// The given description for the property.
/// </summary>
public string Description { get; }
public string Description => description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ namespace KubeOps.Abstractions.Entities.Attributes;
/// This implicitly sets the <see cref="PreserveUnknownFieldsAttribute"/>.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class EmbeddedResourceAttribute : Attribute
{
}
public class EmbeddedResourceAttribute : Attribute;
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
namespace KubeOps.Abstractions.Entities.Attributes;

[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class EntityScopeAttribute : Attribute
public class EntityScopeAttribute(EntityScope scope = default) : Attribute
{
public EntityScopeAttribute(EntityScope scope = default)
{
Scope = scope;
}

public EntityScope Scope { get; }
public EntityScope Scope => scope;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@
/// Defines that the property has an external documentation.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class ExternalDocsAttribute : Attribute
public class ExternalDocsAttribute(string url, string? description = null) : Attribute
{
public ExternalDocsAttribute(string url, string? description = null)
{
Description = description;
Url = url;
}

/// <summary>
/// Additional description.
/// </summary>
public string? Description { get; }
public string? Description => description;

/// <summary>
/// Url where to find the documentation.
/// </summary>
public string Url { get; }
public string Url => url;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
/// ignored during CRD generation.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property)]
public class IgnoreAttribute : Attribute
{
}
public class IgnoreAttribute : Attribute;
28 changes: 11 additions & 17 deletions src/KubeOps.Abstractions/Entities/Attributes/ItemsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,23 @@
/// Define minimum and maximum items count for an array property.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class ItemsAttribute : Attribute
public class ItemsAttribute(long minItems = -1, long maxItems = -1) : Attribute
{
public ItemsAttribute(long minItems = -1, long maxItems = -1)
{
MinItems = minItems switch
{
-1 => null,
_ => minItems,
};
MaxItems = maxItems switch
{
-1 => null,
_ => maxItems,
};
}

/// <summary>
/// Defines the minimal item count for the property.
/// </summary>
public long? MinItems { get; }
public long? MinItems => minItems switch
{
-1 => null,
_ => minItems,
};

/// <summary>
/// Defines the maximal item count for the property.
/// </summary>
public long? MaxItems { get; }
public long? MaxItems => maxItems switch
{
-1 => null,
_ => maxItems,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
/// Define "shortNames" for CRDs.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class KubernetesEntityShortNamesAttribute : Attribute
public class KubernetesEntityShortNamesAttribute(params string[] shortNames) : Attribute
{
public KubernetesEntityShortNamesAttribute(params string[] shortNames)
{
ShortNames = shortNames;
}

/// <summary>
/// Array of shortnames that should be attached to CRDs.
/// </summary>
public string[] ShortNames { get; }
public string[] ShortNames => shortNames;
}
28 changes: 11 additions & 17 deletions src/KubeOps.Abstractions/Entities/Attributes/LengthAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,23 @@
/// Defines length limits for properties.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class LengthAttribute : Attribute
public class LengthAttribute(long minLength = -1, long maxLength = -1) : Attribute
{
public LengthAttribute(long minLength = -1, long maxLength = -1)
{
MinLength = minLength switch
{
-1 => null,
_ => minLength,
};
MaxLength = maxLength switch
{
-1 => null,
_ => maxLength,
};
}

/// <summary>
/// Define the minimum length.
/// </summary>
public long? MinLength { get; }
public long? MinLength => minLength switch
{
-1 => null,
_ => minLength,
};

/// <summary>
/// Define the maximum length.
/// </summary>
public long? MaxLength { get; }
public long? MaxLength => maxLength switch
{
-1 => null,
_ => maxLength,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
/// Defines the factor that a numeric value must adhere to.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class MultipleOfAttribute : Attribute
public class MultipleOfAttribute(double value) : Attribute
{
public MultipleOfAttribute(double value)
{
Value = value;
}

/// <summary>
/// The property should be a multiple of this value.
/// </summary>
public double Value { get; }
public double Value => value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
/// Define a regex validator for the property.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class PatternAttribute : Attribute
public class PatternAttribute(string regexPattern) : Attribute
{
public PatternAttribute(string regexPattern)
{
RegexPattern = regexPattern;
}

/// <summary>
/// The regex pattern to be used.
/// </summary>
public string RegexPattern { get; }
public string RegexPattern => regexPattern;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
/// so that kubernetes does not purge additional structures.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class PreserveUnknownFieldsAttribute : Attribute
{
}
public class PreserveUnknownFieldsAttribute : Attribute;
12 changes: 3 additions & 9 deletions src/KubeOps.Abstractions/Entities/Attributes/RangeMaximum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@
/// Defines a range maximum for a numeric property.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class RangeMaximumAttribute : Attribute
public class RangeMaximumAttribute(double maximum, bool exclusiveMaximum = false) : Attribute
{
public RangeMaximumAttribute(double maximum, bool exclusiveMaximum = false)
{
Maximum = maximum;
ExclusiveMaximum = exclusiveMaximum;
}

/// <summary>
/// Maximum value to be set.
/// </summary>
public double Maximum { get; }
public double Maximum => maximum;

/// <summary>
/// Defines if the maximum value is included or excluded.
/// </summary>
public bool ExclusiveMaximum { get; }
public bool ExclusiveMaximum => exclusiveMaximum;
}
12 changes: 3 additions & 9 deletions src/KubeOps.Abstractions/Entities/Attributes/RangeMinimum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@
/// Defines a range minimum for a numeric property.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class RangeMinimumAttribute : Attribute
public class RangeMinimumAttribute(double minimum, bool exclusiveMinimum = false) : Attribute
{
public RangeMinimumAttribute(double minimum, bool exclusiveMinimum = false)
{
Minimum = minimum;
ExclusiveMinimum = exclusiveMinimum;
}

/// <summary>
/// Minimum value to be set.
/// </summary>
public double Minimum { get; }
public double Minimum => minimum;

/// <summary>
/// Defines if the minimum value is included or excluded.
/// </summary>
public bool ExclusiveMinimum { get; }
public bool ExclusiveMinimum => exclusiveMinimum;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@
/// Defines a property of a specification as required.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class RequiredAttribute : Attribute
{
}
public class RequiredAttribute : Attribute;
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
/// GA > Beta > Alpha > non versions.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class StorageVersionAttribute : Attribute
{
}
public class StorageVersionAttribute : Attribute;
Loading

0 comments on commit 684d1d3

Please sign in to comment.