Skip to content

Commit

Permalink
feature/nanocld: ImagePullPolicy (next-hat#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
leon3s committed Feb 23, 2024
1 parent 9c2132c commit 36291e5
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 51 deletions.
60 changes: 30 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions bin/nanocl/src/commands/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn hook_cargoes(

/// Generate a nanocl daemon client based on the api version specified in the Statefile
fn gen_client(
host: &str,
cli_conf: &CliConfig,
state_ref: &StateRef<Statefile>,
) -> IoResult<NanocldClient> {
let client = match &state_ref.data.api_version {
Expand All @@ -183,9 +183,15 @@ fn gen_client(
}
api_version if state_ref.data.api_version.starts_with('v') => {
NanocldClient::connect_to(&ConnectOpts {
url: host.into(),
url: cli_conf.host.clone(),
ssl: cli_conf
.context
.endpoints
.get("Nanocl")
.expect("Nanocl endpoint is not defined")
.ssl
.clone(),
version: Some(api_version.clone()),
..Default::default()
})
}
_ => {
Expand Down Expand Up @@ -427,10 +433,9 @@ async fn exec_state_apply(
cli_conf: &CliConfig,
opts: &StateApplyOpts,
) -> IoResult<()> {
let host = &cli_conf.host;
let format = cli_conf.user_config.display_format.clone();
let state_ref = parse_state_file(&opts.state_location, &format).await?;
let client = gen_client(host, &state_ref)?;
let client = gen_client(cli_conf, &state_ref)?;
let args = parse_build_args(&state_ref.data, opts.args.clone())?;
let state_file =
execute_template(&state_ref, &args, &client, cli_conf).await?;
Expand Down Expand Up @@ -597,10 +602,9 @@ async fn exec_state_logs(
cli_conf: &CliConfig,
opts: &StateLogsOpts,
) -> IoResult<()> {
let host = &cli_conf.host;
let format = cli_conf.user_config.display_format.clone();
let state_ref = parse_state_file(&opts.state_location, &format).await?;
let client = gen_client(host, &state_ref)?;
let client = gen_client(cli_conf, &state_ref)?;
let args = parse_build_args(&state_ref.data, opts.args.clone())?;
let state_file =
execute_template(&state_ref, &args, &client, cli_conf).await?;
Expand Down Expand Up @@ -633,10 +637,9 @@ async fn exec_state_remove(
cli_conf: &CliConfig,
opts: &StateRemoveOpts,
) -> IoResult<()> {
let host = &cli_conf.host;
let format = cli_conf.user_config.display_format.clone();
let state_ref = parse_state_file(&opts.state_location, &format).await?;
let client = gen_client(host, &state_ref)?;
let client = gen_client(cli_conf, &state_ref)?;
let args = parse_build_args(&state_ref.data, opts.args.clone())?;
let state_file =
inject_data(&state_ref, &args, &cli_conf.context, &client).await?;
Expand Down
27 changes: 27 additions & 0 deletions bin/nanocld/specs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,10 @@ components:
type: string
description: List of secrets to use as environment variables
nullable: true
ImagePullPolicy:
allOf:
- $ref: '#/components/schemas/ImagePullPolicy'
nullable: true
Container:
$ref: '#/components/schemas/Config'
Replication:
Expand Down Expand Up @@ -2108,6 +2112,10 @@ components:
type: string
description: List of secrets to use as environment variables
nullable: true
ImagePullPolicy:
allOf:
- $ref: '#/components/schemas/ImagePullPolicy'
nullable: true
Container:
$ref: '#/components/schemas/Config'
Replication:
Expand Down Expand Up @@ -2141,6 +2149,10 @@ components:
type: string
description: List of secrets to use as environment variables
nullable: true
ImagePullPolicy:
allOf:
- $ref: '#/components/schemas/ImagePullPolicy'
nullable: true
Container:
allOf:
- $ref: '#/components/schemas/Config'
Expand Down Expand Up @@ -3844,6 +3856,13 @@ components:
- $ref: '#/components/schemas/UrlRedirect'
nullable: true
additionalProperties: false
ImagePullPolicy:
type: string
description: Policy for pulling images related to process objects (job, cargo, vm)
enum:
- Never
- Always
- IfNotPresent
IndexInfo:
type: object
description: IndexInfo contains information about a registry.
Expand Down Expand Up @@ -3945,6 +3964,10 @@ components:
description: Remove the job after (x) seconds after execution
nullable: true
minimum: 0
ImagePullPolicy:
allOf:
- $ref: '#/components/schemas/ImagePullPolicy'
nullable: true
Containers:
type: array
items:
Expand Down Expand Up @@ -4014,6 +4037,10 @@ components:
description: Remove the job after (x) seconds after execution
nullable: true
minimum: 0
ImagePullPolicy:
allOf:
- $ref: '#/components/schemas/ImagePullPolicy'
nullable: true
Containers:
type: array
items:
Expand Down
5 changes: 5 additions & 0 deletions bin/nanocld/src/objects/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ impl ObjPatchByPk for CargoDb {
} else {
cargo.spec.metadata
},
image_pull_policy: if obj.spec.image_pull_policy.is_some() {
obj.spec.image_pull_policy.clone()
} else {
cargo.spec.image_pull_policy
},
};
let obj = &CargoObjPutIn {
spec,
Expand Down
1 change: 1 addition & 0 deletions bin/nanocld/src/repositories/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl JobDb {
ttl: p.ttl,
status: status.clone().try_into()?,
containers: p.containers.clone(),
image_pull_policy: p.image_pull_policy.clone(),
})
}

Expand Down
1 change: 1 addition & 0 deletions bin/nanocld/src/repositories/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ impl SpecDb {
secrets: p.secrets,
container: p.container,
replication: p.replication,
image_pull_policy: p.image_pull_policy,
};
Ok(spec)
}
Expand Down
5 changes: 4 additions & 1 deletion bin/nanocld/src/services/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ use nanocl_stubs::node::Node;
use nanocl_stubs::process::{Process, ProcessKind};
use nanocl_stubs::config::DaemonConfig;
use nanocl_stubs::secret::{Secret, SecretPartial, SecretUpdate};
use nanocl_stubs::generic::{GenericCount, GenericClause, GenericFilter};
use nanocl_stubs::generic::{
GenericCount, GenericClause, GenericFilter, ImagePullPolicy,
};
use nanocl_stubs::system::{
BinaryInfo, HostInfo, Event, EventActor, EventActorKind, EventKind,
EventCondition, NativeEventAction,
Expand Down Expand Up @@ -487,6 +489,7 @@ impl Modify for VersionModifier {
EmptyObject,
GenericClause,
GenericFilter,
ImagePullPolicy,
// Event
Event,
EventActor,
Expand Down
Loading

0 comments on commit 36291e5

Please sign in to comment.