From 45f743646e61fb9ddda4ef60c88db07ffe4727f5 Mon Sep 17 00:00:00 2001 From: Patrick Evers Date: Wed, 18 Sep 2024 15:01:08 +0200 Subject: [PATCH] Assembly Attribute Refactor --- examples/SimpleOperator/Program.cs | 2 +- examples/SimpleOperator/SimpleOperator.csproj | 6 + examples/SimpleOperator/install.yaml | 176 ------------------ .../OperatorHostBuilderExtensions.cs | 4 +- .../Metadata/ImageRepositoryMetadata.cs | 14 +- src/K8sOperator.NET/Operator.targets | 19 +- 6 files changed, 22 insertions(+), 199 deletions(-) diff --git a/examples/SimpleOperator/Program.cs b/examples/SimpleOperator/Program.cs index 7ceb41a..a466e79 100644 --- a/examples/SimpleOperator/Program.cs +++ b/examples/SimpleOperator/Program.cs @@ -5,7 +5,7 @@ var builder = OperatorHost.CreateOperatorApplicationBuilder(args) - .WithName("simple-operator") + //.WithName("simple-operator") .WithNamespace("simple-ops-system"); builder.AddController() diff --git a/examples/SimpleOperator/SimpleOperator.csproj b/examples/SimpleOperator/SimpleOperator.csproj index 11b4925..294659d 100644 --- a/examples/SimpleOperator/SimpleOperator.csproj +++ b/examples/SimpleOperator/SimpleOperator.csproj @@ -6,6 +6,12 @@ enable pmdevers + + ghcr.io + pmdevers/simple-operator + 1.0.0 + -alpha0011 + diff --git a/examples/SimpleOperator/install.yaml b/examples/SimpleOperator/install.yaml index 587af14..e69de29 100644 --- a/examples/SimpleOperator/install.yaml +++ b/examples/SimpleOperator/install.yaml @@ -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 ---- - diff --git a/src/K8sOperator.NET/Extensions/OperatorHostBuilderExtensions.cs b/src/K8sOperator.NET/Extensions/OperatorHostBuilderExtensions.cs index de91b6e..0151951 100644 --- a/src/K8sOperator.NET/Extensions/OperatorHostBuilderExtensions.cs +++ b/src/K8sOperator.NET/Extensions/OperatorHostBuilderExtensions.cs @@ -44,18 +44,16 @@ public static IOperatorApplicationBuilder WithNamespace(this IOperatorApplicatio /// The operator application builder. /// The Docker registry. Defaults to "ghcr.io". /// The Docker repository. - /// The name of the Docker image. /// The tag of the Docker image. /// The configured operator application builder. 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; } diff --git a/src/K8sOperator.NET/Metadata/ImageRepositoryMetadata.cs b/src/K8sOperator.NET/Metadata/ImageRepositoryMetadata.cs index 8ea6d44..5eba681 100644 --- a/src/K8sOperator.NET/Metadata/ImageRepositoryMetadata.cs +++ b/src/K8sOperator.NET/Metadata/ImageRepositoryMetadata.cs @@ -17,11 +17,6 @@ public interface IImageMetadata /// string Repository { get; } - /// - /// Gets the name of the Docker image. - /// - string Name { get; } - /// /// Gets the tag of the Docker image. /// @@ -39,26 +34,23 @@ public interface IImageMetadata /// /// The registry of the image. /// The image repository name. -/// The name of the image. /// The tag of the image. [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 { /// /// Default docker image /// - public static DockerImageAttribute Default => new("ghcr.io", "operator", "operator", "latest"); + public static DockerImageAttribute Default => new("ghcr.io", "operator/operator", "latest"); /// public string Registery {get;set;} = registery; /// public string Repository { get; set; } = repository; /// - public string Name { get; set; } = imageName; - /// public string Tag { get; set; } = tag; /// - public string GetImage() => $"{Registery}/{Repository}/{Name}:{Tag}"; + public string GetImage() => $"{Registery}/{Repository}:{Tag}"; /// diff --git a/src/K8sOperator.NET/Operator.targets b/src/K8sOperator.NET/Operator.targets index 05c8b2f..815a8a1 100644 --- a/src/K8sOperator.NET/Operator.targets +++ b/src/K8sOperator.NET/Operator.targets @@ -3,20 +3,23 @@ 1.0.0 $(MSBuildProjectName.Replace(" ", "_").ToLower()) - ghcr.io - $(Company) - $(OperatorName) - $(PackageVersion) + + ghcr.io + $(Company)/$(OperatorName) + $(PackageVersion) + <_Parameter1>$(OperatorName) + + <_Parameter1>$(OperatorName)-system + - <_Parameter1>$(DockerImageRegistery) - <_Parameter2>$(DockerImageRepository) - <_Parameter3>$(DockerImageName) - <_Parameter4>$(DockerImageTag) + <_Parameter1>$(ContainerRegistry) + <_Parameter2>$(ContainerRepository) + <_Parameter4>$(ContainerImageTag)$(ContainerFamily)