Skip to content

Commit

Permalink
Cleanup, fix rbac
Browse files Browse the repository at this point in the history
  • Loading branch information
gamingrobot committed Oct 17, 2023
1 parent 165b436 commit e02ae14
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<V1alpha1Rollout> //IResourceController<V1alpha1Rollout>
[EntityRbac(typeof(V1Alpha1Rollout), Verbs = VerbConstants.ReadAndPatch), UsedImplicitly]
public class RolloutController : GenericController<V1Alpha1Rollout>
{
public RolloutController(IEventStream eventStream) : base(eventStream)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
};
Expand All @@ -109,11 +109,13 @@ private async ValueTask PatchToDesiredStateDeployment(DesiredState desiredState,
await _state.MarkAsDirty(identity);
await _patcher.Patch<V1Deployment>(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<V1alpha1Rollout>(identity.Name, identity.Namespace, o => { PatchAnnotations(desiredState, o.Spec.Template); });
await _patcher.Patch<V1Alpha1Rollout>(identity.Name, identity.Namespace, o => { PatchAnnotations(desiredState, o.Spec.Template); });
}

private async ValueTask PatchToDesiredStateDeploymentConfig(DesiredState desiredState, NamespacedResourceIdentity identity)
{
await _state.MarkAsDirty(identity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
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;

namespace Contrast.K8s.AgentOperator.Core.State.Appliers
{
[UsedImplicitly]
public class RolloutApplier : BaseApplier<V1alpha1Rollout, RolloutResource>
public class RolloutApplier : BaseApplier<V1Alpha1Rollout, RolloutResource>
{
public RolloutApplier(IStateContainer stateContainer, IMediator mediator) : base(stateContainer, mediator)
{
}

public override ValueTask<RolloutResource> CreateFrom(V1alpha1Rollout entity, CancellationToken cancellationToken = default)
public override ValueTask<RolloutResource> 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()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MetadataLabel> Labels,
PodTemplate PodTemplate,
PodSelector Selector)
: IResourceWithPodTemplate;

public record RolloutResource(string Uid,
IReadOnlyCollection<MetadataLabel> Labels,
PodTemplate PodTemplate,
PodSelector Selector)
: IResourceWithPodTemplate;
}


19 changes: 19 additions & 0 deletions src/Contrast.K8s.AgentOperator/Entities/Argo/V1Alpha1Rollout.cs
Original file line number Diff line number Diff line change
@@ -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<V1Alpha1Rollout.RolloutSpec>
{
//Drop-in replacement for Deployment (with additional fields for the rollout info)
public class RolloutSpec : V1DeploymentSpec
{
}
}

}
30 changes: 0 additions & 30 deletions src/Contrast.K8s.AgentOperator/Entities/V1Alpha1ArgoRollout.cs

This file was deleted.

0 comments on commit e02ae14

Please sign in to comment.