Skip to content

Commit

Permalink
OperatorUser crd (#2866)
Browse files Browse the repository at this point in the history
* OperatorUser crd

* prefix crd name with 'mirrord'

* Improve field doc

* Update

* Small crd update

* operator setup fix

* Better target display

* Changelog entry

* Removed unnecessary method on KubeTarget
  • Loading branch information
Razz4780 authored Oct 23, 2024
1 parent 715e1fe commit 7cb7733
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/+operator-user-crd.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added CRD for `MirrordOperatorUser`, adjusted operator setup.
29 changes: 29 additions & 0 deletions mirrord/operator/src/crd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
fmt::{Display, Formatter},
};

use chrono::{DateTime, Utc};
use kube::{CustomResource, Resource};
use kube_target::{KubeTarget, UnknownTargetType};
pub use mirrord_config::feature::split_queues::QueueId;
Expand Down Expand Up @@ -659,3 +660,31 @@ pub struct MirrordSqsSessionSpec {
// so we save that field as a (HEX) string even though its source is a u64
pub session_id: String,
}

/// Describes an operator user.
#[derive(CustomResource, Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[kube(
group = "operator.metalbear.co",
version = "v1",
kind = "MirrordOperatorUser",
root = "MirrordOperatorUser"
)]
#[serde(rename_all = "camelCase")]
pub struct MirrordOperatorUserSpec {
/// Unique ID.
pub user_id: String,
/// Last seen local username.
pub last_username: String,
/// Last seen hostname.
pub last_hostname: String,
/// Last seen Kubernetes username.
pub last_k8s_username: String,
/// Most recent session activity.
pub last_seen: DateTime<Utc>,
/// Total session count.
pub total_sessions_count: u64,
/// Total session duration.
pub total_sessions_duration_seconds: u64,
/// Last session's target.
pub last_target: String,
}
3 changes: 2 additions & 1 deletion mirrord/operator/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use thiserror::Error;

use crate::crd::{
kafka::{MirrordKafkaClientConfig, MirrordKafkaEphemeralTopic, MirrordKafkaTopicsConsumer},
MirrordPolicy, MirrordSqsSession, MirrordWorkloadQueueRegistry, TargetCrd,
MirrordOperatorUser, MirrordPolicy, MirrordSqsSession, MirrordWorkloadQueueRegistry, TargetCrd,
};

pub static OPERATOR_NAME: &str = "mirrord-operator";
Expand Down Expand Up @@ -787,6 +787,7 @@ impl OperatorClusterUserRole {
"mirrordoperators".to_owned(),
"targets".to_owned(),
"targets/port-locks".to_owned(),
MirrordOperatorUser::plural(&()).into_owned(),
]),
verbs: vec!["get".to_owned(), "list".to_owned()],
..Default::default()
Expand Down

0 comments on commit 7cb7733

Please sign in to comment.