Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Argo rollout support #140

Closed
Closed
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
21 changes: 21 additions & 0 deletions src/Contrast.K8s.AgentOperator/Controllers/RolloutController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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 Contrast.K8s.AgentOperator.Core.Kube;
using Contrast.K8s.AgentOperator.Core.State;
using Contrast.K8s.AgentOperator.Entities;
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>
{
public RolloutController(IEventStream eventStream) : base(eventStream)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Contrast.K8s.AgentOperator.Core.State.Resources;
using Contrast.K8s.AgentOperator.Core.State.Resources.Interfaces;
using Contrast.K8s.AgentOperator.Entities.OpenShift;
using Contrast.K8s.AgentOperator.Entities;
using JetBrains.Annotations;
using k8s.Models;
using MediatR;
Expand Down Expand Up @@ -84,6 +85,7 @@ private ValueTask PatchToDesiredState(DesiredState desiredState, ResourceIdentit
{
DaemonSetResource => PatchToDesiredStateDaemonSet(desiredState, identity),
StatefulSetResource => PatchToDesiredStateStatefulSet(desiredState, identity),
RolloutResource => PatchToDesiredStateRollout(desiredState, identity),
DeploymentResource => PatchToDesiredStateDeployment(desiredState, identity),
DeploymentConfigResource => PatchToDesiredStateDeploymentConfig(desiredState, identity),
_ => throw new ArgumentOutOfRangeException()
Expand All @@ -107,7 +109,11 @@ 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); });
}
private async ValueTask PatchToDesiredStateDeploymentConfig(DesiredState desiredState, NamespacedResourceIdentity identity)
{
await _state.MarkAsDirty(identity);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 System.Threading;
using System.Threading.Tasks;
using Contrast.K8s.AgentOperator.Core.Kube;
using Contrast.K8s.AgentOperator.Core.State.Resources;
using Contrast.K8s.AgentOperator.Entities;
using JetBrains.Annotations;
using k8s.Models;
using MediatR;

namespace Contrast.K8s.AgentOperator.Core.State.Appliers
{
[UsedImplicitly]
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)
{
var resource = new RolloutResource(
entity.Uid(),
entity. Metadata.GetLabels(),
entity.Spec.Template.GetPod(),
entity.Spec.Selector.ToPodSelector()
);

return ValueTask.FromResult(resource);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 System.Collections.Generic;
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;

}


30 changes: 30 additions & 0 deletions src/Contrast.K8s.AgentOperator/Entities/V1Alpha1ArgoRollout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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<V1alpha1Rollout.V1alpha1rolloutSpec>
{
public class V1alpha1rolloutSpec : V1DeploymentSpec
{
//public string Host { get; set; }
}
}

}