Skip to content

Commit c15ae7c

Browse files
authored
Assembly Attribute Refactor (#28)
1 parent ba8b21c commit c15ae7c

File tree

6 files changed

+22
-199
lines changed

6 files changed

+22
-199
lines changed

examples/SimpleOperator/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
var builder = OperatorHost.CreateOperatorApplicationBuilder(args)
8-
.WithName("simple-operator")
8+
//.WithName("simple-operator")
99
.WithNamespace("simple-ops-system");
1010

1111
builder.AddController<TestItemController>()

examples/SimpleOperator/SimpleOperator.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Company>pmdevers</Company>
88

9+
10+
<ContainerRegistry>ghcr.io</ContainerRegistry>
11+
<ContainerRepository>pmdevers/simple-operator</ContainerRepository>
12+
<ContainerImageTag>1.0.0</ContainerImageTag>
13+
<ContainerFamily>-alpha0011</ContainerFamily>
14+
915
</PropertyGroup>
1016

1117
<ItemGroup>

examples/SimpleOperator/install.yaml

Lines changed: 0 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -1,176 +0,0 @@
1-
apiVersion: apiextensions.k8s.io/v1
2-
kind: CustomResourceDefinition
3-
metadata:
4-
name: testitems.operator.io
5-
spec:
6-
group: operator.io
7-
names:
8-
kind: TestItem
9-
listKind: TestItemList
10-
plural: testitems
11-
singular: testitem
12-
scope: Cluster
13-
versions:
14-
- name: v1alpha1
15-
schema:
16-
openAPIV3Schema:
17-
properties:
18-
status:
19-
nullable: false
20-
type: object
21-
spec:
22-
nullable: false
23-
properties:
24-
string:
25-
nullable: false
26-
type: string
27-
type: object
28-
type: object
29-
served: true
30-
storage: true
31-
---
32-
apiVersion: apiextensions.k8s.io/v1
33-
kind: CustomResourceDefinition
34-
metadata:
35-
name: projects.operator.io
36-
spec:
37-
group: operator.io
38-
names:
39-
kind: Project
40-
listKind: ProjectList
41-
plural: projects
42-
singular: project
43-
scope: Namespaced
44-
versions:
45-
- name: v1alpha1
46-
schema:
47-
openAPIV3Schema:
48-
properties:
49-
status:
50-
nullable: false
51-
properties:
52-
result:
53-
nullable: false
54-
type: string
55-
required:
56-
- result
57-
type: object
58-
spec:
59-
nullable: false
60-
properties:
61-
name:
62-
nullable: false
63-
type: string
64-
organization:
65-
nullable: false
66-
type: string
67-
project:
68-
nullable: false
69-
type: string
70-
required:
71-
- name
72-
- organization
73-
- project
74-
type: object
75-
type: object
76-
served: true
77-
storage: true
78-
---
79-
apiVersion: rbac.authorization.k8s.io/v1
80-
kind: ClusterRole
81-
metadata:
82-
name: simple-operator-role
83-
rules:
84-
- apiGroups:
85-
- ""
86-
resources:
87-
- events
88-
verbs:
89-
- get
90-
- list
91-
- create
92-
- update
93-
- apiGroups:
94-
- coordination.k8s.io
95-
resources:
96-
- leases
97-
verbs:
98-
- '*'
99-
- apiGroups:
100-
- operator.io
101-
resources:
102-
- testitems
103-
- projects
104-
verbs:
105-
- '*'
106-
- apiGroups:
107-
- operator.io
108-
resources:
109-
- testitems/status
110-
- projects/status
111-
verbs:
112-
- get
113-
- update
114-
- patch
115-
---
116-
apiVersion: rbac.authorization.k8s.io/v1
117-
kind: ClusterRoleBinding
118-
metadata:
119-
name: simple-operator-role-binding
120-
roleRef:
121-
apiGroup: rbac.authorization.k8s.io
122-
kind: ClusterRole
123-
name: simple-operator-role
124-
subjects:
125-
- kind: ServiceAccount
126-
name: default
127-
namespace: system
128-
---
129-
apiVersion: apps/v1
130-
kind: Deployment
131-
metadata:
132-
labels:
133-
operator-deployment: simple-operator
134-
name: simple-operator-deployment
135-
namespace: simple-ops-system
136-
spec:
137-
replicas: 1
138-
revisionHistoryLimit: 0
139-
selector:
140-
matchLabels:
141-
operator-deployment: simple-operator
142-
template:
143-
metadata:
144-
labels:
145-
operator-deployment: simple-operator
146-
spec:
147-
containers:
148-
- env:
149-
- name: test
150-
valueFrom:
151-
fieldRef:
152-
fieldPath: metadata.namespace
153-
image: ghcr.io/operator/operator:latest
154-
name: simple-operator
155-
resources:
156-
limits:
157-
cpu: 100m
158-
memory: 128Mi
159-
requests:
160-
cpu: 100m
161-
memory: 64Mi
162-
securityContext:
163-
allowPrivilegeEscalation: false
164-
capabilities:
165-
drop:
166-
- ALL
167-
runAsGroup: 2024
168-
runAsNonRoot: true
169-
runAsUser: 2024
170-
securityContext:
171-
runAsNonRoot: true
172-
seccompProfile:
173-
type: RuntimeDefault
174-
terminationGracePeriodSeconds: 10
175-
---
176-

src/K8sOperator.NET/Extensions/OperatorHostBuilderExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,16 @@ public static IOperatorApplicationBuilder WithNamespace(this IOperatorApplicatio
4444
/// <param name="builder">The operator application builder.</param>
4545
/// <param name="registery">The Docker registry. Defaults to "ghcr.io".</param>
4646
/// <param name="repository">The Docker repository.</param>
47-
/// <param name="name">The name of the Docker image.</param>
4847
/// <param name="tag">The tag of the Docker image.</param>
4948
/// <returns>The configured operator application builder.</returns>
5049
public static IOperatorApplicationBuilder WithImage(this IOperatorApplicationBuilder builder,
5150
string registery = "ghcr.io",
5251
string repository = "",
53-
string name = "",
5452
string tag = ""
5553
)
5654
{
5755
builder.Metadata.RemoveAll(x => x.GetType() == typeof(DockerImageAttribute));
58-
builder.Metadata.Add(new DockerImageAttribute(registery, repository, name, tag));
56+
builder.Metadata.Add(new DockerImageAttribute(registery, repository, tag));
5957
return builder;
6058
}
6159

src/K8sOperator.NET/Metadata/ImageRepositoryMetadata.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ public interface IImageMetadata
1717
/// </summary>
1818
string Repository { get; }
1919

20-
/// <summary>
21-
/// Gets the name of the Docker image.
22-
/// </summary>
23-
string Name { get; }
24-
2520
/// <summary>
2621
/// Gets the tag of the Docker image.
2722
/// </summary>
@@ -39,26 +34,23 @@ public interface IImageMetadata
3934
/// </summary>
4035
/// <param name="registery">The registry of the image.</param>
4136
/// <param name="repository">The image repository name.</param>
42-
/// <param name="imageName">The name of the image.</param>
4337
/// <param name="tag">The tag of the image.</param>
4438
[AttributeUsage(AttributeTargets.Assembly)]
45-
public class DockerImageAttribute(string registery, string repository, string imageName, string tag) : Attribute, IImageMetadata
39+
public class DockerImageAttribute(string registery, string repository, string tag) : Attribute, IImageMetadata
4640
{
4741
/// <summary>
4842
/// Default docker image
4943
/// </summary>
50-
public static DockerImageAttribute Default => new("ghcr.io", "operator", "operator", "latest");
44+
public static DockerImageAttribute Default => new("ghcr.io", "operator/operator", "latest");
5145

5246
/// <inheritdoc/>
5347
public string Registery {get;set;} = registery;
5448
/// <inheritdoc/>
5549
public string Repository { get; set; } = repository;
5650
/// <inheritdoc/>
57-
public string Name { get; set; } = imageName;
58-
/// <inheritdoc/>
5951
public string Tag { get; set; } = tag;
6052
/// <inheritdoc/>
61-
public string GetImage() => $"{Registery}/{Repository}/{Name}:{Tag}";
53+
public string GetImage() => $"{Registery}/{Repository}:{Tag}";
6254

6355

6456
/// <inheritdoc />

src/K8sOperator.NET/Operator.targets

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
<PropertyGroup>
44
<PackageVersion Condition=" '$(PackageVersion)' == '' ">1.0.0</PackageVersion>
55
<OperatorName>$(MSBuildProjectName.Replace(" ", "_").ToLower())</OperatorName>
6-
<DockerImageRegistery>ghcr.io</DockerImageRegistery>
7-
<DockerImageRepository>$(Company)</DockerImageRepository>
8-
<DockerImageName>$(OperatorName)</DockerImageName>
9-
<DockerImageTag>$(PackageVersion)</DockerImageTag>
6+
7+
<ContainerRegistry>ghcr.io</ContainerRegistry>
8+
<ContainerRepository>$(Company)/$(OperatorName)</ContainerRepository>
9+
<ContainerImageTag>$(PackageVersion)</ContainerImageTag>
10+
<ContainerFamily></ContainerFamily>
1011
</PropertyGroup>
1112
<ItemGroup>
1213
<AssemblyAttribute Include="K8sOperator.NET.Metadata.OperatorNameAttribute">
1314
<_Parameter1>$(OperatorName)</_Parameter1>
1415
</AssemblyAttribute>
16+
<AssemblyAttribute Include="K8sOperator.NET.Metadata.NamespaceAttribute">
17+
<_Parameter1>$(OperatorName)-system</_Parameter1>
18+
</AssemblyAttribute>
1519
<AssemblyAttribute Include="K8sOperator.NET.Metadata.DockerImageAttribute">
16-
<_Parameter1>$(DockerImageRegistery)</_Parameter1>
17-
<_Parameter2>$(DockerImageRepository)</_Parameter2>
18-
<_Parameter3>$(DockerImageName)</_Parameter3>
19-
<_Parameter4>$(DockerImageTag)</_Parameter4>
20+
<_Parameter1>$(ContainerRegistry)</_Parameter1>
21+
<_Parameter2>$(ContainerRepository)</_Parameter2>
22+
<_Parameter4>$(ContainerImageTag)$(ContainerFamily)</_Parameter4>
2023
</AssemblyAttribute>
2124
</ItemGroup>
2225

0 commit comments

Comments
 (0)