Skip to content

Commit 5283e39

Browse files
authored
Merge branch 'main' into feature/1065-field-selector
2 parents 320ee0b + ff0180e commit 5283e39

30 files changed

Lines changed: 685 additions & 92 deletions

docs/docs/operator/build-customization.mdx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,19 +243,17 @@ If you need to override how the CLI is invoked (for example, when installing to
243243

244244
## Using with the CRD Installer for Local Development
245245

246-
For local development, you may want to not automatically generate resources in Debug mode and have them installed in your cluster. You can combine `GenerateOperatorResources` with the [CRD Installer utility](./utilities) for this purpose.
246+
For local development, you may want to not automatically generate resources in Debug mode and have them installed in your cluster. You can combine `GenerateOperatorResources` with the [CRD Installer utility](./utilities#crd-installer-utility) for this purpose.
247247

248248
For example, in your `Program.cs`:
249249

250250
```csharp
251251
builder.Services
252252
.AddKubernetesOperator()
253253
#if DEBUG
254-
.AddCrdInstaller(c =>
255-
{
256-
c.OverwriteExisting = true;
257-
c.DeleteOnShutdown = true;
258-
})
254+
.AddCrdInstaller(c => c
255+
.WithOverwriteExisting()
256+
.WithDeleteOnShutdown())
259257
#endif
260258
.RegisterComponents();
261259
```

docs/docs/operator/utilities.mdx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The CRD Installer is a powerful utility intended **only for development environm
5353
:::
5454

5555
When developing operators, you may want to quickly install or update CustomResourceDefinitions (CRDs) in your cluster. The `CrdInstaller` service automates this process, making it easier to iterate on CRD changes during development.
56+
If the Kubernetes API server is temporarily unavailable when the operator starts, the installer logs the error and retries in the background with backoff instead of stopping the host startup.
5657

5758
### How to Add the CRD Installer
5859

@@ -62,14 +63,12 @@ To enable the CRD installer, add the following to your operator's `Program.cs`:
6263
builder.Services
6364
.AddKubernetesOperator()
6465
#if DEBUG
65-
.AddCrdInstaller(c =>
66-
{
67-
c.OverwriteExisting = true;
68-
c.DeleteOnShutdown = true;
69-
})
66+
.AddCrdInstaller(c => c
67+
.WithOverwriteExisting()
68+
.WithDeleteOnShutdown())
7069
#endif
7170
.RegisterComponents();
7271
```
7372

74-
- `OverwriteExisting`: If `true`, existing CRDs with the same name will be **overwritten**. This is useful for development but can be destructive if used in production, as it may cause data loss.
75-
- `DeleteOnShutdown`: If `true`, all CRDs installed by the operator will be **deleted** when the operator shuts down. This is extremely destructive and should only be used in disposable development environments.
73+
- `WithOverwriteExisting()`: Existing CRDs with the same name will be **overwritten**. This is useful for development but can be destructive if used in production, as it may cause data loss.
74+
- `WithDeleteOnShutdown()`: All CRDs installed by the operator will be **deleted** when the operator shuts down. This is extremely destructive and should only be used in disposable development environments.

examples/Operator/Program.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
builder.Services
1515
.AddKubernetesOperator()
1616
#if DEBUG
17-
.AddCrdInstaller(c =>
18-
{
19-
c.OverwriteExisting = true;
20-
c.DeleteOnShutdown = true;
21-
})
17+
.AddCrdInstaller(c => c
18+
.WithOverwriteExisting()
19+
.WithDeleteOnShutdown())
2220
#endif
2321
.RegisterComponents();
2422

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<PackageReference Include="Roslynator.Analyzers"
5757
Version="4.15.0"
5858
PrivateAssets="All"/>
59-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.203" PrivateAssets="All"/>
59+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.300" PrivateAssets="All"/>
6060
</ItemGroup>
6161

6262
<ItemGroup>

src/KubeOps.Abstractions/Builder/IOperatorBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ IOperatorBuilder AddFinalizer<TImplementation, TEntity>(string identifier)
9393
/// This is intended for development purposes only.
9494
/// </summary>
9595
/// <param name="configure">
96-
/// Configuration action for the <see cref="CrdInstallerSettings"/>.
96+
/// Configuration action for the <see cref="CrdInstallerSettingsBuilder"/>.
9797
/// Determines the behavior of the CRD installer, such as whether existing CRDs
9898
/// should be overwritten or deleted on shutdown.
9999
/// </param>
100100
/// <returns>The builder for chaining.</returns>
101-
IOperatorBuilder AddCrdInstaller(Action<CrdInstallerSettings>? configure = null);
101+
IOperatorBuilder AddCrdInstaller(Action<CrdInstallerSettingsBuilder>? configure = null);
102102
}

src/KubeOps.Abstractions/Crds/CrdInstallerSettings.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
namespace KubeOps.Abstractions.Crds;
66

77
/// <summary>
8-
/// Settings for the CRD installer.
8+
/// Immutable settings for the CRD installer. Created via <see cref="CrdInstallerSettingsBuilder.Build"/>.
99
/// </summary>
10-
public sealed class CrdInstallerSettings
10+
public sealed record CrdInstallerSettings
1111
{
1212
/// <summary>
1313
/// Determines whether existing CRDs should be overwritten.
1414
/// This is useful for development purposes and should be used with caution.
1515
/// It is a destructive operation that may lead to data loss.
1616
/// </summary>
17-
public bool OverwriteExisting { get; set; } = false;
17+
public required bool OverwriteExisting { get; init; }
1818

1919
/// <summary>
2020
/// Determines whether the installed CRDs should be deleted when the operator shuts down.
2121
/// This is a very destructive operation and should only be used in development environments.
2222
/// </summary>
23-
public bool DeleteOnShutdown { get; set; } = false;
23+
public required bool DeleteOnShutdown { get; init; }
2424
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace KubeOps.Abstractions.Crds;
6+
7+
/// <summary>
8+
/// Configures a <see cref="CrdInstallerSettings"/> instance.
9+
/// Set properties directly or use the fluent <c>With*</c> extension methods,
10+
/// then call <see cref="Build"/> to obtain the immutable <see cref="CrdInstallerSettings"/> record.
11+
/// </summary>
12+
public sealed class CrdInstallerSettingsBuilder
13+
{
14+
/// <summary>
15+
/// Determines whether existing CRDs should be overwritten.
16+
/// This is useful for development purposes and should be used with caution.
17+
/// It is a destructive operation that may lead to data loss.
18+
/// </summary>
19+
public bool OverwriteExisting { get; set; }
20+
21+
/// <summary>
22+
/// Determines whether the installed CRDs should be deleted when the operator shuts down.
23+
/// This is a very destructive operation and should only be used in development environments.
24+
/// </summary>
25+
public bool DeleteOnShutdown { get; set; }
26+
27+
/// <summary>
28+
/// Produces an immutable <see cref="CrdInstallerSettings"/> record from the current configuration.
29+
/// </summary>
30+
/// <returns>A fully initialised <see cref="CrdInstallerSettings"/> record.</returns>
31+
public CrdInstallerSettings Build() => new()
32+
{
33+
OverwriteExisting = OverwriteExisting,
34+
DeleteOnShutdown = DeleteOnShutdown,
35+
};
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace KubeOps.Abstractions.Crds;
6+
7+
/// <summary>
8+
/// Fluent extension methods for <see cref="CrdInstallerSettingsBuilder"/>.
9+
/// Each method sets one property and returns the same builder instance for chaining.
10+
/// </summary>
11+
public static class CrdInstallerSettingsBuilderExtensions
12+
{
13+
/// <summary>Sets whether existing CRDs should be overwritten.</summary>
14+
/// <param name="builder">The builder to configure.</param>
15+
/// <param name="value"><c>true</c> to overwrite existing CRDs; <c>false</c> otherwise.</param>
16+
/// <returns>The same <paramref name="builder"/> instance for chaining.</returns>
17+
public static CrdInstallerSettingsBuilder WithOverwriteExisting(
18+
this CrdInstallerSettingsBuilder builder,
19+
bool value = true)
20+
{
21+
builder.OverwriteExisting = value;
22+
return builder;
23+
}
24+
25+
/// <summary>Sets whether installed CRDs should be deleted when the operator shuts down.</summary>
26+
/// <param name="builder">The builder to configure.</param>
27+
/// <param name="value"><c>true</c> to delete installed CRDs on shutdown; <c>false</c> otherwise.</param>
28+
/// <returns>The same <paramref name="builder"/> instance for chaining.</returns>
29+
public static CrdInstallerSettingsBuilder WithDeleteOnShutdown(
30+
this CrdInstallerSettingsBuilder builder,
31+
bool value = true)
32+
{
33+
builder.DeleteOnShutdown = value;
34+
return builder;
35+
}
36+
}

src/KubeOps.Abstractions/KubeOps.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<ItemGroup>
1717
<PackageReference Include="JsonPatch.Net" Version="4.0.1" />
1818
<PackageReference Include="KubernetesClient" Version="19.0.2" />
19-
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.7" />
19+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.8" />
2020
<PackageReference Include="ZiggyCreatures.FusionCache" Version="2.6.0" />
2121
</ItemGroup>
2222

src/KubeOps.Cli/KubeOps.Cli.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<PrivateAssets>all</PrivateAssets>
3131
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3232
</PackageReference>
33-
<PackageReference Include="System.CommandLine" Version="2.0.7" />
33+
<PackageReference Include="System.CommandLine" Version="2.0.8" />
3434
</ItemGroup>
3535

3636
<ItemGroup>

0 commit comments

Comments
 (0)