Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/SimpleOperator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


var builder = OperatorHost.CreateOperatorApplicationBuilder(args)
.WithName("simple-operator")
//.WithName("simple-operator")
.WithNamespace("simple-ops-system");

builder.AddController<TestItemController>()
Expand Down
6 changes: 6 additions & 0 deletions examples/SimpleOperator/SimpleOperator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<ImplicitUsings>enable</ImplicitUsings>
<Company>pmdevers</Company>


<ContainerRegistry>ghcr.io</ContainerRegistry>
<ContainerRepository>pmdevers/simple-operator</ContainerRepository>
<ContainerImageTag>1.0.0</ContainerImageTag>
<ContainerFamily>-alpha0011</ContainerFamily>

</PropertyGroup>

<ItemGroup>
Expand Down
176 changes: 0 additions & 176 deletions examples/SimpleOperator/install.yaml
Original file line number Diff line number Diff line change
@@ -1,176 +0,0 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: testitems.operator.io
spec:
group: operator.io
names:
kind: TestItem
listKind: TestItemList
plural: testitems
singular: testitem
scope: Cluster
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
properties:
status:
nullable: false
type: object
spec:
nullable: false
properties:
string:
nullable: false
type: string
type: object
type: object
served: true
storage: true
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: projects.operator.io
spec:
group: operator.io
names:
kind: Project
listKind: ProjectList
plural: projects
singular: project
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
properties:
status:
nullable: false
properties:
result:
nullable: false
type: string
required:
- result
type: object
spec:
nullable: false
properties:
name:
nullable: false
type: string
organization:
nullable: false
type: string
project:
nullable: false
type: string
required:
- name
- organization
- project
type: object
type: object
served: true
storage: true
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: simple-operator-role
rules:
- apiGroups:
- ""
resources:
- events
verbs:
- get
- list
- create
- update
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- '*'
- apiGroups:
- operator.io
resources:
- testitems
- projects
verbs:
- '*'
- apiGroups:
- operator.io
resources:
- testitems/status
- projects/status
verbs:
- get
- update
- patch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: simple-operator-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: simple-operator-role
subjects:
- kind: ServiceAccount
name: default
namespace: system
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
operator-deployment: simple-operator
name: simple-operator-deployment
namespace: simple-ops-system
spec:
replicas: 1
revisionHistoryLimit: 0
selector:
matchLabels:
operator-deployment: simple-operator
template:
metadata:
labels:
operator-deployment: simple-operator
spec:
containers:
- env:
- name: test
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: ghcr.io/operator/operator:latest
name: simple-operator
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 64Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
runAsGroup: 2024
runAsNonRoot: true
runAsUser: 2024
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
terminationGracePeriodSeconds: 10
---

Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,16 @@ public static IOperatorApplicationBuilder WithNamespace(this IOperatorApplicatio
/// <param name="builder">The operator application builder.</param>
/// <param name="registery">The Docker registry. Defaults to "ghcr.io".</param>
/// <param name="repository">The Docker repository.</param>
/// <param name="name">The name of the Docker image.</param>
/// <param name="tag">The tag of the Docker image.</param>
/// <returns>The configured operator application builder.</returns>
public static IOperatorApplicationBuilder WithImage(this IOperatorApplicationBuilder builder,
string registery = "ghcr.io",
string repository = "",
string name = "",
string tag = ""
)
{
builder.Metadata.RemoveAll(x => x.GetType() == typeof(DockerImageAttribute));
builder.Metadata.Add(new DockerImageAttribute(registery, repository, name, tag));
builder.Metadata.Add(new DockerImageAttribute(registery, repository, tag));
return builder;
}

Expand Down
14 changes: 3 additions & 11 deletions src/K8sOperator.NET/Metadata/ImageRepositoryMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ public interface IImageMetadata
/// </summary>
string Repository { get; }

/// <summary>
/// Gets the name of the Docker image.
/// </summary>
string Name { get; }

/// <summary>
/// Gets the tag of the Docker image.
/// </summary>
Expand All @@ -39,26 +34,23 @@ public interface IImageMetadata
/// </summary>
/// <param name="registery">The registry of the image.</param>
/// <param name="repository">The image repository name.</param>
/// <param name="imageName">The name of the image.</param>
/// <param name="tag">The tag of the image.</param>
[AttributeUsage(AttributeTargets.Assembly)]
public class DockerImageAttribute(string registery, string repository, string imageName, string tag) : Attribute, IImageMetadata
public class DockerImageAttribute(string registery, string repository, string tag) : Attribute, IImageMetadata
{
/// <summary>
/// Default docker image
/// </summary>
public static DockerImageAttribute Default => new("ghcr.io", "operator", "operator", "latest");
public static DockerImageAttribute Default => new("ghcr.io", "operator/operator", "latest");

/// <inheritdoc/>
public string Registery {get;set;} = registery;
/// <inheritdoc/>
public string Repository { get; set; } = repository;
/// <inheritdoc/>
public string Name { get; set; } = imageName;
/// <inheritdoc/>
public string Tag { get; set; } = tag;
/// <inheritdoc/>
public string GetImage() => $"{Registery}/{Repository}/{Name}:{Tag}";
public string GetImage() => $"{Registery}/{Repository}:{Tag}";


/// <inheritdoc />
Expand Down
19 changes: 11 additions & 8 deletions src/K8sOperator.NET/Operator.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
<PropertyGroup>
<PackageVersion Condition=" '$(PackageVersion)' == '' ">1.0.0</PackageVersion>
<OperatorName>$(MSBuildProjectName.Replace(" ", "_").ToLower())</OperatorName>
<DockerImageRegistery>ghcr.io</DockerImageRegistery>
<DockerImageRepository>$(Company)</DockerImageRepository>
<DockerImageName>$(OperatorName)</DockerImageName>
<DockerImageTag>$(PackageVersion)</DockerImageTag>

<ContainerRegistry>ghcr.io</ContainerRegistry>
<ContainerRepository>$(Company)/$(OperatorName)</ContainerRepository>
<ContainerImageTag>$(PackageVersion)</ContainerImageTag>
<ContainerFamily></ContainerFamily>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="K8sOperator.NET.Metadata.OperatorNameAttribute">
<_Parameter1>$(OperatorName)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="K8sOperator.NET.Metadata.NamespaceAttribute">
<_Parameter1>$(OperatorName)-system</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="K8sOperator.NET.Metadata.DockerImageAttribute">
<_Parameter1>$(DockerImageRegistery)</_Parameter1>
<_Parameter2>$(DockerImageRepository)</_Parameter2>
<_Parameter3>$(DockerImageName)</_Parameter3>
<_Parameter4>$(DockerImageTag)</_Parameter4>
<_Parameter1>$(ContainerRegistry)</_Parameter1>
<_Parameter2>$(ContainerRepository)</_Parameter2>
<_Parameter4>$(ContainerImageTag)$(ContainerFamily)</_Parameter4>
</AssemblyAttribute>
</ItemGroup>

Expand Down