From e02ae1447dfe53ffc7e85b64604b4e5c011bcc11 Mon Sep 17 00:00:00 2001 From: Morgan Creekmore Date: Mon, 16 Oct 2023 16:26:51 -0500 Subject: [PATCH] Cleanup, fix rbac --- .../Controllers/RolloutController.cs | 8 ++--- .../Injecting/PodTemplateInjectionHandler.cs | 8 +++-- .../Core/State/Appliers/RolloutApplier.cs | 8 ++--- .../Core/State/Resources/RolloutResource.cs | 15 ++++------ .../Entities/Argo/V1Alpha1Rollout.cs | 19 ++++++++++++ .../Entities/V1Alpha1ArgoRollout.cs | 30 ------------------- 6 files changed, 36 insertions(+), 52 deletions(-) create mode 100644 src/Contrast.K8s.AgentOperator/Entities/Argo/V1Alpha1Rollout.cs delete mode 100644 src/Contrast.K8s.AgentOperator/Entities/V1Alpha1ArgoRollout.cs diff --git a/src/Contrast.K8s.AgentOperator/Controllers/RolloutController.cs b/src/Contrast.K8s.AgentOperator/Controllers/RolloutController.cs index b86e9ab5..ec39686d 100644 --- a/src/Contrast.K8s.AgentOperator/Controllers/RolloutController.cs +++ b/src/Contrast.K8s.AgentOperator/Controllers/RolloutController.cs @@ -3,16 +3,14 @@ using Contrast.K8s.AgentOperator.Core.Kube; using Contrast.K8s.AgentOperator.Core.State; -using Contrast.K8s.AgentOperator.Entities; +using Contrast.K8s.AgentOperator.Entities.Argo; using JetBrains.Annotations; -using k8s.Models; -using KubeOps.Operator.Controller; using KubeOps.Operator.Rbac; namespace Contrast.K8s.AgentOperator.Controllers { - //[EntityRbac(typeof(V1alpha1Rollout), Verbs = VerbConstants.ReadAndPatch), UsedImplicitly] - public class RolloutController : GenericController //IResourceController + [EntityRbac(typeof(V1Alpha1Rollout), Verbs = VerbConstants.ReadAndPatch), UsedImplicitly] + public class RolloutController : GenericController { public RolloutController(IEventStream eventStream) : base(eventStream) { diff --git a/src/Contrast.K8s.AgentOperator/Core/Reactions/Injecting/PodTemplateInjectionHandler.cs b/src/Contrast.K8s.AgentOperator/Core/Reactions/Injecting/PodTemplateInjectionHandler.cs index 9ea3f49e..465bdbb4 100644 --- a/src/Contrast.K8s.AgentOperator/Core/Reactions/Injecting/PodTemplateInjectionHandler.cs +++ b/src/Contrast.K8s.AgentOperator/Core/Reactions/Injecting/PodTemplateInjectionHandler.cs @@ -10,8 +10,8 @@ using Contrast.K8s.AgentOperator.Core.State; using Contrast.K8s.AgentOperator.Core.State.Resources; using Contrast.K8s.AgentOperator.Core.State.Resources.Interfaces; +using Contrast.K8s.AgentOperator.Entities.Argo; using Contrast.K8s.AgentOperator.Entities.OpenShift; -using Contrast.K8s.AgentOperator.Entities; using JetBrains.Annotations; using k8s.Models; using MediatR; @@ -85,8 +85,8 @@ private ValueTask PatchToDesiredState(DesiredState desiredState, ResourceIdentit { DaemonSetResource => PatchToDesiredStateDaemonSet(desiredState, identity), StatefulSetResource => PatchToDesiredStateStatefulSet(desiredState, identity), - RolloutResource => PatchToDesiredStateRollout(desiredState, identity), DeploymentResource => PatchToDesiredStateDeployment(desiredState, identity), + RolloutResource => PatchToDesiredStateRollout(desiredState, identity), DeploymentConfigResource => PatchToDesiredStateDeploymentConfig(desiredState, identity), _ => throw new ArgumentOutOfRangeException() }; @@ -109,11 +109,13 @@ private async ValueTask PatchToDesiredStateDeployment(DesiredState desiredState, await _state.MarkAsDirty(identity); await _patcher.Patch(identity.Name, identity.Namespace, o => { PatchAnnotations(desiredState, o.Spec.Template); }); } + private async ValueTask PatchToDesiredStateRollout(DesiredState desiredState, NamespacedResourceIdentity identity) { await _state.MarkAsDirty(identity); - await _patcher.Patch(identity.Name, identity.Namespace, o => { PatchAnnotations(desiredState, o.Spec.Template); }); + await _patcher.Patch(identity.Name, identity.Namespace, o => { PatchAnnotations(desiredState, o.Spec.Template); }); } + private async ValueTask PatchToDesiredStateDeploymentConfig(DesiredState desiredState, NamespacedResourceIdentity identity) { await _state.MarkAsDirty(identity); diff --git a/src/Contrast.K8s.AgentOperator/Core/State/Appliers/RolloutApplier.cs b/src/Contrast.K8s.AgentOperator/Core/State/Appliers/RolloutApplier.cs index b8e3260b..341f0568 100644 --- a/src/Contrast.K8s.AgentOperator/Core/State/Appliers/RolloutApplier.cs +++ b/src/Contrast.K8s.AgentOperator/Core/State/Appliers/RolloutApplier.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Contrast.K8s.AgentOperator.Core.Kube; using Contrast.K8s.AgentOperator.Core.State.Resources; -using Contrast.K8s.AgentOperator.Entities; +using Contrast.K8s.AgentOperator.Entities.Argo; using JetBrains.Annotations; using k8s.Models; using MediatR; @@ -13,17 +13,17 @@ namespace Contrast.K8s.AgentOperator.Core.State.Appliers { [UsedImplicitly] - public class RolloutApplier : BaseApplier + public class RolloutApplier : BaseApplier { public RolloutApplier(IStateContainer stateContainer, IMediator mediator) : base(stateContainer, mediator) { } - public override ValueTask CreateFrom(V1alpha1Rollout entity, CancellationToken cancellationToken = default) + public override ValueTask CreateFrom(V1Alpha1Rollout entity, CancellationToken cancellationToken = default) { var resource = new RolloutResource( entity.Uid(), - entity. Metadata.GetLabels(), + entity.Metadata.GetLabels(), entity.Spec.Template.GetPod(), entity.Spec.Selector.ToPodSelector() ); diff --git a/src/Contrast.K8s.AgentOperator/Core/State/Resources/RolloutResource.cs b/src/Contrast.K8s.AgentOperator/Core/State/Resources/RolloutResource.cs index c2f1f6ca..acf6ca03 100644 --- a/src/Contrast.K8s.AgentOperator/Core/State/Resources/RolloutResource.cs +++ b/src/Contrast.K8s.AgentOperator/Core/State/Resources/RolloutResource.cs @@ -5,16 +5,11 @@ using Contrast.K8s.AgentOperator.Core.State.Resources.Interfaces; using Contrast.K8s.AgentOperator.Core.State.Resources.Primitives; - namespace Contrast.K8s.AgentOperator.Core.State.Resources { - - public record RolloutResource(string Uid, - IReadOnlyCollection Labels, - PodTemplate PodTemplate, - PodSelector Selector) - : IResourceWithPodTemplate; - + public record RolloutResource(string Uid, + IReadOnlyCollection Labels, + PodTemplate PodTemplate, + PodSelector Selector) + : IResourceWithPodTemplate; } - - diff --git a/src/Contrast.K8s.AgentOperator/Entities/Argo/V1Alpha1Rollout.cs b/src/Contrast.K8s.AgentOperator/Entities/Argo/V1Alpha1Rollout.cs new file mode 100644 index 00000000..f86f48eb --- /dev/null +++ b/src/Contrast.K8s.AgentOperator/Entities/Argo/V1Alpha1Rollout.cs @@ -0,0 +1,19 @@ +// Contrast Security, Inc licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. + +using JetBrains.Annotations; +using k8s.Models; +using KubeOps.Operator.Entities; + +namespace Contrast.K8s.AgentOperator.Entities.Argo +{ + [KubernetesEntity(Group = "argoproj.io", ApiVersion = "v1alpha1", Kind = "Rollout", PluralName = "rollouts"), UsedImplicitly] + public class V1Alpha1Rollout : CustomKubernetesEntity + { + //Drop-in replacement for Deployment (with additional fields for the rollout info) + public class RolloutSpec : V1DeploymentSpec + { + } + } + +} diff --git a/src/Contrast.K8s.AgentOperator/Entities/V1Alpha1ArgoRollout.cs b/src/Contrast.K8s.AgentOperator/Entities/V1Alpha1ArgoRollout.cs deleted file mode 100644 index 4cff62b2..00000000 --- a/src/Contrast.K8s.AgentOperator/Entities/V1Alpha1ArgoRollout.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Contrast Security, Inc licenses this file to you under the Apache 2.0 License. -// See the LICENSE file in the project root for more information. - -using k8s.Models; -using k8s; -using System.Collections.Generic; -using System.Text.Json.Serialization; -using KubeOps.Operator.Entities.Annotations; -using KubeOps.Operator.Entities; -using Contrast.K8s.AgentOperator.Core.Kube; -using JetBrains.Annotations; -using KubeOps.Operator.Rbac; - -namespace Contrast.K8s.AgentOperator.Entities -{ - - - - [IgnoreEntity] - [EntityRbac(typeof(V1alpha1Rollout), Verbs = VerbConstants.ReadAndPatch), UsedImplicitly] - [KubernetesEntity(Group = "argoproj.io", ApiVersion = "v1alpha1", Kind = "Rollout", PluralName = "rollouts")] - public class V1alpha1Rollout : CustomKubernetesEntity - { - public class V1alpha1rolloutSpec : V1DeploymentSpec - { - //public string Host { get; set; } - } - } - -}