Skip to content

Commit

Permalink
fix: cluster ServicePort without name
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaBosak233 committed Jan 27, 2025
1 parent fc3ce10 commit dc13f7b
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 16 deletions.
23 changes: 23 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]

[target.aarch64-unknown-linux-gnu]
rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]

[target.x86_64-unknown-linux-musl]
rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]

[target.aarch64-unknown-linux-musl]
rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]

[target.x86_64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[target.aarch64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[target.x86_64-pc-windows-gnu]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]
17 changes: 9 additions & 8 deletions crates/cluster/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ pub async fn create(
let metadata = ObjectMeta {
name: Some(name.clone()),
labels: Some(BTreeMap::from([
(String::from("cds/app"), String::from("challenges")),
(String::from("cds/resource_id"), name.clone()),
("cds/app".to_owned(), "challenges".to_owned()),
("cds/resource_id".to_owned(), name.clone()),
])),
..Default::default()
};
Expand All @@ -102,7 +102,7 @@ pub async fn create(
.collect();

env_vars.push(EnvVar {
name: injected_flag.env.unwrap_or("FLAG".to_string()),
name: injected_flag.env.unwrap_or("FLAG".to_owned()),
value: Some(injected_flag.value),
..Default::default()
});
Expand All @@ -112,7 +112,7 @@ pub async fn create(
.iter()
.map(|port| ContainerPort {
container_port: *port,
protocol: Some("TCP".to_string()),
protocol: Some("TCP".to_owned()),
..Default::default()
})
.collect();
Expand All @@ -125,7 +125,7 @@ pub async fn create(
image: Some(env.image),
env: Some(env_vars),
ports: Some(container_ports),
image_pull_policy: Some(String::from("IfNotPresent")),
image_pull_policy: Some("IfNotPresent".to_owned()),
resources: Some(ResourceRequirements {
requests: Some(
[("cpu", "10m".to_owned()), ("memory", "32Mi".to_owned())]
Expand Down Expand Up @@ -180,9 +180,10 @@ pub async fn create(
.ports
.iter()
.map(|port| ServicePort {
name: Some(port.to_string()),
port: *port,
target_port: None,
protocol: Some("TCP".to_string()),
protocol: Some("TCP".to_owned()),
..Default::default()
})
.collect();
Expand All @@ -191,11 +192,11 @@ pub async fn create(
metadata: metadata.clone(),
spec: Some(ServiceSpec {
selector: Some(BTreeMap::from([(
String::from("cds/resource_id"),
"cds/resource_id".to_owned(),
name.clone(),
)])),
ports: Some(service_ports),
type_: Some("NodePort".to_string()),
type_: Some("NodePort".to_owned()),
..Default::default()
}),
..Default::default()
Expand Down
1 change: 1 addition & 0 deletions crates/db/src/entity/challenge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: uuid::Uuid,
pub title: String,
#[sea_orm(column_type = "Text")]
pub description: Option<String>,
pub category: i32,
pub tags: Vec<String>,
Expand Down
2 changes: 2 additions & 0 deletions crates/db/src/entity/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
pub title: String,
#[sea_orm(column_type = "Text")]
pub sketch: Option<String>,
#[sea_orm(column_type = "Text")]
pub description: Option<String>,
pub is_enabled: bool,
pub is_public: bool,
Expand Down
6 changes: 2 additions & 4 deletions crates/db/src/entity/submission.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use async_trait::async_trait;
use sea_orm::{Set, entity::prelude::*};
use sea_orm::{DeriveActiveEnum, EnumIter, Set, entity::prelude::*};
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};

use super::{challenge, game, team, user};

Expand All @@ -24,9 +25,6 @@ pub struct Model {
pub rank: i64,
}

use sea_orm::{DeriveActiveEnum, EnumIter};
use serde_repr::{Deserialize_repr, Serialize_repr};

#[derive(
Clone,
Debug,
Expand Down
2 changes: 2 additions & 0 deletions crates/db/src/entity/team.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ pub struct Model {
pub id: i64,
pub name: String,
pub email: Option<String>,
#[sea_orm(column_type = "Text")]
pub slogan: Option<String>,
#[sea_orm(column_type = "Text")]
pub description: Option<String>,
pub invite_token: Option<String>,
#[sea_orm(default_value = false)]
Expand Down
1 change: 1 addition & 0 deletions crates/db/src/entity/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Model {
pub nickname: String,
#[sea_orm(unique)]
pub email: String,
#[sea_orm(column_type = "Text")]
pub description: Option<String>,
pub group: Group,
pub hashed_password: String,
Expand Down
1 change: 1 addition & 0 deletions crates/db/src/transfer/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct User {
pub email: String,
pub group: Group,
pub description: Option<String>,
#[serde(skip_serializing)]
pub hashed_password: String,
pub deleted_at: Option<i64>,
pub created_at: i64,
Expand Down
2 changes: 1 addition & 1 deletion crates/web/src/router/api/pod/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct GetRequest {

pub async fn get(
Extension(ext): Extension<Ext>, Query(params): Query<GetRequest>,
) -> Result<WebResponse<Vec<cds_db::transfer::Pod>>, WebError> {
) -> Result<WebResponse<Vec<Pod>>, WebError> {
let operator = ext.operator.ok_or(WebError::Unauthorized(json!("")))?;

let (mut pods, total) = cds_db::transfer::pod::find(
Expand Down
10 changes: 7 additions & 3 deletions crates/web/src/router/api/team/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ use axum::{
response::IntoResponse,
};
use cds_db::{entity::user::Group, get_db};
use sea_orm::{ActiveModelTrait, ActiveValue::{NotSet, Set}, ColumnTrait, EntityTrait, IntoActiveModel, PaginatorTrait, QueryFilter, QuerySelect};
use sea_orm::ActiveValue::Unchanged;
use sea_orm::{
ActiveModelTrait,
ActiveValue::{NotSet, Set, Unchanged},
ColumnTrait, EntityTrait, IntoActiveModel, PaginatorTrait, QueryFilter, QuerySelect,
};
use serde::{Deserialize, Serialize};
use serde_json::json;
use validator::Validate;
Expand Down Expand Up @@ -445,7 +448,8 @@ pub async fn quit(
if cds_db::entity::user_team::Entity::find()
.filter(cds_db::entity::user_team::Column::TeamId.eq(team.id))
.count(get_db())
.await? == 1
.await?
== 1
{
return Err(WebError::BadRequest(json!("delete_instead_of_leave")));
}
Expand Down

0 comments on commit dc13f7b

Please sign in to comment.